/*******************************************************************************
* kindeditor - wysiwyg html editor for internet
* copyright (c) 2006-2013 kindsoft.net
*
* @author roddy
* @website http://www.kindsoft.net/
* @licence http://www.kindsoft.net/license.php
* @version 4.1.5 (2013-01-20)
*******************************************************************************/
(function (window, undefined) {
if (window.kindeditor) {
return;
}
if (!window.console) {
window.console = {};
}
if (!console.log) {
console.log = function () {};
}
var _version = '4.1.5 (2013-01-20)',
_ua = navigator.useragent.tolowercase(),
_ie = _ua.indexof('msie') > -1 && _ua.indexof('opera') == -1,
_gecko = _ua.indexof('gecko') > -1 && _ua.indexof('khtml') == -1,
_webkit = _ua.indexof('applewebkit') > -1,
_opera = _ua.indexof('opera') > -1,
_mobile = _ua.indexof('mobile') > -1,
_ios = /ipad|iphone|ipod/.test(_ua),
_quirks = document.compatmode != 'css1compat',
_matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
_v = _matches ? _matches[1] : '0',
_time = new date().gettime();
function _isarray(val) {
if (!val) {
return false;
}
return object.prototype.tostring.call(val) === '[object array]';
}
function _isfunction(val) {
if (!val) {
return false;
}
return object.prototype.tostring.call(val) === '[object function]';
}
function _inarray(val, arr) {
for (var i = 0, len = arr.length; i < len; i++) {
if (val === arr[i]) {
return i;
}
}
return -1;
}
function _each(obj, fn) {
if (_isarray(obj)) {
for (var i = 0, len = obj.length; i < len; i++) {
if (fn.call(obj[i], i, obj[i]) === false) {
break;
}
}
} else {
for (var key in obj) {
if (obj.hasownproperty(key)) {
if (fn.call(obj[key], key, obj[key]) === false) {
break;
}
}
}
}
}
function _trim(str) {
return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
}
function _instring(val, str, delimiter) {
delimiter = delimiter === undefined ? ',' : delimiter;
return (delimiter + str + delimiter).indexof(delimiter + val + delimiter) >= 0;
}
function _addunit(val, unit) {
unit = unit || 'px';
return val && /^\d+$/.test(val) ? val + unit : val;
}
function _removeunit(val) {
var match;
return val && (match = /(\d+)/.exec(val)) ? parseint(match[1], 10) : 0;
}
function _escape(val) {
return val.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}
function _unescape(val) {
return val.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&');
}
function _tocamel(str) {
var arr = str.split('-');
str = '';
_each(arr, function(key, val) {
str += (key > 0) ? val.charat(0).touppercase() + val.substr(1) : val;
});
return str;
}
function _tohex(val) {
function hex(d) {
var s = parseint(d, 10).tostring(16).touppercase();
return s.length > 1 ? s : '0' + s;
}
return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
function($0, $1, $2, $3) {
return '#' + hex($1) + hex($2) + hex($3);
}
);
}
function _tomap(val, delimiter) {
delimiter = delimiter === undefined ? ',' : delimiter;
var map = {}, arr = _isarray(val) ? val : val.split(delimiter), match;
_each(arr, function(key, val) {
if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
for (var i = parseint(match[1], 10); i <= parseint(match[2], 10); i++) {
map[i.tostring()] = true;
}
} else {
map[val] = true;
}
});
return map;
}
function _toarray(obj, offset) {
return array.prototype.slice.call(obj, offset || 0);
}
function _undef(val, defaultval) {
return val === undefined ? defaultval : val;
}
function _invalidurl(url) {
return !url || /[<>"]/.test(url);
}
function _addparam(url, param) {
return url.indexof('?') >= 0 ? url + '&' + param : url + '?' + param;
}
function _extend(child, parent, proto) {
if (!proto) {
proto = parent;
parent = null;
}
var childproto;
if (parent) {
var fn = function () {};
fn.prototype = parent.prototype;
childproto = new fn();
_each(proto, function(key, val) {
childproto[key] = val;
});
} else {
childproto = proto;
}
childproto.constructor = child;
child.prototype = childproto;
child.parent = parent ? parent.prototype : null;
}
function _json(text) {
var match;
if ((match = /\{[\s\s]*\}|\[[\s\s]*\]/.exec(text))) {
text = match[0];
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
cx.lastindex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' + ('0000' + a.charcodeat(0).tostring(16)).slice(-4);
});
}
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fa-f]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
return eval('(' + text + ')');
}
throw 'json parse error';
}
var _round = math.round;
var k = {
debug : false,
version : _version,
ie : _ie,
gecko : _gecko,
webkit : _webkit,
opera : _opera,
v : _v,
time : _time,
each : _each,
isarray : _isarray,
isfunction : _isfunction,
inarray : _inarray,
instring : _instring,
trim : _trim,
addunit : _addunit,
removeunit : _removeunit,
escape : _escape,
unescape : _unescape,
tocamel : _tocamel,
tohex : _tohex,
tomap : _tomap,
toarray : _toarray,
undef : _undef,
invalidurl : _invalidurl,
addparam : _addparam,
extend : _extend,
json : _json
};
var _inline_tag_map = _tomap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
_block_tag_map = _tomap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
_single_tag_map = _tomap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
_style_tag_map = _tomap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
_control_tag_map = _tomap('img,table,input,textarea,button'),
_pre_tag_map = _tomap('pre,style,script'),
_nosplit_tag_map = _tomap('html,head,body,td,tr,table,ol,ul,li'),
_autoclose_tag_map = _tomap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
_fill_attr_map = _tomap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
_value_tag_map = _tomap('input,button,textarea,select');
function _getbasepath() {
var els = document.getelementsbytagname('script'), src;
for (var i = 0, len = els.length; i < len; i++) {
src = els[i].src || '';
if (/kindeditor[\w\-\.]*\.js/.test(src)) {
return src.substring(0, src.lastindexof('/') + 1);
}
}
return '';
}
k.basepath = _getbasepath();
k.options = {
designmode : true,
fullscreenmode : false,
filtermode : true,
wellformatmode : true,
shadowmode : true,
loadstylemode : true,
basepath : k.basepath,
themespath : k.basepath + 'themes/',
langpath : k.basepath + 'lang/',
pluginspath : k.basepath + 'plugins/',
themetype : 'default',
langtype : 'zh_cn',
urltype : '',
newlinetag : 'p',
resizetype : 2,
synctype : 'form',
pastetype : 2,
dialogaligntype : 'page',
usecontextmenu : true,
fullscreenshortcut : false,
bodyclass : 'ke-content',
indentchar : '\t',
csspath : '',
cssdata : '',
minwidth : 650,
minheight : 100,
minchangesize : 50,
zindex : 811213,
items : [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],
nodisableitems : ['source', 'fullscreen'],
colortable : [
['#e53333', '#e56600', '#ff9900', '#64451d', '#dfc5a4', '#ffe500'],
['#009900', '#006600', '#99bb00', '#b8d100', '#60d978', '#00d5ff'],
['#337fe5', '#003399', '#4c33e5', '#9933e5', '#cc33e5', '#ee33ee'],
['#ffffff', '#cccccc', '#999999', '#666666', '#333333', '#000000']
],
fontsizetable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
htmltags : {
font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
span : [
'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
'.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
],
div : [
'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
'.background-color', '.font-size', '.font-family', '.font-weight', '.background',
'.font-style', '.text-decoration', '.vertical-align', '.margin-left'
],
table: [
'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
'.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
'.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
'.width', '.height', '.border-collapse'
],
'td,th': [
'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
'.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
'.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
],
a : ['id', 'class', 'href', 'target', 'name'],
embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
'.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
],
pre : ['id', 'class'],
hr : ['id', 'class', '.page-break-after'],
'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
},
layout : ''
};
var _usecapture = false;
var _input_key_map = _tomap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
var _cursormove_key_map = _tomap('33..40');
var _change_key_map = {};
_each(_input_key_map, function(key, val) {
_change_key_map[key] = val;
});
_each(_cursormove_key_map, function(key, val) {
_change_key_map[key] = val;
});
function _bindevent(el, type, fn) {
if (el.addeventlistener){
el.addeventlistener(type, fn, _usecapture);
} else if (el.attachevent){
el.attachevent('on' + type, fn);
}
}
function _unbindevent(el, type, fn) {
if (el.removeeventlistener){
el.removeeventlistener(type, fn, _usecapture);
} else if (el.detachevent){
el.detachevent('on' + type, fn);
}
}
var _event_props = ('altkey,attrchange,attrname,bubbles,button,cancelable,charcode,clientx,clienty,ctrlkey,currenttarget,' +
'data,detail,eventphase,fromelement,handler,keycode,metakey,newvalue,offsetx,offsety,originaltarget,pagex,' +
'pagey,prevvalue,relatednode,relatedtarget,screenx,screeny,shiftkey,srcelement,target,toelement,view,wheeldelta,which').split(',');
function kevent(el, event) {
this.init(el, event);
}
_extend(kevent, {
init : function(el, event) {
var self = this, doc = el.ownerdocument || el.document || el;
self.event = event;
_each(_event_props, function(key, val) {
self[val] = event[val];
});
if (!self.target) {
self.target = self.srcelement || doc;
}
if (self.target.nodetype === 3) {
self.target = self.target.parentnode;
}
if (!self.relatedtarget && self.fromelement) {
self.relatedtarget = self.fromelement === self.target ? self.toelement : self.fromelement;
}
if (self.pagex == null && self.clientx != null) {
var d = doc.documentelement, body = doc.body;
self.pagex = self.clientx + (d && d.scrollleft || body && body.scrollleft || 0) - (d && d.clientleft || body && body.clientleft || 0);
self.pagey = self.clienty + (d && d.scrolltop || body && body.scrolltop || 0) - (d && d.clienttop || body && body.clienttop || 0);
}
if (!self.which && ((self.charcode || self.charcode === 0) ? self.charcode : self.keycode)) {
self.which = self.charcode || self.keycode;
}
if (!self.metakey && self.ctrlkey) {
self.metakey = self.ctrlkey;
}
if (!self.which && self.button !== undefined) {
self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
}
switch (self.which) {
case 186 :
self.which = 59;
break;
case 187 :
case 107 :
case 43 :
self.which = 61;
break;
case 189 :
case 45 :
self.which = 109;
break;
case 42 :
self.which = 106;
break;
case 47 :
self.which = 111;
break;
case 78 :
self.which = 110;
break;
}
if (self.which >= 96 && self.which <= 105) {
self.which -= 48;
}
},
preventdefault : function() {
var ev = this.event;
if (ev.preventdefault) {
ev.preventdefault();
}
ev.returnvalue = false;
},
stoppropagation : function() {
var ev = this.event;
if (ev.stoppropagation) {
ev.stoppropagation();
}
ev.cancelbubble = true;
},
stop : function() {
this.preventdefault();
this.stoppropagation();
}
});
var _eventexpendo = 'kindeditor_' + _time, _eventid = 0, _eventdata = {};
function _getid(el) {
return el[_eventexpendo] || null;
}
function _setid(el) {
el[_eventexpendo] = ++_eventid;
return _eventid;
}
function _removeid(el) {
try {
delete el[_eventexpendo];
} catch(e) {
if (el.removeattribute) {
el.removeattribute(_eventexpendo);
}
}
}
function _bind(el, type, fn) {
if (type.indexof(',') >= 0) {
_each(type.split(','), function() {
_bind(el, this, fn);
});
return;
}
var id = _getid(el);
if (!id) {
id = _setid(el);
}
if (_eventdata[id] === undefined) {
_eventdata[id] = {};
}
var events = _eventdata[id][type];
if (events && events.length > 0) {
_unbindevent(el, type, events[0]);
} else {
_eventdata[id][type] = [];
_eventdata[id].el = el;
}
events = _eventdata[id][type];
if (events.length === 0) {
events[0] = function(e) {
var kevent = e ? new kevent(el, e) : undefined;
_each(events, function(i, event) {
if (i > 0 && event) {
event.call(el, kevent);
}
});
};
}
if (_inarray(fn, events) < 0) {
events.push(fn);
}
_bindevent(el, type, events[0]);
}
function _unbind(el, type, fn) {
if (type && type.indexof(',') >= 0) {
_each(type.split(','), function() {
_unbind(el, this, fn);
});
return;
}
var id = _getid(el);
if (!id) {
return;
}
if (type === undefined) {
if (id in _eventdata) {
_each(_eventdata[id], function(key, events) {
if (key != 'el' && events.length > 0) {
_unbindevent(el, key, events[0]);
}
});
delete _eventdata[id];
_removeid(el);
}
return;
}
if (!_eventdata[id]) {
return;
}
var events = _eventdata[id][type];
if (events && events.length > 0) {
if (fn === undefined) {
_unbindevent(el, type, events[0]);
delete _eventdata[id][type];
} else {
_each(events, function(i, event) {
if (i > 0 && event === fn) {
events.splice(i, 1);
}
});
if (events.length == 1) {
_unbindevent(el, type, events[0]);
delete _eventdata[id][type];
}
}
var count = 0;
_each(_eventdata[id], function() {
count++;
});
if (count < 2) {
delete _eventdata[id];
_removeid(el);
}
}
}
function _fire(el, type) {
if (type.indexof(',') >= 0) {
_each(type.split(','), function() {
_fire(el, this);
});
return;
}
var id = _getid(el);
if (!id) {
return;
}
var events = _eventdata[id][type];
if (_eventdata[id] && events && events.length > 0) {
events[0]();
}
}
function _ctrl(el, key, fn) {
var self = this;
key = /^\d{2,}$/.test(key) ? key : key.touppercase().charcodeat(0);
_bind(el, 'keydown', function(e) {
if (e.ctrlkey && e.which == key && !e.shiftkey && !e.altkey) {
fn.call(el);
e.stop();
}
});
}
function _ready(fn) {
var loaded = false;
function readyfunc() {
if (!loaded) {
loaded = true;
fn(kindeditor);
}
}
function iereadyfunc() {
if (!loaded) {
try {
document.documentelement.doscroll('left');
} catch(e) {
settimeout(iereadyfunc, 100);
return;
}
readyfunc();
}
}
function iereadystatefunc() {
if (document.readystate === 'complete') {
readyfunc();
}
}
if (document.addeventlistener) {
_bind(document, 'domcontentloaded', readyfunc);
} else if (document.attachevent) {
_bind(document, 'readystatechange', iereadystatefunc);
var toplevel = false;
try {
toplevel = window.frameelement == null;
} catch(e) {}
if (document.documentelement.doscroll && toplevel) {
iereadyfunc();
}
}
_bind(window, 'load', readyfunc);
}
if (_ie) {
window.attachevent('onunload', function() {
_each(_eventdata, function(key, events) {
if (events.el) {
_unbind(events.el);
}
});
});
}
k.ctrl = _ctrl;
k.ready = _ready;
function _getcsslist(css) {
var list = {},
reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
match;
while ((match = reg.exec(css))) {
var key = _trim(match[1].tolowercase()),
val = _trim(_tohex(match[2]));
list[key] = val;
}
return list;
}
function _getattrlist(tag) {
var list = {},
reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
match;
while ((match = reg.exec(tag))) {
var key = (match[1] || match[2] || match[4] || match[6]).tolowercase(),
val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
list[key] = val;
}
return list;
}
function _addclasstotag(tag, classname) {
if (/\s+class\s*=/.test(tag)) {
tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
if ((' ' + $2 + ' ').indexof(' ' + classname + ' ') < 0) {
return $2 === '' ? $1 + classname + $3 : $1 + $2 + ' ' + classname + $3;
} else {
return $0;
}
});
} else {
tag = tag.substr(0, tag.length - 1) + ' class="' + classname + '">';
}
return tag;
}
function _formatcss(css) {
var str = '';
_each(_getcsslist(css), function(key, val) {
str += key + ':' + val + ';';
});
return str;
}
function _formaturl(url, mode, host, pathname) {
mode = _undef(mode, '').tolowercase();
if (url.substr(0, 5) != 'data:') {
url = url.replace(/([^:])\/\//g, '$1/');
}
if (_inarray(mode, ['absolute', 'relative', 'domain']) < 0) {
return url;
}
host = host || location.protocol + '//' + location.host;
if (pathname === undefined) {
var m = location.pathname.match(/^(\/.*)\//);
pathname = m ? m[1] : '';
}
var match;
if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
if (match[1] !== host) {
return url;
}
} else if (/^\w+:/.test(url)) {
return url;
}
function getrealpath(path) {
var parts = path.split('/'), paths = [];
for (var i = 0, len = parts.length; i < len; i++) {
var part = parts[i];
if (part == '..') {
if (paths.length > 0) {
paths.pop();
}
} else if (part !== '' && part != '.') {
paths.push(part);
}
}
return '/' + paths.join('/');
}
if (/^\//.test(url)) {
url = host + getrealpath(url.substr(1));
} else if (!/^\w+:\/\//.test(url)) {
url = host + getrealpath(pathname + '/' + url);
}
function getrelativepath(path, depth) {
if (url.substr(0, path.length) === path) {
var arr = [];
for (var i = 0; i < depth; i++) {
arr.push('..');
}
var prefix = '.';
if (arr.length > 0) {
prefix += '/' + arr.join('/');
}
if (pathname == '/') {
prefix += '/';
}
return prefix + url.substr(path.length);
} else {
if ((match = /^(.*)\//.exec(path))) {
return getrelativepath(match[1], ++depth);
}
}
}
if (mode === 'relative') {
url = getrelativepath(host + pathname, 0).substr(2);
} else if (mode === 'absolute') {
if (url.substr(0, host.length) === host) {
url = url.substr(host.length);
}
}
return url;
}
function _formathtml(html, htmltags, urltype, wellformatted, indentchar) {
urltype = urltype || '';
wellformatted = _undef(wellformatted, false);
indentchar = _undef(indentchar, '\t');
var fontsizelist = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\s]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
});
html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '
');
html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1
$2');
html = html.replace(/\u200b/g, '');
html = html.replace(/\u00a9/g, '©');
var htmltagmap = {};
if (htmltags) {
_each(htmltags, function(key, val) {
var arr = key.split(',');
for (var i = 0, len = arr.length; i < len; i++) {
htmltagmap[arr[i]] = _tomap(val);
}
});
if (!htmltagmap.script) {
html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\s]*?)(<\/script>)/ig, '');
}
if (!htmltagmap.style) {
html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\s]*?)(<\/style>)/ig, '');
}
}
var re = /([ \t\n\r]*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>([ \t\n\r]*)/g;
var tagstack = [];
html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
var full = $0,
startnewline = $1 || '',
startslash = $2 || '',
tagname = $3.tolowercase(),
attr = $4 || '',
endslash = $5 ? ' ' + $5 : '',
endnewline = $6 || '';
if (htmltags && !htmltagmap[tagname]) {
return '';
}
if (endslash === '' && _single_tag_map[tagname]) {
endslash = ' /';
}
if (_inline_tag_map[tagname]) {
if (startnewline) {
startnewline = ' ';
}
if (endnewline) {
endnewline = ' ';
}
}
if (_pre_tag_map[tagname]) {
if (startslash) {
endnewline = '\n';
} else {
startnewline = '\n';
}
}
if (wellformatted && tagname == 'br') {
endnewline = '\n';
}
if (_block_tag_map[tagname] && !_pre_tag_map[tagname]) {
if (wellformatted) {
if (startslash && tagstack.length > 0 && tagstack[tagstack.length - 1] === tagname) {
tagstack.pop();
} else {
tagstack.push(tagname);
}
startnewline = '\n';
endnewline = '\n';
for (var i = 0, len = startslash ? tagstack.length : tagstack.length - 1; i < len; i++) {
startnewline += indentchar;
if (!startslash) {
endnewline += indentchar;
}
}
if (endslash) {
tagstack.pop();
} else if (!startslash) {
endnewline += indentchar;
}
} else {
startnewline = endnewline = '';
}
}
if (attr !== '') {
var attrmap = _getattrlist(full);
if (tagname === 'font') {
var fontstylemap = {}, fontstyle = '';
_each(attrmap, function(key, val) {
if (key === 'color') {
fontstylemap.color = val;
delete attrmap[key];
}
if (key === 'size') {
fontstylemap['font-size'] = fontsizelist[parseint(val, 10) - 1] || '';
delete attrmap[key];
}
if (key === 'face') {
fontstylemap['font-family'] = val;
delete attrmap[key];
}
if (key === 'style') {
fontstyle = val;
}
});
if (fontstyle && !/;$/.test(fontstyle)) {
fontstyle += ';';
}
_each(fontstylemap, function(key, val) {
if (val === '') {
return;
}
if (/\s/.test(val)) {
val = "'" + val + "'";
}
fontstyle += key + ':' + val + ';';
});
attrmap.style = fontstyle;
}
_each(attrmap, function(key, val) {
if (_fill_attr_map[key]) {
attrmap[key] = key;
}
if (_inarray(key, ['src', 'href']) >= 0) {
attrmap[key] = _formaturl(val, urltype);
}
if (htmltags && key !== 'style' && !htmltagmap[tagname]['*'] && !htmltagmap[tagname][key] ||
tagname === 'body' && key === 'contenteditable' ||
/^kindeditor_\d+$/.test(key)) {
delete attrmap[key];
}
if (key === 'style' && val !== '') {
var stylemap = _getcsslist(val);
_each(stylemap, function(k, v) {
if (htmltags && !htmltagmap[tagname].style && !htmltagmap[tagname]['.' + k]) {
delete stylemap[k];
}
});
var style = '';
_each(stylemap, function(k, v) {
style += k + ':' + v + ';';
});
attrmap.style = style;
}
});
attr = '';
_each(attrmap, function(key, val) {
if (key === 'style' && val === '') {
return;
}
val = val.replace(/"/g, '"');
attr += ' ' + key + '="' + val + '"';
});
}
if (tagname === 'font') {
tagname = 'span';
}
return startnewline + '<' + startslash + tagname + attr + endslash + '>' + endnewline;
});
html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\s]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
return $1 + $2.replace(/\n/g, '\n') + $3;
});
html = html.replace(/\n\s*\n/g, '\n');
html = html.replace(/\n/g, '\n');
return _trim(html);
}
function _clearmsword(html, htmltags) {
html = html.replace(//ig, '')
.replace(//ig, '')
.replace(/'
];
if (!_isarray(csspath)) {
csspath = [csspath];
}
_each(csspath, function(i, path) {
if (path) {
arr.push('');
}
});
if (cssdata) {
arr.push('');
}
arr.push('