Mercurial Hosting > sceditor
comparison src/sceditor.js @ 46:ab2dc8736d88
fix paste html and cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 30 Aug 2022 14:33:27 -0600 |
parents | bc1bce78276d |
children |
comparison
equal
deleted
inserted
replaced
45:bc1bce78276d | 46:ab2dc8736d88 |
---|---|
2593 appendChild(content, line); | 2593 appendChild(content, line); |
2594 | 2594 |
2595 perLine = Math.sqrt(Object.keys(emoticons).length); | 2595 perLine = Math.sqrt(Object.keys(emoticons).length); |
2596 | 2596 |
2597 onEvent1(content, 'click', 'img', function (target, e) { | 2597 onEvent1(content, 'click', 'img', function (target, e) { |
2598 editor.insert(targetToHtml(target), null, false); | 2598 editor.insert(targetToHtml(target)); |
2599 editor.closeDropDown(true); | 2599 editor.closeDropDown(true); |
2600 | 2600 |
2601 e.preventDefault(); | 2601 e.preventDefault(); |
2602 }); | 2602 }); |
2603 | 2603 |
4761 if (!command || exclude.indexOf(commandName) > -1) { | 4761 if (!command || exclude.indexOf(commandName) > -1) { |
4762 return; | 4762 return; |
4763 } | 4763 } |
4764 | 4764 |
4765 let shortcut = command.shortcut; | 4765 let shortcut = command.shortcut; |
4766 let icon = command.icon || ''; | 4766 let icon = command.icon || ' '+commandName+' '; |
4767 let button = '<button>' + icon + '</button>'; | 4767 let button = '<button>' + icon + '</button>'; |
4768 button = parseHTML(button).firstChild; | 4768 button = parseHTML(button).firstChild; |
4769 button._sceTxtMode = !!command.txtExec; | 4769 button._sceTxtMode = !!command.txtExec; |
4770 button._sceWysiwygMode = !!command.exec; | 4770 button._sceWysiwygMode = !!command.exec; |
4771 toggleClass(button, 'disabled', !command.exec); | 4771 toggleClass(button, 'disabled', !command.exec); |
5588 fixNesting(pasteArea); | 5588 fixNesting(pasteArea); |
5589 } else { | 5589 } else { |
5590 pasteArea.innerHTML = entities(data.text || ''); | 5590 pasteArea.innerHTML = entities(data.text || ''); |
5591 } | 5591 } |
5592 | 5592 |
5593 var paste = { | 5593 let paste = { |
5594 val: pasteArea.innerHTML | 5594 val: pasteArea.innerHTML |
5595 }; | 5595 }; |
5596 | 5596 |
5597 if ('fragmentToSource' in format) { | 5597 if ('toSource' in format) { |
5598 paste.val = format | 5598 paste.val = format |
5599 .fragmentToSource(paste.val, wysiwygDocument, currentNode); | 5599 .toSource(paste.val, wysiwygDocument, currentNode, true); |
5600 } | 5600 } |
5601 | 5601 |
5602 pluginManager.call('paste', paste); | 5602 pluginManager.call('paste', paste); |
5603 trigger(editorContainer, 'paste', paste); | 5603 trigger(editorContainer, 'paste', paste); |
5604 | 5604 |
5605 if ('toHtml' in format) { | |
5606 paste.val = format | |
5607 .toHtml(paste.val, currentNode, true); | |
5608 } | |
5609 | |
5605 pluginManager.call('pasteHtml', paste); | 5610 pluginManager.call('pasteHtml', paste); |
5606 | 5611 |
5607 var parent = rangeHelper.getFirstBlockParent(); | 5612 let parent = rangeHelper.getFirstBlockParent(); |
5608 base.wysiwygEditorInsertHtml(paste.val, null, true); | 5613 base.wysiwygEditorInsertHtml(paste.val, null, true); |
5609 merge(parent); | 5614 merge(parent); |
5610 }; | 5615 }; |
5611 | 5616 |
5612 /** | 5617 /** |
5895 * If the allowMixed param is set to true, HTML any will not be | 5900 * If the allowMixed param is set to true, HTML any will not be |
5896 * escaped | 5901 * escaped |
5897 * | 5902 * |
5898 * @param {string} start | 5903 * @param {string} start |
5899 * @param {string} [end=null] | 5904 * @param {string} [end=null] |
5900 * @param {boolean} [filter=true] | |
5901 * @param {boolean} [allowMixed=false] | |
5902 * @since 1.4.3 | 5905 * @since 1.4.3 |
5903 * @function | 5906 * @function |
5904 * @name insert^2 | 5907 * @name insert^2 |
5905 */ | 5908 */ |
5906 // eslint-disable-next-line max-params | 5909 // eslint-disable-next-line max-params |
5907 base.insert = function ( | 5910 base.insert = function ( |
5908 start, end, filter, allowMixed | 5911 start, end |
5909 ) { | 5912 ) { |
5910 if (base.inSourceMode()) { | 5913 if (base.inSourceMode()) { |
5911 base.sourceEditorInsertText(start, end); | 5914 base.sourceEditorInsertText(start, end); |
5912 return; | 5915 return; |
5913 } | 5916 } |
5914 | 5917 |
5915 // Add the selection between start and end | 5918 // Add the selection between start and end |
5916 if (end) { | 5919 if (end) { |
5917 var html = rangeHelper.selectedHtml(); | 5920 let html = rangeHelper.selectedHtml(); |
5918 | |
5919 if (filter !== false && 'fragmentToSource' in format) { | |
5920 html = format | |
5921 .fragmentToSource(html, wysiwygDocument, currentNode); | |
5922 } | |
5923 | |
5924 start += html + end; | 5921 start += html + end; |
5925 } | |
5926 | |
5927 // Convert any escaped HTML back into HTML if mixed is allowed | |
5928 if (filter !== false && allowMixed === true) { | |
5929 start = start.replace(/</g, '<') | |
5930 .replace(/>/g, '>') | |
5931 .replace(/&/g, '&'); | |
5932 } | 5922 } |
5933 | 5923 |
5934 base.wysiwygEditorInsertHtml(start); | 5924 base.wysiwygEditorInsertHtml(start); |
5935 }; | 5925 }; |
5936 | 5926 |