diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js index b57dbf19741..47c967e0004 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js @@ -387,6 +387,9 @@ M.editor_atto = M.editor_atto || { // Copy text to editable div. atto.append(textarea.get('value')); + // Clean it. + atto.cleanHTML(); + // Add the toolbar and editable zone to the page. textarea.get('parentNode').insert(wrapper, textarea); atto.setStyle('color', textarea.getStyle('color')); @@ -463,6 +466,9 @@ M.editor_atto = M.editor_atto || { node.remove(true); }); + // Remove any and all nasties from source. + atto.cleanHTML(); + return atto.getHTML(); }, @@ -719,6 +725,70 @@ Y.extend(CONTROLMENU, M.core.dialogue, { M.editor_atto = M.editor_atto || {}; M.editor_atto.controlmenu = CONTROLMENU; +/** + * Class for cleaning ugly HTML. + * Rewritten JS from jquery-clean plugin. + * + * @module editor_atto + * @chainable + */ +function cleanHTML() { + var cleaned = this.getHTML(); + + // What are we doing ? + // We are cleaning random HTML from all over the shop into a set of useful html suitable for content. + // We are allowing styles etc, but not e.g. font tags, class="MsoNormal" etc. + + var rules = [ + // Source: "http://stackoverflow.com/questions/2875027/clean-microsoft-word-pasted-text-using-javascript" + // Source: "http://stackoverflow.com/questions/1068280/javascript-regex-multiline-flag-doesnt-work" + + // Remove all HTML comments. + {regex: //gi, replace: ""}, + // Source: "http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php" + // Remove , <\?xml>. + {regex: /<\\?\?xml[^>]*>/gi, replace: ""}, + // Remove , <\o:blah>. + {regex: /<\/?\w+:[^>]*>/gi, replace: ""}, // e.g. ]*>( |\s)*<\/span>/gi, replace: ""}, + // Remove class="Msoblah" + {regex: /class="Mso[^"]*"/gi, replace: ""}, + + // Source: "http://www.codinghorror.com/blog/2006/01/cleaning-words-nasty-html.html" + // Remove forbidden tags for content, title, meta, style, st0-9, head, font, html, body. + {regex: /<(\/?title|\/?meta|\/?style|\/?st\d|\/?head|\/?font|\/?html|\/?body|!\[)[^>]*?>/gi, replace: ""}, + + // Source: "http://www.tim-jarrett.com/labs_javascript_scrub_word.php" + // Replace extended chars with simple text. + {regex: new RegExp(String.fromCharCode(8220), 'gi'), replace: '"'}, + {regex: new RegExp(String.fromCharCode(8216), 'gi'), replace: "'"}, + {regex: new RegExp(String.fromCharCode(8217), 'gi'), replace: "'"}, + {regex: new RegExp(String.fromCharCode(8211), 'gi'), replace: '-'}, + {regex: new RegExp(String.fromCharCode(8212), 'gi'), replace: '--'}, + {regex: new RegExp(String.fromCharCode(189), 'gi'), replace: '1/2'}, + {regex: new RegExp(String.fromCharCode(188), 'gi'), replace: '1/4'}, + {regex: new RegExp(String.fromCharCode(190), 'gi'), replace: '3/4'}, + {regex: new RegExp(String.fromCharCode(169), 'gi'), replace: '(c)'}, + {regex: new RegExp(String.fromCharCode(174), 'gi'), replace: '(r)'}, + {regex: new RegExp(String.fromCharCode(8230), 'gi'), replace: '...'} + ]; + + var i = 0, rule; + + for (i = 0; i < rules.length; i++) { + rule = rules[i]; + cleaned = cleaned.replace(rule.regex, rule.replace); + } + + this.setHTML(cleaned); + return this; +} + +Y.Node.addMethod("cleanHTML", cleanHTML); +Y.NodeList.importMethod(Y.Node.prototype, "cleanHTML"); }, '@VERSION@', {"requires": ["node", "io", "overlay", "escape", "event", "moodle-core-notification"]}); diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js index d4bc57078fa..113a2c9cdda 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-editor_atto-editor",function(e,t){CSS={CONTENT:"editor_atto_content",CONTENTWRAPPER:"editor_atto_content_wrap",TOOLBAR:"editor_atto_toolbar",WRAPPER:"editor_atto"},M.editor_atto=M.editor_atto||{buttonhandlers:{},textupdatedhandlers:{},menus:{},menuhandlers:{},filepickeroptions:{},widgets:{},showhide_menu_handler:function(e){e.preventDefault();var t=this.getAttribute("disabled"),n=this.getAttribute("data-menu"),r=M.editor_atto.menus[n],i=r.get("bodyContent");r.get("visible")||t?(r.hide(),i.detach("clickoutside")):(i.on("clickoutside",function(e){e.target.ancestor()!==this&&e.target!==this&&r.get("visible")&&(i.detach("clickoutside"),r.hide())},this),r.show(),r.bodyNode.one("a").focus())},buttonclicked_handler:function(e){var t=this.getAttribute("data-editor"),n=this.getAttribute("data-plugin"),r=this.getAttribute("data-handler"),i=M.editor_atto.menus[n+"_"+t];i&&i.hide();if(M.editor_atto.is_enabled(t,n))return r=M.editor_atto.buttonhandlers[r],r(e,t)},is_enabled:function(t,n){var r=e.one("#"+t+"_toolbar .atto_"+n+"_button");return!r.hasAttribute("disabled")},disable_all_widgets:function(t){var n,r;for(n in M.editor_atto.widgets)r=e.one("#"+t+"_toolbar .atto_"+n+"_button"),r&&r.setAttribute("disabled","true")},enable_widget:function(t,n){var r=e.one("#"+t+"_toolbar .atto_"+n+"_button");r&&r.removeAttribute("disabled")},enable_all_widgets:function(t){var n,r;for(n in M.editor_atto.widgets)r=e.one("#"+t+"_toolbar .atto_"+n+"_button"),r&&r.removeAttribute("disabled")},add_text_updated_handler:function(e,t){e in M.editor_atto.textupdatedhandlers||(M.editor_atto.textupdatedhandlers[e]=[]),M.editor_atto.textupdatedhandlers[e].push(t)},add_toolbar_menu:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group"),a,f,l;u||(u=e.Node.create('
'),o.append(u)),l=M.util.image_url("t/expanded","moodle"),f=e.Node.create('"),u.append(f),a=o.getAttribute("aria-activedescendant"),a||(f.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",f.generateID())),M.editor_atto.widgets[n]=n;var c=e.Node.create('
'),h=0,p={};for(h=0;h'+p.text+""+"")),M.editor_atto.buttonhandlers[n+"_action_"+h]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+h),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+h),M.editor_atto.buttonhandlers[n+"_action_"+h]=p.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var d=new M.core.dialogue({bodyContent:c,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=d,d.render(),d.align(f,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),d.hide(),d.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.Node.create('
'),r=e.Node.create('
'),i="",s=e.Node.create('")),M.editor_atto.buttonhandlers[n+"_action_"+h]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+h),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+h),M.editor_atto.buttonhandlers[n+"_action_"+h]=p.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var d=new M.core.dialogue({bodyContent:c,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=d,d.render(),d.align(f,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),d.hide(),d.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.Node.create +('
'),r=e.Node.create('
'),i="",s=e.Node.create('