From 60d6073bcfc4fa91253428094813de0dac41a2b4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 9 May 2017 13:01:06 -0400 Subject: 0.16.0 files/modules re-arranged --- src/sdp/output/html.d | 447 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 447 insertions(+) create mode 100644 src/sdp/output/html.d (limited to 'src/sdp/output/html.d') diff --git a/src/sdp/output/html.d b/src/sdp/output/html.d new file mode 100644 index 0000000..6712469 --- /dev/null +++ b/src/sdp/output/html.d @@ -0,0 +1,447 @@ +module sdp.output.html; +template outputHTML() { + import sdp.output; + import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; + import + sdp.output.create_zip_file, + sdp.output.xmls, + sdp.output.xmls_css; + mixin outputXHTMLs; + + void scroll(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, + ) { + mixin SiSUoutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[] doc_html; + string[] doc; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.scroll) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "toc": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "para": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + doc_html ~= xhtml_format.quote_scroll(obj, _txt); + break; + case "group": + doc_html ~= xhtml_format.group_scroll(obj, _txt); + break; + case "block": + doc_html ~= xhtml_format.block_scroll(obj, _txt); + break; + case "poem": + break; + case "verse": + doc_html ~= xhtml_format.verse_scroll(obj, _txt, suffix); + break; + case "code": + doc_html ~= xhtml_format.code(obj, _txt); + break; + case "table": + doc_html ~= xhtml_format.table(obj, _txt); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "endnote": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "glossary": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "bibliography": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "bookindex": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "blurb": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + } + } + } + doc = xhtml_format.html_scroll_head(doc_matters) ~ doc_html ~ xhtml_format.tail; + scroll_write_output(doc_matters, doc); + } + void scroll_write_output(M,C)( + M doc_matters, + C doc, + ) { + debug(asserts) { + static assert(is(typeof(doc) == string[])); + } + string fn_src = doc_matters.source_filename; + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + try { + if (!exists(pth_html.base)) { + pth_html.base.mkdirRecurse; + } + auto f = File(pth_html.fn_scroll(fn_src), "w"); + foreach (o; doc) { + f.writeln(o); + } + } + catch (ErrnoException ex) { + // Handle error + } + } + void seg(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, + ) { + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto xhtml_format = outputXHTMLs(); + string[][string] doc_html; + string[][string] doc_html_endnotes; + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); + if (obj.is_a == "heading") { + 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: + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + top_level_headings[obj.heading_lev_markup] = t[0]; + break; + } + break; + case 4: + segment_filename = obj.segment_anchor_tag; + doc_html[segment_filename] ~= xhtml_format.html_seg_head(doc_matters); + foreach (top_level_heading; top_level_headings) { + // writeln(top_level_heading); + doc_html[segment_filename] ~= top_level_heading; + } + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 5: .. case 7: + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + } + break; + } + } else { + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "toc": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "para": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "group": + auto t = xhtml_format.group_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "block": + auto t = xhtml_format.block_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "poem": + break; + case "verse": + auto t = xhtml_format.verse_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "code": + doc_html[segment_filename] ~= xhtml_format.code(obj, _txt); + break; + case "table": + doc_html[segment_filename] ~= xhtml_format.table(obj, _txt); + doc_html_endnotes[segment_filename] ~= ""; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "endnote": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + break; + case "glossary": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bibliography": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "blurb": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + } + break; + } + } + } + } + seg_write_output(doc_matters, doc_html, doc_html_endnotes); + } + void seg_write_output(M,D,E)( + M doc_matters, + D doc_html, + E doc_html_endnotes, + ) { + debug(asserts) { + static assert(is(typeof(doc_html) == string[][string])); + } + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + auto xhtml_format = outputXHTMLs(); + auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); + try { + if (!exists(pth_html.seg(doc_matters.source_filename))) { + pth_html.seg(doc_matters.source_filename).mkdirRecurse; + } + foreach (seg_filename; doc_matters.segnames) { + auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); + foreach (docseg; doc_html[seg_filename]) { + f.writeln(docseg); + } + foreach (docseg; doc_html_endnotes[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); + } + } + catch (ErrnoException ex) { + // handle error + } + } + void css(M)( + auto return ref M doc_matters, + ) { + auto css = SiSUcss(); + auto pth_html = SiSUpathsHTML!()(doc_matters.src_path_info, doc_matters.language); + try { + if (!exists(pth_html.css)) { + (pth_html.css).mkdirRecurse; + } + auto f = File(pth_html.fn_css, "w"); + f.writeln(css.html_css); + } + catch (ErrnoException ex) { + // Handle error + } + } +} -- cgit v1.2.3