- $r = fopen($file, "r");
- $md = MarkdownDocument::createFromStream($r);
- $md->compile();
- $md->writeHtml(OUTPUT);
- unset($md);
- fclose($r);
+ $file = rtrim($file, "/");
+ if (is_file($file) || is_file($file .= ".md")) {
+ $pi = pathinfo($file);
+
+ switch (@$pi["extension"]) {
+ case "md":
+ $r = fopen($file, "r");
+ $md = MarkdownDocument::createFromStream($r);
+ $md->compile(MarkdownDocument::AUTOLINK);
+ print str_replace("<br/>","<br />",$md->getHtml());
+ fclose($r);
+ ml($file);
+ break;
+ case null:
+ printf("<h1>%s</h1>", basename($file));
+ printf("<pre>%s</pre>\n", htmlspecialchars(file_get_contents($file)));
+ break;
+ }
+ } else {
+ http\Env::setResponseCode(404);
+ printf("<h1>Not Found</h1>\n");
+ printf("<blockquote><p>Sorry, I could not find <code>%s/%s</code>.</p></blockquote>", dirname($file), basename($file, ".md"));
+ }
+}