39 lines
No EOL
1,016 B
PHP
39 lines
No EOL
1,016 B
PHP
|
|
|
|
<?php
|
|
|
|
use Highlight\Highlighter;
|
|
|
|
class Dergdown extends ParsedownExtra
|
|
{
|
|
protected $highlighter;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->highlighter = new Highlighter();
|
|
}
|
|
|
|
protected function blockFencedCodeComplete($block)
|
|
{
|
|
if (! isset($block['element']['text']['attributes'])) {
|
|
return $block;
|
|
}
|
|
|
|
$code = $block['element']['text']['text'];
|
|
$languageClass = $block['element']['text']['attributes']['class'];
|
|
$language = explode('-', $languageClass);
|
|
|
|
try {
|
|
$highlighted = $this->highlighter->highlight($language[1], $code);
|
|
$block['element']['text']['attributes']['class'] = vsprintf('%s hljs %s', [
|
|
$languageClass,
|
|
$highlighted->language,
|
|
]);
|
|
$block['element']['text']['rawHtml'] = $highlighted->value;
|
|
unset($block['element']['text']['text']);
|
|
} catch (DomainException $e) {
|
|
}
|
|
|
|
return $block;
|
|
}
|
|
} |