Skip to content

Instantly share code, notes, and snippets.

@justin-himself
Last active May 16, 2021 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin-himself/5dd6ff3fe5abfecb544ffe1337afb289 to your computer and use it in GitHub Desktop.
Save justin-himself/5dd6ff3fe5abfecb544ffe1337afb289 to your computer and use it in GitHub Desktop.
Wordpress Plugin Enlighter Style Patch
diff -uprN ./gutenberg.orig/enlighterjs.gutenberg.min.css ./gutenberg/enlighterjs.gutenberg.min.css
--- ./gutenberg.orig/enlighterjs.gutenberg.min.css 2021-05-16 14:30:03.000000000 +0800
+++ ./gutenberg/enlighterjs.gutenberg.min.css 2021-01-06 21:53:16.000000000 +0800
@@ -1 +1,2 @@
-/*! EnlighterJS Syntax Highlighter Gutenberg Plugin 1.1.1 | Mozilla Public License 2.0 | https://enlighterjs.org */div[data-type="enlighter/codeblock"]{border:1px solid #cccbcb;border-radius:5px;padding:15px;padding-block-end:1px}div[data-type="enlighter/codeblock"] .block-editor-plain-text{font-family:Menlo,Consolas,monaco,monospace;font-size:14px;color:#23282d;white-space:pre-wrap;outline:0!important;box-shadow:none!important;transition:none;background-color:#f9f9f9;padding:2px;direction:ltr;text-align:left;border-radius:0}div[data-type="enlighter/codeblock"] .enlighter-header .enlighter-title{font-weight:700}div[data-type="enlighter/codeblock"] .enlighter-footer-label{text-align:right;font-size:10px;font-family:Menlo,Consolas,monaco,monospace;color:#23282d;cursor:pointer;padding-top:3px;font-weight:800}div[data-type="enlighter/codeblock"].is-selected .block-editor-plain-text{background-color:#d1d1d1}.enlighter-dropdownmenu{max-height:500px}.enlighter-popover-inline .enlighter-popover-content{padding:16px}.enlighter-popover-inline .enlighter-popover-buttons{display:flex;justify-content:flex-end}.enlighter-popover-inline .enlighter-popover-footer{padding:5px 16px 5px 5px;border-top:solid 1px #d1d1d1;text-align:right}
\ No newline at end of file
+/*! EnlighterJS Syntax Highlighter Gutenberg Plugin 1.1.1 | Mozilla Public License 2.0 | https://enlighterjs.org */
+div[data-type="enlighter/codeblock"]{border:1px solid #cccbcb;border-radius:5px;max-width:100%;padding:15px}div[data-type="enlighter/codeblock"] .block-editor-plain-text{font-family:Menlo,Consolas,monaco,monospace;font-size:14px;color:#23282d;white-space:pre-wrap;outline:0!important;box-shadow:none!important;transition:none;background-color:#f9f9f9;padding:2px;direction:ltr;text-align:left;border-radius:0}div[data-type="enlighter/codeblock"] .enlighter-header .enlighter-title{font-weight:700}div[data-type="enlighter/codeblock"] .enlighter-footer-label{text-align:right;font-size:10px;font-family:Menlo,Consolas,monaco,monospace;color:#23282d;cursor:pointer}div[data-type="enlighter/codeblock"].is-selected .block-editor-plain-text{background-color:#d1d1d1}.enlighter-dropdownmenu{max-height:500px}.enlighter-popover-inline .enlighter-popover-content{padding:16px}.enlighter-popover-inline .enlighter-popover-buttons{display:flex;justify-content:flex-end}.enlighter-popover-inline .enlighter-popover-footer{padding:5px 16px 5px 5px;border-top:solid 1px #d1d1d1;text-align:right}
\ No newline at end of file
diff -uprN ./gutenberg.orig/enlighterjs.gutenberg.min.js ./gutenberg/enlighterjs.gutenberg.min.js
--- ./gutenberg.orig/enlighterjs.gutenberg.min.js 2021-05-16 11:07:33.000000000 +0800
+++ ./gutenberg/enlighterjs.gutenberg.min.js 2021-01-06 21:53:16.000000000 +0800
@@ -1 +1,2 @@
-var EnlighterJS_Gutenberg=function(e){"use strict";var r=wp.editor,a=wp.components,o=wp.element,i=wp.blockEditor,t=wp.blocks,c=wp.richText,l=wp.escapeHtml,u=r.PlainText,g=EnlighterJS_EditorConfig;function s(){var e={};return Object.assign(e,g.languages),e}function p(e){var t=e.onChange,n=e.value,r=s(),e=Object.keys(r).map(function(e){return{title:r[e],isActive:n===e,onClick:function(){return t(e)}}});return wp.element.createElement(a.DropdownMenu,{className:"enlighter-dropdownmenu",icon:"editor-paste-text",label:"Select Language",controls:e})}function h(e){var t=e.onChange,n=e.value,r=s(),e=Object.keys(r).map(function(e){return{label:r[e],value:e}});return wp.element.createElement(a.SelectControl,{label:"Language",value:n,onChange:t,options:e})}function m(e){var t=e.onChange,n=e.value,r=(e={"":"Global settings ("+g.config.theme+")"},Object.assign(e,g.themes),e),e=Object.keys(r).map(function(e){return{label:r[e],value:e}});return wp.element.createElement(a.SelectControl,{label:"Theme",value:n,onChange:t,options:e})}var n={title:"Enlighter Sourcecode",description:"Syntax highlighting with EnlighterJS.",icon:"editor-code",category:"formatting",keywords:["code","sourcecode","enlighter"],attributes:{content:{type:"string",selector:"pre.EnlighterJSRAW",source:"text"},language:{type:"attribute",attribute:"data-enlighter-language",default:"generic"},theme:{type:"attribute",attribute:"data-enlighter-theme",default:""},highlight:{type:"attribute",attribute:"data-enlighter-highlight",default:""},linenumbers:{type:"attribute",attribute:"data-enlighter-linenumbers",default:""},lineoffset:{type:"attribute",attribute:"data-enlighter-lineoffset",default:""},title:{type:"attribute",attribute:"data-enlighter-title",default:""},group:{type:"attribute",attribute:"data-enlighter-group",default:""}},transforms:{from:[{type:"raw",priority:4,isMatch:function(e){return"PRE"===e.nodeName&&1===e.children.length&&"CODE"===e.firstChild.nodeName},transform:function(e){return t.createBlock("enlighter/codeblock",{content:e.textContent})}},{type:"raw",priority:4,isMatch:function(e){return"PRE"===e.nodeName&&"EnlighterJSRAW"===e.className},transform:function(e){return t.createBlock("enlighter/codeblock",{content:e.textContent,language:e.dataset.enlighterLanguage||"",theme:e.dataset.enlighterTheme||"",highlight:e.dataset.enlighterHighlight||"",linenumbers:e.dataset.enlighterLinenumbers||"",lineoffset:e.dataset.enlighterLineoffset||"",title:e.dataset.enlighterTitle||"",group:e.dataset.enlighterGroup||""})}},{type:"block",blocks:["core/code","core/preformatted","core/paragraph"],transform:function(e){e=e.content;return t.createBlock("enlighter/codeblock",{content:e})}}],to:[{type:"block",blocks:["core/code"],transform:function(e){e=e.content;return t.createBlock("core/code",{content:e})}},{type:"block",blocks:["core/preformatted"],transform:function(e){e=e.content;return t.createBlock("core/preformatted",{content:e})}}]},supports:{customClassName:!0,className:!1,html:!1},edit:function(e){var t=e.attributes,n=e.setAttributes;return wp.element.createElement(o.Fragment,null,wp.element.createElement(r.BlockControls,null,wp.element.createElement(a.Toolbar,null,wp.element.createElement(p,{value:t.language,onChange:function(e){return n({language:e})}}))),wp.element.createElement("div",{className:"enlighter-block-wrapper"},wp.element.createElement("div",{className:"enlighter-header"},wp.element.createElement(u,{value:t.content,onChange:function(e){return n({content:e})},placeholder:"Insert Sourcecode..","aria-label":"Code"}),wp.element.createElement("div",{className:"enlighter-footer"},wp.element.createElement("div",{className:"enlighter-footer-label",},(e=t.language,s()[e]||"Unknown language")))),),wp.element.createElement(r.InspectorControls,null,wp.element.createElement(a.PanelBody,{title:"Appearance",icon:"admin-appearance"},wp.element.createElement("p",null,"Override the global plugin settings of the current block."),wp.element.createElement(h,{value:t.language,onChange:function(e){return n({language:e})}}),wp.element.createElement(a.TextControl,{label:"Speciallines",value:t.highlight,onChange:function(e){return n({highlight:e})},placeholder:"1,2,20-22"}),wp.element.createElement(a.TextControl,{label:"Lineoffset",value:t.lineoffset,onChange:function(e){return n({lineoffset:e})},placeholder:"314"}),wp.element.createElement(m,{value:t.theme,onChange:function(e){return n({theme:e})}}),wp.element.createElement(a.RadioControl,{label:"Linenumbers",selected:t.linenumbers,options:[{label:"Global settings",value:""},{label:"Show",value:"true"},{label:"Hide",value:"false"}],onChange:function(e){return n({linenumbers:e})}})),wp.element.createElement(a.PanelBody,{title:"Codegroup",initialOpen:!1,icon:"excerpt-view"},wp.element.createElement("p",null,"Create a group of multiple codeblocks by setting a unique group identifier."),wp.element.createElement(a.TextControl,{label:"Title",value:t.title,onChange:function(e){return n({title:e})},placeholder:"My Codeblock"}),wp.element.createElement(a.TextControl,{label:"Group Identifier",value:t.group,onChange:function(e){return n({group:e})},placeholder:"mygroup-1"}))))},save:function(e){var t=e.attributes,n=e.className,e="EnlighterJSRAW"+(n?" "+n:""),n=t.content?l.escapeEditableHTML(t.content):null;return wp.element.createElement("pre",{className:e,"data-enlighter-language":t.language,"data-enlighter-theme":t.theme,"data-enlighter-highlight":t.highlight,"data-enlighter-linenumbers":t.linenumbers,"data-enlighter-lineoffset":t.lineoffset,"data-enlighter-title":t.title,"data-enlighter-group":t.group},n)}};function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function v(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function w(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=d(n);return v(this,r?(e=d(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}var y={title:"Enlighter Inline Sourcecode",tagName:"code",className:"EnlighterJSRAW",attributes:{language:"data-enlighter-language"},edit:function(){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(l,o.Component);var e,t,n,r=w(l);function l(){!function(e){if(!(e instanceof l))throw new TypeError("Cannot call a class as a function")}(this);for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.call.apply(r,[this].concat(t))}return e=l,(t=[{key:"createFormat",value:function(e){return{type:"enlighter/richtext-inline",attributes:{language:e}}}},{key:"onChangeLanguage",value:function(e){this.props.onChange(c.applyFormat(this.props.value,this.createFormat(e)))}},{key:"toggleFormatting",value:function(){this.props.onChange(c.toggleFormat(this.props.value,this.createFormat("generic")))}},{key:"render",value:function(){var e=this.props.isActive&&window.getSelection(),t=e&&e.getRangeAt(0),e=this.props.activeAttributes.language||"generic";return wp.element.createElement(o.Fragment,null,wp.element.createElement(i.BlockFormatControls,null,wp.element.createElement(i.RichTextToolbarButton,{icon:"editor-code",title:"Enlighter Inline Code",onClick:this.toggleFormatting.bind(this),isActive:this.props.isActive})),this.props.isActive&&wp.element.createElement(a.Popover,{position:"bottom center",anchorRef:t,className:"enlighter-popover-inline"},wp.element.createElement("div",{className:"enlighter-popover-content"},wp.element.createElement(h,{value:e,onChange:this.onChangeLanguage.bind(this)}),wp.element.createElement("div",{className:"enlighter-popover-buttons"},wp.element.createElement(a.Button,{isSecondary:!0,isSmall:!0,onClick:this.toggleFormatting.bind(this)},"Clear"))),wp.element.createElement("div",{className:"enlighter-popover-footer"},wp.element.createElement("small",null,"EnlighterJS Syntax Highlighter"))))}}])&&f(e.prototype,t),n&&f(e,n),l}()};t.registerBlockType("enlighter/codeblock",n),c.registerFormatType("enlighter/richtext-inline",y);return e.version="1.1.1",Object.defineProperty(e,"__esModule",{value:!0}),e}({});
\ No newline at end of file
+/*! EnlighterJS Syntax Highlighter Gutenberg Plugin 1.1.1 | Mozilla Public License 2.0 | https://enlighterjs.org */
+var EnlighterJS_Gutenberg=function(e){"use strict";var r=wp.editor,a=wp.components,o=wp.element,i=wp.blockEditor,t=wp.blocks,c=wp.richText,l=wp.escapeHtml,u=r.PlainText,g=EnlighterJS_EditorConfig;function s(){var e={};return Object.assign(e,g.languages),e}function p(e){var t=e.onChange,n=e.value,r=s(),e=Object.keys(r).map(function(e){return{title:r[e],isActive:n===e,onClick:function(){return t(e)}}});return wp.element.createElement(a.DropdownMenu,{className:"enlighter-dropdownmenu",icon:"editor-paste-text",label:"Select Language",controls:e})}function h(e){var t=e.onChange,n=e.value,r=s(),e=Object.keys(r).map(function(e){return{label:r[e],value:e}});return wp.element.createElement(a.SelectControl,{label:"Language",value:n,onChange:t,options:e})}function m(e){var t=e.onChange,n=e.value,r=(e={"":"Global settings ("+g.config.theme+")"},Object.assign(e,g.themes),e),e=Object.keys(r).map(function(e){return{label:r[e],value:e}});return wp.element.createElement(a.SelectControl,{label:"Theme",value:n,onChange:t,options:e})}var n={title:"Enlighter Sourcecode",description:"Syntax highlighting with EnlighterJS.",icon:"editor-code",category:"formatting",keywords:["code","sourcecode","enlighter"],attributes:{content:{type:"string",selector:"pre.EnlighterJSRAW",source:"text"},language:{type:"attribute",attribute:"data-enlighter-language",default:"generic"},theme:{type:"attribute",attribute:"data-enlighter-theme",default:""},highlight:{type:"attribute",attribute:"data-enlighter-highlight",default:""},linenumbers:{type:"attribute",attribute:"data-enlighter-linenumbers",default:""},lineoffset:{type:"attribute",attribute:"data-enlighter-lineoffset",default:""},title:{type:"attribute",attribute:"data-enlighter-title",default:""},group:{type:"attribute",attribute:"data-enlighter-group",default:""}},transforms:{from:[{type:"raw",priority:4,isMatch:function(e){return"PRE"===e.nodeName&&1===e.children.length&&"CODE"===e.firstChild.nodeName},transform:function(e){return t.createBlock("enlighter/codeblock",{content:e.textContent})}},{type:"raw",priority:4,isMatch:function(e){return"PRE"===e.nodeName&&"EnlighterJSRAW"===e.className},transform:function(e){return t.createBlock("enlighter/codeblock",{content:e.textContent,language:e.dataset.enlighterLanguage||"",theme:e.dataset.enlighterTheme||"",highlight:e.dataset.enlighterHighlight||"",linenumbers:e.dataset.enlighterLinenumbers||"",lineoffset:e.dataset.enlighterLineoffset||"",title:e.dataset.enlighterTitle||"",group:e.dataset.enlighterGroup||""})}},{type:"block",blocks:["core/code","core/preformatted","core/paragraph"],transform:function(e){e=e.content;return t.createBlock("enlighter/codeblock",{content:e})}}],to:[{type:"block",blocks:["core/code"],transform:function(e){e=e.content;return t.createBlock("core/code",{content:e})}},{type:"block",blocks:["core/preformatted"],transform:function(e){e=e.content;return t.createBlock("core/preformatted",{content:e})}}]},supports:{customClassName:!0,className:!1,html:!1},edit:function(e){var t=e.attributes,n=e.setAttributes;return wp.element.createElement(o.Fragment,null,wp.element.createElement(r.BlockControls,null,wp.element.createElement(a.Toolbar,null,wp.element.createElement(p,{value:t.language,onChange:function(e){return n({language:e})}}))),wp.element.createElement("div",{className:"enlighter-block-wrapper"},wp.element.createElement("div",{className:"enlighter-header"},wp.element.createElement("div",{className:"enlighter-title"},(e=t.language,s()[e]||"Unknown language"))),wp.element.createElement(u,{value:t.content,onChange:function(e){return n({content:e})},placeholder:"Insert Sourcecode..","aria-label":"Code"}),wp.element.createElement("div",{className:"enlighter-footer"},wp.element.createElement("div",{className:"enlighter-footer-label"},wp.element.createElement("strong",null,"EnlighterJS")," Syntax Highlighter"))),wp.element.createElement(r.InspectorControls,null,wp.element.createElement(a.PanelBody,{title:"Appearance",icon:"admin-appearance"},wp.element.createElement("p",null,"Override the global plugin settings of the current block."),wp.element.createElement(h,{value:t.language,onChange:function(e){return n({language:e})}}),wp.element.createElement(a.TextControl,{label:"Speciallines",value:t.highlight,onChange:function(e){return n({highlight:e})},placeholder:"1,2,20-22"}),wp.element.createElement(a.TextControl,{label:"Lineoffset",value:t.lineoffset,onChange:function(e){return n({lineoffset:e})},placeholder:"314"}),wp.element.createElement(m,{value:t.theme,onChange:function(e){return n({theme:e})}}),wp.element.createElement(a.RadioControl,{label:"Linenumbers",selected:t.linenumbers,options:[{label:"Global settings",value:""},{label:"Show",value:"true"},{label:"Hide",value:"false"}],onChange:function(e){return n({linenumbers:e})}})),wp.element.createElement(a.PanelBody,{title:"Codegroup",initialOpen:!1,icon:"excerpt-view"},wp.element.createElement("p",null,"Create a group of multiple codeblocks by setting a unique group identifier."),wp.element.createElement(a.TextControl,{label:"Title",value:t.title,onChange:function(e){return n({title:e})},placeholder:"My Codeblock"}),wp.element.createElement(a.TextControl,{label:"Group Identifier",value:t.group,onChange:function(e){return n({group:e})},placeholder:"mygroup-1"}))))},save:function(e){var t=e.attributes,n=e.className,e="EnlighterJSRAW"+(n?" "+n:""),n=t.content?l.escapeEditableHTML(t.content):null;return wp.element.createElement("pre",{className:e,"data-enlighter-language":t.language,"data-enlighter-theme":t.theme,"data-enlighter-highlight":t.highlight,"data-enlighter-linenumbers":t.linenumbers,"data-enlighter-lineoffset":t.lineoffset,"data-enlighter-title":t.title,"data-enlighter-group":t.group},n)}};function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function v(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function w(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=d(n);return v(this,r?(e=d(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}var y={title:"Enlighter Inline Sourcecode",tagName:"code",className:"EnlighterJSRAW",attributes:{language:"data-enlighter-language"},edit:function(){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(l,o.Component);var e,t,n,r=w(l);function l(){!function(e){if(!(e instanceof l))throw new TypeError("Cannot call a class as a function")}(this);for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.call.apply(r,[this].concat(t))}return e=l,(t=[{key:"createFormat",value:function(e){return{type:"enlighter/richtext-inline",attributes:{language:e}}}},{key:"onChangeLanguage",value:function(e){this.props.onChange(c.applyFormat(this.props.value,this.createFormat(e)))}},{key:"toggleFormatting",value:function(){this.props.onChange(c.toggleFormat(this.props.value,this.createFormat("generic")))}},{key:"render",value:function(){var e=this.props.isActive&&window.getSelection(),t=e&&e.getRangeAt(0),e=this.props.activeAttributes.language||"generic";return wp.element.createElement(o.Fragment,null,wp.element.createElement(i.BlockFormatControls,null,wp.element.createElement(i.RichTextToolbarButton,{icon:"editor-code",title:"Enlighter Inline Code",onClick:this.toggleFormatting.bind(this),isActive:this.props.isActive})),this.props.isActive&&wp.element.createElement(a.Popover,{position:"bottom center",anchorRef:t,className:"enlighter-popover-inline"},wp.element.createElement("div",{className:"enlighter-popover-content"},wp.element.createElement(h,{value:e,onChange:this.onChangeLanguage.bind(this)}),wp.element.createElement("div",{className:"enlighter-popover-buttons"},wp.element.createElement(a.Button,{isSecondary:!0,isSmall:!0,onClick:this.toggleFormatting.bind(this)},"Clear"))),wp.element.createElement("div",{className:"enlighter-popover-footer"},wp.element.createElement("small",null,"EnlighterJS Syntax Highlighter"))))}}])&&f(e.prototype,t),n&&f(e,n),l}()};t.registerBlockType("enlighter/codeblock",n),c.registerFormatType("enlighter/richtext-inline",y);return e.version="1.1.1",Object.defineProperty(e,"__esModule",{value:!0}),e}({});
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment