flatpress-plugin-syntaxhigh.../plugin.syntaxhighlighter.php

71 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/*
2023-06-21 00:21:46 +02:00
Plugin Name: SyntaxHighlighter-NG
Version: 1.0.1
2023-06-21 00:21:46 +02:00
Plugin URI: https://git.la10cy.net/DeltaLima/flatpress-plugin-syntaxhighlighter-ng
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
*/
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
$languages[] = "{$lang}";
2023-06-21 00:21:46 +02:00
// remove unique
$languages = array_unique($languages);
return $languages;
}
function plugin_syntaxhighlighter_head() {
$pdir=plugin_geturl('syntaxhighlighter');
2023-06-21 00:21:46 +02:00
echo <<<PRISMJS
<!-- start of prism.js header -->
<link rel="stylesheet" type="text/css" href="{$pdir}res/prism.okaidia.css" />
<!-- end of prism.js header -->
2023-06-21 00:21:46 +02:00
PRISMJS;
}
add_action('wp_head', 'plugin_syntaxhighlighter_head');
function plugin_syntaxhighlighter_foot() {
// 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
$used_languages = json_encode(plugin_syntaxhighlighter_add());
$pdir=plugin_geturl('syntaxhighlighter');
2023-06-21 00:21:46 +02:00
// javascript part
echo <<<PRISMBOX
<!-- start of prism.js footer -->
2023-06-21 01:23:19 +02:00
<script type="text/javascript" src="{$pdir}res/prism.full.js"></script>
2023-06-21 00:21:46 +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 -->
<script type="text/javascript">
var used_languages = $used_languages;
wrap_pre_tags(used_languages);
</script>
<!-- end of prism.js footer -->
2023-06-21 00:21:46 +02:00
PRISMBOX;
}
add_action('wp_footer', 'plugin_syntaxhighlighter_foot');
?>