-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.php
56 lines (51 loc) · 1.22 KB
/
parser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace jack\cmd;
$composerAutoload = [
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../autoload.php',
];
foreach ($composerAutoload as $autoload) {
if (file_exists($autoload)) {
require($autoload);
break;
}
}
$parser = new ColoredMarkdown();
if (php_sapi_name() === 'cli') {
if ($argc > 1)
$markdown = file_get_contents($argv[1]);
else
$markdown = stream_get_contents(STDIN);
if (isset($debug) && $debug)
{
echo $parser->parse($markdown);
die();
}
else
{
$head = <<<EOF
<head>
<title>Colored Markdown Demo</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {inlineMath: [["$","$"]]}
});
</script>
<script type="text/javascript" src="MathJax/MathJax.js"></script>
<link rel="stylesheet" href="static/my.css" type="text/css" />
</head>
<body>
EOF;
echo $head . $parser->parse($markdown) . '</body>';
die();
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['text']) {
$markdown = $_POST['text'];
echo $parser->parse($markdown);
die();
} else {
http_response_code(404);
die();
}