📄 kupucontentfilters.js
字号:
/***************************************************************************** * * Copyright (c) 2003-2004 Kupu Contributors. All rights reserved. * * This software is distributed under the terms of the Kupu * License. See LICENSE.txt for license text. For a list of Kupu * Contributors see CREDITS.txt. * *****************************************************************************/// $Id: kupucontentfilters.js,v 1.1 2005/03/26 20:31:36 svieujot Exp $//----------------------------------------------------------------------------// // ContentFilters//// These are (or currently 'this is') filters for HTML cleanup and // conversion. Kupu filters should be classes that should get registered to// the editor using the registerFilter method with 2 methods: 'initialize'// and 'filter'. The first will be called with the editor as its only// argument and the latter with a reference to the ownerdoc (always use // that to create new nodes and such) and the root node of the HTML DOM as // its arguments.////----------------------------------------------------------------------------function NonXHTMLTagFilter() { /* filter out non-XHTML tags*/ // A mapping from element name to whether it should be left out of the // document entirely. If you want an element to reappear in the resulting // document *including* it's contents, add it to the mapping with a 1 value. // If you want an element not to appear but want to leave it's contents in // tact, add it to the mapping with a 0 value. If you want an element and // it's contents to be removed from the document, don't add it. if (arguments.length) { // allow an optional filterdata argument this.filterdata = arguments[0]; } else { // provide a default filterdata dict this.filterdata = {'html': 1, 'body': 1, 'head': 1, 'title': 1, 'a': 1, 'abbr': 1, 'acronym': 1, 'address': 1, 'b': 1, 'base': 1, 'blockquote': 1, 'br': 1, 'caption': 1, 'cite': 1, 'code': 1, 'col': 1, 'colgroup': 1, 'dd': 1, 'dfn': 1, 'div': 1, 'dl': 1, 'dt': 1, 'em': 1, 'h1': 1, 'h2': 1, 'h3': 1, 'h4': 1, 'h5': 1, 'h6': 1, 'h7': 1, 'i': 1, 'img': 1, 'kbd': 1, 'li': 1, 'link': 1, 'meta': 1, 'ol': 1, 'p': 1, 'pre': 1, 'q': 1, 'samp': 1, 'script': 1, 'span': 1, 'strong': 1, 'style': 1, 'sub': 1, 'sup': 1, 'table': 1, 'tbody': 1, 'td': 1, 'tfoot': 1, 'th': 1, 'thead': 1, 'tr': 1, 'ul': 1, 'u': 1, 'var': 1, // even though they're deprecated we should leave // font tags as they are, since Kupu sometimes // produces them itself. 'font': 1, 'center': 0 }; }; this.initialize = function(editor) { /* init */ this.editor = editor; }; this.filter = function(ownerdoc, htmlnode) { return this._filterHelper(ownerdoc, htmlnode); }; this._filterHelper = function(ownerdoc, node) { /* filter unwanted elements */ if (node.nodeType == 3) { return ownerdoc.createTextNode(node.nodeValue); } else if (node.nodeType == 4) { return ownerdoc.createCDATASection(node.nodeValue); }; // create a new node to place the result into // XXX this can be severely optimized by doing stuff inline rather // than on creating new elements all the time! var newnode = ownerdoc.createElement(node.nodeName); // copy the attributes for (var i=0; i < node.attributes.length; i++) { var attr = node.attributes[i]; newnode.setAttribute(attr.nodeName, attr.nodeValue); }; for (var i=0; i < node.childNodes.length; i++) { var child = node.childNodes[i]; var nodeType = child.nodeType; var nodeName = child.nodeName.toLowerCase(); if (nodeType == 3 || nodeType == 4) { newnode.appendChild(this._filterHelper(ownerdoc, child)); }; if (nodeName in this.filterdata && this.filterdata[nodeName]) { newnode.appendChild(this._filterHelper(ownerdoc, child)); } else if (nodeName in this.filterdata) { for (var j=0; j < child.childNodes.length; j++) { newnode.appendChild(this._filterHelper(ownerdoc, child.childNodes[j])); }; }; }; return newnode; };};//-----------------------------------------------------------------------------//// XHTML validation support//// This class is the XHTML 1.0 transitional DTD expressed as Javascript// data structures.//function XhtmlValidation(editor) { // Support functions this.Set = function(ary) { if (typeof(ary)==typeof('')) ary = [ary]; if (ary instanceof Array) { for (var i = 0; i < ary.length; i++) { this[ary[i]] = 1; } } else { for (var v in ary) { // already a set? this[v] = 1; } } } this._exclude = function(array, exceptions) { var ex; if (exceptions.split) { ex = exceptions.split("|"); } else { ex = exceptions; } var exclude = new this.Set(ex); var res = []; for (var k=0; k < array.length;k++) { if (!exclude[array[k]]) res.push(array[k]); } return res; } this.setAttrFilter = function(attributes, filter) { for (var j = 0; j < attributes.length; j++) { var attr = attributes[j]; this.attrFilters[attr] = filter || this._defaultCopyAttribute; } } this.setTagAttributes = function(tags, attributes) { for (var j = 0; j < tags.length; j++) { this.tagAttributes[tags[j]] = attributes; } } // define some new attributes for existing tags this.includeTagAttributes = function(tags, attributes) { for (var j = 0; j < tags.length; j++) { var tag = tags[j]; this.tagAttributes[tag] = this.tagAttributes[tag].concat(attributes); } } this.excludeTagAttributes = function(tags, attributes) { var bad = new this.Set(attributes); var tagset = new this.Set(tags); for (var tag in tagset) { var val = this.tagAttributes[tag]; for (var i = val.length; i >= 0; i--) { if (bad[val[i]]) { val = val.concat(); // Copy val.splice(i,1); } } this.tagAttributes[tag] = val; } } this.excludeTags = function(badtags) { if (typeof(badtags)==typeof('')) badtags = [badtags]; for (var i = 0; i < badtags.length; i++) { delete this.tagAttributes[badtags[i]]; } } this.excludeAttributes = function(badattrs) { this.excludeTagAttributes(this.tagAttributes, badattrs); for (var i = 0; i < badattrs.length; i++) { delete this.attrFilters[badattrs[i]]; } } if (editor.getBrowserName()=="IE") { this._getTagName = function(htmlnode) { var nodename = htmlnode.nodeName.toLowerCase(); if (htmlnode.scopeName && htmlnode.scopeName != "HTML") { nodename = htmlnode.scopeName+':'+nodename; } return nodename; } } else { this._getTagName = function(htmlnode) { return htmlnode.nodeName.toLowerCase(); } }; // Supporting declarations this.elements = new function(validation) { // A list of all attributes this.attributes = [ 'abbr','accept','accept-charset','accesskey','action','align','alink', 'alt','archive','axis','background','bgcolor','border','cellpadding', 'cellspacing','char','charoff','charset','checked','cite','class', 'classid','clear','code','codebase','codetype','color','cols','colspan', 'compact','content','coords','data','datetime','declare','defer','dir', 'disabled','enctype','face','for','frame','frameborder','headers', 'height','href','hreflang','hspace','http-equiv','id','ismap','label', 'lang','language','link','longdesc','marginheight','marginwidth', 'maxlength','media','method','multiple','name','nohref','noshade','nowrap', 'object','onblur','onchange','onclick','ondblclick','onfocus','onkeydown', 'onkeypress','onkeyup','onload','onmousedown','onmousemove','onmouseout', 'onmouseover','onmouseup','onreset','onselect','onsubmit','onunload', 'profile','prompt','readonly','rel','rev','rows','rowspan','rules', 'scheme','scope','scrolling','selected','shape','size','span','src', 'standby','start','style','summary','tabindex','target','text','title', 'type','usemap','valign','value','valuetype','vlink','vspace','width', 'xml:lang','xml:space','xmlns']; // Core attributes this.coreattrs = ['id', 'title', 'style', 'class']; this.i18n = ['lang', 'dir', 'xml:lang']; // All event attributes are here but commented out so we don't // have to remove them later. this.events = []; // 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'.split('|'); this.focusevents = []; // ['onfocus','onblur'] this.loadevents = []; // ['onload', 'onunload'] this.formevents = []; // ['onsubmit','onreset'] this.inputevents = [] ; // ['onselect', 'onchange'] this.focus = ['accesskey', 'tabindex'].concat(this.focusevents); this.attrs = [].concat(this.coreattrs, this.i18n, this.events); // entities this.special_extra = ['object','applet','img','map','iframe']; this.special_basic=['br','span','bdo']; this.special = [].concat(this.special_basic, this.special_extra); this.fontstyle_extra = ['big','small','font','basefont']; this.fontstyle_basic = ['tt','i','b','u','s','strike']; this.fontstyle = [].concat(this.fontstyle_basic, this.fontstyle_extra); this.phrase_extra = ['sub','sup']; this.phrase_basic=[ 'em','strong','dfn','code','q', 'samp','kbd','var', 'cite','abbr','acronym']; this.inline_forms = ['input','select','textarea','label','button']; this.misc_inline = ['ins','del']; this.misc = ['noscript'].concat(this.misc_inline); this.inline = ['a'].concat(this.special, this.fontstyle, this.phrase, this.inline_forms); this.Inline = ['#PCDATA'].concat(this.inline, this.misc_inline); this.heading = ['h1','h2','h3','h4','h5','h6']; this.lists = ['ul','ol','dl','menu','dir']; this.blocktext = ['pre','hr','blockquote','address','center','noframes']; this.block = ['p','div','isindex','fieldset','table'].concat( this.heading, this.lists, this.blocktext);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -