✨ Rewrite for Kirby
This commit is contained in:
parent
07201d05de
commit
f854d60108
116 changed files with 4156 additions and 8875 deletions
22
site/plugins/kirby-highlighter/snippets/blocks/code.php
Normal file
22
site/plugins/kirby-highlighter/snippets/blocks/code.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/** @var \Kirby\Cms\Block $block */
|
||||
$highlighter = new \Highlight\Highlighter();
|
||||
$language = $block->language()->value();
|
||||
$code = $block->code()->fromBase64()->value();
|
||||
|
||||
if (empty($language) || !in_array($language, $highlighter->listRegisteredLanguages())) {
|
||||
$language = 'plaintext';
|
||||
}
|
||||
|
||||
$highlightedCode = $highlighter->highlight($language, $code)->value;
|
||||
|
||||
// Handle line numbering
|
||||
if (option('johannschopplich.highlighter.line-numbering', false)) {
|
||||
$lines = preg_split('/\R/', $highlightedCode);
|
||||
$lineClass = option('johannschopplich.highlighter.line-numbering-class', 'hljs-code-line');
|
||||
$highlightedCode = '<span class="' . $lineClass . '">' . implode("</span>\n<span class=\"$lineClass\">", $lines) . '</span>';
|
||||
}
|
||||
|
||||
?>
|
||||
<pre class="<?= option('johannschopplich.highlighter.class', 'hljs') ?>"><code data-language="<?= $language ?>"><?= $highlightedCode ?></code></pre>
|
Loading…
Add table
Add a link
Reference in a new issue