1
0
www.mikescher.com/www/internals/ParsedownCustom.php

95 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2018-01-01 23:03:05 +01:00
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../extern/Parsedown.php');
require_once (__DIR__ . '/../extern/ParsedownExtra.php');
class ParsedownCustom extends ParsedownExtra
{
protected function element(array $Element)
{
if (isset($Element['custom']) && $Element['custom'] && isset($Element['handler']))
return $this->{$Element['handler']}($Element['text']);
else
return parent::element($Element);
}
protected function blockFencedCode($Line)
{
$Block = parent::blockFencedCode($Line);
if ($Block === null) return $Block;
$Block['custom'] = false;
2018-01-03 00:08:42 +01:00
if (isset($Block['element']['text']['attributes']))
2018-01-01 23:03:05 +01:00
{
2018-01-03 00:08:42 +01:00
foreach ($Block['element']['text']['attributes'] as $attr)
{
$spl = explode('__', $attr);
if ($spl[0] === 'language-befungerunner')
{
$Block['element']['handler'] = 'handleBef93';
$Block['custom'] = true;
$Block['element']['text']['b93_speed'] = null;
$Block['element']['text']['b93_interactive'] = true;
$Block['element']['text']['b93_editable'] = true;
foreach ($spl as $param)
{
if (startsWith($param, 'speed-')) $Block['element']['text']['b93_speed'] = intval( substr($param, strlen('speed-')));
if (startsWith($param, 'interactive-')) $Block['element']['text']['b93_interactive'] = boolval(substr($param, strlen('interactive-')));
if (startsWith($param, 'editable-')) $Block['element']['text']['b93_editable'] = boolval(substr($param, strlen('editable-')));
}
return $Block;
}
else if ($spl[0] === 'language-bfjoustrunner')
{
$Block['element']['handler'] = 'handleBFJoust';
$Block['custom'] = true;
return $Block;
}
}
2018-01-01 23:03:05 +01:00
}
return $Block;
}
protected function blockFencedCodeComplete($Block)
{
if (! $Block['custom']) { return parent::blockFencedCodeComplete($Block); }
$Block['element']['custom'] = true;
return $Block;
}
protected function handleBFJoust(array $Element)
{
global $PARAM_CODE_LEFT;
global $PARAM_CODE_RIGHT;
$split = preg_split("/\-{16,}/", $Element['text']);
$PARAM_CODE_LEFT = trim($split[0]);
$PARAM_CODE_RIGHT = trim($split[1]);
2018-01-26 21:12:04 +01:00
return require (__DIR__ . '/../fragments/widget_bfjoust.php');
2018-01-01 23:03:05 +01:00
}
protected function handleBef93(array $Element)
{
2018-01-03 00:08:42 +01:00
global $PARAM_BEFUNGE93RUNNER;
$PARAM_BEFUNGE93RUNNER =
[
'code' => $Element['text'],
'url' => '',
'interactive' => $Element['b93_interactive'],
'speed' => $Element['b93_speed'],
'editable' => $Element['b93_editable'],
];
2018-01-26 21:12:04 +01:00
return require (__DIR__ . '/../fragments/widget_befunge93.php');
2018-01-01 23:03:05 +01:00
}
}