From a9a46fca7397aaa357bfdc2b98e181617bb6887b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 1 May 2017 18:46:11 -0400 Subject: xmls work particularly with epub output --- src/sdp/output_epub3.d | 190 +++++++++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 76 deletions(-) (limited to 'src/sdp/output_epub3.d') diff --git a/src/sdp/output_epub3.d b/src/sdp/output_epub3.d index 3df1992..074808c 100644 --- a/src/sdp/output_epub3.d +++ b/src/sdp/output_epub3.d @@ -122,10 +122,24 @@ template outputEPub3() { string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { enum DomTags { none, open, close, close_and_open, open_still, } auto markup = InlineMarkup(); - string toc =" + + + \n"; return toc; } string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { int counter = 0; string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere auto markup = InlineMarkup(); + auto rgx = Rgx(); enum DomTags { none, open, close, close_and_open, open_still, } string toc = format(q"¶ - - - %s%s - - - - - - - - - %s - - - %s - - ¶", - 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 + + + %s%s + + + + + + + + + %s + + + %s + + ¶", + 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; doc_abstraction[sect]) { if (obj.is_a == "heading") { + string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip; + string hashtag =(obj.heading_lev_markup <= 4) ? "" : ("#" ~ obj.ocn.to!string); foreach_reverse (k; 0 .. 7) { switch (obj.dom_markedup[k]) { case DomTags.close : - // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags - toc ~= ""; + toc ~= "\n "; break; case DomTags.close_and_open : - // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags - // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; - toc ~= ""; - toc ~= format(q"¶ - - %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) - ); + toc ~= "\n "; + toc ~= format(q"¶ + + + %s + + ¶", + counter, + _txt, + obj.segment_anchor_tag, + hashtag, + ); break; case DomTags.open : - // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; - toc ~= format(q"¶ - - %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) - ); + toc ~= format(q"¶ + + + %s + + ¶", + counter, + _txt, + obj.segment_anchor_tag, + hashtag, + ); break; default : break; @@ -271,6 +298,7 @@ template outputEPub3() { string[] top_level_headings = ["","","",""]; string[string] oepbs_content_parts; string suffix = ".xhtml"; + string[] doc_parts_; foreach (part; doc_matters.keys_seq.seg) { foreach (obj; doc_abstraction[part]) { string _txt = xhtml_format.special_characters(obj, obj.text); @@ -298,23 +326,23 @@ template outputEPub3() { top_level_headings[3] = ""; goto default; default: - auto t = xhtml_format.heading_seg(obj, suffix); - top_level_headings[obj.heading_lev_markup] = t[0]; + doc_parts_ ~= obj.segment_anchor_tag; + doc_epub3[obj.segment_anchor_tag] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); + doc_epub3[obj.segment_anchor_tag] ~= t[0]; + doc_epub3_endnotes[obj.segment_anchor_tag] ~= t[1]; break; } break; case 4: segment_filename = obj.segment_anchor_tag; - doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters.dochead_meta); - foreach (top_level_heading; top_level_headings) { - doc_epub3[segment_filename] ~= top_level_heading; - } - auto t = xhtml_format.heading_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case 5: .. case 7: - auto t = xhtml_format.heading_seg(obj, _txt, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -337,7 +365,9 @@ template outputEPub3() { case "para": switch (obj.is_a) { case "toc": - doc_epub3[segment_filename] ~= xhtml_format.toc_seg(obj, _txt); + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -467,35 +497,41 @@ template outputEPub3() { } } if (obj.is_a == "heading") { - if (obj.heading_lev_markup == 4) { - oepbs_content_parts["manifest_documents"] ~= format(q"¶ + if (obj.heading_lev_markup <= 4) { + oepbs_content_parts["manifest_documents"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, obj.segment_anchor_tag, ); - oepbs_content_parts["spine"] ~= format(q"¶ + oepbs_content_parts["spine"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, ); - oepbs_content_parts["guide"] ~= format(q"¶ + oepbs_content_parts["guide"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, obj.segment_anchor_tag, ); } else if (obj.heading_lev_markup > 4) { - oepbs_content_parts["manifest_documents"] ~= format(q"¶ + oepbs_content_parts["manifest_documents"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, obj.obj_cite_number, obj.segment_anchor_tag, obj.obj_cite_number, ); - oepbs_content_parts["spine"] ~= format(q"¶ + oepbs_content_parts["spine"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, obj.obj_cite_number, ); - oepbs_content_parts["guide"] ~= format(q"¶ + oepbs_content_parts["guide"] ~= + format(q"¶ ¶", obj.segment_anchor_tag, obj.obj_cite_number, @@ -521,6 +557,7 @@ template outputEPub3() { oebps_toc_nav_xhtml, oebps_toc_ncx, oebps_content_opf, + doc_parts_, ); } void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( @@ -532,8 +569,8 @@ template outputEPub3() { Otnx oebps_toc_nav_xhtml, Otn oebps_toc_ncx, Oc oebps_content_opf, + string[] doc_parts_, ) { - auto css = SiSUcss(); debug(asserts) { static assert(is(typeof(doc_epub3) == string[][string])); static assert(is(typeof(mimetypes) == string)); @@ -567,7 +604,7 @@ template outputEPub3() { } } { /+ OEBPS/[segments].xhtml (the document contents) +/ - foreach (seg_filename; doc_matters.segnames) { + foreach (seg_filename; doc_matters.segnames_lv_0_to_4) { string fn = pth_epub3.fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); /+ add zip archive file members (with their content) +/ auto zip_arc_member_file = new ArchiveMember(); @@ -717,6 +754,7 @@ template outputEPub3() { } } { /+ OEBPS/epub.css +/ + auto css = SiSUcss(); debug(epub_output) { fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.source_filename); File(fn_dbg, "w").writeln(css.epub_css); @@ -727,7 +765,7 @@ template outputEPub3() { // add OEBPS/content.opf to zip archive zip_arc_member_file.name = fn; auto zip_data = new OutBuffer(); - zip_data.write(oebps_content_opf.dup); // cast as: char[] + zip_data.write(css.epub_css.dup); // cast as: char[] zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); /+ create the zip file +/ -- cgit v1.2.3