2023-06-20 23:18:53 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2023-06-21 00:21:46 +02:00
|
|
|
Plugin Name: SyntaxHighlighter-NG
|
2023-06-22 00:33:47 +02:00
|
|
|
Version: 1.0.2
|
2023-06-21 00:21:46 +02:00
|
|
|
Plugin URI: https://git.la10cy.net/DeltaLima/flatpress-plugin-syntaxhighlighter-ng
|
2023-06-21 14:07:40 +02:00
|
|
|
Description: <a href="https://git.la10cy.net/DeltaLima/flatpress-plugin-syntaxhighlighter-ng/">SyntaxHighlighter-NG</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>)
|
2023-06-21 00:21:46 +02:00
|
|
|
Author: 2005 NoWhereMan, 2023 DeltaLima
|
|
|
|
Author URI: https://deltalima.org
|
2023-06-21 21:58:43 +02:00
|
|
|
License: MIT
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the “Software”), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
|
2023-06-20 23:18:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function plugin_syntaxhighlighter_add($lang=null) {
|
|
|
|
static $languages = array();
|
|
|
|
|
|
|
|
$pdir=plugin_geturl('syntaxhighlighter');
|
|
|
|
|
2023-06-21 00:21:46 +02:00
|
|
|
// create array containing the used languages
|
2023-06-20 23:18:53 +02:00
|
|
|
$languages[] = "{$lang}";
|
2023-06-21 00:21:46 +02:00
|
|
|
// remove unique
|
2023-06-20 23:18:53 +02:00
|
|
|
$languages = array_unique($languages);
|
|
|
|
|
|
|
|
return $languages;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function plugin_syntaxhighlighter_head() {
|
2023-06-22 00:10:50 +02:00
|
|
|
|
|
|
|
$config = include('config.php');
|
2023-06-20 23:18:53 +02:00
|
|
|
$pdir=plugin_geturl('syntaxhighlighter');
|
2023-06-21 00:21:46 +02:00
|
|
|
echo <<<PRISMJS
|
2023-06-21 01:11:10 +02:00
|
|
|
<!-- start of prism.js header -->
|
2023-06-20 23:18:53 +02:00
|
|
|
|
2023-06-22 00:06:05 +02:00
|
|
|
<link rel="stylesheet" type="text/css" href="{$pdir}res/prism-{$config['theme']}.css" />
|
2023-06-20 23:18:53 +02:00
|
|
|
|
2023-06-21 01:11:10 +02:00
|
|
|
<!-- end of prism.js header -->
|
2023-06-21 00:21:46 +02:00
|
|
|
PRISMJS;
|
2023-06-20 23:18:53 +02:00
|
|
|
|
|
|
|
}
|
2023-06-21 14:07:40 +02:00
|
|
|
|
2023-06-20 23:18:53 +02:00
|
|
|
add_action('wp_head', 'plugin_syntaxhighlighter_head');
|
|
|
|
|
|
|
|
|
|
|
|
function plugin_syntaxhighlighter_foot() {
|
|
|
|
|
2023-06-22 00:10:50 +02:00
|
|
|
$config = include('config.php');
|
2023-06-21 14:07:40 +02:00
|
|
|
// convert the returned array into a json one, to have an easier time
|
2023-06-21 00:21:46 +02:00
|
|
|
// giving it to the javascript below
|
2023-06-20 23:18:53 +02:00
|
|
|
$used_languages = json_encode(plugin_syntaxhighlighter_add());
|
|
|
|
|
2023-06-21 14:07:40 +02:00
|
|
|
$pdir=plugin_geturl('syntaxhighlighter');
|
2023-06-21 00:21:46 +02:00
|
|
|
// javascript part
|
2023-06-21 14:07:40 +02:00
|
|
|
echo <<<PRISMBOX
|
|
|
|
<!-- start of prism.js footer -->
|
2023-06-20 23:18:53 +02:00
|
|
|
|
2023-06-22 00:10:50 +02:00
|
|
|
<script type="text/javascript" src="{$pdir}res/prism.{$config['size']}.js"></script>
|
2023-06-21 00:21:46 +02:00
|
|
|
|
2023-06-21 14:07:40 +02:00
|
|
|
<!-- include wrapping-function to wrap content of pre html-tags into code-tags, as said in https://prismjs.com/index.html#basic-usage -->
|
|
|
|
<script type="text/javascript" src="{$pdir}res/syntaxhighlighter-ng.js"></script>
|
|
|
|
|
|
|
|
<!-- call wrap_pre_tags() from syntaxhighlighter-ng.js -->
|
2023-06-20 23:18:53 +02:00
|
|
|
<script type="text/javascript">
|
2023-06-22 00:06:05 +02:00
|
|
|
var used_languages = {$used_languages};
|
2023-06-21 14:07:40 +02:00
|
|
|
wrap_pre_tags(used_languages);
|
2023-06-20 23:18:53 +02:00
|
|
|
</script>
|
|
|
|
|
2023-06-21 01:11:10 +02:00
|
|
|
<!-- end of prism.js footer -->
|
2023-06-21 00:21:46 +02:00
|
|
|
PRISMBOX;
|
2023-06-20 23:18:53 +02:00
|
|
|
}
|
|
|
|
|
2023-06-21 14:07:40 +02:00
|
|
|
add_action('wp_footer', 'plugin_syntaxhighlighter_foot');
|
2023-06-20 23:18:53 +02:00
|
|
|
|
|
|
|
?>
|