From a0ebd3b3ff6f56d739ee058f0ff823857aeae0d7 Mon Sep 17 00:00:00 2001 From: DeltaLima Date: Wed, 21 Jun 2023 14:07:40 +0200 Subject: [PATCH] separated javascript to res/syntaxhighlighter-ng.js, cleanup things --- plugin.syntaxhighlighter.php | 58 +++++++++--------------------------- res/syntaxhighlighter-ng.js | 33 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 res/syntaxhighlighter-ng.js diff --git a/plugin.syntaxhighlighter.php b/plugin.syntaxhighlighter.php index 2b9a90b..6591f29 100644 --- a/plugin.syntaxhighlighter.php +++ b/plugin.syntaxhighlighter.php @@ -1,9 +1,9 @@ SyntaxHighlighter-NG 1.0.0 (forked from Arvid's forum post, using now prism.js) +Description: SyntaxHighlighter-NG (forked from Arvid's forum post, using now prism.js) Author: 2005 NoWhereMan, 2023 DeltaLima Author URI: https://deltalima.org */ @@ -35,66 +35,36 @@ echo << + echo << - + + + + PRISMBOX; } + add_action('wp_footer', 'plugin_syntaxhighlighter_foot'); - - ?> diff --git a/res/syntaxhighlighter-ng.js b/res/syntaxhighlighter-ng.js new file mode 100644 index 0000000..1fc033a --- /dev/null +++ b/res/syntaxhighlighter-ng.js @@ -0,0 +1,33 @@ +// wrap the content of
 elements into  for prism.js
+// as told mentioned in https://prismjs.com/index.html#basic-usage
+// Author: DeltaLima
+// Date: 21.06.2023
+
+function wrap_pre_tags(used_languages) {
+  // iterate through all used_languages
+  for (let iUl = 0;iUl < used_languages.length; iUl++)
+  {
+    // preElements, array of 
 elements
+    // handle [code] without language definition as "none"
+    // and we have to look for them up a bit different
+    if ( used_languages[iUl] == "" )
+    {
+      used_languages[iUl] == "none"
+      var preElements = document.querySelectorAll("pre:not([class])");
+    } else {
+      var preElements = document.querySelectorAll("pre." + used_languages[iUl]);
+    }
+
+    // iterate through all 
+    for (let iEl = 0;iEl < preElements.length; iEl++)
+    {
+      // put the content of 
 tag into org_html
+      org_html = preElements[iEl].innerHTML;
+      // put  tag with 'language-' class and class for 'line-numbers'
+      // prism.js plugin around the 
 content
+      new_html = "" + org_html + "";
+      // write back our new html and enjoy syntax highlightning :)
+      preElements[iEl].innerHTML = new_html;
+    }
+  }
+}