From 08ae603106743119c511d7be7a3e79f78b5de7c2 Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Tue, 30 Jul 2024 16:40:14 +0200 Subject: [PATCH] Section References & Minor style adjustment --- docs/external/graphviz.nml | 32 ++++++++++++++++++++++ docs/external/latex.nml | 5 +--- docs/index.nml | 4 +-- docs/lua/lua.nml | 5 +--- docs/styles/basic.nml | 5 +--- docs/styles/user-defined.nml | 5 +--- docs/template.nml | 19 +++++++++++++ src/compiler/compiler.rs | 41 +++++++++++++++++----------- src/compiler/navigation.rs | 2 +- src/elements/section.rs | 31 ++++++++++++++++----- style.css | 52 ++++++++++++++++++++++++++---------- 11 files changed, 145 insertions(+), 56 deletions(-) create mode 100644 docs/external/graphviz.nml diff --git a/docs/external/graphviz.nml b/docs/external/graphviz.nml new file mode 100644 index 0000000..06a5455 --- /dev/null +++ b/docs/external/graphviz.nml @@ -0,0 +1,32 @@ +@import ../template.nml +%% + +# Graphs from graphviz + +[graph] +digraph { + bgcolor=transparent; + + filelist [color=green, label="File List"]; + doclist [color=green, label="Document List"]; + iscached [shape=diamond, color=red, label="Cached?"]; + parse [color=white, label=Parse]; + compile [color=white, label=Compile]; + cache [shape=box, color=blue, label=Cache]; + + edge [color=gray] + filelist -> iscached; + iscached -> cache[dir=both]; + iscached -> doclist[label="+"]; + + iscached -> parse[label="No"]; + parse -> compile; + compile -> cache[label="+"]; + compile -> doclist[label="+"]; + + buildnav [color=white, label="Build Navigation"]; + doclist -> buildnav; + output [color=white, label="Output"]; + buildnav -> output; +} +[/graph] diff --git a/docs/external/latex.nml b/docs/external/latex.nml index 5f32a73..ee8e586 100644 --- a/docs/external/latex.nml +++ b/docs/external/latex.nml @@ -1,8 +1,5 @@ @import ../template.nml -@compiler.output = latex.html -@nav.title = LaTeX -@nav.category = External Tools -@html.page_title = Documentation | LaTeX +%% @LaTeX = $|[kind=inline, caption=LaTeX]\LaTeX|$ diff --git a/docs/index.nml b/docs/index.nml index 89dd307..1787221 100644 --- a/docs/index.nml +++ b/docs/index.nml @@ -1,6 +1,4 @@ @import template.nml -@compiler.output = index.html -@nav.title = Documentation -@html.page_title = Documentation | Index +%% # Welcome to the NML documentation! diff --git a/docs/lua/lua.nml b/docs/lua/lua.nml index 8766885..5c1f597 100644 --- a/docs/lua/lua.nml +++ b/docs/lua/lua.nml @@ -1,8 +1,5 @@ @import ../template.nml -@compiler.output = lua.html -@nav.title = Lua -@nav.category = Lua -@html.page_title = Documentation | Lua +%% # Running lua code diff --git a/docs/styles/basic.nml b/docs/styles/basic.nml index 1284409..5c4a812 100644 --- a/docs/styles/basic.nml +++ b/docs/styles/basic.nml @@ -1,8 +1,5 @@ @import ../template.nml -@compiler.output = basic.html -@nav.title = Basic -@nav.category = Styles -@html.page_title = Documentation | Basic Styles +%% # Basic styles ## Bold diff --git a/docs/styles/user-defined.nml b/docs/styles/user-defined.nml index 5980851..4082253 100644 --- a/docs/styles/user-defined.nml +++ b/docs/styles/user-defined.nml @@ -1,7 +1,4 @@ @import ../template.nml -@compiler.output = user-defined.html -@nav.title = User-Defined -@nav.category = Styles -@html.page_title = Documentation | User-Defined Styles +%% # TODO diff --git a/docs/template.nml b/docs/template.nml index 8957313..3848b46 100644 --- a/docs/template.nml +++ b/docs/template.nml @@ -6,3 +6,22 @@ \definecolor{__color1}{HTML}{d5d5d5} \\ \everymath{\color{__color1}\displaystyle} @tex.main.block_prepend = \color{__color1} + +@< +function make_doc(categories, title, page_title) + -- Navigation + nml.variable.insert("nav.title", title) + if categories[1] ~= nil + then + nml.variable.insert("nav.category", categories[1]) + if categories[2] ~= nil + then + nml.variable.insert("nav.subcategory", categories[2]) + end + end + + -- HTML + nml.variable.insert("html.page_title", "NML | " .. page_title) + nml.variable.insert("compiler.output", page_title .. ".html") +end +>@ diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 2b491ee..0d28d08 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -38,6 +38,24 @@ impl Compiler { } } + /// Sanitizes text for a [`Target`] + pub fn sanitize>(target: Target, str: S) -> String { + match target { + Target::HTML => str + .as_ref() + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """), + _ => todo!("Sanitize not implemented"), + } + } + + /// Gets a reference name + pub fn refname>(target: Target, str: S) -> String { + Self::sanitize(target, str).replace(' ', "_") + } + /// Inserts or get a reference id for the compiled document /// /// # Parameters @@ -74,18 +92,6 @@ impl Compiler { self.cache.as_ref().map(RefCell::borrow_mut) } - pub fn sanitize>(target: Target, str: S) -> String { - match target { - Target::HTML => str - .as_ref() - .replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace("\"", """), - _ => todo!("Sanitize not implemented"), - } - } - pub fn header(&self, document: &dyn Document) -> String { pub fn get_variable_or_error( document: &dyn Document, @@ -109,8 +115,11 @@ impl Compiler { result += ""; result += ""; if let Some(page_title) = get_variable_or_error(document, "html.page_title") { - result += format!("{}", Compiler::sanitize(self.target(), page_title.to_string())) - .as_str(); + result += format!( + "{}", + Compiler::sanitize(self.target(), page_title.to_string()) + ) + .as_str(); } if let Some(css) = document.get_variable("html.css") { @@ -120,7 +129,7 @@ impl Compiler { ) .as_str(); } - result += r#"
"#; + result += r#"
"#; // TODO: TOC // TODO: Author, Date, Title, Div @@ -148,7 +157,7 @@ impl Compiler { let header = self.header(document); // Body - let mut body = r#"
"#.to_string(); + let mut body = r#"
"#.to_string(); for i in 0..borrow.len() { let elem = &borrow[i]; diff --git a/src/compiler/navigation.rs b/src/compiler/navigation.rs index 395a73f..bed071d 100644 --- a/src/compiler/navigation.rs +++ b/src/compiler/navigation.rs @@ -23,7 +23,7 @@ impl NavEntry { let mut result = String::new(); match target { Target::HTML => { - result += r#"