📄 kupucontentfilters.js
字号:
this.Flow = ['#PCDATA','form'].concat(this.block, this.inline); }(this); this._commonsetting = function(self, names, value) { for (var n = 0; n < names.length; n++) { self[names[n]] = value; } } // The tagAttributes class returns all valid attributes for a tag, // e.g. a = this.tagAttributes.head // a.head -> [ 'lang', 'xml:lang', 'dir', 'id', 'profile' ] this.tagAttributes = new function(el, validation) { this.title = el.i18n.concat('id'); this.html = this.title.concat('xmlns'); this.head = this.title.concat('profile'); this.base = ['id', 'href', 'target']; this.meta = this.title.concat('http-equiv','name','content', 'scheme'); this.link = el.attrs.concat('charset','href','hreflang','type', 'rel','rev','media','target'); this.style = this.title.concat('type','media','title', 'xml:space'); this.script = ['id','charset','type','language','src','defer', 'xml:space']; this.iframe = [ 'longdesc','name','src','frameborder','marginwidth', 'marginheight','scrolling','align','height','width'].concat(el.coreattrs); this.body = ['background','bgcolor','text','link','vlink','alink'].concat(el.attrs, el.loadevents); validation._commonsetting(this, ['p','div'].concat(el.heading), ['align'].concat(el.attrs)); this.dl = this.dir = this.menu = el.attrs.concat('compact'); this.ul = this.menu.concat('type'); this.ol = this.ul.concat('start'); this.li = el.attrs.concat('type','value'); this.hr = el.attrs.concat('align','noshade','size','width'); this.pre = el.attrs.concat('width','xml:space'); this.blockquote = this.q = el.attrs.concat('cite'); this.ins = this.del = this.blockquote.concat('datetime'); this.a = el.attrs.concat(el.focus,'charset','type','name','href','hreflang','rel','rev','shape','coords','target'); this.bdo = el.coreattrs.concat(el.events, 'lang','xml:lang','dir'); this.br = el.coreattrs.concat('clear'); validation._commonsetting(this, ['noscript','noframes','dt', 'dd', 'address','center','span','em', 'strong', 'dfn','code', 'samp','kbd','var','cite','abbr','acronym','sub','sup','tt', 'i','b','big','small','u','s','strike', 'fieldset'], el.attrs); this.basefont = ['id','size','color','face']; this.font = el.coreattrs.concat(el.i18n, 'size','color','face'); this.object = el.attrs.concat('declare','classid','codebase','data','type','codetype','archive','standby','height','width','usemap','name','tabindex','align','border','hspace','vspace'); this.param = ['id','name','value','valuetype','type']; this.applet = el.coreattrs.concat('codebase','archive','code','object','alt','name','width','height','align','hspace','vspace'); this.img = el.attrs.concat('src','alt','name','longdesc','height','width','usemap','ismap','align','border','hspace','vspace'); this.map = this.title.concat('title','name', 'style', 'class', el.events); this.area = el.attrs.concat('shape','coords','href','nohref','alt','target', el.focus); this.form = el.attrs.concat('action','method','name','enctype',el.formevents,'accept','accept-charset','target'); this.label = el.attrs.concat('for','accesskey', el.focusevents); this.input = el.attrs.concat('type','name','value','checked','disabled','readonly','size','maxlength','src','alt','usemap',el.input,'accept','align', el.focus); this.select = el.attrs.concat('name','size','multiple','disabled','tabindex', el.focusevents,el.input); this.optgroup = el.attrs.concat('disabled','label'); this.option = el.attrs.concat('selected','disabled','label','value'); this.textarea = el.attrs.concat('name','rows','cols','disabled','readonly', el.inputevents, el.focus); this.legend = el.attrs.concat('accesskey','align'); this.button = el.attrs.concat('name','value','type','disabled',el.focus); this.isindex = el.coreattrs.concat('prompt', el.i18n); this.table = el.attrs.concat('summary','width','border','frame','rules','cellspacing','cellpadding','align','bgcolor'); this.caption = el.attrs.concat('align'); this.col = this.colgroup = el.attrs.concat('span','width','align','char','charoff','valign'); this.thead = el.attrs.concat('align','char','charoff','valign'); this.tfoot = this.tbody = this.thead; this.tr = this.thead.concat('bgcolor'); this.td = this.th = this.tr.concat('abbr','axis','headers','scope','rowspan','colspan','nowrap','width','height'); }(this.elements, this); // State array. For each tag identifies what it can contain. // I'm not attempting to check the order or number of contained // tags (yet). this.States = new function(el, validation) { var here = this; function setStates(tags, value) { var valset = new validation.Set(value); for (var i = 0; i < tags.length; i++) { here[tags[i]] = valset; } } setStates(['html'], ['head','body']); setStates(['head'], ['title','base','script','style', 'meta','link','object','isindex']); setStates([ 'base', 'meta', 'link', 'hr', 'param', 'img', 'area', 'input', 'br', 'basefont', 'isindex', 'col', ], []); setStates(['title','style','script','option','textarea'], ['#PCDATA']); setStates([ 'noscript', 'iframe', 'noframes', 'body', 'div', 'li', 'dd', 'blockquote', 'center', 'ins', 'del', 'td', 'th', ], el.Flow); setStates(el.heading, el.Inline); setStates([ 'p', 'dt', 'address', 'span', 'bdo', 'caption', 'em', 'strong', 'dfn','code','samp','kbd','var', 'cite','abbr','acronym','q','sub','sup','tt','i', 'b','big','small','u','s','strike','font','label', 'legend'], el.Inline); setStates(['ul', 'ol', 'menu', 'dir', 'ul', ], ['li']); setStates(['dl'], ['dt','dd']); setStates(['pre'], validation._exclude(el.Inline, "img|object|applet|big|small|sub|sup|font|basefont")); setStates(['a'], validation._exclude(el.Inline, "a")); setStates(['applet', 'object'], ['#PCDATA', 'param','form'].concat(el.block, el.inline, el.misc)); setStates(['map'], ['form', 'area'].concat(el.block, el.misc)); setStates(['form'], validation._exclude(el.Flow, ['form'])); setStates(['select'], ['optgroup','option']); setStates(['optgroup'], ['option']); setStates(['fieldset'], ['#PCDATA','legend','form'].concat(el.block,el.inline,el.misc)); setStates(['button'], validation._exclude(el.Flow, ['a','form','iframe'].concat(el.inline_forms))); setStates(['table'], ['caption','col','colgroup','thead','tfoot','tbody','tr']); setStates(['thead', 'tfoot', 'tbody'], ['tr']); setStates(['colgroup'], ['col']); setStates(['tr'], ['th','td']); }(this.elements, this); // Permitted elements for style. this.styleWhitelist = new this.Set(['text-align', 'list-style-type', 'float']); this.classBlacklist = new this.Set(['MsoNormal', 'MsoTitle', 'MsoHeader', 'MsoFootnoteText', 'Bullet1', 'Bullet2']); this.classFilter = function(value) { var classes = value.split(' '); var filtered = []; for (var i = 0; i < classes.length; i++) { var c = classes[i]; if (c && !this.classBlacklist[c]) { filtered.push(c); } } return filtered.join(' '); } this._defaultCopyAttribute = function(name, htmlnode, xhtmlnode) { var val = htmlnode.getAttribute(name); if (val) xhtmlnode.setAttribute(name, val); } // Set up filters for attributes. this.attrFilters = new function(validation, editor) { var attrs = validation.elements.attributes; for (var i=0; i < attrs.length; i++) { this[attrs[i]] = validation._defaultCopyAttribute; } this['class'] = function(name, htmlnode, xhtmlnode) { var val = htmlnode.getAttribute('class'); if (val) val = validation.classFilter(val); if (val) xhtmlnode.setAttribute('class', val); } // allow a * wildcard to make all attributes valid in the filter // note that this is pretty slow on IE this['*'] = function(name, htmlnode, xhtmlnode) { for (var i=0; i < htmlnode.attributes.length; i++) { var attr = htmlnode.attributes[i]; if (attr.value !== null && attr.value !== undefined) { xhtmlnode.setAttribute(attr.name, attr.value); }; }; } if (editor.getBrowserName()=="IE") { this['class'] = function(name, htmlnode, xhtmlnode) { var val = htmlnode.className; if (val) val = validation.classFilter(val); if (val) xhtmlnode.setAttribute('class', val); } this['http-equiv'] = function(name, htmlnode, xhtmlnode) { var val = htmlnode.httpEquiv; if (val) xhtmlnode.setAttribute('http-equiv', val); } this['xml:lang'] = this['xml:space'] = function(name, htmlnode, xhtmlnode) { try { var val = htmlnode.getAttribute(name); if (val) xhtmlnode.setAttribute(name, val); } catch(e) { } } } this.rowspan = this.colspan = function(name, htmlnode, xhtmlnode) { var val = htmlnode.getAttribute(name); if (val && val != '1') xhtmlnode.setAttribute(name, val); } this.style = function(name, htmlnode, xhtmlnode) { var val = htmlnode.style.cssText; if (val) { var styles = val.split(/; */); for (var i = styles.length; i >= 0; i--) if (styles[i]) { var parts = /^([^:]+): *(.*)$/.exec(styles[i]); var name = parts[1].toLowerCase(); if (validation.styleWhitelist[name]) { styles[i] = name+': '+parts[2]; } else { styles.splice(i,1); // delete } } if (styles[styles.length-1]) styles.push(''); val = styles.join('; ').strip(); } if (val) xhtmlnode.setAttribute('style', val); } }(this, editor); // Exclude unwanted tags. this.excludeTags(['center']); if (editor.config && editor.config.htmlfilter) { this.filterStructure = editor.config.htmlfilter.filterstructure; var exclude = editor.config.htmlfilter; if (exclude.a) this.excludeAttributes(exclude.a); if (exclude.t) this.excludeTags(exclude.t); if (exclude.c) { var c = exclude.c; if (!c.length) c = [c]; for (var i = 0; i < c.length; i++) { this.excludeTagAttributes(c[i].t, c[i].a); } } if (exclude.style) { var s = exclude.style; for (var i = 0; i < s.length; i++) { this.styleWhitelist[s[i]] = 1; } } if (exclude['class']) { var c = exclude['class']; for (var i = 0; i < c.length; i++) { this.classBlacklist[c[i]] = 1; } } }; // Copy all valid attributes from htmlnode to xhtmlnode. this._copyAttributes = function(htmlnode, xhtmlnode, valid) { if (valid.contains('*')) { // allow all attributes on this tag this.attrFilters['*'](name, htmlnode, xhtmlnode); return; }; for (var i = 0; i < valid.length; i++) { var name = valid[i]; var filter = this.attrFilters[name]; if (filter) filter(name, htmlnode, xhtmlnode); } } this._convertToSarissaNode = function(ownerdoc, htmlnode, xhtmlparent) { return this._convertNodes(ownerdoc, htmlnode, xhtmlparent, new this.Set(['html'])); }; this._convertNodes = function(ownerdoc, htmlnode, xhtmlparent, permitted) { var name, parentnode = xhtmlparent; var nodename = this._getTagName(htmlnode); var nostructure = !this.filterstructure; // TODO: This permits valid tags anywhere. it should use the state // table in xhtmlvalid to only permit tags where the XHTML DTD // says they are valid. var validattrs = this.tagAttributes[nodename]; if (validattrs && (nostructure || permitted[nodename])) { try { var xhtmlnode = ownerdoc.createElement(nodename); parentnode = xhtmlnode; } catch (e) { }; if (validattrs && xhtmlnode) this._copyAttributes(htmlnode, xhtmlnode, validattrs); } var kids = htmlnode.childNodes; if (kids && /base|meta|link|hr|param|img|area|input|br|basefont|isindex|col/.exec(nodename)) { kids = []; // IE bug: base can think it has children } var permittedChildren = this.States[parentnode.tagName] || permitted; if (kids.length == 0) { if (htmlnode.text && htmlnode.text != "" && (nostructure || permittedChildren['#PCDATA'])) { var text = htmlnode.text; var tnode = ownerdoc.createTextNode(text); parentnode.appendChild(tnode); } } else { for (var i = 0; i < kids.length; i++) { var kid = kids[i]; if (kid.nodeType == 1) { var newkid = this._convertNodes(ownerdoc, kid, parentnode, permittedChildren); if (newkid != null) { parentnode.appendChild(newkid); }; } else if (kid.nodeType == 3) { if (nostructure || permittedChildren['#PCDATA']) parentnode.appendChild(ownerdoc.createTextNode(kid.nodeValue)); } else if (kid.nodeType == 4) { if (nostructure || permittedChildren['#PCDATA']) parentnode.appendChild(ownerdoc.createCDATASection(kid.nodeValue)); } } } return xhtmlnode; };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -