1
0

ParsedownCustom

This commit is contained in:
2018-01-01 23:03:05 +01:00
parent 32f1e8437b
commit e56ca264a3
36 changed files with 939 additions and 277 deletions

View File

@@ -0,0 +1,73 @@
<?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;
if (isset($Block['element']['text']['attributes']) && in_array('language-befungerunner', $Block['element']['text']['attributes']))
{
$Block['element']['handler'] = 'handleBef93';
$Block['custom'] = true;
}
else if (isset($Block['element']['text']['attributes']) && in_array('language-bfjoustrunner', $Block['element']['text']['attributes']))
{
$Block['element']['handler'] = 'handleBFJoust';
$Block['custom'] = true;
}
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]);
return require (__DIR__ . '/../fragments/bfjoust_runner.php');
}
protected function handleBef93(array $Element)
{
global $PARAM_CODE;
global $PARAM_URL;
global $PARAM_INTERACTIVE;
$PARAM_CODE = $Element['text'];
$PARAM_URL = '';
$PARAM_INTERACTIVE = true;
return require (__DIR__ . '/../fragments/befunge93_runner.php');
}
}

View File

@@ -5,6 +5,9 @@ $CONFIG = require 'config.php';
$CSS_BASE = ($CONFIG['prod']) ? ('styles.min.css') : ('styles.css');
global $REGISTERED_SCRIPTS;
$REGISTERED_SCRIPTS = [];
function startsWith($haystack, $needle)
{
$length = strlen($needle);
@@ -59,4 +62,23 @@ function formatMilliseconds($millis)
{
return floor($millis / (60 * 60 * 1000)) . ' hours';
}
}
function includeScriptOnce($script, $echo = true)
{
global $REGISTERED_SCRIPTS;
if ($echo)
{
if (in_array($script, $REGISTERED_SCRIPTS)) return false;
$REGISTERED_SCRIPTS []= $script;
echo "<script src=\"$script\" type=\"text/javascript\"></script>";
return true;
}
else
{
if (in_array($script, $REGISTERED_SCRIPTS)) return '';
$REGISTERED_SCRIPTS []= $script;
return "<script src=\"$script\" type=\"text/javascript\"></script>";
}
}

View File

@@ -22,7 +22,7 @@ class Blog
[ 'id' => 1, 'date' => '2014-07-10', 'visible' => true, 'title' => 'Project Euler with Befunge', 'fragment' => '', 'type' => 'euler', 'cat' => 'blog' ],
[ 'id' => 3, 'date' => '2014-07-15', 'visible' => true, 'title' => '.Net format specifier Cheat Sheet', 'fragment' => 'net_format_spec.md', 'type' => 'markdown', 'cat' => 'blog' ],
[ 'id' => 19, 'date' => '2014-08-04', 'visible' => true, 'title' => 'I am Number Four', 'fragment' => 'v4.md', 'type' => 'markdown', 'cat' => 'log' ],
[ 'id' => 7, 'date' => '2014-09-28', 'visible' => true, 'title' => 'My BFJoust arena and battle-bot', 'fragment' => '', 'type' => 'bfjoust', 'cat' => 'blog' ],
[ 'id' => 7, 'date' => '2014-09-28', 'visible' => true, 'title' => 'My BFJoust arena and battle-bot', 'fragment' => 'bfjoust.md', 'type' => 'markdown', 'cat' => 'blog' ],
[ 'id' => 8, 'date' => '2014-11-05', 'visible' => true, 'title' => 'Rapla Enhancement Script', 'fragment' => 'rapla_css.md', 'type' => 'markdown', 'cat' => 'blog' ],
[ 'id' => 20, 'date' => '2015-01-09', 'visible' => true, 'title' => 'More Befunge with Project Euler', 'fragment' => 'more_euler.md', 'type' => 'markdown', 'cat' => 'log' ],
[ 'id' => 9, 'date' => '2016-10-22', 'visible' => true, 'title' => 'A complete sudoku solver in Befunge-93', 'fragment' => 'sudoku_befunge.md', 'type' => 'markdown', 'cat' => 'blog' ],