Created
July 6, 2020 19:19
-
-
Save neckro/f0c073a879b50a48b9e5b9516b0f5876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
$file = realpath(@$_GET['f']); | |
$p = pathinfo($file); | |
if (!$file || strtolower(@$p['extension']) !== 'md') { | |
http_response_code(403); | |
exit; | |
} | |
$cmd = sprintf( | |
'./peg-multimarkdown/multimarkdown %s --smart', | |
escapeshellcmd($file) | |
); | |
$html = html_entity_decode( | |
preg_replace( | |
[ | |
'/–(\d)/', // wrong dash before number | |
'/–/', // wrong em-dash | |
], | |
[ | |
'‑\1', // non-breaking hyphen | |
'—' // proper em-dash | |
], | |
shell_exec($cmd) | |
), | |
ENT_HTML5, | |
'UTF-8' | |
); | |
// set the title to the contents of the first header tag | |
if (preg_match('/<(h[1-4][^>]*>)(.*)<\//U', $html, $matches)) { | |
// strip extraneous HTML tags | |
$title = preg_replace('/<.*>/U', '', $matches[2]); | |
} else { | |
$title = str_replace('_', ' ', $p['filename']); | |
} | |
header("Content-Type: text/html"); | |
?><!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> | |
<link href="/cgi/static/markdown.css" rel="stylesheet" /> | |
<title><?= $title ?></title> | |
</head> | |
<body> | |
<?= $html ?> | |
<?php /* <a href="?orig" style="display: block; position: absolute; right: 0; margin-top: 1em; padding: .2em; line-height: 0.8em; background-color: #ddd; font-size: .8em; font-family: monospace;"><?= "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ?></a> */?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment