From 30b6d716f3e4448667ee61bdda044df739d6ad68 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 4 Feb 2022 18:48:25 -0500 Subject: epub, work on --- src/doc_reform/io_out/epub3.d | 156 +++++------------------------------------- 1 file changed, 17 insertions(+), 139 deletions(-) (limited to 'src/doc_reform/io_out/epub3.d') diff --git a/src/doc_reform/io_out/epub3.d b/src/doc_reform/io_out/epub3.d index 6593db5..a49304f 100644 --- a/src/doc_reform/io_out/epub3.d +++ b/src/doc_reform/io_out/epub3.d @@ -70,8 +70,7 @@ template outputEPub3() { .replaceAll(rgx.xhtml_quotation, """) // """ .replaceAll(rgx.xhtml_less_than, "<") // "<" .replaceAll(rgx.xhtml_greater_than, ">") // ">" - .replaceAll(rgx.br_line, "
") - .replaceAll(rgx.br_nl, "
") + .replaceAll(rgx.br_line, "
") .replaceAll(rgx.nbsp_char, " "); return _txt; } @@ -114,8 +113,7 @@ template outputEPub3() { urn:uuid:%s - - + ┃", _uuid, @@ -147,7 +145,7 @@ template outputEPub3() { ); } content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; content ~= parts["spine"]; content ~= " " ~ "" ~ "\n "; content ~= " " ~ "" ~ "\n "; @@ -196,7 +194,6 @@ template outputEPub3() {

Contents

+ _toc_nav_tail ~=" \n"; @@ -281,115 +281,6 @@ template outputEPub3() { toc ~= _toc_nav_tail; return toc; } - @safe string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { - int counter_play_order = 0; - string _uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere - auto markup = InlineMarkup(); - static auto rgx = RgxO(); - enum DomTags { none, open, close, close_and_open, open_still, } - string toc; - string toc_ = format(q"┃ - - - - %s%s - - - - - - - - %s - - - %s - - ┃", - (doc_matters.conf_make_meta.meta.title_full).special_characters_text, // title - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : " by " ~ (doc_matters.conf_make_meta.meta.creator_author).special_characters_text, // author - _uuid, // uuid - "3", // content depth - (doc_matters.conf_make_meta.meta.title_full).special_characters_text, // title - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : (doc_matters.conf_make_meta.meta.creator_author).special_characters_text, // author - ); - string _toc_ncx_tail = ""; - foreach (sect; doc_matters.has.keys_seq.seg) { - foreach (obj; doc_abstraction[sect]) { - if (sect == "head") { toc = toc_; - } - if (obj.metainfo.is_a == "heading") { - string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip.special_characters_text; - // writeln(_txt, " --- ", obj.metainfo.dom_structure_collapsed_tags_status); // DEBUG line - string hashtag = (obj.metainfo.heading_lev_markup <= 4) ? "" : ("#" ~ obj.metainfo.ocn.to!string); - foreach_reverse (k; 0 .. 7) { - switch (obj.metainfo.dom_structure_collapsed_tags_status[k]) { // for epub may need to construct for levels 1 to 4 only - case DomTags.close : - if (sect != "head") { - toc ~= "\n "; // issue at start of some documents - } - break; - case DomTags.close_and_open : - toc ~= "\n "; - goto default; - case DomTags.open : - goto default; - default : - string _toc; - if ((obj.metainfo.dom_structure_collapsed_tags_status[k] == DomTags.open - || obj.metainfo.dom_structure_collapsed_tags_status[k] == DomTags.close_and_open - // || obj.metainfo.dom_structure_collapsed_tags_status[k] == DomTags.open_still - )) { - ++counter_play_order; - _toc = format(q"┃ - - - %s - - ┃", - counter_play_order, - _txt, - obj.tags.segment_anchor_tag_epub, - hashtag, - ); - } - if (obj.metainfo.dom_structure_collapsed_tags_status[k] == DomTags.close_and_open) { - toc ~= _toc; - } else if (obj.metainfo.dom_structure_collapsed_tags_status[k] == DomTags.open) { - toc ~= _toc; - } - break; - } - if (doc_matters.has.keys_seq.seg[doc_matters.has.keys_seq.seg.length - 2] == sect) { - if (k == 6) {_toc_ncx_tail = "";} - switch (obj.metainfo.dom_structure_collapsed_tags_status[k]) { - case 0: case 2: - // case DomTags.none: case DomTags.close: - break; - case 1: case 3: case 4: - // case DomTags.open: case DomTags.close_and_open: case DomTags.open_still: - if (k != 0) { - } - _toc_ncx_tail ~= " " ~ markup.indent_by_spaces_provided(k, " ") ~ "" ~ "\n"; - break; - default : - break; - } - if (k == 0) { - _toc_ncx_tail ~= format(q"┃ - ┃"); - } - } - } - } - } - } - toc ~= _toc_ncx_tail; - return toc; - } @system void outputEPub3(D,I)( const D doc_abstraction, I doc_matters, @@ -406,7 +297,6 @@ template outputEPub3() { /+ fixed output +/ string mimetypes; string meta_inf_container_xml; - string oebps_toc_ncx; string oebps_toc_nav_xhtml; /+ variable output +/ string oebps_content_opf; @@ -654,25 +544,25 @@ template outputEPub3() { assert(obj.text.length > 0); if (obj.metainfo.heading_lev_markup <= 4) { oepbs_content_parts["manifest_documents"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, obj.tags.segment_anchor_tag_epub, ); oepbs_content_parts["spine"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, ); oepbs_content_parts["guide"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, obj.tags.segment_anchor_tag_epub, ); } else if (obj.metainfo.heading_lev_markup > 4) { oepbs_content_parts["manifest_documents"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, obj.metainfo.object_number, @@ -680,13 +570,13 @@ template outputEPub3() { obj.metainfo.object_number, ); oepbs_content_parts["spine"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, obj.metainfo.object_number, ); oepbs_content_parts["guide"] ~= - format(q"┃ + format(q"┃ ┃", obj.tags.segment_anchor_tag_epub, obj.metainfo.object_number, @@ -698,11 +588,10 @@ template outputEPub3() { } } /+ epub specific documents +/ - epubWrite.mimetypes = epub3_mimetypes; + epubWrite.mimetypes = epub3_mimetypes; epubWrite.meta_inf_container_xml = epub3_container_xml; - epubWrite.oebps_toc_ncx = doc_abstraction.epub2_oebps_toc_ncx(doc_matters); - epubWrite.oebps_toc_nav_xhtml = doc_abstraction.epub3_oebps_toc_nav_xhtml(doc_matters); - epubWrite.oebps_content_opf = doc_abstraction.epub3_oebps_content(doc_matters, oepbs_content_parts); + epubWrite.oebps_toc_nav_xhtml = doc_abstraction.epub3_oebps_toc_nav_xhtml(doc_matters); + epubWrite.oebps_content_opf = doc_abstraction.epub3_oebps_content(doc_matters, oepbs_content_parts); epubWrite.epub3_write_output_files(doc_matters); } @system void epub3_write_output_files(W,M)( @@ -714,7 +603,6 @@ template outputEPub3() { static assert(is(typeof(epub_write.mimetypes) == string)); static assert(is(typeof(epub_write.meta_inf_container_xml) == string)); static assert(is(typeof(epub_write.oebps_toc_nav_xhtml) == string)); - static assert(is(typeof(epub_write.oebps_toc_ncx) == string)); static assert(is(typeof(epub_write.oebps_content_opf) == string)); } static auto rgx = RgxO(); @@ -821,16 +709,6 @@ template outputEPub3() { fn = pth_epub3.fn_oebps_toc_nav_xhtml; EPUBzip(epub_write.oebps_toc_nav_xhtml, fn); } - { /+ OEBPS/toc.ncx (navigation toc epub2) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.oebps_toc_ncx); - } - } - fn = pth_epub3.fn_oebps_toc_ncx; - EPUBzip(epub_write.oebps_toc_ncx, fn); - } { /+ OEBPS/content.opf (doc manifest) +/ { /+ debug +/ if (doc_matters.opt.action.debug_do) { -- cgit v1.2.3