mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-04-26 13:30:11 +00:00
[highlightjs] Add new addon
This commit is contained in:
parent
940520c720
commit
0afab99d84
89 changed files with 8428 additions and 0 deletions
51
highlightjs/highlightjs.php
Normal file
51
highlightjs/highlightjs.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Name: Syntax Highlighting
|
||||
* Description: Highlights syntax of code blocks with highlight.js
|
||||
* Version: 1.0
|
||||
* Author: Hypolite Petovan <hypolite@mrpetovan.com>
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Addon;
|
||||
|
||||
function highlightjs_install()
|
||||
{
|
||||
Addon::registerHook('page_end', __FILE__, 'highlightjs_page_end');
|
||||
}
|
||||
|
||||
function highlightjs_uninstall()
|
||||
{
|
||||
Addon::unregisterHook('page_end', __FILE__, 'highlightjs_page_end');
|
||||
}
|
||||
|
||||
function highlightjs_page_end(App $a, &$b)
|
||||
{
|
||||
$basedir = $a->get_baseurl() . '/addon/highlightjs/asset';
|
||||
|
||||
if ($a->getCurrentTheme() == 'frio') {
|
||||
$style = 'bootstrap';
|
||||
} else {
|
||||
$style = 'default';
|
||||
}
|
||||
|
||||
$a->page['htmlhead'] .= <<< HTML
|
||||
|
||||
<link rel="stylesheet" href="{$basedir}/styles/{$style}.css">
|
||||
|
||||
HTML;
|
||||
|
||||
$b .= <<< HTML
|
||||
|
||||
<script type="text/javascript" src="{$basedir}/highlight.pack.js"></script>
|
||||
<script type="text/javascript">
|
||||
hljs.initHighlightingOnLoad();
|
||||
|
||||
document.addEventListener('postprocess_liveupdate', function () {
|
||||
var blocks = document.querySelectorAll('pre code:not(.hljs)');
|
||||
Array.prototype.forEach.call(blocks, hljs.highlightBlock);
|
||||
});
|
||||
</script>
|
||||
|
||||
HTML;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue