changing doc format and HTML literals

This commit is contained in:
udo
2026-04-22 01:56:46 +00:00
parent 8223dcc6b3
commit f7b066b374
123 changed files with 1917 additions and 1611 deletions
+142 -86
View File
@@ -1,97 +1,157 @@
struct DocPage {
String title;
String content;
StringList sig_lines;
StringList param_lines;
StringList see_lines;
};
StringMap* already_shown_items;
String doc_default_title(String page)
{
String page_title = page;
if(page_title.length() > 1 && page_title[1] == '_')
nibble(page_title, "_");
return(page_title);
}
String doc_markdown_inline(String text)
{
text = trim(text);
if(text == "")
return("");
String html = markdown_to_html(text);
if(html.length() >= 7 && html.substr(0, 3) == "<p>" && html.substr(html.length() - 4) == "</p>")
return(html.substr(3, html.length() - 7));
return(html);
}
String doc_legacy_heading(String section)
{
if(section == "desc")
return("");
if(section == "related")
return("## PHP & JS Equivalents");
return("## " + section);
}
DocPage load_doc_page(String page)
{
DocPage result;
StringList lines = split(file_get_contents("pages/" + page + ".txt"), "\n");
String current_section = "";
bool content_mode = false;
StringList content_lines;
for(auto line : lines)
{
if(!content_mode && line != "" && line.substr(0, 1) == ":")
{
String section = trim(line.substr(1));
if(section == "title" || section == "sig" || section == "params" || section == "see")
{
current_section = section;
continue;
}
if(section == "content")
{
content_mode = true;
current_section = "content";
continue;
}
current_section = "legacy";
String heading = doc_legacy_heading(section);
if(heading != "")
{
if(content_lines.size() > 0 && content_lines.back() != "")
content_lines.push_back("");
content_lines.push_back(heading);
content_lines.push_back("");
}
continue;
}
if(current_section == "title")
{
if(result.title != "")
result.title += "\n";
result.title += line;
}
else if(current_section == "sig")
{
result.sig_lines.push_back(line);
}
else if(current_section == "params")
{
result.param_lines.push_back(line);
}
else if(current_section == "see")
{
if(trim(line) != "")
result.see_lines.push_back(trim(line));
}
else
{
content_lines.push_back(line);
}
}
result.content = join(content_lines, "\n");
result.title = trim(result.title);
return(result);
}
void render_doc_params(StringList param_lines)
{
if(param_lines.size() == 0)
return;
<><div class="params"><h3>Parameters</h3></>
for(auto line : param_lines)
{
if(trim(line) == "")
continue;
String name = trim(nibble(line, ":"));
String value = trim(line);
<><div><b><?= name ?></b><?
if(value != "")
{
?> : <?: doc_markdown_inline(value) ?><?
}
?></div></>
}
<></div></>
}
void render_doc_page(String page)
{
(*already_shown_items)[page] = "Y";
auto doc = split(file_get_contents("pages/"+page+".txt"), "\n");
String layout_class = "text";
u32 line_idx = 0;
for(auto s : doc)
DocPage doc_page = load_doc_page(page);
String title = doc_default_title(page);
if(doc_page.title != "")
title = doc_page.title;
<><section class="doc-page"><div class="sig"><h2><?= title ?></h2></>
if(doc_page.sig_lines.size() > 0)
{
line_idx++;
if(s == "")
{
<><pre><? print(join(doc_page.sig_lines, "\n")); ?></pre></>
}
<></div></>
}
else if(s.substr(0, 1) == ":")
{
layout_class = s.substr(1);
if(line_idx > 1)
{
<></div></>
}
<><div class="<?= layout_class ?>"></>
if(layout_class == "params")
{
<><h3>Parameters</h3></>
}
else if(layout_class == "sig")
{
String page_name = page;
if(page[1] == '_')
{
nibble(page_name, "_");
}
<><h2><?= page_name ?></h2></>
}
else if(layout_class == "pre")
{
layout_class = "sig";
}
else if(layout_class == "desc")
{
<><h3>Description</h3></>
}
else if(layout_class == "related")
{
<><h3>Related PHP and JS</h3></>
}
else if(layout_class == "see")
{
render_doc_params(doc_page.param_lines);
}
else
{
<><h3><?= layout_class ?></h3></>
}
}
else
{
if(s.substr(0, 1) == "-")
{
nibble(s, "-");
<><li><?= (s) ?></li></>
}
else if(layout_class == "sig")
{
<><pre><? print(s); ?></pre></>
}
else if(layout_class == "params")
{
<><div><b><?= trim(nibble(s, ":")) ?></b> : <?= trim(s) ?></div></>
}
else if(layout_class == "see")
{
if(s[0] == '>')
{
//render_see_section(s.substr(1));
}
else
{
<><div><a href="index.uce?p=<?= trim(s) ?>"><?= trim(s) ?><span style="opacity:0.5">()</span></a></div></>
}
}
else
{
<><div><?: markdown_to_html(s) ?></div></>
}
}
}
if(trim(doc_page.content) != "")
{
<><div class="content"><?: markdown_to_html(doc_page.content) ?></div></>
}
<></section></>
}
void render_see_section(String name)
{
StringList lines = split(file_get_contents("areas/"+name+".txt"), "\n");
StringList lines = split(file_get_contents("areas/" + name + ".txt"), "\n");
s32 idx = 0;
for(auto line : lines)
{
@@ -110,12 +170,9 @@ void render_see_section(String name)
RENDER(Request& context)
{
StringMap shown_items;
already_shown_items = &shown_items;
String page = first(context.get["p"], "index");
<><html>
<head>
<link rel="stylesheet" href='style.css?v=<?= time() ?>'></link>
@@ -143,5 +200,4 @@ RENDER(Request& context)
?>
</body>
</html></>
}