From 38f95f4d8f85e240bc8203d3556f4a9c9fbfeddc Mon Sep 17 00:00:00 2001 From: Andi Dittrich Date: Sat, 25 Apr 2020 19:05:05 +0200 Subject: [PATCH] added new editor filters #251 --- CHANGES.md | 3 ++ README.md | 38 ++------------------ modules/editor/EditorConfig.php | 20 ++++++++--- resources/tinymce/enlighterjs.tinymce.min.js | 4 +-- 4 files changed, 23 insertions(+), 42 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6537d6f..0a7f4df 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * Added: EnlighterJS `v3.3.0` * Added: EnlighterJS Theme-Customizer `v2.2.0` * Added: compatbility mode for [CodeColorer](https://wordpress.org/support/plugin/codecolorer/) . features requested [by ajtruckle on GitHub](https://github.com/EnlighterJS/Plugin.WordPress/issues/222) +* Added: filters to alter the editor config (Gutenberg+TinyMCE) - features requested [by ajtruckle on GitHub](https://github.com/EnlighterJS/Plugin.WordPress/issues/251) * Bugfix: added missing languages to the list (abap,scala,qml,verilog) * Added: [apachehttpd/htaccess](https://httpd.apache.org/docs/2.4/configuring.html) support @@ -25,6 +26,8 @@ * Changed: removed tab "fonts" * Bugfix: highlighted-line hover selector was invalid -> selection of `background-color:hover` was not possible - thanks to [ajtruckle on GitHub](https://github.com/EnlighterJS/Plugin.ThemeCustomizer/issues/4) #4 +* Bugfix: removed typos in code edit dialog - thanks to [ajtruckle on GitHub](https://github.com/EnlighterJS/Plugin.TinyMCE/issues/10) + ### 4.1.0 ### diff --git a/README.md b/README.md index c1c1615..2f4d4a5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Tags: syntax highlighting, javascript, code, coding, sourcecode, mootools, jquer Donate link: https://enlighterjs.org Requires at least: 5.0 Tested up to: 5.4 -Stable tag: 4.1.0 +Stable tag: 4.2.0 License: GPL-2.0 License URI: https://opensource.org/licenses/gpl-2.0.php @@ -31,7 +31,7 @@ It also supports the automatic creation of tab-panes to display code-groups toge * Powerful generic highlighting engine for unknown languages * Theme Customizer * Inline Syntax Highlighting -* Advanced configuration options (CDN usage, ..) are available within the options page. +* Advanced configuration options are available within the options page. * Supports code-groups (displays multiple code-blocks within a tab-pane) * Extensible language and theme engines - add your own one. * Simple CSS based themes @@ -131,40 +131,6 @@ All modern webbrowsers with enabled Javascript and HTML5 capabilities for "data- ### 4.2 ### Everything has been changed - read enlighterjs.org/wp-v4 before upgrading - THIS RELEASE IS NOT BACKWARD COMPATIBLE -### 4.1 ### -Everything has been changed - read enlighterjs.org/wp-v4 before upgrading - THIS RELEASE IS NOT BACKWARD COMPATIBLE - -### 4.0 ### -Everything has been changed - read enlighterjs.org/wp-v4 before upgrading - THIS RELEASE IS NOT BACKWARD COMPATIBLE - -### 3.3 ### -PHP 5.3 Backward Compatibility - -### 3.0 ### -New fault-tolerant Shortcode-Processor is integrated. You can switch back to the old one on the Enlighter Settings Page -> Editing -> Shortcode - -### 2.11 ### -Bugfix Release (initialization may fail when upgrading to 2.10) - -### 2.9 ### -Bugfix Release (TinyMCE and EnlighterJS Core) - -### 2.6 ### -Renamed the EnlighterJS files to `EnlighterJS.min.css` and `EnlighterJS.min.js`. In case you have applied custom modifications these changes may broke your setup and you need to change it! -Added [EnlighterJS v2.5](https://enlighterjs.org/) with some optimization. - -### 2.4 ### -Removed WordPress 3.8 Visual Editor compatibility - Enlighter now requires WordPress >= 3.9 including TinyMCE 4 - -### 2.2 ### -Full Visual-Editor (TinyMCE4) Integration including codeblock-settings (WordPress >= 3.9 required) - -### 2.0 ### -Added Inline-Syntax-Highlighting as well as some other cool feature - please go to the settings page and click "Apply Settings" - -### 1.8 ### -Added Visual-Editor (TinyMCE) Integration (will avoid auto-whitespace-removing issues) - ## Frequently Asked Questions ## The WordPress plugin [related FAQ page](https://github.com/EnlighterJS/documentation/blob/master/wordpress/FAQ.md) is available [on GitHub](https://github.com/EnlighterJS/documentation/blob/master/wordpress/FAQ.md) within the documentation repository! \ No newline at end of file diff --git a/modules/editor/EditorConfig.php b/modules/editor/EditorConfig.php index b7557f7..1d10aac 100644 --- a/modules/editor/EditorConfig.php +++ b/modules/editor/EditorConfig.php @@ -27,10 +27,16 @@ public function __construct($config, $ejs, $languageManager, $themeManager){ } public function getEditorConfigCode(){ + // filtered languages + $languages = apply_filters('enlighter_editor_languages', $this->_languageManager->getLanguages()); + + // filtered themes + $themes = apply_filters('enlighter_editor_themes', $this->_themeManager->getThemes()); + // create config object - return 'EnlighterJS_EditorConfig = ' . json_encode(array( - 'languages' => $this->_languageManager->getLanguages(), - 'themes' => $this->_themeManager->getThemes(), + $config = array( + 'languages' => $languages, + 'themes' => $themes, 'config' => $this->_enlighterjs->getConfig(), 'tinymce' => array( 'tabIndentation' => $this->_config['tinymce-tabindentation'], @@ -39,6 +45,12 @@ public function getEditorConfigCode(){ 'text' => array( 'quicktags' => $this->_config['quicktag-mode'] ) - )) . ';'; + ); + + // apply config + $config = apply_filters('enlighter_editor_config', $config); + + // create config object + return 'EnlighterJS_EditorConfig = ' . json_encode($config) . ';'; } } \ No newline at end of file diff --git a/resources/tinymce/enlighterjs.tinymce.min.js b/resources/tinymce/enlighterjs.tinymce.min.js index f164028..5e07fd6 100644 --- a/resources/tinymce/enlighterjs.tinymce.min.js +++ b/resources/tinymce/enlighterjs.tinymce.min.js @@ -1,2 +1,2 @@ -/*! EnlighterJS TinyMCE Plugin 4.0.0 | Mozilla Public License 2.0 | https://tinymce.enlighterjs.org */ -!function(){"use strict";var e=window.console||{},t=(e.error?e.error.bind(e):null)||function(){};if("undefined"==typeof EnlighterJS_EditorConfig)return void t("No EnlighterJS Config found");if("undefined"==typeof tinymce)return void t("TinyMCE not loaded");var n=tinymce,i=EnlighterJS_EditorConfig,l=function(e,t){var l=function(t){return"PRE"==t.nodeName&&e.dom.hasClass(t,"EnlighterJSRAW")},a=function(t){return"CODE"==t.nodeName&&e.dom.hasClass(t,"EnlighterJSRAW")},o=function(t){return("CODE"==t.nodeName||"PRE"==t.nodeName)&&e.dom.hasClass(t,"EnlighterJSRAW")},r=function(e,t){var i=[];return null!==t&&i.push({text:"Standard ("+t+")",value:null}),n.each(e,function(e,t){i.push({text:e,value:t})}),i},d=r(i.languages,null),s=r(i.themes,i.config.theme),g={open:function(t,n){t.onsubmit=n,e.windowManager.open(t)}},u={show:function(t,n){u.hide();var i=e.dom.create("div",{id:"EnlighterToolbar","data-mce-bogus":"1",contenteditable:!1}),l=e.dom.create("div",{"class":"editicon","data-mce-bogus":"1",contenteditable:!1});i.appendChild(l),e.dom.bind(i,"mousedown",function(e){e.stopPropagation(),n()}),e.getBody().appendChild(i);var a=e.dom.getRect(t);e.dom.setStyles(i,{top:a.y,left:a.x,width:a.w})},hide:function(){var t=e.dom.get("EnlighterToolbar");t&&e.dom.remove(t)}},c=function(e,t){return{title:"Code Settings - EnlighterJS Syntax Highlighter",minWidth:700,body:[{type:"listbox",name:"mode",label:"Mode",values:[{text:"Block-Code",value:"block"},{text:"Inline-Code",value:"inline"}],value:e.mode,style:"direction: ltr; text-align: left"},{type:"listbox",name:"language",label:"Language",values:d,value:e.language,style:"direction: ltr; text-align: left"},{type:"listbox",name:"theme",label:"Theme",values:s,value:e.theme,style:"direction: ltr; text-align: left"},{type:"checkbox",name:"linenums",label:"Show Linenumbers",checked:e.linenumbers,disabled:t},{type:"textbox",name:"highlight",label:"Point out Lines (e.g. 1,2-6,9)",multiline:!1,value:e.highlight,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"offset",label:"Linennumber offset (e.g. 5)",multiline:!1,value:e.lineoffset,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"group",label:"Codegroup Identifier",multiline:!1,value:e.group,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"title",label:"Codegroup Title",multiline:!1,value:e.title,disabled:t,style:"direction: ltr; text-align: left"}]}},h=function(e,t){return{title:"Code Insert - EnlighterJS Syntax Highlighter",layout:"flex",direction:"column",align:"stretch",width:e-50,height:t-150,body:[{type:"listbox",name:"lang",label:"Language",values:d,style:"direction: ltr; text-align: left"},{type:"listbox",name:"mode",label:"Mode",values:[{text:"Block-Code",value:"block"},{text:"Inline-Code",value:"inline"}],value:"block",style:"direction: ltr; text-align: left"},{type:"checkbox",name:"indentation",label:"Left-Align Indentation",checked:i.config.indent>0,disabled:i.config.indent<0},{type:"checkbox",name:"addspaces",label:"Surround with spaces",checked:!1,disabled:!1},{type:"textbox",name:"code",flex:1,multiline:!0,spellcheck:!1,style:"direction: ltr; text-align: left",classes:"monospace",autofocus:!0}]}},f=function(){var t=e.dom.getViewPort(),l=Math.min(t.w,window.innerWidth)||700,a=Math.min(t.h,window.innerHeight)||500;g.open(h(l,a),function(t){var l=t.data.code.replace(/\r\n/gim,"\n"),a="inline"==t.data.mode?"code":"pre";if("block"==t.data.mode&&t.data.indentation){l=l.replace(/^(\t*)/gim,function(e,t,n,l){return new Array(i.config.indent*t.length+1).join(" ")});for(var o=99999,r=l.split("\n"),d=0;d0){var g=s.match(/^( *)/gim);if(!g||1!=g.length){o=0;break}o=Math.min(g[0].length,o)}}if(o>0&&o<99999){var u=new RegExp("^( ){"+o+"}","gmi");l=l.replace(u,"")}}l=n.html.Entities.encodeAllRaw(l);var c=t.data.addspaces?" ":"";e.insertContent(c+"<"+a+' class="EnlighterJSRAW" data-enlighter-language="'+t.data.lang+'">'+l+""+c+"

")})},m=function(t,n){if(o(t)){var l=a(e.selection.getNode())?"inline":"block";if(n.mode!=l){var r=e.dom.create("block"==n.mode?"pre":"code",{"class":"EnlighterJSRAW"});e.dom.replace(r,t,!0),t=r}var d=function(e){n[e]?t.setAttribute("data-enlighter-"+e,n[e]):t.removeAttribute("data-enlighter-"+e)};d("language"),d("theme"),d("highlight"),d("lineoffset"),d("group"),d("title"),n.linenumbers==i.config.linenumbers?t.removeAttribute("data-enlighter-linenumbers"):t.setAttribute("data-enlighter-linenumbers",n.linenumbers?"true":"false")}},b=function(e,t){if(!o(e))return{};var n=e.getAttribute("data-enlighter-linenumbers");return{language:e.getAttribute("data-enlighter-language"),linenumbers:null==n?i.config.linenumbers:"true"==n,highlight:e.getAttribute("data-enlighter-highlight"),lineoffset:e.getAttribute("data-enlighter-lineoffset"),theme:e.getAttribute("data-enlighter-theme"),group:e.getAttribute("data-enlighter-group"),title:e.getAttribute("data-enlighter-title"),mode:t?"inline":"block"}},p=function(){var t=e.selection.getNode(),n=a(t),i=b(t,n);g.open(c(i,n),function(e){m(t,{language:e.data.language,linenumbers:e.data.linenums,highlight:e.data.highlight,lineoffset:e.data.offset,theme:e.data.theme,title:e.data.title,group:e.data.group,mode:e.data.mode})})},v=!1;e.on("PastePreProcess",function(e){v&&(e.stopPropagation(),e.content=e.content.replace(/^\s*([\s\S]+)<\/pre>\s*$/gi,"$2").replace(/\n/g,"
").replace(/ /g," ").replace(//g,"").replace(/<\/span>/g,""))});var y=null;e.on("NodeChange",function(t){t.stopPropagation();var n=e.selection.getNode();l(n)?(u.show(n,p),v=!0):(u.hide(),v=!1),y&&(o(n)?y.disabled(!1):y.disabled(!0))}),e.addButton("EnlighterInsert",{title:"Code Insert",image:t+"/code-insert-icon.png",onclick:f}),e.addButton("EnlighterEdit",{title:"Code Settings",disabled:!0,image:t+"/code-edit-icon.png",onPostRender:function(){y=this},onclick:p}),i.tinymce.keyboardShortcuts===!0&&e.on("init",function(){e.shortcuts.remove("access+x"),e.shortcuts.add("access+x","Enlighter inline code",function(){e.formatter.toggle("enlighterjs_inlinecode")}),e.formatter.register("enlighterjs_inlinecode",{inline:"code",classes:"EnlighterJSRAW",attributes:{"data-enlighter-language":"generic"}})});var x=i.config.indent,C=x>0?new Array(x+1).join(" "):null;i.tinymce.tabIndentation===!0&&null!==C&&(e.on("KeyUp",function(e){v&&(9!==e.keyCode||e.ctrlKey||e.altKey||e.metaKey||e.preventDefault())}),e.on("KeyPress KeyDown",function(t){if(v&&!(9!==t.keyCode||t.ctrlKey||t.altKey||t.metaKey||t.isDefaultPrevented())){t.preventDefault();var n=e.selection.getRng(!0),i=e.selection.getNode(),l=i.textContent,a=l.substring(0,n.startOffset).split("\n").length-1,o=l.substring(0,n.endOffset).split("\n").length-1,r=l.substring(0,n.startOffset).lastIndexOf("\n")+1,d=l.split("\n"),s=0;if(t.shiftKey)for(var g=a;g<=o;g++){var u=d[g].replace(/^(\s*).*?$/,"$1").length,c=Math.min(u,x),h=d[g].substr(c);d[g]=h,s+=h.length+1}else for(var g=a;g<=o;g++){var h=C+d[g];d[g]=h,s+=h.length+1}i.textContent=d.join("\n"),n.setStart(i.firstChild,r),n.setEnd(i.firstChild,r+s-1),e.selection.setRng(n)}}))};n.PluginManager.add("enlighterjs",l)}(); \ No newline at end of file +/*! EnlighterJS TinyMCE Plugin 5.0.1 | Mozilla Public License 2.0 | https://tinymce.enlighterjs.org */ +!function(){"use strict";var e=window.console||{},t=(e.error?e.error.bind(e):null)||function(){};if("undefined"!=typeof EnlighterJS_EditorConfig)if("undefined"!=typeof tinymce){var c=tinymce,u=EnlighterJS_EditorConfig;c.PluginManager.add("enlighterjs",function(h,e){function a(e){return"CODE"==e.nodeName&&h.dom.hasClass(e,"EnlighterJSRAW")}function o(e){return("CODE"==e.nodeName||"PRE"==e.nodeName)&&h.dom.hasClass(e,"EnlighterJSRAW")}function t(e,t){var n=[];return null!==t&&n.push({text:"Standard ("+t+")",value:null}),c.each(e,function(e,t){n.push({text:e,value:t})}),n}function i(){var e,t,n=h.selection.getNode(),i=a(n),l=function(e,t){if(!o(e))return{};var n=e.getAttribute("data-enlighter-linenumbers");return{language:e.getAttribute("data-enlighter-language"),linenumbers:null==n?u.config.linenumbers:"true"==n,highlight:e.getAttribute("data-enlighter-highlight"),lineoffset:e.getAttribute("data-enlighter-lineoffset"),theme:e.getAttribute("data-enlighter-theme"),group:e.getAttribute("data-enlighter-group"),title:e.getAttribute("data-enlighter-title"),mode:t?"inline":"block"}}(n,i);s((t=i,{title:"Code Settings - EnlighterJS Syntax Highlighter",minWidth:700,body:[{type:"listbox",name:"mode",label:"Mode",values:[{text:"Block-Code",value:"block"},{text:"Inline-Code",value:"inline"}],value:(e=l).mode,style:"direction: ltr; text-align: left"},{type:"listbox",name:"language",label:"Language",values:r,value:e.language,style:"direction: ltr; text-align: left"},{type:"listbox",name:"theme",label:"Theme",values:d,value:e.theme,style:"direction: ltr; text-align: left"},{type:"checkbox",name:"linenums",label:"Show line numbers",checked:e.linenumbers,disabled:t},{type:"textbox",name:"offset",label:"Line number offset",multiline:!1,value:e.lineoffset,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"highlight",label:"Highlight lines (e.g. 1,2-6,9)",multiline:!1,value:e.highlight,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"group",label:"Codegroup identifier",multiline:!1,value:e.group,disabled:t,style:"direction: ltr; text-align: left"},{type:"textbox",name:"title",label:"Codegroup title",multiline:!1,value:e.title,disabled:t,style:"direction: ltr; text-align: left"}]}),function(e){!function(t,n){if(o(t)){var e=a(h.selection.getNode())?"inline":"block";if(n.mode!=e){var i=h.dom.create("block"==n.mode?"pre":"code",{class:"EnlighterJSRAW"});h.dom.replace(i,t,!0),t=i}var l=function(e){n[e]?t.setAttribute("data-enlighter-"+e,n[e]):t.removeAttribute("data-enlighter-"+e)};l("language"),l("theme"),l("highlight"),l("lineoffset"),l("group"),l("title"),n.linenumbers==u.config.linenumbers?t.removeAttribute("data-enlighter-linenumbers"):t.setAttribute("data-enlighter-linenumbers",n.linenumbers?"true":"false")}}(n,{language:e.data.language,linenumbers:e.data.linenums,highlight:e.data.highlight,lineoffset:e.data.offset,theme:e.data.theme,title:e.data.title,group:e.data.group,mode:e.data.mode})})}var r=t(u.languages,null),d=t(u.themes,u.config.theme),s=function(e,t){e.onsubmit=t,h.windowManager.open(e)},g={show:function(t,n){g.hide();var e=h.dom.create("div",{id:"EnlighterToolbar","data-mce-bogus":"1",contenteditable:!1}),i=h.dom.create("div",{class:"editicon","data-mce-bogus":"1",contenteditable:!1});e.appendChild(i),h.dom.bind(i,"mousedown",function(e){e.stopPropagation(),n()});var l=h.dom.create("div",{class:"deleteicon","data-mce-bogus":"1",contenteditable:!1});e.appendChild(l),h.dom.bind(l,"mousedown",function(e){e.stopPropagation(),console.log("DELETE NODE"),h.windowManager.confirm("Do you want to delete the current codeblock?",function(e){e&&t.remove()})}),h.getBody().appendChild(e);var a=h.dom.getRect(t);h.dom.setStyles(e,{top:a.y,left:a.x,width:a.w})},hide:function(){var e=h.dom.get("EnlighterToolbar");e&&h.dom.remove(e)}},f=!1;h.on("PastePreProcess",function(e){f&&(e.stopPropagation(),e.content=e.content.replace(/^\s*([\s\S]+)<\/pre>\s*$/gi,"$2").replace(/\n/g,"
").replace(/ /g," ").replace(//g,"").replace(/<\/span>/g,""))});var l=null;h.on("NodeChange",function(e){e.stopPropagation();var t,n=h.selection.getNode();f="PRE"==(t=n).nodeName&&h.dom.hasClass(t,"EnlighterJSRAW")?(g.show(n,i),!0):(g.hide(),!1),l&&(o(n)?l.disabled(!1):l.disabled(!0))}),h.addButton("EnlighterInsert",{title:"Code Insert",image:e+"/code-insert-icon.png",onclick:function(){var e=h.dom.getViewPort(),t=Math.min(e.w,window.innerWidth)||700,n=Math.min(e.h,window.innerHeight)||500;s({title:"Code Insert - EnlighterJS Syntax Highlighter",layout:"flex",direction:"column",align:"stretch",width:t-50,height:n-150,body:[{type:"listbox",name:"lang",label:"Language",values:r,style:"direction: ltr; text-align: left"},{type:"listbox",name:"mode",label:"Mode",values:[{text:"Block-Code",value:"block"},{text:"Inline-Code",value:"inline"}],value:"block",style:"direction: ltr; text-align: left"},{type:"checkbox",name:"indentation",label:"Left-align indentation",checked:0'+t+""+s+"

")})}}),h.addButton("EnlighterEdit",{title:"Code Settings",disabled:!0,image:e+"/code-edit-icon.png",onPostRender:function(){l=this},onclick:i}),!0===u.tinymce.keyboardShortcuts&&h.on("init",function(){h.shortcuts.remove("access+x"),h.shortcuts.add("access+x","Enlighter inline code",function(){h.formatter.toggle("enlighterjs_inlinecode")}),h.formatter.register("enlighterjs_inlinecode",{inline:"code",classes:"EnlighterJSRAW",attributes:{"data-enlighter-language":"generic"}})});var m=u.config.indent,b=0