a recusive descent markdown parser in PHP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

<?php
require __DIR__."/vendor/autoload.php";
echo "
<style>
body {
padding: 4rem;
margin: 0;
font-family: sans-serif;
}
img {
max-width: 100%;
}
code {
word-break: break-word;
white-space: break-spaces;
}
table {
width: 100%;
}
</style>
";
$file = dirname(__FILE__)."/README.md";
$source = file_get_contents($file);
try {
$Instance = new parkdown\Parkdown($source, true, $file);
echo $Instance->html();
} catch (parkdown\ParserError $error) {
echo "<pre>";
$message = explode(" ", $error->getMessage());
$location = array_shift($message);
$file = explode(":", $location)[0];
if ($file === "INPUT_STRING")
echo "$location ".implode(" ", $message);
else
echo "<a href='vscode://file/".substr($location, 0, -1)."'>$location</a> ".implode(" ", $message);
$stackTrace = explode("\n", $error->getTraceAsString());
echo "<p><small>";
foreach ($stackTrace as $step) {
$step = explode(" ", $step);
array_shift($step);
$location = array_shift($step);
$location = preg_replace("/\(([0-9]+)\):/", ":\$1:", $location);
echo "<a href='vscode://file/".substr($location, 0, -1)."'>$location</a> ".implode(" ", $step)."<br>";
}
echo "</small></p>";
}