1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
|
TinyMCE_Engine.prototype.extractCodeBlocks = function(code, codeBlocks, decode, brTolineBreaks, switchView) {
var codeBlockCount = 0;
var sourceCodeRegex = new RegExp("(\\[" + tinyMCE.codeRegex + "=?[^\\]]*(.|\\n)*?\\[\\/\\2\\])");
while (code.match(sourceCodeRegex)) {
var uniqueString = Math.random().toString().substr(2) + "_codeblock_" + codeBlockCount;
var codeBlock = RegExp.$1;
// Handles tabs (WYSIWYG to code view)
if (decode) {
// IE inserts one space for a tab
if (tinyMCE.isIE && !tinyMCE.isOpera) {
codeBlock = codeBlock.replace(/\s/g, '\t');
}
// Firefox inserts 3 spaces for one tab (i.e. from clipboard)
else if (tinyMCE.isGecko) {
codeBlock = codeBlock.replace(/ /g, '\t');
}
}
// No image tag for smileys in code but just the smiley code
for (var smileyCode in smilies) {
// Build smiley regex but dont get smiley codes in alt attribute
var smileyRegex = new RegExp('<img\\s[^>]*?alt="'+smileyCode.pregQuote()+'"[^>]*?>', 'gi');
codeBlock = codeBlock.replace(smileyRegex, smileyCode);
}
// Generates entities before removing HTML code (code view to WYSIWYG not if content is loaded)
if (!decode && switchView) {
codeBlock = tinyMCE.encodeHTMLEntities(codeBlock);
}
// Keeps line breaks (submit -> WYSIWYG to code view)
if (brTolineBreaks) {
codeBlock = codeBlock.replace(/<br[^>]*>/gi, '\n');
}
// Encodes entities (WYSIWYG to code view)
if (decode) {
// Removes HTML in code blocks. only entities will remain. (html which was inserted in WYSIWYG mode).
codeBlock = codeBlock.replace(/<[^>]+>/g, '');
codeBlock = tinyMCE.decodeHTMLEntities(codeBlock);
}
// Stores code blocks in array
codeBlocks[uniqueString] = codeBlock;
code = code.replace(sourceCodeRegex, uniqueString);
codeBlockCount++;
}
return code;
}
|