X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.php;h=53c652913cae1b0804bbac55e7dd177fb257acfa;hb=c814ac9fbd7245879173e1abf0c30c9a9d186b78;hp=93454eceddd5abfb2dd306e4bb90420805fb4cc7;hpb=46d9b15be0fb214993462c7fa1187896b949d00a;p=mdref%2Fmdref diff --git a/index.php b/index.php index 93454ec..53c6529 100644 --- a/index.php +++ b/index.php @@ -62,7 +62,25 @@ function head($file, $lines = 1) { return $ld; } -function ns($file) { +function ns($path) { + $ns = ""; + $parts = explode("/", $path); + $upper = ctype_upper($path[0]); + for ($i = 0; $i < count($parts); ++$i) { + if (!strlen($parts[$i]) || $parts[$i] === ".") { + continue; + } + if (strlen($ns)) { + if ($upper && !ctype_upper($parts[$i][0])) { + $ns .= "::"; + } else { + $ns .= "\\"; + } + } + $ns .= $parts[$i]; + $upper = ctype_upper($parts[$i][0]); + } + return $ns; return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); } @@ -98,12 +116,13 @@ function ls($dir) { if (!isset($pi["extension"]) || $pi["extension"] != "md") { continue; } - if (!is_dir("$dir/".$pi["filename"])) { + /* ignore files where an accompanying directory exists */ + if (is_dir("$dir/".$pi["filename"])) { continue; } } else { - /* ignore directories where an companying file exists */ - if (is_file("$path.md")) { + /* ignore directories where no accompanying file exists */ + if (!is_file("$path.md")) { continue; } } @@ -130,28 +149,47 @@ function ml($file) { return; } if (!ctype_upper($pi["filename"][0])) { - return; - } - $dir = $pi["dirname"] . "/" . $pi["filename"]; - if (is_dir($dir)) { - printf("

Methods:

\n"); - printf("\n"); } } -function md($file) { +function md($file, $res) { $file = rtrim($file, "/"); if (is_file($file) || is_file($file .= ".md")) { $pi = pathinfo($file); @@ -160,7 +198,7 @@ function md($file) { case "md": $r = fopen($file, "r"); $md = MarkdownDocument::createFromStream($r); - $md->compile(MarkdownDocument::AUTOLINK); + $md->compile(MarkdownDocument::AUTOLINK|MarkdownDocument::TOC); print str_replace("
","
",$md->getHtml()); fclose($r); ml($file); @@ -171,17 +209,12 @@ function md($file) { break; } } else { - http\Env::setResponseCode(404); + $res->setResponseCode(404); printf("

Not Found

\n"); printf("

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

", dirname($file), basename($file, ".md")); } } -function index($pn) { - ?> - "text/css", "js"=>"application/javascript"]; $r = new http\Env\Request; @@ -229,7 +262,7 @@ ob_start($s); ob_end_flush(); ?> - +