diff --git a/css/styles-settings.css b/css/styles-settings.css index b3dfe30..ccc1729 100644 --- a/css/styles-settings.css +++ b/css/styles-settings.css @@ -2,21 +2,16 @@ .prismatic-version { color: #c7c7c7; font-size: 90%; } -.wp-admin .prismatic-label { display: block; color: #777; font-style: italic; } -.wp-admin .inline-block { display: inline-block; } +.wp-admin form h2 { margin-top: 20px; } -.wp-admin form h2 { margin-top: 25px; } +.wp-admin .prismatic-label { display: block; margin: 3px 0 0 3px; color: #777; font-size: 13px; font-style: italic; } +.wp-admin .inline-block { display: inline-block; vertical-align: baseline; } +.wp-admin textarea + label { margin: 0 0 0 3px; } -.wp-admin input[type="text"] { width: 55%; } -.wp-admin textarea { width: 77%; } +.wp-admin input[type=checkbox] { margin-top: -3px; } +.wp-admin input[type=checkbox] + label { margin: 0; } -.ui-dialog .ui-dialog-titlebar { font-size: 16px; } -.ui-dialog .ui-dialog-buttonpane, .ui-dialog .ui-dialog-titlebar, .ui-dialog .ui-dialog-content { text-align: center; } +.ui-dialog .ui-dialog-buttonpane, .ui-dialog .ui-dialog-titlebar, .ui-dialog .cfx-modal-dialog { text-align: center; } .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: none; } .ui-dialog .ui-dialog-buttonpane .ui-button { margin: 0; } -.ui-dialog .ui-dialog-buttonpane .ui-button:first-child { margin-right: 15px; } - -@media (max-width: 1000px) { - .wp-admin input[type="text"] { width: 77%; } - .wp-admin textarea { width: 88%; } -} +.ui-dialog .ui-dialog-buttonpane .ui-button:first-child { margin-right: 15px; } \ No newline at end of file diff --git a/inc/prismatic-blocks.php b/inc/prismatic-blocks.php index 1aef8ce..7363e5c 100644 --- a/inc/prismatic-blocks.php +++ b/inc/prismatic-blocks.php @@ -4,6 +4,8 @@ function prismatic_register_block_assets() { global $prismatic_options_general; + if (!function_exists('register_block_type')) return; + $script_url = null; if (isset($prismatic_options_general['library'])) { diff --git a/inc/prismatic-core.php b/inc/prismatic-core.php index ab52b4e..b3d6274 100644 --- a/inc/prismatic-core.php +++ b/inc/prismatic-core.php @@ -142,6 +142,13 @@ function prismatic_add_filters() { add_filter('the_content', 'prismatic_encode', 1); add_filter('the_content', 'prismatic_decode_replace', 3); + if (function_exists('get_fields')) { // ACF + + add_filter('acf/load_value', 'prismatic_encode', 1); + add_filter('acf/load_value', 'prismatic_decode_replace', 3); + + } + } if (prismatic_check_admin($library, 'excerpts')) { diff --git a/inc/resources-enqueue.php b/inc/resources-enqueue.php index 8fb9edf..52fdb24 100644 --- a/inc/resources-enqueue.php +++ b/inc/resources-enqueue.php @@ -117,7 +117,16 @@ function prismatic_prism_enqueue() { wp_enqueue_script('prismatic-prism', PRISMATIC_URL .'lib/prism/js/prism-core.js', array(), null, true); - + if ( + (isset($prismatic_options_prism['show_language']) && $prismatic_options_prism['show_language']) || + (isset($prismatic_options_prism['copy_clipboard']) && $prismatic_options_prism['copy_clipboard']) + ) { + + wp_enqueue_style('prismatic-plugin-styles', PRISMATIC_URL .'lib/prism/css/plugin-styles.css', array(), null, 'all'); + + wp_enqueue_script('prismatic-prism-toolbar', PRISMATIC_URL .'lib/prism/js/plugin-toolbar.js', array('prismatic-prism'), null, true); + + } if (isset($prismatic_options_prism['line_highlight']) && $prismatic_options_prism['line_highlight']) { @@ -137,7 +146,11 @@ function prismatic_prism_enqueue() { } - + if (isset($prismatic_options_prism['copy_clipboard']) && $prismatic_options_prism['copy_clipboard']) { + + wp_enqueue_script('prismatic-copy-clipboard', PRISMATIC_URL .'lib/prism/js/plugin-copy-clipboard.js', array('prismatic-prism'), null, true); + + } $prefix = array('lang-', 'language-'); @@ -155,7 +168,6 @@ function prismatic_prism_enqueue() { } - if (is_admin()) { // todo: once gutenberg is further developed, find a better way to add editor support @@ -250,7 +262,7 @@ function prismatic_active_languages($library) { $content = $post->post_content; - $languages = prismatic_active_languages_loop($library, '', $content, array()); + $languages = prismatic_active_languages_loop($library, '', $content, array(), null); } else { @@ -262,7 +274,9 @@ function prismatic_active_languages($library) { $comments = ($post->comment_count) ? get_comments(array('post_id' => $post->ID, 'status' => 'approve')) : array(); - $languages = prismatic_active_languages_loop($library, $excerpt, $content, $comments); + $fields = function_exists('get_fields') ? get_fields($post->ID) : null; // ACF + + $languages = prismatic_active_languages_loop($library, $excerpt, $content, $comments, $fields); } else { @@ -274,7 +288,7 @@ function prismatic_active_languages($library) { $comments = array(); - $langs_array[] = prismatic_active_languages_loop($library, $excerpt, $content, $comments); + $langs_array[] = prismatic_active_languages_loop($library, $excerpt, $content, $comments, null); } @@ -300,7 +314,7 @@ function prismatic_active_languages($library) { } -function prismatic_active_languages_loop($library, $excerpt, $content, $comments) { +function prismatic_active_languages_loop($library, $excerpt, $content, $comments, $fields) { $languages = array(); @@ -332,6 +346,20 @@ function prismatic_active_languages_loop($library, $excerpt, $content, $comments } + if ($fields) { + + foreach ($fields as $key => $value) { + + if (strpos($value, $cls) !== false) { + + $languages[] = $cls; + + } + + } + + } + } } @@ -394,6 +422,8 @@ function prismatic_prism_classes() { 'language-typescript', 'language-visual-basic', 'language-yaml', + + 'language-none', ), array( diff --git a/inc/settings-register.php b/inc/settings-register.php index 17bddfd..e0f25f3 100644 --- a/inc/settings-register.php +++ b/inc/settings-register.php @@ -22,11 +22,12 @@ function prismatic_register_settings() { add_settings_section('settings_prism', 'Prism.js settings', 'prismatic_section_prism', 'prismatic_options_prism'); - add_settings_field('prism_theme', 'Theme', 'prismatic_callback_select', 'prismatic_options_prism', 'settings_prism', array('id' => 'prism_theme', 'section' => 'prism', 'label' => esc_html__('Prism theme', 'prismatic'))); - add_settings_field('line_highlight', 'Line Highlight', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'line_highlight', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Line Highlight', 'prismatic') .'')); - add_settings_field('line_numbers', 'Line Numbers', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'line_numbers', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Line Numbers', 'prismatic') .'')); - add_settings_field('show_language', 'Show Language', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'show_language', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Show Language', 'prismatic') .'')); - add_settings_field('singular_only', 'Limit to Posts', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'singular_only', 'section' => 'prism', 'label' => esc_html__('Limit to Posts and Pages', 'prismatic'))); + add_settings_field('prism_theme', 'Theme', 'prismatic_callback_select', 'prismatic_options_prism', 'settings_prism', array('id' => 'prism_theme', 'section' => 'prism', 'label' => esc_html__('Prism theme', 'prismatic'))); + add_settings_field('line_highlight', 'Line Highlight', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'line_highlight', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Line Highlight', 'prismatic') .'')); + add_settings_field('line_numbers', 'Line Numbers', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'line_numbers', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Line Numbers', 'prismatic') .'')); + add_settings_field('show_language', 'Show Language', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'show_language', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Show Language', 'prismatic') .'')); + add_settings_field('copy_clipboard', 'Copy to Clipboard', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'copy_clipboard', 'section' => 'prism', 'label' => esc_html__('Enable', 'prismatic') .' '. esc_html__('Copy to Clipboard', 'prismatic') .'')); + add_settings_field('singular_only', 'Limit to Posts', 'prismatic_callback_checkbox', 'prismatic_options_prism', 'settings_prism', array('id' => 'singular_only', 'section' => 'prism', 'label' => esc_html__('Limit to Posts and Pages', 'prismatic'))); add_settings_section('settings_prism_code', 'Code Escaping', 'prismatic_section_prism_code', 'prismatic_options_prism'); diff --git a/languages/prismatic.pot b/languages/prismatic.pot index 6fc7217..177cc0f 100644 --- a/languages/prismatic.pot +++ b/languages/prismatic.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-19 18:46+0000\n" +"POT-Creation-Date: 2019-11-02 19:47+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: \n" @@ -14,69 +14,69 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Loco https://localise.biz/" -#: prismatic.php:174 +#: prismatic.php:175 msgid "Settings" msgstr "" -#: prismatic.php:188 +#: prismatic.php:189 msgid "Plugin Homepage" msgstr "" -#: prismatic.php:189 +#: prismatic.php:190 msgid "Homepage" msgstr "" -#: prismatic.php:194 +#: prismatic.php:195 msgid "Click here to rate and review this plugin on WordPress.org" msgstr "" -#: prismatic.php:195 +#: prismatic.php:196 msgid "Rate this plugin" msgstr "" -#: prismatic.php:200 +#: prismatic.php:201 msgid "Get Prismatic Pro!" msgstr "" -#: prismatic.php:201 +#: prismatic.php:202 msgid "Go Pro" msgstr "" -#: prismatic.php:220 +#: prismatic.php:221 msgid "Warning:" msgstr "" -#: prismatic.php:221 +#: prismatic.php:222 msgid "" "Pro version of Prismatic currently active. Free and Pro versions cannot be " "activated at the same time. " msgstr "" -#: prismatic.php:222 prismatic.php:247 +#: prismatic.php:223 prismatic.php:248 msgid "Please return to the" msgstr "" -#: prismatic.php:222 prismatic.php:248 +#: prismatic.php:223 prismatic.php:249 msgid "WP Admin Area" msgstr "" -#: prismatic.php:223 +#: prismatic.php:224 msgid "and try again." msgstr "" -#: prismatic.php:245 +#: prismatic.php:246 msgid "requires WordPress " msgstr "" -#: prismatic.php:246 +#: prismatic.php:247 msgid " or higher, and has been deactivated! " msgstr "" -#: prismatic.php:248 +#: prismatic.php:249 msgid "to upgrade WordPress and try again." msgstr "" -#: prismatic.php:268 prismatic.php:274 +#: prismatic.php:269 prismatic.php:275 msgid "Cheatin’ huh?" msgstr "" @@ -216,7 +216,7 @@ msgid "Prism theme" msgstr "" #: inc/settings-register.php:26 inc/settings-register.php:27 -#: inc/settings-register.php:28 +#: inc/settings-register.php:28 inc/settings-register.php:29 msgid "Enable" msgstr "" @@ -232,34 +232,38 @@ msgstr "" msgid "Show Language" msgstr "" -#: inc/settings-register.php:29 inc/settings-register.php:46 -msgid "Limit to Posts and Pages" +#: inc/settings-register.php:29 +msgid "Copy to Clipboard" msgstr "" -#: inc/settings-register.php:33 inc/settings-register.php:50 -#: inc/settings-register.php:60 -msgid "Code escaping for content" +#: inc/settings-register.php:30 inc/settings-register.php:47 +msgid "Limit to Posts and Pages" msgstr "" #: inc/settings-register.php:34 inc/settings-register.php:51 #: inc/settings-register.php:61 -msgid "Code escaping for excerpts" +msgid "Code escaping for content" msgstr "" #: inc/settings-register.php:35 inc/settings-register.php:52 #: inc/settings-register.php:62 +msgid "Code escaping for excerpts" +msgstr "" + +#: inc/settings-register.php:36 inc/settings-register.php:53 +#: inc/settings-register.php:63 msgid "Code escaping for comments" msgstr "" -#: inc/settings-register.php:43 +#: inc/settings-register.php:44 msgid "Highlight theme" msgstr "" -#: inc/settings-register.php:44 +#: inc/settings-register.php:45 msgid "Init script for Highlight.js (required)" msgstr "" -#: inc/settings-register.php:45 +#: inc/settings-register.php:46 msgid "Support no-prefix class names" msgstr "" diff --git a/lib/prism/css/plugin-styles.css b/lib/prism/css/plugin-styles.css new file mode 100644 index 0000000..375e8db --- /dev/null +++ b/lib/prism/css/plugin-styles.css @@ -0,0 +1,9 @@ +div.code-toolbar > div.toolbar { top: 5px; right: 5px; } + +div.toolbar:before, div.toolbar:after { content: ''; display: table; clear: both; } + +div.code-toolbar > div.toolbar div.toolbar-item { float: left; margin: 0 0 0 3px; } + +div.code-toolbar > div.toolbar a, +div.code-toolbar > div.toolbar button, +div.code-toolbar > div.toolbar span { display: block; padding: 3px 5px; line-height: 11px; font-size: 11px; border-radius: 2px; cursor: default; } \ No newline at end of file diff --git a/lib/prism/js/plugin-copy-clipboard.js b/lib/prism/js/plugin-copy-clipboard.js new file mode 100644 index 0000000..199b425 --- /dev/null +++ b/lib/prism/js/plugin-copy-clipboard.js @@ -0,0 +1 @@ +!function(){if("undefined"!=typeof self&&self.Prism&&self.document)if(Prism.plugins.toolbar){var r=window.ClipboardJS||void 0;r||"function"!=typeof require||(r=require("clipboard"));var i=[];if(!r){var o=document.createElement("script"),e=document.querySelector("head");o.onload=function(){if(r=window.ClipboardJS)for(;i.length;)i.pop()()},o.src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js",e.appendChild(o)}Prism.plugins.toolbar.registerButton("copy-to-clipboard",function(e){var t=document.createElement("button");return t.textContent="Copy",r?o():i.push(o),t;function o(){var o=new r(t,{text:function(){return e.code}});o.on("success",function(){t.textContent="Copied!",n()}),o.on("error",function(){t.textContent="Press Ctrl+C to copy",n()})}function n(){setTimeout(function(){t.textContent="Copy"},5e3)}})}else console.warn("Copy to Clipboard plugin loaded before Toolbar plugin.")}(); \ No newline at end of file diff --git a/lib/prism/js/plugin-show-language.js b/lib/prism/js/plugin-show-language.js index a18adaa..955d54b 100644 --- a/lib/prism/js/plugin-show-language.js +++ b/lib/prism/js/plugin-show-language.js @@ -1,2 +1 @@ -!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var r=[],i={},a=function(){};Prism.plugins.toolbar={};var t=Prism.plugins.toolbar.registerButton=function(t,a){var e;e="function"==typeof a?a:function(t){var e;return"function"==typeof a.onClick?((e=document.createElement("button")).type="button",e.addEventListener("click",function(){a.onClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a")).href=a.url:e=document.createElement("span"),a.className&&e.classList.add(a.className),e.textContent=a.text,e},t in i?console.warn('There is a button with the key "'+t+'" registered already.'):r.push(i[t]=e)},e=Prism.plugins.toolbar.hook=function(n){var t=n.element.parentNode;if(t&&/pre/i.test(t.nodeName)&&!t.parentNode.classList.contains("code-toolbar")){var e=document.createElement("div");e.classList.add("code-toolbar"),t.parentNode.insertBefore(e,t),e.appendChild(t);var o=document.createElement("div");o.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(r=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return i[t]||a})),r.forEach(function(t){var e=t(n);if(e){var a=document.createElement("div");a.classList.add("toolbar-item"),a.appendChild(e),o.appendChild(a)}}),e.appendChild(o)}};t("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var a,n,o=e.getAttribute("data-label");try{n=document.querySelector("template#"+o)}catch(t){}return n?a=n.content:(e.hasAttribute("data-url")?(a=document.createElement("a")).href=e.getAttribute("data-url"):a=document.createElement("span"),a.textContent=o),a}}),Prism.hooks.add("complete",e)}}(); -!function(){if("undefined"!=typeof self&&self.Prism&&self.document)if(Prism.plugins.toolbar){var i={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",js:"JavaScript",abap:"ABAP",abnf:"Augmented Backus–Naur form",apacheconf:"Apache Configuration",apl:"APL",arff:"ARFF",asciidoc:"AsciiDoc",adoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",shell:"Bash",basic:"BASIC",bnf:"Backus–Naur form",rbnf:"Routing Backus–Naur form",csharp:"C#",cs:"C#",dotnet:"C#",cpp:"C++",cil:"CIL",coffee:"CoffeeScript",cmake:"CMake",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",jinja2:"Django/Jinja2","dns-zone-file":"DNS zone file","dns-zone":"DNS zone file",dockerfile:"Docker",ebnf:"Extended Backus–Naur form",ejs:"EJS",erb:"ERB",fsharp:"F#","firestore-security-rules":"Firestore security rules",gcode:"G-code",gdscript:"GDScript",gedcom:"GEDCOM",glsl:"GLSL",gml:"GameMaker Language",gamemakerlanguage:"GameMaker Language",graphql:"GraphQL",hs:"Haskell",hcl:"HCL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",javadoc:"JavaDoc",javadoclike:"JavaDoc-like",javastacktrace:"Java stack trace",jq:"JQ",jsdoc:"JSDoc","js-extras":"JS Extras","js-templates":"JS Templates",json:"JSON",jsonp:"JSONP",json5:"JSON5",latex:"LaTeX",tex:"TeX",context:"ConTeXt",lilypond:"LilyPond",ly:"LilyPond",emacs:"Lisp",elisp:"Lisp","emacs-lisp":"Lisp",lolcode:"LOLCODE",md:"Markdown","markup-templating":"Markup templating",matlab:"MATLAB",mel:"MEL",n1ql:"N1QL",n4js:"N4JS",n4jsd:"N4JS","nand2tetris-hdl":"Nand To Tetris HDL",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",objectpascal:"Object Pascal",pcaxis:"PC-Axis",px:"PC-Axis",php:"PHP",phpdoc:"PHPDoc","php-extras":"PHP Extras",plsql:"PL/SQL",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",py:"Python",q:"Q (kdb+ database)",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)",rb:"Ruby",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)","shell-session":"Shell session",soy:"Soy (Closure Template)","splunk-spl":"Splunk SPL",sql:"SQL",tap:"TAP",toml:"TOML",tt2:"Template Toolkit 2",trig:"TriG",ts:"TypeScript","t4-cs":"T4 Text Templates (C#)",t4:"T4 Text Templates (C#)","t4-vb":"T4 Text Templates (VB)","t4-templating":"T4 templating",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim","visual-basic":"Visual Basic",vb:"Visual Basic",wasm:"WebAssembly",wiki:"Wiki markup",xeoracube:"XeoraCube",xojo:"Xojo (REALbasic)",xquery:"XQuery",yaml:"YAML",yml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(e){var a=e.element.parentNode;if(a&&/pre/i.test(a.nodeName)){var s,t=a.getAttribute("data-language")||i[e.language]||((s=e.language)?(s.substring(0,1).toUpperCase()+s.substring(1)).replace(/s(?=cript)/,"S"):s);if(t){var o=document.createElement("span");return o.textContent=t,o}}})}else console.warn("Show Languages plugin loaded before Toolbar plugin.")}(); \ No newline at end of file +!function(){if("undefined"!=typeof self&&self.Prism&&self.document)if(Prism.plugins.toolbar){var r={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",js:"JavaScript",abap:"ABAP",abnf:"Augmented Backus–Naur form",antlr4:"ANTLR4",g4:"ANTLR4",apacheconf:"Apache Configuration",apl:"APL",aql:"AQL",arff:"ARFF",asciidoc:"AsciiDoc",adoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",shell:"Bash",basic:"BASIC",bbcode:"BBcode",bnf:"Backus–Naur form",rbnf:"Routing Backus–Naur form",csharp:"C#",cs:"C#",dotnet:"C#",cpp:"C++",cil:"CIL",coffee:"CoffeeScript",cmake:"CMake",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",jinja2:"Django/Jinja2","dns-zone-file":"DNS zone file","dns-zone":"DNS zone file",dockerfile:"Docker",ebnf:"Extended Backus–Naur form",ejs:"EJS",etlua:"Embedded Lua templating",erb:"ERB",fsharp:"F#","firestore-security-rules":"Firestore security rules",ftl:"FreeMarker Template Language",gcode:"G-code",gdscript:"GDScript",gedcom:"GEDCOM",glsl:"GLSL",gml:"GameMaker Language",gamemakerlanguage:"GameMaker Language",graphql:"GraphQL",hs:"Haskell",hcl:"HCL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",javadoc:"JavaDoc",javadoclike:"JavaDoc-like",javastacktrace:"Java stack trace",jq:"JQ",jsdoc:"JSDoc","js-extras":"JS Extras","js-templates":"JS Templates",json:"JSON",jsonp:"JSONP",json5:"JSON5",latex:"LaTeX",tex:"TeX",context:"ConTeXt",lilypond:"LilyPond",ly:"LilyPond",emacs:"Lisp",elisp:"Lisp","emacs-lisp":"Lisp",lolcode:"LOLCODE",md:"Markdown","markup-templating":"Markup templating",matlab:"MATLAB",mel:"MEL",moon:"MoonScript",n1ql:"N1QL",n4js:"N4JS",n4jsd:"N4JS","nand2tetris-hdl":"Nand To Tetris HDL",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",objectpascal:"Object Pascal",pcaxis:"PC-Axis",px:"PC-Axis",php:"PHP",phpdoc:"PHPDoc","php-extras":"PHP Extras",plsql:"PL/SQL",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",py:"Python",q:"Q (kdb+ database)",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)","robot-framework":"Robot Framework",robot:"Robot Framework",rb:"Ruby",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)","shell-session":"Shell session",solidity:"Solidity (Ethereum)",soy:"Soy (Closure Template)",sparql:"SPARQL",rq:"SPARQL","splunk-spl":"Splunk SPL",sqf:"SQF: Status Quo Function (Arma 3)",sql:"SQL",tap:"TAP",toml:"TOML",tt2:"Template Toolkit 2",trig:"TriG",ts:"TypeScript","t4-cs":"T4 Text Templates (C#)",t4:"T4 Text Templates (C#)","t4-vb":"T4 Text Templates (VB)","t4-templating":"T4 templating",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim","visual-basic":"Visual Basic",vb:"Visual Basic",wasm:"WebAssembly",wiki:"Wiki markup",xeoracube:"XeoraCube",xojo:"Xojo (REALbasic)",xquery:"XQuery",yaml:"YAML",yml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(e){var a=e.element.parentNode;if(a&&/pre/i.test(a.nodeName)){var s,t=a.getAttribute("data-language")||r[e.language]||((s=e.language)?(s.substring(0,1).toUpperCase()+s.substring(1)).replace(/s(?=cript)/,"S"):s);if(t){var o=document.createElement("span");return o.textContent=t,o}}})}else console.warn("Show Languages plugin loaded before Toolbar plugin.")}(); \ No newline at end of file diff --git a/lib/prism/js/plugin-toolbar.js b/lib/prism/js/plugin-toolbar.js new file mode 100644 index 0000000..3b9f082 --- /dev/null +++ b/lib/prism/js/plugin-toolbar.js @@ -0,0 +1 @@ +!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var r=[],i={},a=function(){};Prism.plugins.toolbar={};var t=Prism.plugins.toolbar.registerButton=function(t,a){var e;e="function"==typeof a?a:function(t){var e;return"function"==typeof a.onClick?((e=document.createElement("button")).type="button",e.addEventListener("click",function(){a.onClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a")).href=a.url:e=document.createElement("span"),a.className&&e.classList.add(a.className),e.textContent=a.text,e},t in i?console.warn('There is a button with the key "'+t+'" registered already.'):r.push(i[t]=e)},e=Prism.plugins.toolbar.hook=function(n){var t=n.element.parentNode;if(t&&/pre/i.test(t.nodeName)&&!t.parentNode.classList.contains("code-toolbar")){var e=document.createElement("div");e.classList.add("code-toolbar"),t.parentNode.insertBefore(e,t),e.appendChild(t);var o=document.createElement("div");o.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(r=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return i[t]||a})),r.forEach(function(t){var e=t(n);if(e){var a=document.createElement("div");a.classList.add("toolbar-item"),a.appendChild(e),o.appendChild(a)}}),e.appendChild(o)}};t("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var a,n,o=e.getAttribute("data-label");try{n=document.querySelector("template#"+o)}catch(t){}return n?a=n.content:(e.hasAttribute("data-url")?(a=document.createElement("a")).href=e.getAttribute("data-url"):a=document.createElement("span"),a.textContent=o),a}}),Prism.hooks.add("complete",e)}}(); \ No newline at end of file diff --git a/prismatic.php b/prismatic.php index fd6c245..dba0fa4 100644 --- a/prismatic.php +++ b/prismatic.php @@ -9,9 +9,9 @@ Author URI: https://plugin-planet.com/ Donate link: https://monzillamedia.com/donate.html Requires at least: 4.1 - Tested up to: 5.2 - Stable tag: 2.2 - Version: 2.2 + Tested up to: 5.3 + Stable tag: 2.3 + Version: 2.3 Requires PHP: 5.6.20 Text Domain: prismatic Domain Path: /languages @@ -100,6 +100,7 @@ if (!class_exists('Prismatic')) { 'line_highlight' => false, 'line_numbers' => false, 'show_language' => false, + 'copy_clipboard' => false, 'singular_only' => true, ); @@ -141,7 +142,7 @@ if (!class_exists('Prismatic')) { private function constants() { - if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '2.2'); + if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '2.3'); if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.1'); if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic'); if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr'); diff --git a/readme.txt b/readme.txt index 20cf791..170980a 100644 --- a/readme.txt +++ b/readme.txt @@ -9,9 +9,9 @@ Contributors: specialk Author URI: https://plugin-planet.com/ Donate link: https://monzillamedia.com/donate.html Requires at least: 4.1 -Tested up to: 5.2 -Stable tag: 2.2 -Version: 2.2 +Tested up to: 5.3 +Stable tag: 2.3 +Version: 2.3 Requires PHP: 5.6.20 Text Domain: prismatic Domain Path: /languages @@ -43,12 +43,14 @@ Check out a [demo post using Highlight.js](https://dev-tricks.com/favorite-highl * Enable Prism plugin [Line Numbers](https://prismjs.com/plugins/line-numbers/) * Enable Prism plugin [Line Highlight](https://prismjs.com/plugins/line-highlight/) * Enable Prism plugin [Show Language](https://prismjs.com/plugins/show-language/) +* Enable Prism plugin [Copy Code Button](https://prismjs.com/plugins/copy-to-clipboard/) * Highlights code in post content, excerpts, and comments * Detects `language-` and `lang-` class prefixes * Limit syntax highlighting to Posts and Pages * Highlight single-line and multi-line code * Granular control over code escaping * Smart loading of CSS & JS assets +* Support for ACF on single post views **Highlight.js Features** @@ -304,6 +306,19 @@ There also is a Prismatic Quicktag button ("pre") for those using the Plain-Text +**Usage: Prism.js Plugins** + +Currently the Prismatic plugin provides four plugins for Prism.js. + +* [Line Highlight](https://prismjs.com/plugins/line-highlight/) - Requires adding `data-line` attribute to the pre element +* [Line Numbers](https://prismjs.com/plugins/line-numbers/) - Requires adding `line-numbers` attribute to the pre element +* [Show Language](https://prismjs.com/plugins/show-language/) - No additional steps required +* [Copy to Clipboard](https://prismjs.com/plugins/copy-to-clipboard/) - No additional steps required + +Any/all of these plugins can be enabled in the Prism.js settings. To learn more about usage and options, visit the plugin links in the above list. + + + **About Prism.js** Prism.js version used in Prismatic plugin: __1.17.1__ @@ -343,7 +358,7 @@ __Supported Languages__ Go = go GraphQL = graphql Groovy = groovy - HTML = markup + HTML/XML/Etc. = markup HTTP = http Ini = ini Java = java @@ -385,7 +400,9 @@ So for example, to specify a code block as C++, you would write: Note: in the previous example, ignore the `class="optional"` added to the code tag (for the "Alternate" syntax); it is used to prevent markdown from mangling the code example on this web page. -To disable Prism.js syntax highlighting for any snippet, simply omit the language class. +To disable Prism.js syntax highlighting for any snippet, simply omit the language class. Or, to disable syntax highlighting for a code snippet while also loading the Prism.js stylesheet, add a class of `language-none`, for example: + + ... _I'm glad to add more languages, [make a suggestion](https://perishablepress.com/contact/)_ @@ -427,7 +444,7 @@ __Supported Languages__ GML = gml Go = go, golang Groovy = groovy - HTML/XML = xml, html, xhtml, rss, atom, xjb, xsd, xsl, plist + HTML/XML/Etc. = xml, html, xhtml, rss, atom, xjb, xsd, xsl, plist HTTP = http, https Ini = ini JSON = json @@ -504,6 +521,16 @@ If for some reason you want to view syntax-highlighted code inside of the Block The code won't be highlighted initially, but if you refresh the page after making changes, or visit the page again in the future, the code will be displayed with syntax highlighting applied. +**How to syntax highlight code inside of ACF field?** + +As of Prismatic version 2.3, code snippets inside of ACF fields are highlighted automatically. Simply add the required class (e.g., `language-php`) just like any other code snippet, and the plugin will detect and highlight the code. To also escape the highlighted code, enable escaping for post content via the setting, Prism > Code Escaping > Content. Note: ACF is supported only on single post views. + + +**How to make highlighting work with Autoptimize?** + +For Prismatic plugin to work with Autoptimize, a script needs to be excluded. For details, check out [this post](https://ncoughlin.com/prismatic-syntax-highlighter-compatibility-autoptimize-plugin/) by Nick Coughlin. + + **Got a question?** Send any questions or feedback via my [contact form](https://perishablepress.com/contact/) @@ -536,6 +563,17 @@ Links, tweets and likes also appreciated. Thank you! :) Thank you to everyone providing feedback! If you like Prismatic, please take a moment to [give a 5-star rating](https://wordpress.org/support/plugin/prismatic/reviews/?rate=5#new-post). It helps to keep development and support going strong. Thank you! +**2.3 (2019/10/27)** + +* Updates styles for plugin settings page +* Fixes bug with older versions of WordPress +* Adds "copy code to clipboard" button for Prism.js +* Adds support for Prism.js highlighting in ACF fields +* Adds support for `language-none` for Prism.js +* Generates new default translation template +* Updates documentation with further infos +* Tests on WordPress 5.3 + **2.2 (2019/08/16)** * Resolves several warnings in PHP 7+