plugin.js000064400000240664150213074230006411 0ustar00(function () { var paste = (function (domGlobals) { 'use strict'; var Cell = function (initial) { var value = initial; var get = function () { return value; }; var set = function (v) { value = v; }; var clone = function () { return Cell(get()); }; return { get: get, set: set, clone: clone }; }; var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager'); var hasProPlugin = function (editor) { if (/(^|[ ,])powerpaste([, ]|$)/.test(editor.settings.plugins) && global$1.get('powerpaste')) { if (typeof domGlobals.window.console !== 'undefined' && domGlobals.window.console.log) { domGlobals.window.console.log('PowerPaste is incompatible with Paste plugin! Remove \'paste\' from the \'plugins\' option.'); } return true; } else { return false; } }; var DetectProPlugin = { hasProPlugin: hasProPlugin }; var get = function (clipboard, quirks) { return { clipboard: clipboard, quirks: quirks }; }; var Api = { get: get }; var firePastePreProcess = function (editor, html, internal, isWordHtml) { return editor.fire('PastePreProcess', { content: html, internal: internal, wordContent: isWordHtml }); }; var firePastePostProcess = function (editor, node, internal, isWordHtml) { return editor.fire('PastePostProcess', { node: node, internal: internal, wordContent: isWordHtml }); }; var firePastePlainTextToggle = function (editor, state) { return editor.fire('PastePlainTextToggle', { state: state }); }; var firePaste = function (editor, ieFake) { return editor.fire('paste', { ieFake: ieFake }); }; var Events = { firePastePreProcess: firePastePreProcess, firePastePostProcess: firePastePostProcess, firePastePlainTextToggle: firePastePlainTextToggle, firePaste: firePaste }; var shouldPlainTextInform = function (editor) { return editor.getParam('paste_plaintext_inform', true); }; var shouldBlockDrop = function (editor) { return editor.getParam('paste_block_drop', false); }; var shouldPasteDataImages = function (editor) { return editor.getParam('paste_data_images', false); }; var shouldFilterDrop = function (editor) { return editor.getParam('paste_filter_drop', true); }; var getPreProcess = function (editor) { return editor.getParam('paste_preprocess'); }; var getPostProcess = function (editor) { return editor.getParam('paste_postprocess'); }; var getWebkitStyles = function (editor) { return editor.getParam('paste_webkit_styles'); }; var shouldRemoveWebKitStyles = function (editor) { return editor.getParam('paste_remove_styles_if_webkit', true); }; var shouldMergeFormats = function (editor) { return editor.getParam('paste_merge_formats', true); }; var isSmartPasteEnabled = function (editor) { return editor.getParam('smart_paste', true); }; var isPasteAsTextEnabled = function (editor) { return editor.getParam('paste_as_text', false); }; var getRetainStyleProps = function (editor) { return editor.getParam('paste_retain_style_properties'); }; var getWordValidElements = function (editor) { var defaultValidElements = '-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' + '-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,' + 'td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody'; return editor.getParam('paste_word_valid_elements', defaultValidElements); }; var shouldConvertWordFakeLists = function (editor) { return editor.getParam('paste_convert_word_fake_lists', true); }; var shouldUseDefaultFilters = function (editor) { return editor.getParam('paste_enable_default_filters', true); }; var Settings = { shouldPlainTextInform: shouldPlainTextInform, shouldBlockDrop: shouldBlockDrop, shouldPasteDataImages: shouldPasteDataImages, shouldFilterDrop: shouldFilterDrop, getPreProcess: getPreProcess, getPostProcess: getPostProcess, getWebkitStyles: getWebkitStyles, shouldRemoveWebKitStyles: shouldRemoveWebKitStyles, shouldMergeFormats: shouldMergeFormats, isSmartPasteEnabled: isSmartPasteEnabled, isPasteAsTextEnabled: isPasteAsTextEnabled, getRetainStyleProps: getRetainStyleProps, getWordValidElements: getWordValidElements, shouldConvertWordFakeLists: shouldConvertWordFakeLists, shouldUseDefaultFilters: shouldUseDefaultFilters }; var shouldInformUserAboutPlainText = function (editor, userIsInformedState) { return userIsInformedState.get() === false && Settings.shouldPlainTextInform(editor); }; var displayNotification = function (editor, message) { editor.notificationManager.open({ text: editor.translate(message), type: 'info' }); }; var togglePlainTextPaste = function (editor, clipboard, userIsInformedState) { if (clipboard.pasteFormat.get() === 'text') { clipboard.pasteFormat.set('html'); Events.firePastePlainTextToggle(editor, false); } else { clipboard.pasteFormat.set('text'); Events.firePastePlainTextToggle(editor, true); if (shouldInformUserAboutPlainText(editor, userIsInformedState)) { displayNotification(editor, 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.'); userIsInformedState.set(true); } } editor.focus(); }; var Actions = { togglePlainTextPaste: togglePlainTextPaste }; var register = function (editor, clipboard, userIsInformedState) { editor.addCommand('mceTogglePlainTextPaste', function () { Actions.togglePlainTextPaste(editor, clipboard, userIsInformedState); }); editor.addCommand('mceInsertClipboardContent', function (ui, value) { if (value.content) { clipboard.pasteHtml(value.content, value.internal); } if (value.text) { clipboard.pasteText(value.text); } }); }; var Commands = { register: register }; var global$2 = tinymce.util.Tools.resolve('tinymce.Env'); var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay'); var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools'); var global$5 = tinymce.util.Tools.resolve('tinymce.util.VK'); var internalMimeType = 'x-tinymce/html'; var internalMark = ''; var mark = function (html) { return internalMark + html; }; var unmark = function (html) { return html.replace(internalMark, ''); }; var isMarked = function (html) { return html.indexOf(internalMark) !== -1; }; var InternalHtml = { mark: mark, unmark: unmark, isMarked: isMarked, internalHtmlMime: function () { return internalMimeType; } }; var global$6 = tinymce.util.Tools.resolve('tinymce.html.Entities'); var isPlainText = function (text) { return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text); }; var toBRs = function (text) { return text.replace(/\r?\n/g, '
'); }; var openContainer = function (rootTag, rootAttrs) { var key; var attrs = []; var tag = '<' + rootTag; if (typeof rootAttrs === 'object') { for (key in rootAttrs) { if (rootAttrs.hasOwnProperty(key)) { attrs.push(key + '="' + global$6.encodeAllRaw(rootAttrs[key]) + '"'); } } if (attrs.length) { tag += ' ' + attrs.join(' '); } } return tag + '>'; }; var toBlockElements = function (text, rootTag, rootAttrs) { var blocks = text.split(/\n\n/); var tagOpen = openContainer(rootTag, rootAttrs); var tagClose = ''; var paragraphs = global$4.map(blocks, function (p) { return p.split(/\n/).join('
'); }); var stitch = function (p) { return tagOpen + p + tagClose; }; return paragraphs.length === 1 ? paragraphs[0] : global$4.map(paragraphs, stitch).join(''); }; var convert = function (text, rootTag, rootAttrs) { return rootTag ? toBlockElements(text, rootTag, rootAttrs) : toBRs(text); }; var Newlines = { isPlainText: isPlainText, convert: convert, toBRs: toBRs, toBlockElements: toBlockElements }; var global$7 = tinymce.util.Tools.resolve('tinymce.html.DomParser'); var global$8 = tinymce.util.Tools.resolve('tinymce.html.Serializer'); var global$9 = tinymce.util.Tools.resolve('tinymce.html.Node'); var global$a = tinymce.util.Tools.resolve('tinymce.html.Schema'); function filter(content, items) { global$4.each(items, function (v) { if (v.constructor === RegExp) { content = content.replace(v, ''); } else { content = content.replace(v[0], v[1]); } }); return content; } function innerText(html) { var schema = global$a(); var domParser = global$7({}, schema); var text = ''; var shortEndedElements = schema.getShortEndedElements(); var ignoreElements = global$4.makeMap('script noscript style textarea video audio iframe object', ' '); var blockElements = schema.getBlockElements(); function walk(node) { var name = node.name, currentNode = node; if (name === 'br') { text += '\n'; return; } if (name === 'wbr') { return; } if (shortEndedElements[name]) { text += ' '; } if (ignoreElements[name]) { text += ' '; return; } if (node.type === 3) { text += node.value; } if (!node.shortEnded) { if (node = node.firstChild) { do { walk(node); } while (node = node.next); } } if (blockElements[name] && currentNode.next) { text += '\n'; if (name === 'p') { text += '\n'; } } } html = filter(html, [//g]); walk(domParser.parse(html)); return text; } function trimHtml(html) { function trimSpaces(all, s1, s2) { if (!s1 && !s2) { return ' '; } return '\xA0'; } html = filter(html, [ /^[\s\S]*]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig, /|/g, [ /( ?)\u00a0<\/span>( ?)/g, trimSpaces ], /
/g, /
$/i ]); return html; } function createIdGenerator(prefix) { var count = 0; return function () { return prefix + count++; }; } var isMsEdge = function () { return domGlobals.navigator.userAgent.indexOf(' Edge/') !== -1; }; var Utils = { filter: filter, innerText: innerText, trimHtml: trimHtml, createIdGenerator: createIdGenerator, isMsEdge: isMsEdge }; function isWordContent(content) { return / 1) { currentListNode.attr('start', '' + start); } paragraphNode.wrap(currentListNode); } else { currentListNode.append(paragraphNode); } paragraphNode.name = 'li'; if (level > lastLevel && prevListNode) { prevListNode.lastChild.append(currentListNode); } lastLevel = level; removeIgnoredNodes(paragraphNode); trimListStart(paragraphNode, /^\u00a0+/); trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/); trimListStart(paragraphNode, /^\u00a0+/); } var elements = []; var child = node.firstChild; while (typeof child !== 'undefined' && child !== null) { elements.push(child); child = child.walk(); if (child !== null) { while (typeof child !== 'undefined' && child.parent !== node) { child = child.walk(); } } } for (var i = 0; i < elements.length; i++) { node = elements[i]; if (node.name === 'p' && node.firstChild) { var nodeText = getText(node); if (isBulletList(nodeText)) { convertParagraphToLi(node, 'ul'); continue; } if (isNumericList(nodeText)) { var matches = /([0-9]+)\./.exec(nodeText); var start = 1; if (matches) { start = parseInt(matches[1], 10); } convertParagraphToLi(node, 'ol', start); continue; } if (node._listLevel) { convertParagraphToLi(node, 'ul', 1); continue; } currentListNode = null; } else { prevListNode = currentListNode; currentListNode = null; } } } function filterStyles(editor, validStyles, node, styleValue) { var outputStyles = {}, matches; var styles = editor.dom.parseStyle(styleValue); global$4.each(styles, function (value, name) { switch (name) { case 'mso-list': matches = /\w+ \w+([0-9]+)/i.exec(styleValue); if (matches) { node._listLevel = parseInt(matches[1], 10); } if (/Ignore/i.test(value) && node.firstChild) { node._listIgnore = true; node.firstChild._listIgnore = true; } break; case 'horiz-align': name = 'text-align'; break; case 'vert-align': name = 'vertical-align'; break; case 'font-color': case 'mso-foreground': name = 'color'; break; case 'mso-background': case 'mso-highlight': name = 'background'; break; case 'font-weight': case 'font-style': if (value !== 'normal') { outputStyles[name] = value; } return; case 'mso-element': if (/^(comment|comment-list)$/i.test(value)) { node.remove(); return; } break; } if (name.indexOf('mso-comment') === 0) { node.remove(); return; } if (name.indexOf('mso-') === 0) { return; } if (Settings.getRetainStyleProps(editor) === 'all' || validStyles && validStyles[name]) { outputStyles[name] = value; } }); if (/(bold)/i.test(outputStyles['font-weight'])) { delete outputStyles['font-weight']; node.wrap(new global$9('b', 1)); } if (/(italic)/i.test(outputStyles['font-style'])) { delete outputStyles['font-style']; node.wrap(new global$9('i', 1)); } outputStyles = editor.dom.serializeStyle(outputStyles, node.name); if (outputStyles) { return outputStyles; } return null; } var filterWordContent = function (editor, content) { var retainStyleProperties, validStyles; retainStyleProperties = Settings.getRetainStyleProps(editor); if (retainStyleProperties) { validStyles = global$4.makeMap(retainStyleProperties.split(/[, ]/)); } content = Utils.filter(content, [ /
/gi, /]+id="?docs-internal-[^>]*>/gi, //gi, /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi, [ /<(\/?)s>/gi, '<$1strike>' ], [ / /gi, '\xA0' ], [ /([\s\u00a0]*)<\/span>/gi, function (str, spaces) { return spaces.length > 0 ? spaces.replace(/./, ' ').slice(Math.floor(spaces.length / 2)).split('').join('\xA0') : ''; } ] ]); var validElements = Settings.getWordValidElements(editor); var schema = global$a({ valid_elements: validElements, valid_children: '-li[p]' }); global$4.each(schema.elements, function (rule) { if (!rule.attributes.class) { rule.attributes.class = {}; rule.attributesOrder.push('class'); } if (!rule.attributes.style) { rule.attributes.style = {}; rule.attributesOrder.push('style'); } }); var domParser = global$7({}, schema); domParser.addAttributeFilter('style', function (nodes) { var i = nodes.length, node; while (i--) { node = nodes[i]; node.attr('style', filterStyles(editor, validStyles, node, node.attr('style'))); if (node.name === 'span' && node.parent && !node.attributes.length) { node.unwrap(); } } }); domParser.addAttributeFilter('class', function (nodes) { var i = nodes.length, node, className; while (i--) { node = nodes[i]; className = node.attr('class'); if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) { node.remove(); } node.attr('class', null); } }); domParser.addNodeFilter('del', function (nodes) { var i = nodes.length; while (i--) { nodes[i].remove(); } }); domParser.addNodeFilter('a', function (nodes) { var i = nodes.length, node, href, name; while (i--) { node = nodes[i]; href = node.attr('href'); name = node.attr('name'); if (href && href.indexOf('#_msocom_') !== -1) { node.remove(); continue; } if (href && href.indexOf('file://') === 0) { href = href.split('#')[1]; if (href) { href = '#' + href; } } if (!href && !name) { node.unwrap(); } else { if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) { node.unwrap(); continue; } node.attr({ href: href, name: name }); } } }); var rootNode = domParser.parse(content); if (Settings.shouldConvertWordFakeLists(editor)) { convertFakeListsToProperLists(rootNode); } content = global$8({ validate: editor.settings.validate }, schema).serialize(rootNode); return content; }; var preProcess = function (editor, content) { return Settings.shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content; }; var WordFilter = { preProcess: preProcess, isWordContent: isWordContent }; var preProcess$1 = function (editor, html) { var parser = global$7({}, editor.schema); parser.addNodeFilter('meta', function (nodes) { global$4.each(nodes, function (node) { return node.remove(); }); }); var fragment = parser.parse(html, { forced_root_block: false, isRootContent: true }); return global$8({ validate: editor.settings.validate }, editor.schema).serialize(fragment); }; var processResult = function (content, cancelled) { return { content: content, cancelled: cancelled }; }; var postProcessFilter = function (editor, html, internal, isWordHtml) { var tempBody = editor.dom.create('div', { style: 'display:none' }, html); var postProcessArgs = Events.firePastePostProcess(editor, tempBody, internal, isWordHtml); return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented()); }; var filterContent = function (editor, content, internal, isWordHtml) { var preProcessArgs = Events.firePastePreProcess(editor, content, internal, isWordHtml); var filteredContent = preProcess$1(editor, preProcessArgs.content); if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) { return postProcessFilter(editor, filteredContent, internal, isWordHtml); } else { return processResult(filteredContent, preProcessArgs.isDefaultPrevented()); } }; var process = function (editor, html, internal) { var isWordHtml = WordFilter.isWordContent(html); var content = isWordHtml ? WordFilter.preProcess(editor, html) : html; return filterContent(editor, content, internal, isWordHtml); }; var ProcessFilters = { process: process }; var pasteHtml = function (editor, html) { editor.insertContent(html, { merge: Settings.shouldMergeFormats(editor), p