X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.php;h=93454eceddd5abfb2dd306e4bb90420805fb4cc7;hb=46d9b15be0fb214993462c7fa1187896b949d00a;hp=5c4f5a77e4513ae8f7c8c75b1b5653e26d0f4e17;hpb=d3e33e708a783c634a3f8f5db634a7f03f8520f4;p=mdref%2Fmdref diff --git a/index.php b/index.php index 5c4f5a7..93454ec 100644 --- a/index.php +++ b/index.php @@ -62,30 +62,6 @@ function head($file, $lines = 1) { return $ld; } -function tail($file, $lines = 1) { - $bs = 512; - $fs = 0; - $ld = []; - if (is_resource($file) || ($file = fopen($file, "r"))) { - fseek($file, 0, SEEK_END); - $fs = ftell($file); - $fp = $fs; - $ls = ""; - while ($fp > 0 && count($ld) < $lines) { - do { - fseek($file, -min($fp, $bs), SEEK_CUR); - $fp = ftell($file); - $ls = fread($file, $fs-$fp) . $ls; - } while ($fp > 0 && -1 === ($eol = strrpos($ls, "\n", $ls))); - - array_unshift($ld, substr($ls, $eol)); - $ls = substr($ls, 0, $eol-1); - } - } - - return $ld; -} - function ns($file) { return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); } @@ -97,16 +73,17 @@ function urlpath($dir, $file) { function ls($dir) { $dir = rtrim(is_dir($dir) ? $dir : dirname($dir) ."/". basename($dir, ".md"), "/"); printf("\n"); @@ -142,55 +123,60 @@ function ls($dir) { function ml($file) { $pi = pathinfo($file); - if (ctype_upper($pi["filename"][0])) { + if (!isset($pi["extension"])) { + return; + } + if ($pi["extension"] !== "md") { + return; + } + if (!ctype_upper($pi["filename"][0])) { + return; + } + $dir = $pi["dirname"] . "/" . $pi["filename"]; + if (is_dir($dir)) { printf("

Methods:

\n"); - $dir = $pi["dirname"] . "/" . $pi["filename"]; - if (is_dir($dir)) { - printf("\n"); } } function md($file) { $file = rtrim($file, "/"); if (is_file($file) || is_file($file .= ".md")) { - if (extension_loaded("discount") && getenv("DISCOUNT")) { + $pi = pathinfo($file); + + switch (@$pi["extension"]) { + case "md": $r = fopen($file, "r"); $md = MarkdownDocument::createFromStream($r); $md->compile(MarkdownDocument::AUTOLINK); print str_replace("
","
",$md->getHtml()); fclose($r); - } else { - printf("\n", - rawurlencode(file_get_contents($file))); + ml($file); + break; + case null: + printf("

%s

", basename($file)); + printf("
%s
\n", htmlspecialchars(file_get_contents($file))); + break; } - ml($file); } else { - printf("

Quick Markdown Doc Browser

\n"); - printf("

v0.1.0

\n"); - printf("

"); - ob_start(function($s) { - return nl2br(htmlspecialchars($s)); - }); - readfile("LICENSE"); - ob_end_flush(); - printf("

\n"); + http\Env::setResponseCode(404); + printf("

Not Found

\n"); + printf("

Sorry, I could not find %s/%s.

", dirname($file), basename($file, ".md")); } } - function index($pn) { ?> path; switch($p) { +case "./index.php": + exit; case "./index.js": -case "./markdown.js": case "./index.css": $s->setHeader("Content-type", $t[pathinfo($p, PATHINFO_EXTENSION)]); $s->setBody(new http\Message\Body(fopen($p, "r"))); @@ -231,7 +218,25 @@ ob_start($s); - + +

Quick Markdown Documentation Browser

+

v

+
+ + + + +