diff options
Diffstat (limited to 'org/output.org')
-rw-r--r-- | org/output.org | 1082 |
1 files changed, 928 insertions, 154 deletions
diff --git a/org/output.org b/org/output.org index e9253dc..6292faa 100644 --- a/org/output.org +++ b/org/output.org @@ -23,51 +23,70 @@ +/ template SiSUoutputHub() { struct SDPoutput { - void hub(S)( + void hub(S,T)( auto ref const S contents, - string[][string] document_section_keys_sequenced, - string[] html_segnames, - string[string][string] dochead_make, - string[string][string] dochead_meta, - string fn_src, - bool[string] opt_action_bool + auto ref T doc_matters, ) { auto rgx = Rgx(); - if (opt_action_bool["source"]) { - writeln("sisupod source"); + if (doc_matters.opt_action_bool["source"]) { + writeln("source"); } - if (opt_action_bool["sisupod"]) { + if (doc_matters.opt_action_bool["sisupod"]) { + mixin SiSUpod; + auto sisupod=SDPsisupod(); + sisupod.sisupod_assemble(doc_matters.source_filename); writeln("sisupod source"); } - if (opt_action_bool["text"]) { + if (doc_matters.opt_action_bool["text"]) { writeln("text processing"); } - if (opt_action_bool["html"]) { + if (doc_matters.opt_action_bool["html"]) { mixin SiSUoutputHTML; auto html=SDPoutputHTML(); html.css_write; html.scroll( contents, - document_section_keys_sequenced, - dochead_make, - dochead_meta, - fn_src, - opt_action_bool + doc_matters, + ); + html.seg( + contents, + doc_matters, + ); + } else if(doc_matters.opt_action_bool["html_seg"]) { + mixin SiSUoutputHTML; + auto html=SDPoutputHTML(); + html.css_write; + html.seg( + contents, + doc_matters, + ); + } else if(doc_matters.opt_action_bool["html_scroll"]) { + mixin SiSUoutputHTML; + auto html=SDPoutputHTML(); + html.css_write; + html.scroll( + contents, + doc_matters, ); } - if (opt_action_bool["epub"]) { - writeln("epub processing"); + if (doc_matters.opt_action_bool["epub"]) { + mixin SiSUoutputEPub; + auto epub=SDPoutputEPub(); + epub.doc_content( // consolidate + contents, + doc_matters, + ); } - if (opt_action_bool["pdf"]) { + if (doc_matters.opt_action_bool["pdf"]) { writeln("pdf processing"); } - if (opt_action_bool["odt"]) { + if (doc_matters.opt_action_bool["odt"]) { writeln("odt processing"); } - if (opt_action_bool["sqlite"]) { + if (doc_matters.opt_action_bool["sqlite"]) { writeln("sqlite processing"); } - if (opt_action_bool["postgresql"]) { + if (doc_matters.opt_action_bool["postgresql"]) { writeln("pgsql processing"); } } @@ -75,27 +94,115 @@ template SiSUoutputHub() { } #+END_SRC -** templates outpt types (file, db)s +** templates output types (file, db)s +*** sisupod + +#+BEGIN_SRC d :tangle ../src/sdp/source_sisupod.d +template SiSUpod() { + struct SDPsisupod { + <<source_sisupod_mkdirs>> + <<source_sisupod_config>> + <<source_sisupod_text>> + <<source_sisupod_images>> + } +} +#+END_SRC + +*** text +*** xhtml common + +#+BEGIN_SRC d :tangle ../src/sdp/output_xhtmls.d +template SiSUoutputXHTMLs() { + struct SDPoutputXHTMLs { + <<xhtml_format_objects>> +<<xhtml_format_objects_code>> + } +} +#+END_SRC + *** html #+BEGIN_SRC d :tangle ../src/sdp/output_html.d template SiSUoutputHTML() { struct SDPoutputHTML { + mixin SiSUoutputXHTMLs; <<output_html>> + <<output_html_scroll>> + <<output_html_seg>> <<output_html_css>> } } #+END_SRC +*** epub + +#+BEGIN_SRC d :tangle ../src/sdp/output_epub.d +template SiSUoutputEPub() { + struct SDPoutputEPub { + mixin InternalMarkup; + mixin SiSUoutputXHTMLs; + <<output_epub_fixed>> + <<output_epub_constructs>> + <<output_epub_xhtml>> + <<output_epub_xhtml_seg>> + <<output_epub_css>> + } +} +#+END_SRC + * output functions :output: -** text :text: -** html [#A] :html: -*** html text objects +** sisupod :sisupod: +*** TODO output files + +#+name: source_sisupod_config +#+BEGIN_SRC d +void sisupod_assemble( + string fn_src, +) { + mixin SiSUpaths; + auto pth_sisupod = SiSUpodPaths(); + mixin SiSUlanguageCodes; + auto lang = Lang(); + /+ + dir structure + /tmp/_sisu_processing_/ralph/en/sisupod + ├── doc + │ └── en + └── image + + - create directory structure + + +/ + assert (match(fn_src, rgx.src_fn)); + try { + /+ create directory structure +/ + mkdirRecurse(pth_sisupod.doc(fn_src)); + mkdirRecurse(pth_sisupod.conf(fn_src)); + mkdirRecurse(pth_sisupod.css(fn_src)); + mkdirRecurse(pth_sisupod.image(fn_src)); + /+ copy relevant files +/ + auto f_out = pth_sisupod.fn_doc(fn_src, "en"); // you need fn without path and then to insert back language code for output sub-directory + debug(sisupod) { + writeln(__LINE__, ": ", fn_src, " -> ", f_out); + } + mkdirRecurse(pth_sisupod.doc_lng(fn_src, "en")); // need to extract language code directories (from directory structure or filenames & have a default) + copy(fn_src, f_out); + } + catch (ErrnoException ex) { + // Handle error + } +} +#+END_SRC + +** text [#C] :text: +** xml offspring (xhtml html epub) +*** format xhtml objects :format: **** misc +***** anchor tags -#+name: output_html +#+name: xhtml_format_objects #+BEGIN_SRC d -string _html_anchor_tags(const(string[]) anchor_tags) { +string _xhtml_anchor_tags(const(string[]) anchor_tags) { string tags=""; if (anchor_tags.length > 0) { foreach (tag; anchor_tags) { @@ -108,14 +215,136 @@ string _html_anchor_tags(const(string[]) anchor_tags) { } #+END_SRC +***** doc head & tails +****** scroll head + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto scroll_head( + string[string][string] dochead_meta, +) { + 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; +} +#+END_SRC + +****** seg head + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto seg_head( + string[string][string] dochead_meta, +) { + 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; +} +#+END_SRC + +****** xhtml tail + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto tail() { + string o; + o = format(q"¶ <a name="bottom" id="bottom"></a> + <a name="end" id="end"></a> +</div> +</body> +</html>¶"); + return o; +} +#+END_SRC + +**** toc + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto 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; +} +#+END_SRC + **** heading -#+name: output_html +#+name: xhtml_format_objects #+BEGIN_SRC d -auto html_heading(O)( +auto heading(O)( auto ref const O obj, ) { - auto tags = _html_anchor_tags(obj.anchor_tags); + auto tags = _xhtml_anchor_tags(obj.anchor_tags); string o; if (obj.obj_cite_number.empty) { o = format(q"¶<br><hr /><br> @@ -155,12 +384,12 @@ auto html_heading(O)( **** para -#+name: output_html +#+name: xhtml_format_objects #+BEGIN_SRC d -auto html_para(O)( +auto para(O)( auto ref const O obj, ) { - auto tags = _html_anchor_tags(obj.anchor_tags); + auto tags = _xhtml_anchor_tags(obj.anchor_tags); string o; if (obj.obj_cite_number.empty) { o = format(q"¶ <div class="substance"> @@ -197,9 +426,9 @@ auto html_para(O)( **** nugget -#+name: output_html +#+name: xhtml_format_objects #+BEGIN_SRC d -auto html_nugget(O)( +auto nugget(O)( auto ref const O obj, ) { string o; @@ -230,73 +459,11 @@ auto html_nugget(O)( } #+END_SRC -**** scroll head +**** endnote -#+name: output_html +#+name: xhtml_format_objects #+BEGIN_SRC d -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; -} -#+END_SRC - -**** scroll toc - -#+name: output_html -#+BEGIN_SRC d -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; -} -#+END_SRC - -**** scroll endnote - -#+name: output_html -#+BEGIN_SRC d -auto html_endnote(O)( +auto endnote(O)( auto ref const O obj, ) { string o; @@ -312,48 +479,89 @@ auto html_endnote(O)( } #+END_SRC -**** scroll tail +**** code -#+name: output_html +#+name: xhtml_format_objects_code #+BEGIN_SRC d -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; + auto code(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; + } +#+END_SRC + +*** html output [#A] :html: +**** scroll :scroll: +***** output file + +#+name: output_html_scroll +#+BEGIN_SRC d +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); + } + } + catch (ErrnoException ex) { + // Handle error + } } #+END_SRC -*** html hub, sort objects [#A] -**** scroll +***** (sections & objects) switch (for html output format) -#+name: output_html +#+name: output_html_scroll #+BEGIN_SRC d -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); @@ -369,10 +577,10 @@ void scroll(C)( 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); @@ -384,22 +592,22 @@ void scroll(C)( 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); @@ -415,22 +623,22 @@ void scroll(C)( 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); @@ -444,23 +652,35 @@ void scroll(C)( } } } + doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; + scroll_write_output_file(doc_matters.source_filename, doc); +} #+END_SRC -**** scroll output file +**** seg :seg: +***** output files -#+name: output_html +#+name: output_html_seg #+BEGIN_SRC d - doc = scroll_head_html ~ body_html ~ scroll_tail_html; +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) { @@ -469,8 +689,164 @@ void scroll(C)( } #+END_SRC -**** seg -*** css :css: +***** (sections & objects) switch (for html output format) + +#+name: output_html_seg +#+BEGIN_SRC d +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); +} +#+END_SRC + +**** css :css: #+name: output_html_css #+BEGIN_SRC d @@ -1769,6 +2145,405 @@ auto css_write() { 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 + } +} +#+END_SRC + +*** epub [#B] :epub: +**** epub special files :format: +***** fixed +****** mimetype (file) + +#+name: output_epub_fixed +#+BEGIN_SRC d +string epub_mimetypes() { + string o; + o = format(q"¶application/epub+zip¶"); + return o; +} +#+END_SRC + +****** META-INF/container.xml (file) + +#+name: output_epub_fixed +#+BEGIN_SRC d +string epub_container_xml() { + string o; + o = format(q"¶<?xml version='1.0' encoding='utf-8'?> +<container version="1.0" + xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> + <rootfiles> + <rootfile full-path="OEBPS/content.opf" + media-type="application/oebps-package+xml" /> + </rootfiles> +</container>¶"); + return o; +} +#+END_SRC + +***** TODO constructs (in OEBPS) +****** TODO OEBPS/content.opf (register content: files, images etc.) + +#+name: output_epub_constructs +#+BEGIN_SRC d +string epub_oebps_content( + // string[string][string] dochead_meta, +) { + // string[] toc; + // int counter = 0; + string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere + string content = format(q"¶<?xml version='1.0' encoding='utf-8'?> +<?xml version='1.0' encoding='utf-8'?> +<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="EPB-UUID"> + <opf:metadata + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:opf="http://www.idpf.org/2007/opf" + xmlns:dcterms="http://purl.org/dc/terms/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + unique-identifier="urn:uuid:%s" version="2.0"> + <dc:title>%s</dc:title> + <dc:creator opf:file-as="%s" opf:role="aut">%s</dc:creator> + <dc:language>en</dc:language> + <dc:date opf:event="published">%s</dc:date> + <dc:rights>Copyright: %s</dc:rights> + <dc:identifier opf:scheme="URI">ox/current/en/epub/sisu_markup.epub</dc:identifier> + <dc:identifier id="bookid">urn:uuid:%s</dc:identifier> + <!-- <dc:identifier id="EPB-UUID">urn:uuid:%s</dc:identifier> --> + </opf:metadata> + <manifest> + <!-- NCX --> + <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" /> + <!-- CSS Style Sheets --> + <item id="main-css" href="css/xhtml.css" media-type="text/css" />¶", + uuid, + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author + (doc_matters.dochead_meta["date"]["published"].empty) ? "" : " by " ~ doc_matters.dochead_meta["date"]["published"], // date + (doc_matters.dochead_meta["rights"]["copyright"].empty) ? "" : " by " ~ doc_matters.dochead_meta["rights"]["copyright"], // rights + uuid, + uuid, + ); + foreach (sect; doc_matters.keys_seq_seg) { + foreach (obj; contents[sect]) { + } + } + return content; +} +#+END_SRC + +****** TODO OEBPS/toc.ncx (navigable toc using Dom structure) + +#+name: output_epub_constructs +#+BEGIN_SRC d +string epub_oebps_toc() { + int counter = 0; + string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere + auto markup = InlineMarkup(); + enum DomTags { none, open, close, close_and_open, open_still, } + string toc = format(q"¶<?xml version='1.0' encoding='utf-8'?> +<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1"> + <head> + <!-- four required metadata items (for all NCX documents, + (including the relaxed constraints of OPS 2.0) --> + <title>%s%s</title> + <link href="css/xhtml.css" rel="stylesheet" type="text/css" id="main-css" /> + <meta name="dtb:uid" content="urn:uuid:%s" /> + <!-- <meta name="epub-creator" content="SiSU http://www.jus.uio.no/sisu (this copy)" /> --> + <meta name="dtb:depth" content="%s" /> + <meta name="dtb:totalPageCount" content="0" /> + <meta name="dtb:maxPageNumber" content="0" /> + </head> + <docTitle> + <text>%s</text> + </docTitle> + <docAuthor> + <text>%s</text> + </docAuthor> + <navMap>¶", + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author + uuid, // uuid + "3", // content depth + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : doc_matters.dochead_meta["creator"]["author"], // author + ); + foreach (sect; doc_matters.keys_seq_seg) { + foreach (obj; contents[sect]) { + if (obj.is_a == "heading") { + foreach_reverse (k; 0 .. 7) { + switch (obj.dom_markedup[k]) { + case DomTags.close : + writeln(markup.indent_by_spaces_provided(k), "</", k, ">"); +toc ~= "</navPoint>"; + break; + case DomTags.close_and_open : + writeln(markup.indent_by_spaces_provided(k), "</", k, ">"); + writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); + ++counter; +toc ~= "</navPoint>"; +toc ~= format(q"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> +<navLabel> + <text>%s</text> +</navLabel> +<content src="%s" />¶", +counter, +obj.text, +obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (links done in segment_anchor_tag) +); + break; + case DomTags.open : + writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); + ++counter; +toc ~= format(q"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> +<navLabel> + <text>%s</text> +</navLabel> +<content src="%s" />¶", +counter, +obj.text, +obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (fix links in segment_anchor_tag) +); + break; + default : + break; + } + } + } + } + } + toc ~= format(q"¶ </navMap> +</ncx>¶"); + return toc; +} +#+END_SRC + +**** (sections & objects) switch (for epub xhtml output format) + +#+name: output_epub_xhtml_seg +#+BEGIN_SRC d +void doc_content(C,T)( + auto ref const C contents, + auto ref T doc_matters, +) { + auto xhtml_format = SDPoutputXHTMLs(); + auto rgx = Rgx(); + // string[] toc; + string[][string] doc_epub; + string[] doc; + string segment_filename; + string[] seg_filenames; + string[] top_level_headings = ["","","",""]; + auto mimetypes = epub_mimetypes; + auto meta_inf_container_xml = epub_container_xml; + auto oebps_toc_ncx = epub_oebps_toc; + auto oebps_content_opf = epub_oebps_content; + foreach (part; doc_matters.keys_seq_seg) { + foreach (obj; contents[part]) { + if (obj.is_a == "heading") { + switch (obj.heading_lev_markup) { + // case 0: + // break; + 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); + break; + } + break; + case 4: + seg_filenames ~= obj.segment_anchor_tag; + segment_filename = obj.segment_anchor_tag; + doc_epub[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); + foreach (top_level_heading; top_level_headings) { + // writeln(top_level_heading); + doc_epub[segment_filename] ~= top_level_heading; + } + doc_epub[segment_filename] ~= xhtml_format.heading(obj); + break; + case 5: .. case 7: + doc_epub[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_epub[segment_filename] ~= xhtml_format.toc(obj); + // doc_epub ~= xhtml_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_epub[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_epub[segment_filename] ~= xhtml_format.nugget(obj); + // doc_epub ~= xhtml_verse(obj); + break; + case "group": + doc_epub[segment_filename] ~= xhtml_format.nugget(obj); + // doc_epub ~= xhtml_group(obj); + break; + case "block": + doc_epub[segment_filename] ~= xhtml_format.nugget(obj); + // doc_epub ~= xhtml_block(obj); + break; + case "quote": + doc_epub[segment_filename] ~= xhtml_format.nugget(obj); + // doc_epub ~= xhtml_quote(obj); + break; + case "table": + doc_epub[segment_filename] ~= xhtml_format.para(obj); // + // doc_epub ~= xhtml_table(obj); + break; + case "code": + doc_epub[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_epub[segment_filename] ~= xhtml_format.endnote(obj); + break; + case "glossary": + doc_epub[segment_filename] ~= xhtml_format.para(obj); + break; + case "bibliography": + doc_epub[segment_filename] ~= xhtml_format.para(obj); + break; + case "bookindex": + doc_epub[segment_filename] ~= xhtml_format.para(obj); + break; + case "blurb": + doc_epub[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); + epub_write_output_files( + doc_matters.source_filename, + seg_filenames, + doc_epub, + mimetypes, + meta_inf_container_xml, + oebps_toc_ncx, + oebps_content_opf, + ); +} +#+END_SRC + +**** TODO output files + +#+name: output_epub_xhtml_seg +#+BEGIN_SRC d +void epub_write_output_files( + string fn_src, + string[] seg_filenames, + string[][string] doc_epub, + string mimetypes, + string meta_inf_container_xml, + string oebps_toc_ncx, + string oebps_content_opf, +) { + mixin SiSUpaths; + auto pth_epub = EpubPaths(); + // doc = xhtml_format.scroll_head ~ doc_epub ~ xhtml_format.tail; + auto xhtml_format = SDPoutputXHTMLs(); + try { + mkdirRecurse(pth_epub.doc_meta_inf(fn_src)); + mkdirRecurse(pth_epub.doc_oebps_css(fn_src)); + mkdirRecurse(pth_epub.doc_oebps_image(fn_src)); + /+ OEBPS/[segments].xhtml +/ + foreach (seg_filename; seg_filenames) { + auto f = File(pth_epub.fn_oebps_content_xhtml(fn_src, seg_filename), "w"); + /+ // f.writeln(seg_head); // not needed built and inserted earlier +/ + foreach (docseg; doc_epub[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); // needed for each lev4 + } + /+ mimetypes +/ + auto f = File(pth_epub.fn_mimetypes(fn_src), "w"); + f.writeln(mimetypes); + /+ META-INF/container.xml +/ + f = File(pth_epub.fn_dmi_container_xml(fn_src), "w"); + f.writeln(meta_inf_container_xml); + /+ OEBPS/toc.ncx +/ + f = File(pth_epub.fn_oebps_toc_ncx(fn_src), "w"); + f.writeln(oebps_toc_ncx); + /+ OEBPS/content.opf +/ + f = File(pth_epub.fn_oebps_content_opf(fn_src), "w"); + f.writeln(oebps_content_opf); } catch (ErrnoException ex) { // Handle error @@ -1776,8 +2551,7 @@ auto css_write() { } #+END_SRC -** epub [#B] :epub: -** pdf :pdf: +** pdf [#C] :pdf: ** odt :odt: ** sqlite [#B] :sqlite: ** pgsql :pgsql: |