- 时间:2021-12-10 19:23 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:分离出Discuz! 5.0发帖时使用的编辑器与大家分享!
下载: 代码如下:
' + text + '
';
codecount++;
return "[\tWEB_CODE_" + pcodecount + "\t]";
}
function parsestyle(tagoptions, appendtags) {
var searchlist = [
['align', true, 'text-align:\\s*(left|center|right);?', 1],
['color', true, '^(?:\\s|)color:\\s*([^;]+);?', 1],
['font', true, 'font-family:\\s*([^;]+);?', 1],
['size', true, 'font-size:\\s*(\\d+(px|pt|in|cm|mm|pc|em|ex|%|));?', 1],
['b', false, 'font-weight:\\s*(bold);?'],
['i', false, 'font-style:\\s*(italic);?'],
['u', false, 'text-decoration:\\s*(underline);?']
];
var style = getoptionvalue('style', tagoptions);
re = /^(?:\s|)color:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)(;?)/ig;
style = style.replace(re, function($1, $2, $3, $4, $5) {return("color:#" + parseInt($2).toString(16) + parseInt($3).toString(16) + parseInt($4).toString(16) + $5);});
var len = searchlist.length;
for(var i = 0; i < len; i++) {
re = new RegExp(searchlist[i][2], "ig");
match = re.exec(style);
if(match != null) {
opnvalue = match[searchlist[i][3]];
prepend += '[' + searchlist[i][0] + (searchlist[i][1] == true ? '=' + opnvalue + ']' : ']');
append = '[/' + searchlist[i][0] + ']' + appendtags;
}
}
}
function parsetable(width, str) {
if(typeof width == 'undefined') {
var width = '';
} else {
width = width.substr(width.length - 1, width.length) == '%' ? (width.substr(0, width.length - 1) <= 98 ? width : '98%') : (width <= 560 ? width : '98%');
}
var string = '<table '
+ (width == '' ? '' : 'width="' + width + '" ')
+ 'align="center" class="t_table">';
str = str.replace(/\[td=(\d{1,2}),(\d{1,2})(,(\d{1,3}%?))?\]/ig, '<td colspan="$1" rowspan="$2" width="$4">');
str = str.replace(/\[tr\]/ig, '<tr>');
str = str.replace(/\[td\]/ig, '<td>');
str = str.replace(/\[\/td\]/ig, '</td>');
str = str.replace(/\[\/tr\]/ig, '</tr>');
string += str;
string += '</table>';
return string;
}
function recursion(tagname, text, dofunction, extraargs) {
if(extraargs == null) {
extraargs = '';
}
tagname = tagname.toLowerCase();
var open_tag = '<' + tagname;
var open_tag_len = open_tag.length;
var close_tag = '</' + tagname + '>';
var close_tag_len = close_tag.length;
var beginsearchpos = 0;
do {
var textlower = text.toLowerCase();
var tagbegin = textlower.indexOf(open_tag, beginsearchpos);
if(tagbegin == -1) {
break;
}
var strlen = text.length;
var inquote = '';
var found = false;
var tagnameend = false;
var optionend = 0;
var t_char = '';
for(optionend = tagbegin; optionend <= strlen; optionend++) {
t_char = text.charAt(optionend);
if((t_char == '"' || t_char == "'") && inquote == '') {
inquote = t_char;
} else if((t_char == '"' || t_char == "'") && inquote == t_char) {
inquote = '';
} else if(t_char == '>' && !inquote) {
found = true;
break;
} else if((t_char == '=' || t_char == ' ') && !tagnameend) {
tagnameend = optionend;
}
}
if(!found) {
break;
}
if(!tagnameend) {
tagnameend = optionend;
}
var offset = optionend - (tagbegin + open_tag_len);
var tagoptions = text.substr(tagbegin + open_tag_len, offset)
var acttagname = textlower.substr(tagbegin * 1 + 1, tagnameend - tagbegin - 1);
if(acttagname != tagname) {
beginsearchpos = optionend;
continue;
}
var tagend = textlower.indexOf(close_tag, optionend);
if(tagend == -1) {
break;
}
var nestedopenpos = textlower.indexOf(open_tag, optionend);
while(nestedopenpos != -1 && tagend != -1) {
if(nestedopenpos > tagend) {
break;
}
tagend = textlower.indexOf(close_tag, tagend + close_tag_len);
nestedopenpos = textlower.indexOf(open_tag, nestedopenpos + open_tag_len);
}
if(tagend == -1) {
beginsearchpos = optionend;
continue;
}
var localbegin = optionend + 1;
var localtext = eval(dofunction)(tagoptions, text.substr(localbegin, tagend - localbegin), tagname, extraargs);
text = text.substring(0, tagbegin) + localtext + text.substring(tagend + close_tag_len);
beginsearchpos = tagbegin + localtext.length;
} while(tagbegin != -1);
return text;
}
function simpletag(options, text, tagname, parseto) {
if(trim(text) == '') {
return '';
}
text = recursion(tagname, text, 'simpletag', parseto);
return '[' + parseto + ']' + text + '[/' + parseto + ']';
}
function strpos(haystack, needle, offset) {
if(typeof offset == 'undefined') {
offset = 0;
}
index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
return index == -1 ? false : index;
}
function tabletag(attributes) {
var width = '';
re = /width=(["']?)(\d{1,3}%?)(\1)/ig;
var matches = re.exec(attributes);
if(matches != null && matches.length) {
width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?
(matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :
(matches[2] <= 560 ? matches[2] : '98%');
} else {
re = /width\s?:\s?(\d{1,3})([px|%])/ig;
var matches = re.exec(attributes);
if(matches != null && matches.length) {
width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%');
}
}
return width == '' ? '[table]' : '[table=' + width + ']';
}
function tdtag(attributes) {
var colspan = 1;
var rowspan = 1;
var width = '';
re = /colspan=(["']?)(\d{1,2})(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
colspan = matches[2];
}
re = /rowspan=(["']?)(\d{1,2})(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
rowspan = matches[2];
}
re = /width=(["']?)(\d{1,3}%?)(\1)/ig;
var matches = re.exec(attributes);
if(matches != null) {
width = matches[2];
}
return in_array(width, ['', '0', '100%']) ?
(colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') :
'[td=' + colspan + ',' + rowspan + ',' + width + ']';
}
function trim(str) {
return (str.replace(/(\s+)$/g, '')).replace(/^\s+/g, '');
}
[/code]