1
0

ParsedownCustom

This commit is contained in:
Mike Schwörer 2018-01-01 23:03:05 +01:00
parent 32f1e8437b
commit e56ca264a3
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
36 changed files with 939 additions and 277 deletions

View File

@ -234,7 +234,6 @@ html, body {
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none; }
.bc_markdown pre {
font-size: 14px;
display: block;
@ -250,41 +249,48 @@ html, body {
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px; }
.bc_markdown blockquote {
padding: 0 0 0 15px;
margin: 0 0 20px;
border-left: 5px solid #CCC; }
.mdtable_container {
overflow-x: auto; }
.mdtable {
.bc_markdown img {
max-width: 100%; }
.bc_markdown table {
border-collapse: collapse;
text-align: left;
width: 100%;
border: 1px solid #666; }
.mdtable td, .mdtable th {
.bc_markdown table td, .bc_markdown table th {
padding: 3px 10px; }
.mdtable thead th {
.bc_markdown table thead th {
background-color: #7D7D7D;
color: #FFFFFF;
font-weight: bold;
border-left: 1px solid #444; }
.mdtable thead th:first-child {
.bc_markdown table thead th:first-child {
border: none; }
.mdtable tbody td {
.bc_markdown table tbody td {
border-left: 1px solid #666;
font-weight: normal; }
.mdtable tbody .alt td {
.bc_markdown table tbody .alt td {
background: #EBEBEB; }
.mdtable tbody td:first-child {
.bc_markdown table tbody td:first-child {
border-left: none; }
.mdtable tbody tr:last-child td {
.bc_markdown table tbody tr:last-child td {
border-bottom: none; }
.mdtable tbody tr:nth-child(odd) {
.bc_markdown table tbody tr:nth-child(odd) {
background-color: #ccc; }
.mdtable_container {
overflow-x: auto; }
.notable {
width: unset !important;
border: none !important; }
.notable th, .notable td, .notable tr {
border: none !important;
background: transparent !important; }
#PEB_tableProblems .PEB_tablerowProblems:hover {
background-color: #888; }
#PEB_tableProblems .PEB_TC_Value {
@ -611,7 +617,7 @@ html, body {
white-space: pre;
font-family: Consolas, Monaco, "Courier New", Menlo, monospace;
padding: 9.5px;
font-size: 11pt; }
font-size: 10pt; }
.bce_code .bce_code_ctrl {
background: #BBB;
display: flex;

View File

@ -51,16 +51,19 @@ html,body{margin:0;padding:0;height:100%}
.bc_markdown code{font-family:Consolas,Monaco,"Courier New",Menlo,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;-moz-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}
.bc_markdown pre{font-size:14px;display:block;padding:9.5px;margin:0 0 10px;line-height:20px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;background-color:#f8f8f8;color:black;border:1px solid rgba(0,0,0,0.15);-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}
.bc_markdown blockquote{padding:0 0 0 15px;margin:0 0 20px;border-left:5px solid #CCC}
.bc_markdown img{max-width:100%}
.bc_markdown table{border-collapse:collapse;text-align:left;width:100%;border:1px solid #666}
.bc_markdown table td,.bc_markdown table th{padding:3px 10px}
.bc_markdown table thead th{background-color:#7d7d7d;color:#fff;font-weight:bold;border-left:1px solid #444}
.bc_markdown table thead th:first-child{border:0}
.bc_markdown table tbody td{border-left:1px solid #666;font-weight:normal}
.bc_markdown table tbody .alt td{background:#ebebeb}
.bc_markdown table tbody td:first-child{border-left:0}
.bc_markdown table tbody tr:last-child td{border-bottom:0}
.bc_markdown table tbody tr:nth-child(odd){background-color:#ccc}
.mdtable_container{overflow-x:auto}
.mdtable{border-collapse:collapse;text-align:left;width:100%;border:1px solid #666}
.mdtable td,.mdtable th{padding:3px 10px}
.mdtable thead th{background-color:#7d7d7d;color:#fff;font-weight:bold;border-left:1px solid #444}
.mdtable thead th:first-child{border:0}
.mdtable tbody td{border-left:1px solid #666;font-weight:normal}
.mdtable tbody .alt td{background:#ebebeb}
.mdtable tbody td:first-child{border-left:0}
.mdtable tbody tr:last-child td{border-bottom:0}
.mdtable tbody tr:nth-child(odd){background-color:#ccc}
.notable{width:unset !important;border:none !important}
.notable th,.notable td,.notable tr{border:none !important;background:transparent !important}
#PEB_tableProblems .PEB_tablerowProblems:hover{background-color:#888}
#PEB_tableProblems .PEB_TC_Value{font-family:Consolas,Monaco,"Courier New",Menlo,monospace}
#PEB_tableProblems .PEB_TC_Value:not(:hover){color:transparent;-o-transition:.5s;-ms-transition:.5s;-moz-transition:.5s;-webkit-transition:.5s;transition:.5s}
@ -160,7 +163,7 @@ html,body{margin:0;padding:0;height:100%}
.bfjoust_runner_owner #run_speed{width:70px}
.bfjoust_runner_owner #board{background-color:#FFF;border-radius:6px;border:1px solid #CCC}
.bce_code{background:#f8f8f8;color:black;border:1px solid rgba(0,0,0,0.15)}
.bce_code .bce_code_data{overflow-x:auto;white-space:pre;font-family:Consolas,Monaco,"Courier New",Menlo,monospace;padding:9.5px;font-size:11pt}
.bce_code .bce_code_data{overflow-x:auto;white-space:pre;font-family:Consolas,Monaco,"Courier New",Menlo,monospace;padding:9.5px;font-size:10pt}
.bce_code .bce_code_ctrl{background:#BBB;display:flex;flex-direction:row}
.bce_code .bce_code_ctrl .ctrl_btn_left,.bce_code .bce_code_ctrl .ctrl_btn_right{display:flex;flex-direction:row}
.bce_code .bce_code_ctrl .ctrl_btn_left{margin-right:auto}

View File

@ -11,7 +11,7 @@
font-family: $FONT_CODE;
padding: 9.5px;
font-size: 11pt;
font-size: 10pt;
}
.bce_code_ctrl {

View File

@ -18,7 +18,9 @@
padding: 8px;
}
.bc_markdown code {
.bc_markdown {
code {
font-family: $FONT_CODE;
direction: ltr;
text-align: left;
@ -33,7 +35,7 @@
hyphens: none;
}
.bc_markdown pre {
pre {
font-size: 14px;
display: block;
padding: 9.5px;
@ -50,15 +52,17 @@
border-radius: 2px;
}
.bc_markdown blockquote {
blockquote {
padding: 0 0 0 15px;
margin: 0 0 20px;
border-left: 5px solid #CCC;
}
.mdtable_container {overflow-x: auto;}
img {
max-width: 100%;
}
.mdtable {
table {
border-collapse: collapse;
text-align: left;
width: 100%;
@ -99,7 +103,17 @@
tbody tr:nth-child(odd) {
background-color: #ccc;
}
}
}
.mdtable_container {overflow-x: auto;}
.notable {
width: unset !important;
border: none !important;
th,td,tr {
border: none !important;
background: transparent !important;
}
}

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -770,11 +770,15 @@ function collapse(code) {
//######################################################
window.onload = function ()
{
document.getElementById("a_expand").onclick = onExpandClicked;
document.getElementById("a_collapse").onclick = onCollapseClicked;
document.getElementById("a_run").onclick = onRunClicked;
document.getElementById("a_stop").onclick = onStopClicked;
document.getElementById("a_arena").onclick = onArenaClicked;
};
function onExpandClicked() {
var source1 = document.getElementById("source_1");

526
www/extern/ParsedownExtra.php vendored Normal file
View File

@ -0,0 +1,526 @@
<?php
#
#
# Parsedown Extra
# https://github.com/erusev/parsedown-extra
#
# (c) Emanuil Rusev
# http://erusev.com
#
# For the full license information, view the LICENSE file that was distributed
# with this source code.
#
#
class ParsedownExtra extends Parsedown
{
# ~
const version = '0.7.0';
# ~
function __construct()
{
if (parent::version < '1.5.0')
{
throw new Exception('ParsedownExtra requires a later version of Parsedown');
}
$this->BlockTypes[':'] []= 'DefinitionList';
$this->BlockTypes['*'] []= 'Abbreviation';
# identify footnote definitions before reference definitions
array_unshift($this->BlockTypes['['], 'Footnote');
# identify footnote markers before before links
array_unshift($this->InlineTypes['['], 'FootnoteMarker');
}
#
# ~
function text($text)
{
$markup = parent::text($text);
# merge consecutive dl elements
$markup = preg_replace('/<\/dl>\s+<dl>\s+/', '', $markup);
# add footnotes
if (isset($this->DefinitionData['Footnote']))
{
$Element = $this->buildFootnoteElement();
$markup .= "\n" . $this->element($Element);
}
return $markup;
}
#
# Blocks
#
#
# Abbreviation
protected function blockAbbreviation($Line)
{
if (preg_match('/^\*\[(.+?)\]:[ ]*(.+?)[ ]*$/', $Line['text'], $matches))
{
$this->DefinitionData['Abbreviation'][$matches[1]] = $matches[2];
$Block = array(
'hidden' => true,
);
return $Block;
}
}
#
# Footnote
protected function blockFootnote($Line)
{
if (preg_match('/^\[\^(.+?)\]:[ ]?(.*)$/', $Line['text'], $matches))
{
$Block = array(
'label' => $matches[1],
'text' => $matches[2],
'hidden' => true,
);
return $Block;
}
}
protected function blockFootnoteContinue($Line, $Block)
{
if ($Line['text'][0] === '[' and preg_match('/^\[\^(.+?)\]:/', $Line['text']))
{
return;
}
if (isset($Block['interrupted']))
{
if ($Line['indent'] >= 4)
{
$Block['text'] .= "\n\n" . $Line['text'];
return $Block;
}
}
else
{
$Block['text'] .= "\n" . $Line['text'];
return $Block;
}
}
protected function blockFootnoteComplete($Block)
{
$this->DefinitionData['Footnote'][$Block['label']] = array(
'text' => $Block['text'],
'count' => null,
'number' => null,
);
return $Block;
}
#
# Definition List
protected function blockDefinitionList($Line, $Block)
{
if ( ! isset($Block) or isset($Block['type']))
{
return;
}
$Element = array(
'name' => 'dl',
'handler' => 'elements',
'text' => array(),
);
$terms = explode("\n", $Block['element']['text']);
foreach ($terms as $term)
{
$Element['text'] []= array(
'name' => 'dt',
'handler' => 'line',
'text' => $term,
);
}
$Block['element'] = $Element;
$Block = $this->addDdElement($Line, $Block);
return $Block;
}
protected function blockDefinitionListContinue($Line, array $Block)
{
if ($Line['text'][0] === ':')
{
$Block = $this->addDdElement($Line, $Block);
return $Block;
}
else
{
if (isset($Block['interrupted']) and $Line['indent'] === 0)
{
return;
}
if (isset($Block['interrupted']))
{
$Block['dd']['handler'] = 'text';
$Block['dd']['text'] .= "\n\n";
unset($Block['interrupted']);
}
$text = substr($Line['body'], min($Line['indent'], 4));
$Block['dd']['text'] .= "\n" . $text;
return $Block;
}
}
#
# Header
protected function blockHeader($Line)
{
$Block = parent::blockHeader($Line);
if (preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
{
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
$Block['element']['text'] = substr($Block['element']['text'], 0, $matches[0][1]);
}
return $Block;
}
#
# Markup
protected function blockMarkupComplete($Block)
{
if ( ! isset($Block['void']))
{
$Block['markup'] = $this->processTag($Block['markup']);
}
return $Block;
}
#
# Setext
protected function blockSetextHeader($Line, array $Block = null)
{
$Block = parent::blockSetextHeader($Line, $Block);
if (preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['text'], $matches, PREG_OFFSET_CAPTURE))
{
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
$Block['element']['text'] = substr($Block['element']['text'], 0, $matches[0][1]);
}
return $Block;
}
#
# Inline Elements
#
#
# Footnote Marker
protected function inlineFootnoteMarker($Excerpt)
{
if (preg_match('/^\[\^(.+?)\]/', $Excerpt['text'], $matches))
{
$name = $matches[1];
if ( ! isset($this->DefinitionData['Footnote'][$name]))
{
return;
}
$this->DefinitionData['Footnote'][$name]['count'] ++;
if ( ! isset($this->DefinitionData['Footnote'][$name]['number']))
{
$this->DefinitionData['Footnote'][$name]['number'] = ++ $this->footnoteCount; # » &
}
$Element = array(
'name' => 'sup',
'attributes' => array('id' => 'fnref'.$this->DefinitionData['Footnote'][$name]['count'].':'.$name),
'handler' => 'element',
'text' => array(
'name' => 'a',
'attributes' => array('href' => '#fn:'.$name, 'class' => 'footnote-ref'),
'text' => $this->DefinitionData['Footnote'][$name]['number'],
),
);
return array(
'extent' => strlen($matches[0]),
'element' => $Element,
);
}
}
private $footnoteCount = 0;
#
# Link
protected function inlineLink($Excerpt)
{
$Link = parent::inlineLink($Excerpt);
$remainder = substr($Excerpt['text'], $Link['extent']);
if (preg_match('/^[ ]*{('.$this->regexAttribute.'+)}/', $remainder, $matches))
{
$Link['element']['attributes'] += $this->parseAttributeData($matches[1]);
$Link['extent'] += strlen($matches[0]);
}
return $Link;
}
#
# ~
#
protected function unmarkedText($text)
{
$text = parent::unmarkedText($text);
if (isset($this->DefinitionData['Abbreviation']))
{
foreach ($this->DefinitionData['Abbreviation'] as $abbreviation => $meaning)
{
$pattern = '/\b'.preg_quote($abbreviation, '/').'\b/';
$text = preg_replace($pattern, '<abbr title="'.$meaning.'">'.$abbreviation.'</abbr>', $text);
}
}
return $text;
}
#
# Util Methods
#
protected function addDdElement(array $Line, array $Block)
{
$text = substr($Line['text'], 1);
$text = trim($text);
unset($Block['dd']);
$Block['dd'] = array(
'name' => 'dd',
'handler' => 'line',
'text' => $text,
);
if (isset($Block['interrupted']))
{
$Block['dd']['handler'] = 'text';
unset($Block['interrupted']);
}
$Block['element']['text'] []= & $Block['dd'];
return $Block;
}
protected function buildFootnoteElement()
{
$Element = array(
'name' => 'div',
'attributes' => array('class' => 'footnotes'),
'handler' => 'elements',
'text' => array(
array(
'name' => 'hr',
),
array(
'name' => 'ol',
'handler' => 'elements',
'text' => array(),
),
),
);
uasort($this->DefinitionData['Footnote'], 'self::sortFootnotes');
foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData)
{
if ( ! isset($DefinitionData['number']))
{
continue;
}
$text = $DefinitionData['text'];
$text = parent::text($text);
$numbers = range(1, $DefinitionData['count']);
$backLinksMarkup = '';
foreach ($numbers as $number)
{
$backLinksMarkup .= ' <a href="#fnref'.$number.':'.$definitionId.'" rev="footnote" class="footnote-backref">&#8617;</a>';
}
$backLinksMarkup = substr($backLinksMarkup, 1);
if (substr($text, - 4) === '</p>')
{
$backLinksMarkup = '&#160;'.$backLinksMarkup;
$text = substr_replace($text, $backLinksMarkup.'</p>', - 4);
}
else
{
$text .= "\n".'<p>'.$backLinksMarkup.'</p>';
}
$Element['text'][1]['text'] []= array(
'name' => 'li',
'attributes' => array('id' => 'fn:'.$definitionId),
'text' => "\n".$text."\n",
);
}
return $Element;
}
# ~
protected function parseAttributeData($attributeString)
{
$Data = array();
$attributes = preg_split('/[ ]+/', $attributeString, - 1, PREG_SPLIT_NO_EMPTY);
foreach ($attributes as $attribute)
{
if ($attribute[0] === '#')
{
$Data['id'] = substr($attribute, 1);
}
else # "."
{
$classes []= substr($attribute, 1);
}
}
if (isset($classes))
{
$Data['class'] = implode(' ', $classes);
}
return $Data;
}
# ~
protected function processTag($elementMarkup) # recursive
{
# http://stackoverflow.com/q/1148928/200145
libxml_use_internal_errors(true);
$DOMDocument = new DOMDocument;
# http://stackoverflow.com/q/11309194/200145
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
# http://stackoverflow.com/q/4879946/200145
$DOMDocument->loadHTML($elementMarkup);
$DOMDocument->removeChild($DOMDocument->doctype);
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
$elementText = '';
if ($DOMDocument->documentElement->getAttribute('markdown') === '1')
{
foreach ($DOMDocument->documentElement->childNodes as $Node)
{
$elementText .= $DOMDocument->saveHTML($Node);
}
$DOMDocument->documentElement->removeAttribute('markdown');
$elementText = "\n".$this->text($elementText)."\n";
}
else
{
foreach ($DOMDocument->documentElement->childNodes as $Node)
{
$nodeMarkup = $DOMDocument->saveHTML($Node);
if ($Node instanceof DOMElement and ! in_array($Node->nodeName, $this->textLevelElements))
{
$elementText .= $this->processTag($nodeMarkup);
}
else
{
$elementText .= $nodeMarkup;
}
}
}
# because we don't want for markup to get encoded
$DOMDocument->documentElement->nodeValue = 'placeholder\x1A';
$markup = $DOMDocument->saveHTML($DOMDocument->documentElement);
$markup = str_replace('placeholder\x1A', $elementText, $markup);
return $markup;
}
# ~
protected function sortFootnotes($A, $B) # callback
{
return $A['number'] - $B['number'];
}
#
# Fields
#
protected $regexAttribute = '(?:[#.][-\w]+[ ]*)';
}

View File

@ -0,0 +1,31 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
global $PARAM_CODE;
global $PARAM_URL;
global $PARAM_INTERACTIVE;
$result = '';
$result .= '<div class="bce_code">' . "\n";
$result .= ' <div class="bce_code_data">' .htmlspecialchars($PARAM_CODE) . '</div>' . "\n";
$result .= ' <div class="bce_code_ctrl">' . "\n";
if ($PARAM_INTERACTIVE) {
$result .= ' <div class="ctrl_btn_left">' . "\n";
$result .= ' <div class="ctrl_btn">Start</div>' . "\n";
$result .= ' <div class="ctrl_btn">Stop</div>' . "\n";
$result .= ' <div class="ctrl_btn">Reset</div>' . "\n";
$result .= ' </div>' . "\n";
}
if ($PARAM_URL !== '') {
$result .= ' <div class="ctrl_btn_right">' . "\n";
$result .= ' <a class="ctrl_btn" href="' .$PARAM_URL . '" download target="_blank">Download</a>' . "\n";
$result .= ' </div>' . "\n";
}
$result .= ' </div>' . "\n";
$result .= '</div>' . "\n";
$result .= includeScriptOnce("/data/javascript/blogpost_bef93runner.js", false) . "\n";
return $result;

View File

@ -4,44 +4,37 @@ require_once (__DIR__ . '/../internals/base.php');
global $PARAM_CODE_LEFT;
global $PARAM_CODE_RIGHT;
?>
$result = '';
<div class="bfjoust_runner_owner" >
<div class="hsplit">
<textarea class="hsplit_1 source" id="source_1"><?php echo htmlspecialchars($PARAM_CODE_LEFT); ?></textarea>
<textarea class="hsplit_2 source" id="source_2"><?php echo htmlspecialchars($PARAM_CODE_RIGHT); ?></textarea>
</div>
$result .= '<div class="bfjoust_runner_owner">' . "\n";
$result .= ' <div class="hsplit">' . "\n";
$result .= ' <textarea class="hsplit_1 source" id="source_1">' . htmlspecialchars($PARAM_CODE_LEFT) . '</textarea>' . "\n";
$result .= ' <textarea class="hsplit_2 source" id="source_2">' . htmlspecialchars($PARAM_CODE_RIGHT) . '</textarea>' . "\n";
$result .= ' </div>' . "\n";
<div id="commandpanel">
<div>
<div>
<a href="#" id="a_expand">expand</a>
|
<a href="#" id="a_collapse">collapse</a>
|
<a href="#" id="a_run">run</a>
(size:
<input type="number" id="run_size" min="10" max="30" value="30" width="30">
speed:
<input type="number" id="run_speed" min="0" max="10000" value="10">
)
|
<a href="#" id="a_stop">stop</a>
|
<a href="#" id="a_arena">arena</a>
</div>
</div>
</div>
$result .= ' <div id="commandpanel">' . "\n";
$result .= ' <div>' . "\n";
$result .= ' <div>' . "\n";
$result .= ' <a href="#" id="a_expand">expand</a>|<a href="#" id="a_collapse">collapse</a>|<a href="#" id="a_run">run</a>' . "\n";
$result .= ' (size:<input type="number" id="run_size" min="10" max="30" value="30" width="30"> speed:<input type="number" id="run_speed" min="0" max="10000" value="10">)' . "\n";
$result .= ' | <a href="#" id="a_stop">stop</a> | <a href="#" id="a_arena">arena</a>' . "\n";
$result .= ' </div>' . "\n";
$result .= ' </div>' . "\n";
$result .= ' </div>' . "\n";
<div class="hsplit">
<textarea class="hsplit_1 sink" id="sink_1"></textarea>
<textarea class="hsplit_2 sink" id="sink_2"></textarea>
</div>
$result .= ' <div class="hsplit">' . "\n";
$result .= ' <textarea class="hsplit_1 sink" id="sink_1"></textarea>' . "\n";
$result .= ' <textarea class="hsplit_2 sink" id="sink_2"></textarea>' . "\n";
$result .= ' </div>' . "\n";
<div class="hsplit">
<canvas class="hsplit_1 bottomelem" id="board"></canvas>
<textarea class="hsplit_2 bottomelem" id="log" wrap="off"> </textarea>
</div>
</div>
$result .= ' <div class="hsplit">' . "\n";
$result .= ' <canvas class="hsplit_1 bottomelem" id="board"></canvas>' . "\n";
$result .= ' <textarea class="hsplit_2 bottomelem" id="log" wrap="off"> </textarea>' . "\n";
$result .= ' </div>' . "\n";
$result .= '</div>' . "\n";
<script src="/data/javascript/blogpost_BFJoustBot_script.js"></script>
$result .= '' . "\n";
$result .= includeScriptOnce("/data/javascript/blogpost_BFJoustBot_script.js", false) . "\n";
return $result;

View File

@ -1,34 +0,0 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../extern/Parsedown.php');
?>
<div class="blogcontent bc_markdown">
<div class="bc_header">
<?php echo $post['date']; ?>
</div>
<div class="bc_data">
<?php
$code_own = file_get_contents(__DIR__ . '/../statics/blog/bfjoust_MultiVAC.bfjoust');
$code_opp = file_get_contents(__DIR__ . '/../statics/blog/bfjoust_Patashu_lazy.bfjoust');
$pd = new Parsedown();
$dat = file_get_contents( __DIR__ . '/../statics/blog/bfjoust.md');
$dat = str_replace("{{CODE}}", $code_own, $dat);
echo $pd->text($dat);
global $PARAM_CODE_LEFT;
global $PARAM_CODE_RIGHT;
$PARAM_CODE_LEFT = $code_own;
$PARAM_CODE_RIGHT = $code_opp;
include (__DIR__ . '/../fragments/bfjoust_runner.php');
?>
</div>
</div>

View File

@ -12,7 +12,7 @@ $problems = Euler::listAll();
<div style="position: relative;">
<a href="https://github.com/Mikescher/Project-Euler_Befunge" style="position: absolute; top: 0; right: 0; border: 0;">
<img src="/data/images/github_band.png" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
<img src="/data/images/blog/github_band.png" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
</div>

View File

@ -2,7 +2,7 @@
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../internals/euler.php');
require_once (__DIR__ . '/../extern/Parsedown.php');
require_once (__DIR__ . '/../internals/ParsedownCustom.php');
$subview = $OPTIONS['subview'];
@ -11,7 +11,7 @@ $problem = Euler::getEulerProblem(intval(explode('-', $subview)[1]));
if ($post === NULL) httpError(404, 'problem not found');
$pd = new Parsedown();
$pd = new ParsedownCustom();
$arr = [];
@ -29,7 +29,7 @@ $max = ceil($max / 20) * 20;
<div style="position: relative;">
<a href="https://github.com/Mikescher/Project-Euler_Befunge" style="position: absolute; top: 0; right: 0; border: 0;">
<img src="/data/images/github_band.png" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
<img src="/data/images/blog/github_band.png" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
</div>
@ -45,44 +45,22 @@ $max = ceil($max / 20) * 20;
<div class="bce_description"><?php echo $pd->text(file_get_contents($problem['file_description'])); ?></div>
<br/>
<?php if ($problem['abbreviated']): ?>
<b>Solution:</b>
<div class="bce_code">
<div class="bce_code_data"><?php echo htmlspecialchars(file_get_contents($problem['file_code'])); ?></div>
<div class="bce_code_ctrl">
<div class="ctrl_btn_right">
<a class="ctrl_btn" href="<?php echo $problem['url_raw']; ?>" download target="_blank">Download</a>
</div>
</div>
</div>
<?php
global $PARAM_CODE;
global $PARAM_URL;
$PARAM_CODE = file_get_contents($problem['file_code']);
$PARAM_URL = $problem['url_raw'];
$PARAM_INTERACTIVE = !$problem['abbreviated'];
echo require (__DIR__ . '/../fragments/befunge93_runner.php');
?>
<br/>
<?php else: ?>
<b>Solution:</b>
<div class="bce_code">
<div class="bce_code_data"><?php echo htmlspecialchars(file_get_contents($problem['file_code'])); ?></div>
<div class="bce_code_ctrl">
<div class="ctrl_btn_left">
<div class="ctrl_btn">Start</div>
<div class="ctrl_btn">Stop</div>
<div class="ctrl_btn">Reset</div>
</div>
<div class="ctrl_btn_right">
<a class="ctrl_btn" href="<?php echo $problem['url_raw']; ?>" download target="_blank">Download</a>
</div>
</div>
</div>
<br/>
<?php endif; ?>
<b>Explanation:</b>
<div class="bce_explanation"><?php echo $pd->text(file_get_contents($problem['file_explanation'])); ?></div>
<br/>
<table>
<table class="notable">
<tr>
<td><b>Interpreter steps:</b></td>
<td><?php echo number_format($problem['steps'], 0, null, ' '); ?></td>

View File

@ -1,7 +1,7 @@
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/blog.php');
require_once (__DIR__ . '/../extern/Parsedown.php');
require_once (__DIR__ . '/../internals/ParsedownCustom.php');
?>
<div class="blogcontent bc_markdown">
@ -12,7 +12,7 @@ require_once (__DIR__ . '/../extern/Parsedown.php');
<div class="bc_data">
<?php
$pd = new Parsedown();
$pd = new ParsedownCustom();
echo $pd->text(Blog::getPostFragment($post));
?>
</div>

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);
@ -60,3 +63,22 @@ 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' ],

View File

@ -9,7 +9,50 @@ The thing that surprised me the most is the [strategically depth](http://esolang
So here is my own bot *(originally made for [stackexchange](http://codegolf.stackexchange.com/questions/36645/brainfedbotsforbattling-a-brainf-tournament))*, it can't really keep up with the big ones from egojoust but I'm fairly proud of it:
```
{{CODE}}
> # Build 9 big decoys
(-)*4>(+)*4> # A few small ones
(>)*6
(<(-)*80<(+)*80)*3 # And more big ones
<(+)*76 # For Confusion :/
<(-)*76
<(-)*28 # Just for you, Wall E
(>)*10
( # Walk forwards and clear everything
([+ # clear pos decoys
{
(-)*16
(-[ # clear neg decoys
{
(-)*112 # Big decoy / flag clearen: 128~16=112
[+]
}
])%16
}
])%16
[-] # Counter DecoyBot ~_~
(+)*2 # Leave a small trail behind
>
([- # The same thing with reversed polarity
{
(+)*16
(+[
{
(+)*112
[-]
}
])%16
}
])%16
[+]
(-)*2
>
)*11
```
A few notes to the BFJoust extensions to the brainfuck language:
@ -28,3 +71,53 @@ I wrote a little [BFJoust script](https://maximum-sonata.codio.io/index.html) wh
And at last a few words to the arena: In BFJoust there are 40 different settings, every board length two times. One time normal and one time with one bot inverted (`+` <-> `-`). This way you can eliminate luck and see which bot performs better.
```bfjoustrunner
> # Build 9 big decoys
(-)*4>(+)*4> # A few small ones
(>)*6
(<(-)*80<(+)*80)*3 # And more big ones
<(+)*76 # For Confusion :/
<(-)*76
<(-)*28 # Just for you, Wall E
(>)*10
( # Walk forwards and clear everything
([+ # clear pos decoys
{
(-)*16
(-[ # clear neg decoys
{
(-)*112 # Big decoy / flag clearen: 128~16=112
[+]
}
])%16
}
])%16
[-] # Counter DecoyBot ~_~
(+)*2 # Leave a small trail behind
>
([- # The same thing with reversed polarity
{
(+)*16
(+[
{
(+)*112
[-]
}
])%16
}
])%16
[+]
(-)*2
>
)*11
------------------------------------------------------------------------------------------------------------------------
#Patashu_lazy from #esoteric hill
>(+)*5>(-)*5>(+)*5>(-)*5>(-)*5>(+)*5>(+)*5>(-)*5(>(-.)*128)*21[-]((-)*2048(+)*2048.)*2
```

View File

@ -1,44 +0,0 @@
> # Build 9 big decoys
(-)*4>(+)*4> # A few small ones
(>)*6
(<(-)*80<(+)*80)*3 # And more big ones
<(+)*76 # For Confusion :/
<(-)*76
<(-)*28 # Just for you, Wall E
(>)*10
( # Walk forwards and clear everything
([+ # clear pos decoys
{
(-)*16
(-[ # clear neg decoys
{
(-)*112 # Big decoy / flag clearen: 128~16=112
[+]
}
])%16
}
])%16
[-] # Counter DecoyBot ~_~
(+)*2 # Leave a small trail behind
>
([- # The same thing with reversed polarity
{
(+)*16
(+[
{
(+)*112
[-]
}
])%16
}
])%16
[+]
(-)*2
>
)*11

View File

@ -1,3 +0,0 @@
#Patashu_lazy from #esoteric hill
>(+)*5>(-)*5>(+)*5>(-)*5>(-)*5>(+)*5>(+)*5>(-)*5(>(-.)*128)*21[-]((-)*2048(+)*2048.)*2

View File

@ -1,10 +1,10 @@
![rapla_logo](/data/blog/Rapscript/logo.png)
![rapla_logo](/data/images/blog/rapla_logo.png)
I don't think many of you know [rapla](https://code.google.com/p/rapla/). And you should probably be thankful about that. But if you happen to study at the DHBW-KA, or any other place that uses rapla you could be interested in my enhancement-script.
Rapla is a Resource scheduling and event planing software (mostly used for timetables), and my rapscript enhances the *(not very good)* online view.
![full_preview](/data/blog/Rapscript/preview.png)
![full_preview](/data/images/blog/rapla_preview.png)
It contains the following features:
@ -18,5 +18,5 @@ It contains the following features:
The script works on [Greasemonkey](https://addons.mozilla.org/de/firefox/addon/greasemonkey/) for Firefox or [Tampermonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo) for Google Chrome and can be downloaded from this Gist:
[Open Gist](https://gist.github.com/Mikescher/f3d51a40dd0c5228df86)
# [Open Gist](https://gist.github.com/Mikescher/f3d51a40dd0c5228df86)

View File

@ -1,4 +1,4 @@
![sudoku debug](/data/blog/SudokuSolver/sudoku.png)
![sudoku debug](/data/images/blog/sudoku.png)
Because of [this project euler puzzle](https://www.mikescher.com/blog/1/Project_Euler_with_Befunge/problem-096) I spend the last few days implementing a sudoku solver in befunge-93 (as always I ignored the 80x25 size restriction because otherwise befunge-93 would be not turing-complete and I'm pretty sure this problem impossible).
@ -7,7 +7,7 @@ My solver is universal and can solve both ones. If there are no obvious cells it
Below i try to describe my general approach and a few caveats I stumbled across. You can look at the full up-to-date source code on [github](https://github.com/Mikescher/BefungePrograms).
~~~
~~~befungerunner
v XX ########### ########### ############################# #############################
C C #36 2 89# # # # # # #
PPPPP # 361 # # # # # # #

View File

@ -1,5 +1,5 @@
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
![Grid Image](/data/blog/Befunge/p015.gif)
![Grid Image](/data/images/blog/p015.gif)
How many such routes are there through a 20×20 grid?

View File

@ -1,6 +1,6 @@
Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.
![](https://projecteuler.net/project/images/p068_1.gif)
![](/data/images/blog/p068_1.gif)
Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely.
For example, the above solution can be described by the set: `4,3,2; 6,2,1; 5,1,3`.
@ -23,4 +23,4 @@ By concatenating each group it is possible to form 9-digit strings; the maximum
Using the numbers 1 to 10, and depending on arrangements, it is possible to form 16- and 17-digit strings.
What is the maximum 16-digit string for a "magic" 5-gon ring?
![](https://projecteuler.net/project/images/p068_2.gif)
![](/data/images/blog/p068_2.gif)

View File

@ -1,6 +1,6 @@
By counting carefully it can be seen that a rectangular grid measuring 3 by 2 contains eighteen rectangles:
![Grid Image](/data/blog/Befunge/p085.gif)
![Grid Image](/data/images/blog/p085.gif)
Although there exists no rectangular grid that contains exactly two million rectangles,
find the area of the grid with the nearest solution.

View File

@ -1,7 +1,7 @@
The points `P(x1, y1)` and `Q(x2, y2)` are plotted at integer co-ordinates and are joined to the origin,
`O(0,0)`, to form `OPQ`.
![img](/data/blog/Befunge/p091_1.gif)
![img](/data/images/blog/p091_1.gif)
There are exactly fourteen triangles containing a right angle that can be formed when each co-ordinate
lies between 0 and 2 inclusive; that is,
@ -10,6 +10,6 @@ lies between 0 and 2 inclusive; that is,
0 <= x1, y1, x2, y2 <= 2.
~~~
![img](/data/blog/Befunge/p091_2.gif)
![img](/data/images/blog/p091_2.gif)
Given that `0 <= x1, y1, x2, y2 <= 50`, how many right triangles can be formed?