Compare commits

..

No commits in common. "b98a1777754327abfd27f2869609e0af4e2100c8" and "bbfe6cdfb6a500e326037d052204207af2e36a9d" have entirely different histories.

15 changed files with 68 additions and 24 deletions

View file

@ -1,11 +1,11 @@
<?php <?php
/* /*
Plugin Name: SyntaxHighlighter-NG Plugin Name: SyntaxHighlighter
Version: 1.0 Version: 1.0
Plugin URI: https://git.la10cy.net/DeltaLima/flatpress-plugin-syntaxhighlighter-ng Plugin URI: http://flatpress.sf.net
Description: <a href="https://git.la10cy.net/DeltaLima/flatpress-plugin-syntaxhighlighter-ng/">SyntaxHighlighter-NG 1.0.0</a> (forked from <a href="https://forum.flatpress.org/viewtopic.php?p=1130&hilit=syntax+highlight#p1135">Arvid's forum post</a>, using now <a href="https://prismjs.com">prism.js</a>) Description: <a href="http://www.dreamprojections.com/syntaxhighlighter/">dp.SyntaxHighlighter 1.4.0</a> (edited to work with pre, thanks to <a href="https://www.gertthiel.de/blog/archive/2005/11/25/dp-syntaxhighlighter-pre">Gert Thiel </a>)
Author: 2005 NoWhereMan, 2023 DeltaLima Author: NoWhereMan
Author URI: https://deltalima.org Author URI: http://flatpress.sf.net
*/ */
@ -14,11 +14,51 @@ function plugin_syntaxhighlighter_add($lang=null) {
$pdir=plugin_geturl('syntaxhighlighter'); $pdir=plugin_geturl('syntaxhighlighter');
// create array containing the used languages //if ($lang) {
//~ switch ($lang) {
//~ case 'c':
//~ case 'cpp':
//~ case 'c++':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushCpp.js\"></script>\n"; break;
//~ case 'css':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushCss.js\"></script>\n"; break;
//~ case 'c#':
//~ case 'c-sharp':
//~ case 'csharp':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushCSharp.js\"></script>\n"; break;
//~ case 'vb':
//~ case 'vb.net':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushVb.js\"></script>\n"; break;
//~ case 'delphi':
//~ case 'pascal':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushDelphi.js\"></script>\n"; break;
//~ case 'js':
//~ case 'jscript':
//~ case 'javascript':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushJScript.js\"></script>\n"; break;
//~ case 'php':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushPhp.js\"></script>\n"; break;
//~ case 'py':
//~ case 'python':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushPython.js\"></script>\n"; break;
//~ case 'ruby':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushRuby.js\"></script>\n"; break;
//~ case 'sql':
//~ $scripts[] = "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushSql.js\"></script>\n"; break;
//~ case 'xml':
//~ case 'xhtml':
//~ case 'xslt':
//~ case 'html':
//~ case 'xhtml':
//~ "<script type=\"text/javascript\" src=\"{$pdir}res/shBrushXml.js\"></script>\n";
//~ }
$languages[] = "{$lang}"; $languages[] = "{$lang}";
// remove unique
$languages = array_unique($languages); $languages = array_unique($languages);
//}
//return $scripts;
return $languages; return $languages;
} }
@ -26,13 +66,14 @@ function plugin_syntaxhighlighter_add($lang=null) {
function plugin_syntaxhighlighter_head() { function plugin_syntaxhighlighter_head() {
$pdir=plugin_geturl('syntaxhighlighter'); $pdir=plugin_geturl('syntaxhighlighter');
echo <<<PRISMJS echo <<<SHL
<!-- start of prism.js --> <!-- start of SHL -->
<!-- <link rel="stylesheet" type="text/css" href="{$pdir}res/SyntaxHighlighter.css" /> -->
<link rel="stylesheet" type="text/css" href="{$pdir}res/prism.css" /> <link rel="stylesheet" type="text/css" href="{$pdir}res/prism.css" />
<!-- end of prism.js --> <!-- end of SHL -->
PRISMJS; SHL;
} }
add_action('wp_head', 'plugin_syntaxhighlighter_head'); add_action('wp_head', 'plugin_syntaxhighlighter_head');
@ -40,22 +81,25 @@ add_action('wp_head', 'plugin_syntaxhighlighter_head');
function plugin_syntaxhighlighter_foot() { function plugin_syntaxhighlighter_foot() {
// convert the returned array into an json one, to have an easier time //$used_languages = implode(plugin_syntaxhighlighter_add(), "\n");
// giving it to the javascript below
$used_languages = json_encode(plugin_syntaxhighlighter_add()); $used_languages = json_encode(plugin_syntaxhighlighter_add());
$pdir=plugin_geturl('syntaxhighlighter'); $pdir=plugin_geturl('syntaxhighlighter');
// javascript part echo <<<SHLBOX
echo <<<PRISMBOX <!-- start of SHL -->
<!-- start of prism.js --> <!-- <script type="text/javascript" src="{$pdir}res/shCore.js"></script> -->
<!-- 1337ASD $used_languages-->
<!-- <script type="text/javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script> -->
<script type="text/javascript" src="{$pdir}res/prism.js"></script> <script type="text/javascript" src="{$pdir}res/prism.js"></script>
<!-- wrapping the content of pre html-tags into code-tags, as said in https://prismjs.com/index.html#basic-usage -->
<script type="text/javascript"> <script type="text/javascript">
// wrap the content of <pre> elements into <code></code> for prismjs // wrap the content of <pre> elements into <code></code> for prismjs
// get an array of <pre></pre> elements // get an array of pre elements
//var preEl = document.getElementsByTagName("pre"); //var preEl = document.getElementsByTagName("pre");
// split used_languages list into array // split used_languages list into array
@ -63,17 +107,17 @@ function plugin_syntaxhighlighter_foot() {
for (let iUl = 0;iUl < used_languages.length; iUl++) for (let iUl = 0;iUl < used_languages.length; iUl++)
{ {
// do nothing on empty element // do nothing on empty elements
if ( used_languages[iUl] != "" ) if ( used_languages[iUl] != "" )
{ {
// get all <pre> elements with certain language alert(used_languages[iUl]);
let preElements = document.querySelectorAll("pre." + used_languages[iUl]); let preElements = document.querySelectorAll("pre." + used_languages[iUl]);
for (let iEl = 0;iEl < preElements.length; iEl++) for (let iEl = 0;iEl < preElements.length; iEl++)
{ {
org_html = preElements[iEl].innerHTML; org_html = preElements[iEl].innerHTML;
new_html = "<code class=\"language-" + used_languages[iUl] + "\">" + org_html + "</code>"; new_html = "<code class=\"language-" + used_languages[iUl] + "\">" + org_html + "</code>";
alert(new_html);
preElements[iEl].innerHTML = new_html; preElements[iEl].innerHTML = new_html;
} }
} }
@ -95,7 +139,7 @@ function plugin_syntaxhighlighter_foot() {
</script> </script>
<!-- end of SHL --> <!-- end of SHL -->
PRISMBOX; SHLBOX;
} }
add_action('wp_footer', 'plugin_syntaxhighlighter_foot'); add_action('wp_footer', 'plugin_syntaxhighlighter_foot');

View file