2021-11-22 22:53:02 +08:00
|
|
|
<?php
|
|
|
|
|
2023-01-24 20:30:27 +08:00
|
|
|
use SukWs\Bookshelf\Data\PageMeta;
|
2023-01-25 13:03:58 +08:00
|
|
|
use SukWs\Bookshelf\Utils\HTML\HTML;
|
|
|
|
use SukWs\Bookshelf\Utils\LaTeX\LaTeX;
|
2023-01-25 00:45:22 +08:00
|
|
|
use SukWs\Bookshelf\Utils\Markdown\Markdown;
|
|
|
|
use SukWs\Bookshelf\Utils\ReST\ReST;
|
2021-11-24 14:24:09 +08:00
|
|
|
|
2023-01-24 19:08:15 +08:00
|
|
|
// if the `compatibility.article.title.oldversion` is enabled
|
|
|
|
// that means the title should be auto-generated from book.xml
|
|
|
|
// but not written on page.md.
|
|
|
|
// this code will generate a title from book.xml if the start
|
|
|
|
// of the page.md is not `# Title` formatting page title.
|
2023-01-25 00:45:22 +08:00
|
|
|
if (PageMeta::compatibilityOldTitlePolicy() && PageMeta::$page->hasContent(Markdown::type[0])) {
|
|
|
|
$pageMarkdownContent = PageMeta::$page->getContent(Markdown::type[0]);
|
2021-11-24 14:24:09 +08:00
|
|
|
$length = strlen($pageMarkdownContent);
|
|
|
|
for ($i=0; $i<$length; $i++) {
|
|
|
|
if (empty(trim($pageMarkdownContent[$i]))) {
|
|
|
|
continue;
|
|
|
|
} else if ($pageMarkdownContent[$i] == '#' && $pageMarkdownContent[$i+1] != '#') {
|
|
|
|
break;
|
|
|
|
}
|
2021-11-25 03:36:59 +08:00
|
|
|
echo "<!-- compatibility old-title policy triggered -->\n";
|
2021-11-24 14:24:09 +08:00
|
|
|
echo "<h1 id='phb-page-".PageMeta::$page->getId()."'>".PageMeta::$page->getName()."</h1>\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 00:45:22 +08:00
|
|
|
$parsers = array(
|
2023-01-25 13:03:58 +08:00
|
|
|
new HTML(),
|
2023-01-25 00:45:22 +08:00
|
|
|
new Markdown(),
|
2023-01-25 13:03:58 +08:00
|
|
|
new LaTeX(),
|
2023-01-25 00:45:22 +08:00
|
|
|
new ReST()
|
|
|
|
);
|
|
|
|
|
|
|
|
$htmlContent = null;
|
|
|
|
|
|
|
|
foreach ($parsers as $parser) {
|
|
|
|
$ok = false;
|
|
|
|
foreach ($parser->type() as $suffix) {
|
|
|
|
if (PageMeta::$page->hasContent($suffix)) {
|
|
|
|
$htmlContent = $parser->parse(PageMeta::$page->getContent($suffix));
|
|
|
|
$ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($ok) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $htmlContent;
|