bgneal@312: /**
bgneal@312: * editor_plugin_src.js
bgneal@312: *
bgneal@312: * Copyright 2009, Moxiecode Systems AB
bgneal@312: * Released under LGPL License.
bgneal@312: *
bgneal@312: * License: http://tinymce.moxiecode.com/license
bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@312: */
bgneal@312:
bgneal@312: (function() {
bgneal@312: var each = tinymce.each,
bgneal@312: defs = {
bgneal@312: paste_auto_cleanup_on_paste : true,
bgneal@442: paste_enable_default_filters : true,
bgneal@312: paste_block_drop : false,
bgneal@312: paste_retain_style_properties : "none",
bgneal@312: paste_strip_class_attributes : "mso",
bgneal@312: paste_remove_spans : false,
bgneal@312: paste_remove_styles : false,
bgneal@312: paste_remove_styles_if_webkit : true,
bgneal@312: paste_convert_middot_lists : true,
bgneal@312: paste_convert_headers_to_strong : false,
bgneal@312: paste_dialog_width : "450",
bgneal@312: paste_dialog_height : "400",
bgneal@312: paste_text_use_dialog : false,
bgneal@312: paste_text_sticky : false,
bgneal@442: paste_text_sticky_default : false,
bgneal@312: paste_text_notifyalways : false,
bgneal@312: paste_text_linebreaktype : "p",
bgneal@312: paste_text_replacements : [
bgneal@312: [/\u2026/g, "..."],
bgneal@312: [/[\x93\x94\u201c\u201d]/g, '"'],
bgneal@312: [/[\x60\x91\x92\u2018\u2019]/g, "'"]
bgneal@312: ]
bgneal@312: };
bgneal@312:
bgneal@312: function getParam(ed, name) {
bgneal@312: return ed.getParam(name, defs[name]);
bgneal@312: }
bgneal@312:
bgneal@312: tinymce.create('tinymce.plugins.PastePlugin', {
bgneal@312: init : function(ed, url) {
bgneal@312: var t = this;
bgneal@312:
bgneal@312: t.editor = ed;
bgneal@312: t.url = url;
bgneal@312:
bgneal@312: // Setup plugin events
bgneal@312: t.onPreProcess = new tinymce.util.Dispatcher(t);
bgneal@312: t.onPostProcess = new tinymce.util.Dispatcher(t);
bgneal@312:
bgneal@312: // Register default handlers
bgneal@312: t.onPreProcess.add(t._preProcess);
bgneal@312: t.onPostProcess.add(t._postProcess);
bgneal@312:
bgneal@312: // Register optional preprocess handler
bgneal@312: t.onPreProcess.add(function(pl, o) {
bgneal@312: ed.execCallback('paste_preprocess', pl, o);
bgneal@312: });
bgneal@312:
bgneal@312: // Register optional postprocess
bgneal@312: t.onPostProcess.add(function(pl, o) {
bgneal@312: ed.execCallback('paste_postprocess', pl, o);
bgneal@312: });
bgneal@312:
bgneal@442: ed.onKeyDown.addToTop(function(ed, e) {
bgneal@442: // Block ctrl+v from adding an undo level since the default logic in tinymce.Editor will add that
bgneal@442: if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
bgneal@442: return false; // Stop other listeners
bgneal@442: });
bgneal@442:
bgneal@312: // Initialize plain text flag
bgneal@442: ed.pasteAsPlainText = getParam(ed, 'paste_text_sticky_default');
bgneal@312:
bgneal@312: // This function executes the process handlers and inserts the contents
bgneal@312: // force_rich overrides plain text mode set by user, important for pasting with execCommand
bgneal@312: function process(o, force_rich) {
bgneal@442: var dom = ed.dom, rng, nodes;
bgneal@312:
bgneal@312: // Execute pre process handlers
bgneal@312: t.onPreProcess.dispatch(t, o);
bgneal@312:
bgneal@312: // Create DOM structure
bgneal@312: o.node = dom.create('div', 0, o.content);
bgneal@312:
bgneal@442: // If pasting inside the same element and the contents is only one block
bgneal@442: // remove the block and keep the text since Firefox will copy parts of pre and h1-h6 as a pre element
bgneal@442: if (tinymce.isGecko) {
bgneal@442: rng = ed.selection.getRng(true);
bgneal@442: if (rng.startContainer == rng.endContainer && rng.startContainer.nodeType == 3) {
bgneal@442: nodes = dom.select('p,h1,h2,h3,h4,h5,h6,pre', o.node);
bgneal@442:
bgneal@442: // Is only one block node and it doesn't contain word stuff
bgneal@442: if (nodes.length == 1 && o.content.indexOf('__MCE_ITEM__') === -1)
bgneal@442: dom.remove(nodes.reverse(), true);
bgneal@442: }
bgneal@442: }
bgneal@442:
bgneal@312: // Execute post process handlers
bgneal@312: t.onPostProcess.dispatch(t, o);
bgneal@312:
bgneal@312: // Serialize content
bgneal@312: o.content = ed.serializer.serialize(o.node, {getInner : 1});
bgneal@312:
bgneal@312: // Plain text option active?
bgneal@312: if ((!force_rich) && (ed.pasteAsPlainText)) {
bgneal@312: t._insertPlainText(ed, dom, o.content);
bgneal@312:
bgneal@312: if (!getParam(ed, "paste_text_sticky")) {
bgneal@312: ed.pasteAsPlainText = false;
bgneal@312: ed.controlManager.setActive("pastetext", false);
bgneal@312: }
bgneal@312: } else {
bgneal@312: t._insert(o.content);
bgneal@312: }
bgneal@312: }
bgneal@312:
bgneal@312: // Add command for external usage
bgneal@312: ed.addCommand('mceInsertClipboardContent', function(u, o) {
bgneal@312: process(o, true);
bgneal@312: });
bgneal@312:
bgneal@312: if (!getParam(ed, "paste_text_use_dialog")) {
bgneal@312: ed.addCommand('mcePasteText', function(u, v) {
bgneal@312: var cookie = tinymce.util.Cookie;
bgneal@312:
bgneal@312: ed.pasteAsPlainText = !ed.pasteAsPlainText;
bgneal@312: ed.controlManager.setActive('pastetext', ed.pasteAsPlainText);
bgneal@312:
bgneal@312: if ((ed.pasteAsPlainText) && (!cookie.get("tinymcePasteText"))) {
bgneal@312: if (getParam(ed, "paste_text_sticky")) {
bgneal@312: ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky'));
bgneal@312: } else {
bgneal@312: ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky'));
bgneal@312: }
bgneal@312:
bgneal@312: if (!getParam(ed, "paste_text_notifyalways")) {
bgneal@312: cookie.set("tinymcePasteText", "1", new Date(new Date().getFullYear() + 1, 12, 31))
bgneal@312: }
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312:
bgneal@312: ed.addButton('pastetext', {title: 'paste.paste_text_desc', cmd: 'mcePasteText'});
bgneal@312: ed.addButton('selectall', {title: 'paste.selectall_desc', cmd: 'selectall'});
bgneal@312:
bgneal@312: // This function grabs the contents from the clipboard by adding a
bgneal@312: // hidden div and placing the caret inside it and after the browser paste
bgneal@312: // is done it grabs that contents and processes that
bgneal@312: function grabContent(e) {
bgneal@442: var n, or, rng, oldRng, sel = ed.selection, dom = ed.dom, body = ed.getBody(), posY, textContent;
bgneal@312:
bgneal@312: // Check if browser supports direct plaintext access
bgneal@442: if (e.clipboardData || dom.doc.dataTransfer) {
bgneal@442: textContent = (e.clipboardData || dom.doc.dataTransfer).getData('Text');
bgneal@442:
bgneal@442: if (ed.pasteAsPlainText) {
bgneal@442: e.preventDefault();
bgneal@442: process({content : textContent.replace(/\r?\n/g, '
')});
bgneal@442: return;
bgneal@442: }
bgneal@312: }
bgneal@312:
bgneal@312: if (dom.get('_mcePaste'))
bgneal@312: return;
bgneal@312:
bgneal@312: // Create container to paste into
bgneal@442: n = dom.add(body, 'div', {id : '_mcePaste', 'class' : 'mcePaste', 'data-mce-bogus' : '1'}, '\uFEFF\uFEFF');
bgneal@312:
bgneal@312: // If contentEditable mode we need to find out the position of the closest element
bgneal@312: if (body != ed.getDoc().body)
bgneal@312: posY = dom.getPos(ed.selection.getStart(), body).y;
bgneal@312: else
bgneal@442: posY = body.scrollTop + dom.getViewPort().y;
bgneal@312:
bgneal@312: // Styles needs to be applied after the element is added to the document since WebKit will otherwise remove all styles
bgneal@312: dom.setStyles(n, {
bgneal@312: position : 'absolute',
bgneal@312: left : -10000,
bgneal@312: top : posY,
bgneal@312: width : 1,
bgneal@312: height : 1,
bgneal@312: overflow : 'hidden'
bgneal@312: });
bgneal@312:
bgneal@312: if (tinymce.isIE) {
bgneal@442: // Store away the old range
bgneal@442: oldRng = sel.getRng();
bgneal@442:
bgneal@312: // Select the container
bgneal@312: rng = dom.doc.body.createTextRange();
bgneal@312: rng.moveToElementText(n);
bgneal@312: rng.execCommand('Paste');
bgneal@312:
bgneal@312: // Remove container
bgneal@312: dom.remove(n);
bgneal@312:
bgneal@312: // Check if the contents was changed, if it wasn't then clipboard extraction failed probably due
bgneal@312: // to IE security settings so we pass the junk though better than nothing right
bgneal@442: if (n.innerHTML === '\uFEFF\uFEFF') {
bgneal@312: ed.execCommand('mcePasteWord');
bgneal@312: e.preventDefault();
bgneal@312: return;
bgneal@312: }
bgneal@312:
bgneal@442: // Restore the old range and clear the contents before pasting
bgneal@442: sel.setRng(oldRng);
bgneal@442: sel.setContent('');
bgneal@442:
bgneal@442: // For some odd reason we need to detach the the mceInsertContent call from the paste event
bgneal@442: // It's like IE has a reference to the parent element that you paste in and the selection gets messed up
bgneal@442: // when it tries to restore the selection
bgneal@442: setTimeout(function() {
bgneal@442: // Process contents
bgneal@442: process({content : n.innerHTML});
bgneal@442: }, 0);
bgneal@312:
bgneal@312: // Block the real paste event
bgneal@312: return tinymce.dom.Event.cancel(e);
bgneal@312: } else {
bgneal@312: function block(e) {
bgneal@312: e.preventDefault();
bgneal@312: };
bgneal@312:
bgneal@312: // Block mousedown and click to prevent selection change
bgneal@312: dom.bind(ed.getDoc(), 'mousedown', block);
bgneal@312: dom.bind(ed.getDoc(), 'keydown', block);
bgneal@312:
bgneal@312: or = ed.selection.getRng();
bgneal@312:
bgneal@442: // Move select contents inside DIV
bgneal@312: n = n.firstChild;
bgneal@312: rng = ed.getDoc().createRange();
bgneal@312: rng.setStart(n, 0);
bgneal@442: rng.setEnd(n, 2);
bgneal@312: sel.setRng(rng);
bgneal@312:
bgneal@312: // Wait a while and grab the pasted contents
bgneal@312: window.setTimeout(function() {
bgneal@442: var h = '', nl;
bgneal@312:
bgneal@442: // Paste divs duplicated in paste divs seems to happen when you paste plain text so lets first look for that broken behavior in WebKit
bgneal@442: if (!dom.select('div.mcePaste > div.mcePaste').length) {
bgneal@442: nl = dom.select('div.mcePaste');
bgneal@312:
bgneal@442: // WebKit will split the div into multiple ones so this will loop through then all and join them to get the whole HTML string
bgneal@442: each(nl, function(n) {
bgneal@442: var child = n.firstChild;
bgneal@312:
bgneal@442: // WebKit inserts a DIV container with lots of odd styles
bgneal@442: if (child && child.nodeName == 'DIV' && child.style.marginTop && child.style.backgroundColor) {
bgneal@442: dom.remove(child, 1);
bgneal@442: }
bgneal@442:
bgneal@442: // Remove apply style spans
bgneal@442: each(dom.select('span.Apple-style-span', n), function(n) {
bgneal@442: dom.remove(n, 1);
bgneal@442: });
bgneal@442:
bgneal@442: // Remove bogus br elements
bgneal@442: each(dom.select('br[data-mce-bogus]', n), function(n) {
bgneal@442: dom.remove(n);
bgneal@442: });
bgneal@442:
bgneal@442: // WebKit will make a copy of the DIV for each line of plain text pasted and insert them into the DIV
bgneal@442: if (n.parentNode.className != 'mcePaste')
bgneal@442: h += n.innerHTML;
bgneal@312: });
bgneal@442: } else {
bgneal@442: // Found WebKit weirdness so force the content into plain text mode
bgneal@442: h = '
' + dom.encode(textContent).replace(/\r?\n/g, ''; bgneal@442: } bgneal@312: bgneal@312: // Remove the nodes bgneal@442: each(dom.select('div.mcePaste'), function(n) { bgneal@312: dom.remove(n); bgneal@312: }); bgneal@312: bgneal@312: // Restore the old selection bgneal@312: if (or) bgneal@312: sel.setRng(or); bgneal@312: bgneal@312: process({content : h}); bgneal@312: bgneal@312: // Unblock events ones we got the contents bgneal@312: dom.unbind(ed.getDoc(), 'mousedown', block); bgneal@312: dom.unbind(ed.getDoc(), 'keydown', block); bgneal@312: }, 0); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Check if we should use the new auto process method bgneal@312: if (getParam(ed, "paste_auto_cleanup_on_paste")) { bgneal@312: // Is it's Opera or older FF use key handler bgneal@312: if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) { bgneal@442: ed.onKeyDown.addToTop(function(ed, e) { bgneal@312: if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45)) bgneal@312: grabContent(e); bgneal@312: }); bgneal@312: } else { bgneal@312: // Grab contents on paste event on Gecko and WebKit bgneal@312: ed.onPaste.addToTop(function(ed, e) { bgneal@312: return grabContent(e); bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: bgneal@442: ed.onInit.add(function() { bgneal@442: ed.controlManager.setActive("pastetext", ed.pasteAsPlainText); bgneal@442: bgneal@442: // Block all drag/drop events bgneal@442: if (getParam(ed, "paste_block_drop")) { bgneal@312: ed.dom.bind(ed.getBody(), ['dragend', 'dragover', 'draggesture', 'dragdrop', 'drop', 'drag'], function(e) { bgneal@312: e.preventDefault(); bgneal@312: e.stopPropagation(); bgneal@312: bgneal@312: return false; bgneal@312: }); bgneal@442: } bgneal@442: }); bgneal@312: bgneal@312: // Add legacy support bgneal@312: t._legacySupport(); bgneal@312: }, bgneal@312: bgneal@312: getInfo : function() { bgneal@312: return { bgneal@312: longname : 'Paste text/word', bgneal@312: author : 'Moxiecode Systems AB', bgneal@312: authorurl : 'http://tinymce.moxiecode.com', bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste', bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: _preProcess : function(pl, o) { bgneal@312: var ed = this.editor, bgneal@312: h = o.content, bgneal@312: grep = tinymce.grep, bgneal@312: explode = tinymce.explode, bgneal@312: trim = tinymce.trim, bgneal@312: len, stripClass; bgneal@312: bgneal@442: //console.log('Before preprocess:' + o.content); bgneal@442: bgneal@312: function process(items) { bgneal@312: each(items, function(v) { bgneal@312: // Remove or replace bgneal@312: if (v.constructor == RegExp) bgneal@312: h = h.replace(v, ''); bgneal@312: else bgneal@312: h = h.replace(v[0], v[1]); bgneal@312: }); bgneal@312: } bgneal@442: bgneal@442: if (ed.settings.paste_enable_default_filters == false) { bgneal@442: return; bgneal@442: } bgneal@442: bgneal@442: // IE9 adds BRs before/after block elements when contents is pasted from word or for example another browser bgneal@442: if (tinymce.isIE && document.documentMode >= 9) bgneal@442: process([[/(?:
') + '
]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "
$1
"); bgneal@312: } bgneal@312: bgneal@312: if (getParam(ed, "paste_convert_middot_lists")) { bgneal@312: process([ bgneal@312: [//gi, '$&__MCE_ITEM__'], // Convert supportLists to a list item marker bgneal@442: [/(]+(?:mso-list:|:\s*symbol)[^>]+>)/gi, '$1__MCE_ITEM__'], // Convert mso-list and symbol spans to item markers bgneal@442: [/(]+(?:MsoListParagraph)[^>]+>)/gi, '$1__MCE_ITEM__'] // Convert mso-list and symbol paragraphs to item markers (FF)
bgneal@312: ]);
bgneal@312: }
bgneal@312:
bgneal@312: process([
bgneal@312: // Word comments like conditional comments etc
bgneal@312: //gi,
bgneal@312:
bgneal@312: // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags
bgneal@312: /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
bgneal@312:
bgneal@312: // Convert "],
bgneal@312: [/<\/h[1-6][^>]*>/gi, " into for line-though
bgneal@312: [/<(\/?)s>/gi, "<$1strike>"],
bgneal@312:
bgneal@312: // Replace nsbp entites to char since it's easier to handle
bgneal@312: [/ /gi, "\u00a0"]
bgneal@312: ]);
bgneal@312:
bgneal@312: // Remove bad attributes, with or without quotes, ensuring that attribute text is really inside a tag.
bgneal@312: // If JavaScript had a RegExp look-behind, we could have integrated this with the last process() array and got rid of the loop. But alas, it does not, so we cannot.
bgneal@312: do {
bgneal@312: len = h.length;
bgneal@312: h = h.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1");
bgneal@312: } while (len != h.length);
bgneal@312:
bgneal@312: // Remove all spans if no styles is to be retained
bgneal@312: if (getParam(ed, "paste_retain_style_properties").replace(/^none$/i, "").length == 0) {
bgneal@312: h = h.replace(/<\/?span[^>]*>/gi, "");
bgneal@312: } else {
bgneal@312: // We're keeping styles, so at least clean them up.
bgneal@312: // CSS Reference: http://msdn.microsoft.com/en-us/library/aa155477.aspx
bgneal@312:
bgneal@312: process([
bgneal@312: // Convert ___ to string of alternating breaking/non-breaking spaces of same length
bgneal@312: [/([\s\u00a0]*)<\/span>/gi,
bgneal@312: function(str, spaces) {
bgneal@312: return (spaces.length > 0)? spaces.replace(/./, " ").slice(Math.floor(spaces.length/2)).split("").join("\u00a0") : "";
bgneal@312: }
bgneal@312: ],
bgneal@312:
bgneal@312: // Examine all styles: delete junk, transform some, and keep the rest
bgneal@312: [/(<[a-z][^>]*)\sstyle="([^"]*)"/gi,
bgneal@312: function(str, tag, style) {
bgneal@312: var n = [],
bgneal@312: i = 0,
bgneal@312: s = explode(trim(style).replace(/"/gi, "'"), ";");
bgneal@312:
bgneal@312: // Examine each style definition within the tag's style attribute
bgneal@312: each(s, function(v) {
bgneal@312: var name, value,
bgneal@312: parts = explode(v, ":");
bgneal@312:
bgneal@312: function ensureUnits(v) {
bgneal@312: return v + ((v !== "0") && (/\d$/.test(v)))? "px" : "";
bgneal@312: }
bgneal@312:
bgneal@312: if (parts.length == 2) {
bgneal@312: name = parts[0].toLowerCase();
bgneal@312: value = parts[1].toLowerCase();
bgneal@312:
bgneal@312: // Translate certain MS Office styles into their CSS equivalents
bgneal@312: switch (name) {
bgneal@312: case "mso-padding-alt":
bgneal@312: case "mso-padding-top-alt":
bgneal@312: case "mso-padding-right-alt":
bgneal@312: case "mso-padding-bottom-alt":
bgneal@312: case "mso-padding-left-alt":
bgneal@312: case "mso-margin-alt":
bgneal@312: case "mso-margin-top-alt":
bgneal@312: case "mso-margin-right-alt":
bgneal@312: case "mso-margin-bottom-alt":
bgneal@312: case "mso-margin-left-alt":
bgneal@312: case "mso-table-layout-alt":
bgneal@312: case "mso-height":
bgneal@312: case "mso-width":
bgneal@312: case "mso-vertical-align-alt":
bgneal@312: n[i++] = name.replace(/^mso-|-alt$/g, "") + ":" + ensureUnits(value);
bgneal@312: return;
bgneal@312:
bgneal@312: case "horiz-align":
bgneal@312: n[i++] = "text-align:" + value;
bgneal@312: return;
bgneal@312:
bgneal@312: case "vert-align":
bgneal@312: n[i++] = "vertical-align:" + value;
bgneal@312: return;
bgneal@312:
bgneal@312: case "font-color":
bgneal@312: case "mso-foreground":
bgneal@312: n[i++] = "color:" + value;
bgneal@312: return;
bgneal@312:
bgneal@312: case "mso-background":
bgneal@312: case "mso-highlight":
bgneal@312: n[i++] = "background:" + value;
bgneal@312: return;
bgneal@312:
bgneal@312: case "mso-default-height":
bgneal@312: n[i++] = "min-height:" + ensureUnits(value);
bgneal@312: return;
bgneal@312:
bgneal@312: case "mso-default-width":
bgneal@312: n[i++] = "min-width:" + ensureUnits(value);
bgneal@312: return;
bgneal@312:
bgneal@312: case "mso-padding-between-alt":
bgneal@312: n[i++] = "border-collapse:separate;border-spacing:" + ensureUnits(value);
bgneal@312: return;
bgneal@312:
bgneal@312: case "text-line-through":
bgneal@312: if ((value == "single") || (value == "double")) {
bgneal@312: n[i++] = "text-decoration:line-through";
bgneal@312: }
bgneal@312: return;
bgneal@312:
bgneal@312: case "mso-zero-height":
bgneal@312: if (value == "yes") {
bgneal@312: n[i++] = "display:none";
bgneal@312: }
bgneal@312: return;
bgneal@312: }
bgneal@312:
bgneal@312: // Eliminate all MS Office style definitions that have no CSS equivalent by examining the first characters in the name
bgneal@312: if (/^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?!align|decor|indent|trans)|top-bar|version|vnd|word-break)/.test(name)) {
bgneal@312: return;
bgneal@312: }
bgneal@312:
bgneal@312: // If it reached this point, it must be a valid CSS style
bgneal@312: n[i++] = name + ":" + parts[1]; // Lower-case name, but keep value case
bgneal@312: }
bgneal@312: });
bgneal@312:
bgneal@312: // If style attribute contained any valid styles the re-write it; otherwise delete style attribute.
bgneal@312: if (i > 0) {
bgneal@312: return tag + ' style="' + n.join(';') + '"';
bgneal@312: } else {
bgneal@312: return tag;
bgneal@312: }
bgneal@312: }
bgneal@312: ]
bgneal@312: ]);
bgneal@312: }
bgneal@312: }
bgneal@312:
bgneal@312: // Replace headers with
bgneal@312: if (getParam(ed, "paste_convert_headers_to_strong")) {
bgneal@312: process([
bgneal@312: [/
]*>|<\/tr>/gi, "\n"], // Single linebreak for
tags and table rows
bgneal@312: [/<\/t[dh]>\s*
"]
bgneal@312: ]);
bgneal@312: }
bgneal@312: else {
bgneal@312: process([
bgneal@312: /^\s+|\s+$/g,
bgneal@312: [/\n\n/g, "
"],
bgneal@312: [/\n/g, "
"]
bgneal@312: ]);
bgneal@312: }
bgneal@312:
bgneal@312: // This next piece of code handles the situation where we're pasting more than one paragraph of plain
bgneal@312: // text, and we are pasting the content into the middle of a block node in the editor. The block
bgneal@312: // node gets split at the selection point into "Para A" and "Para B" (for the purposes of explaining).
bgneal@312: // The first paragraph of the pasted text is appended to "Para A", and the last paragraph of the
bgneal@312: // pasted text is prepended to "Para B". Any other paragraphs of pasted text are placed between
bgneal@312: // "Para A" and "Para B". This code solves a host of problems with the original plain text plugin and
bgneal@312: // now handles styles correctly. (Pasting plain text into a styled paragraph is supposed to make the
bgneal@312: // plain text take the same style as the existing paragraph.)
bgneal@312: if ((pos = h.indexOf("
")) != -1) { bgneal@312: rpos = h.lastIndexOf("
");
bgneal@312: node = sel.getNode();
bgneal@312: breakElms = []; // Get list of elements to break
bgneal@312:
bgneal@312: do {
bgneal@312: if (node.nodeType == 1) {
bgneal@312: // Don't break tables and break at body
bgneal@312: if (node.nodeName == "TD" || node.nodeName == "BODY") {
bgneal@312: break;
bgneal@312: }
bgneal@312:
bgneal@312: breakElms[breakElms.length] = node;
bgneal@312: }
bgneal@312: } while (node = node.parentNode);
bgneal@312:
bgneal@312: // Are we in the middle of a block node?
bgneal@312: if (breakElms.length > 0) {
bgneal@312: before = h.substring(0, pos);
bgneal@312: after = "";
bgneal@312:
bgneal@312: for (i=0, len=breakElms.length; i