aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/output_html.d
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdp/output_html.d')
-rw-r--r--src/sdp/output_html.d429
1 files changed, 211 insertions, 218 deletions
diff --git a/src/sdp/output_html.d b/src/sdp/output_html.d
index 0390799..1975958 100644
--- a/src/sdp/output_html.d
+++ b/src/sdp/output_html.d
@@ -1,215 +1,43 @@
template SiSUoutputHTML() {
struct SDPoutputHTML {
- string _html_anchor_tags(const(string[]) anchor_tags) {
- string tags="";
- if (anchor_tags.length > 0) {
- foreach (tag; anchor_tags) {
- if (!(tag.empty)) {
- tags ~= "<a name=\"" ~ tag ~ "\"></a>";
- }
+ mixin SiSUoutputXHTMLs;
+
+ void scroll_write_output_file(
+ string fn_src,
+ string[] doc,
+ ) {
+ mixin SiSUpaths;
+ auto pth_html = HtmlPaths();
+ try {
+ mkdirRecurse(pth_html.base);
+ auto f = File(pth_html.fn_scroll(fn_src), "w");
+ foreach (o; doc) {
+ f.writeln(o);
}
}
- return tags;
- }
- auto html_heading(O)(
- auto ref const O obj,
- ) {
- auto tags = _html_anchor_tags(obj.anchor_tags);
- string o;
- if (obj.obj_cite_number.empty) {
- o = format(q"¶<br><hr /><br>
- <div class="substance">
- <h%s class="%s">%s
- %s
- </h%s>
- </div>¶",
- obj.heading_lev_markup,
- obj.is_a,
- tags,
- obj.text,
- obj.heading_lev_markup,
- );
- } else {
- o = format(q"¶<br><hr /><br>
- <div class="substance">
- <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label>
- <h%s class="%s" id="%s"><a name="%s"></a>%s
- %s
- </h%s>
- </div>¶",
- obj.obj_cite_number,
- obj.obj_cite_number,
- obj.heading_lev_markup,
- obj.is_a,
- obj.obj_cite_number,
- obj.obj_cite_number,
- tags,
- obj.text,
- obj.heading_lev_markup,
- );
- }
- return o;
- }
- auto html_para(O)(
- auto ref const O obj,
- ) {
- auto tags = _html_anchor_tags(obj.anchor_tags);
- string o;
- if (obj.obj_cite_number.empty) {
- o = format(q"¶ <div class="substance">
- <p class="%s" indent="h%si%s">%s
- %s
- </p>
- </div>¶",
- obj.is_a,
- obj.indent_hang,
- obj.indent_base,
- tags,
- obj.text
- );
- } else {
- o = format(q"¶ <div class="substance">
- <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label>
- <p class="%s" indent="h%si%s" id="%s">%s
- %s
- </p>
- </div>¶",
- obj.obj_cite_number,
- obj.obj_cite_number,
- obj.is_a,
- obj.indent_hang,
- obj.indent_base,
- obj.obj_cite_number,
- tags,
- obj.text
- );
- }
- return o;
- }
- auto html_nugget(O)(
- auto ref const O obj,
- ) {
- string o;
- if (obj.obj_cite_number.empty) {
- o = format(q"¶ <div class="substance">
- <p class="%s">
- %s
- </p>
- </div>¶",
- obj.is_a,
- obj.text
- );
- } else {
- o = format(q"¶ <div class="substance">
- <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label>
- <p class="%s" id="%s">
- %s
- </p>
- </div>¶",
- obj.obj_cite_number,
- obj.obj_cite_number,
- obj.is_a,
- obj.obj_cite_number,
- obj.text
- );
- }
- return o;
- }
- auto scroll_head_html() {
- string o;
- o = format(q"¶<!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>
- %s%s
- </title>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <meta name="dc.title" content="Title" />
- <meta name="dc.author" content="Author" />
- <meta name="dc.publisher" content="SiSU http://www.jus.uio.no/sisu (this copy)" />
- <meta name="dc.date" content="year" />
- <meta name="dc.date.created" content="year" />
- <meta name="dc.date.issued" content="year" />
- <meta name="dc.date.available" content="year" />
- <meta name="dc.date.valid" content="year" />
- <meta name="dc.date.modified" content="year" />
- <meta name="dc.language" content="US" />
- <meta name="dc.rights" content="Copyright: Copyright (C) year holder />
- <meta name="generator" content="sdp [SiSU 7.1.8 of 2016w08/5 (2016-02-26)] (n*x and D)" />
- <link rel="generator" href="http://www.sisudoc.org/" />
- <link rel="shortcut icon" href="../_sisu/image/rb7.ico" />
- <link href="../../_sisu/css/html.css" rel="stylesheet">
- <link href="../../../_sisu/css/html.css" rel="stylesheet">
- </head>
- <body lang="en">
- <a name="top" id="top"></a>¶",
- dochead_meta["title"]["full"],
- (dochead_meta["creator"]["author"].empty) ? "" : ", " ~ dochead_meta["creator"]["author"],
- );
- return o;
- }
- auto html_toc(O)(
- auto ref const O obj,
- ) {
- string o;
- o = format(q"¶ <div class="substance">
- <p class="%s" indent="h%si%s">
- %s
- </p>
- </div>¶",
- obj.is_a,
- obj.indent_hang,
- obj.indent_base,
- obj.text
- );
- return o;
- }
- auto html_endnote(O)(
- auto ref const O obj,
- ) {
- string o;
- o = format(q"¶ <p class="%s" indent="h%si%s">
- %s
- </p>¶",
- obj.is_a,
- obj.indent_hang,
- obj.indent_base,
- obj.text
- );
- return o;
- }
- auto scroll_tail_html() {
- string o;
- o = format(q"¶ <a name="bottom" id="bottom"></a>
- <a name="end" id="end"></a>
- </div>
- </body>
- </html>¶");
- return o;
+ catch (ErrnoException ex) {
+ // Handle error
+ }
}
- void scroll(C)(
+ void scroll(C,T)(
auto ref const C contents,
- string[][string] document_section_keys_sequenced,
- string[string][string] dochead_make,
- string[string][string] dochead_meta,
- string fn_src,
- bool[string] opt_action_bool
+ auto ref T doc_matters,
) {
+ auto xhtml_format = SDPoutputXHTMLs();
auto rgx = Rgx();
- string[] body_html;
+ string[] doc_html;
string[] doc;
- foreach (part; document_section_keys_sequenced["scroll"]) {
+ foreach (part; doc_matters.keys_seq_scroll) {
foreach (obj; contents[part]) {
if (obj.use == "frontmatter") {
switch (obj.is_of) {
case "para":
switch (obj.is_a) {
case "heading":
- body_html ~= html_heading(obj);
+ doc_html ~= xhtml_format.heading(obj);
break;
case "toc":
- body_html ~= html_toc(obj);
+ doc_html ~= xhtml_format.toc(obj);
break;
default:
writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
@@ -225,10 +53,10 @@ template SiSUoutputHTML() {
case "para":
switch (obj.is_a) {
case "heading":
- body_html ~= html_heading(obj);
+ doc_html ~= xhtml_format.heading(obj);
break;
case "para":
- body_html ~= html_para(obj);
+ doc_html ~= xhtml_format.para(obj);
break;
default:
writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
@@ -240,22 +68,22 @@ template SiSUoutputHTML() {
case "poem":
break;
case "verse":
- body_html ~= html_nugget(obj);
+ doc_html ~= xhtml_format.nugget(obj);
break;
case "group":
- body_html ~= html_nugget(obj);
+ doc_html ~= xhtml_format.nugget(obj);
break;
case "block":
- body_html ~= html_nugget(obj);
+ doc_html ~= xhtml_format.nugget(obj);
break;
case "quote":
- body_html ~= html_nugget(obj);
+ doc_html ~= xhtml_format.nugget(obj);
break;
case "table":
- body_html ~= html_para(obj); //
+ doc_html ~= xhtml_format.para(obj); //
break;
case "code":
- body_html ~= html_nugget(obj);
+ doc_html ~= xhtml_format.code(obj);
break;
default:
writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
@@ -271,22 +99,22 @@ template SiSUoutputHTML() {
case "para":
switch (obj.is_a) {
case "heading":
- body_html ~= html_heading(obj);
+ doc_html ~= xhtml_format.heading(obj);
break;
case "endnote":
- body_html ~= html_endnote(obj);
+ doc_html ~= xhtml_format.endnote(obj);
break;
case "glossary":
- body_html ~= html_para(obj);
+ doc_html ~= xhtml_format.para(obj);
break;
case "bibliography":
- body_html ~= html_para(obj);
+ doc_html ~= xhtml_format.para(obj);
break;
case "bookindex":
- body_html ~= html_para(obj);
+ doc_html ~= xhtml_format.para(obj);
break;
case "blurb":
- body_html ~= html_para(obj);
+ doc_html ~= xhtml_format.para(obj);
break;
default:
writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
@@ -300,23 +128,185 @@ template SiSUoutputHTML() {
}
}
}
- doc = scroll_head_html ~ body_html ~ scroll_tail_html;
+ doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail;
+ scroll_write_output_file(doc_matters.source_filename, doc);
+ }
+ void seg_write_output_files(
+ string fn_src,
+ string[] seg_filenames,
+ string[][string] doc_html,
+ ) {
+ mixin SiSUpaths;
+ auto pth_html = HtmlPaths();
+ auto xhtml_format = SDPoutputXHTMLs();
auto m = matchFirst(fn_src, rgx.src_fn);
- auto fn = m["fn_base"] ~ ".html";
- auto pth_html = "en/html";
- auto pth_seg = pth_html ~ "/" ~ m["fn_base"];
- auto pth_html_fn = pth_html ~ "/" ~ fn;
try {
- mkdirRecurse(pth_seg);
- auto f = File(pth_html_fn, "w");
- foreach (o; doc) {
- f.writeln(o);
+ mkdirRecurse(pth_html.seg(fn_src));
+ foreach (seg_filename; seg_filenames) {
+ // writeln(__LINE__, ": ", fn);
+ auto f = File(pth_html.fn_seg(fn_src, seg_filename), "w");
+ /+ // f.writeln(seg_head); // not needed built and inserted earlier +/
+ foreach (docseg; doc_html[seg_filename]) {
+ f.writeln(docseg);
+ }
+ f.writeln(xhtml_format.tail); // needed for each lev4
}
}
catch (ErrnoException ex) {
// Handle error
}
}
+ void seg(C,T)(
+ auto ref const C contents,
+ auto ref T doc_matters,
+ ) {
+ auto xhtml_format = SDPoutputXHTMLs();
+ auto rgx = Rgx();
+ string[][string] doc_html;
+ string[] doc;
+ string segment_filename;
+ string[] seg_filenames;
+ string[] top_level_headings = ["","","",""];
+ foreach (part; doc_matters.keys_seq_seg) {
+ foreach (obj; contents[part]) {
+ if (obj.is_a == "heading") { // all headings: frontmatter, body & backmatter
+ switch (obj.heading_lev_markup) {
+ case 0: .. case 3:
+ /+ fill buffer, and replace with new levels from 1 to 3 +/
+ switch (obj.heading_lev_markup) {
+ case 0:
+ top_level_headings[0] = "";
+ top_level_headings[1] = "";
+ top_level_headings[2] = "";
+ top_level_headings[3] = "";
+ goto default;
+ case 1:
+ top_level_headings[1] = "";
+ top_level_headings[2] = "";
+ top_level_headings[3] = "";
+ goto default;
+ case 2:
+ top_level_headings[2] = "";
+ top_level_headings[3] = "";
+ goto default;
+ case 3:
+ top_level_headings[3] = "";
+ goto default;
+ default:
+ top_level_headings[obj.heading_lev_markup] = xhtml_format.heading(obj); // should probably have different css tagging (fontsize etc)
+ break;
+ }
+ break;
+ case 4:
+ seg_filenames ~= obj.segment_anchor_tag;
+ segment_filename = obj.segment_anchor_tag;
+ doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); // consider placing seg_head here as can more easily populate it with lev4 info
+ foreach (top_level_heading; top_level_headings) {
+ // writeln(top_level_heading);
+ doc_html[segment_filename] ~= top_level_heading;
+ }
+ doc_html[segment_filename] ~= xhtml_format.heading(obj);
+ break;
+ case 5: .. case 7:
+ doc_html[segment_filename] ~= xhtml_format.heading(obj);
+ break;
+ default:
+ writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ } else if (obj.use == "frontmatter") {
+ switch (obj.is_of) {
+ case "para":
+ switch (obj.is_a) {
+ case "toc":
+ doc_html[segment_filename] ~= xhtml_format.toc(obj);
+ break;
+ default:
+ // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ break;
+ default:
+ // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ } else if (obj.use == "body") {
+ switch (obj.is_of) {
+ case "para":
+ switch (obj.is_a) {
+ case "para":
+ doc_html[segment_filename] ~= xhtml_format.para(obj);
+ break;
+ default:
+ // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ break;
+ case "block":
+ switch (obj.is_a) {
+ case "poem": // double check why both poem & verse
+ break;
+ case "verse":
+ doc_html[segment_filename] ~= xhtml_format.nugget(obj);
+ break;
+ case "group":
+ doc_html[segment_filename] ~= xhtml_format.nugget(obj);
+ break;
+ case "block":
+ doc_html[segment_filename] ~= xhtml_format.nugget(obj);
+ break;
+ case "quote":
+ doc_html[segment_filename] ~= xhtml_format.nugget(obj);
+ break;
+ case "table":
+ doc_html[segment_filename] ~= xhtml_format.para(obj); //
+ break;
+ case "code":
+ doc_html[segment_filename] ~= xhtml_format.code(obj);
+ break;
+ default:
+ writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ break;
+ default:
+ // writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);
+ break;
+ }
+ } else if (obj.use == "backmatter") {
+ switch (obj.is_of) {
+ case "para":
+ switch (obj.is_a) {
+ case "endnote":
+ doc_html[segment_filename] ~= xhtml_format.endnote(obj);
+ break;
+ case "glossary":
+ doc_html[segment_filename] ~= xhtml_format.para(obj);
+ break;
+ case "bibliography":
+ doc_html[segment_filename] ~= xhtml_format.para(obj);
+ break;
+ case "bookindex":
+ doc_html[segment_filename] ~= xhtml_format.para(obj);
+ break;
+ case "blurb":
+ doc_html[segment_filename] ~= xhtml_format.para(obj);
+ break;
+ default:
+ // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ break;
+ default:
+ writeln(__FILE__, ":", __LINE__, ": ", obj.is_a);
+ break;
+ }
+ }
+ }
+ }
+ writeln(doc_matters.keys_seq_seg);
+ seg_write_output_files(doc_matters.source_filename, seg_filenames, doc_html);
+ }
auto html_css() {
string css;
css="/* SiSU css default stylesheet */
@@ -1612,6 +1602,9 @@ template SiSUoutputHTML() {
mkdirRecurse(pth_css);
auto f = File(pth_css_fn, "w");
f.writeln(html_css);
+ // foreach (o; doc) {
+ // f.writeln(o);
+ // }
}
catch (ErrnoException ex) {
// Handle error