diff options
Diffstat (limited to 'src/doc_reform/output/epub3.d')
-rw-r--r-- | src/doc_reform/output/epub3.d | 204 |
1 files changed, 126 insertions, 78 deletions
diff --git a/src/doc_reform/output/epub3.d b/src/doc_reform/output/epub3.d index 1bcf13d..e862a3f 100644 --- a/src/doc_reform/output/epub3.d +++ b/src/doc_reform/output/epub3.d @@ -102,8 +102,8 @@ template outputEPub3() { content ~= " " ~ "</guide>" ~ "\n "; content ~= "" ~ "</package>"; debug(epubmanifest) { - foreach (s; doc_matters.xml.keys_seq.seg) { - foreach (obj; doc_abstraction[s]) { + foreach (part; doc_matters.xml.keys_seq.seg) { // TODO + foreach (obj; doc_abstraction[part]) { if (obj.metainfo.is_a == "heading") { if (obj.metainfo.heading_lev_markup == 4) { writefln( @@ -235,8 +235,8 @@ template outputEPub3() { doc_matters.conf_make_meta.meta.title_full, // title (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : " by " ~ doc_matters.conf_make_meta.meta.creator_author, // author - uuid, // uuid - "3", // content depth + uuid, // uuid + "3", // content depth doc_matters.conf_make_meta.meta.title_full, // title (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : doc_matters.conf_make_meta.meta.creator_author, // author @@ -311,7 +311,7 @@ template outputEPub3() { foreach (obj; doc_abstraction[part]) { string _txt = xhtml_format.special_characters(obj, obj.text); if (obj.metainfo.is_a == "heading") { - assert(part == "head" || "toc_seg" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex_seg" || "blurb" || "tail"); + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); switch (obj.metainfo.heading_lev_markup) { case 0: .. case 3: /+ fill buffer, and replace with new levels from 1 to 3 +/ @@ -356,21 +356,27 @@ template outputEPub3() { doc_epub3_endnotes[segment_filename] ~= t[1]; break; case 8: .. case 9: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } } break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + } } break; } } else { - assert(part == "head" || "toc_seg" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex_seg" || "blurb" || "tail"); + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); switch (obj.metainfo.is_of_part) { - case "frontmatter": assert(part == "head" || "toc_seg"); + case "frontmatter": assert(part == "head" || "toc"); switch (obj.metainfo.is_of_type) { case "para": switch (obj.metainfo.is_a) { @@ -380,15 +386,21 @@ template outputEPub3() { doc_epub3_endnotes[segment_filename] ~= t[1]; break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } } break; } break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } } break; } @@ -403,8 +415,11 @@ template outputEPub3() { doc_epub3_endnotes[segment_filename] ~= t[1]; break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } } break; } @@ -441,21 +456,27 @@ template outputEPub3() { doc_epub3_endnotes[segment_filename] ~= ""; break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } } break; } break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } } break; } break; case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex_seg" || "blurb" || "tail"); + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); switch (obj.metainfo.is_of_type) { case "para": switch (obj.metainfo.is_a) { @@ -473,7 +494,7 @@ template outputEPub3() { doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; - case "bookindex": assert(part == "bookindex_seg"); + case "bookindex": assert(part == "bookindex"); auto t = xhtml_format.para_seg(doc_matters, obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; @@ -484,15 +505,21 @@ template outputEPub3() { doc_epub3_endnotes[segment_filename] ~= t[1]; break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } } break; } break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } } break; } @@ -500,8 +527,11 @@ template outputEPub3() { case "comment": break; default: - if ((doc_matters.opt.action.debug_do)) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + } } break; } @@ -600,15 +630,17 @@ template outputEPub3() { if (!exists(pth_epub3.base)) { pth_epub3.base.mkdirRecurse; } - debug(epub_output) { - if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename))) { - pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename))) { - pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename))) { - pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename).mkdirRecurse; + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename))) { + pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename))) { + pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename))) { + pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename).mkdirRecurse; + } } } { /+ OEBPS/[segments].xhtml (the document contents) +/ @@ -617,19 +649,25 @@ template outputEPub3() { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn; auto zip_data = new OutBuffer(); - debug(epub_output) { - string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.src.filename, seg_filename); - auto f = File(fn_dbg, "w"); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.src.filename, seg_filename); + auto f = File(fn_dbg, "w"); + foreach (docseg; doc_epub3[seg_filename]) { + f.writeln(docseg); + } + foreach (docseg; doc_epub3_endnotes[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); + } } foreach (docseg; doc_epub3[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } zip_data.write(docseg.dup); } foreach (docseg; doc_epub3_endnotes[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } zip_data.write(docseg.dup); } - debug(epub_output) { f.writeln(xhtml_format.tail); } zip_data.write(xhtml_format.tail.dup); zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); @@ -638,12 +676,14 @@ template outputEPub3() { } } string fn; - debug(epub_output) { string fn_dbg; } + string fn_dbg; File f; { /+ mimetypes (identify zip file type) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.src.filename); - File(fn_dbg, "w").writeln(mimetypes); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.src.filename); + File(fn_dbg, "w").writeln(mimetypes); + } } fn = pth_epub3.fn_mimetypes(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); @@ -655,9 +695,11 @@ template outputEPub3() { createZipFile!()(fn_epub, zip.build()); } { /+ META-INF/container.xml (identify doc root) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.src.filename); - File(fn_dbg, "w").writeln(meta_inf_container_xml); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.src.filename); + File(fn_dbg, "w").writeln(meta_inf_container_xml); + } } fn = pth_epub3.fn_dmi_container_xml(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); @@ -669,9 +711,11 @@ template outputEPub3() { createZipFile!()(fn_epub, zip.build()); } { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.src.filename); - File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.src.filename); + File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); + } } fn = pth_epub3.fn_oebps_toc_nav_xhtml(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); @@ -683,9 +727,11 @@ template outputEPub3() { createZipFile!()(fn_epub, zip.build()); } { /+ OEBPS/toc.ncx (navigation toc epub2) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.src.filename); - File(fn_dbg, "w").writeln(oebps_toc_ncx); + { /+ 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(oebps_toc_ncx); + } } fn = pth_epub3.fn_oebps_toc_ncx(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); @@ -697,9 +743,11 @@ template outputEPub3() { createZipFile!()(fn_epub, zip.build()); } { /+ OEBPS/content.opf (doc manifest) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.src.filename); - File(fn_dbg, "w").writeln(oebps_content_opf); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.src.filename); + File(fn_dbg, "w").writeln(oebps_content_opf); + } } fn = pth_epub3.fn_oebps_content_opf(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); @@ -712,20 +760,18 @@ template outputEPub3() { } { /+ OEBPS/_sisu/image (images) +/ foreach (image; doc_matters.srcs.image_list) { - debug(epub_output) { - if (exists(doc_matters.src_path_info.image_root ~ "/" ~ image)) { - (doc_matters.src_path_info.image_root ~ "/" ~ image) - .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename)) ~ "/" ~ image); - } - } - } - foreach (image; doc_matters.srcs.image_list) { - debug(epub_output) { - debug(epub_images) { - writeln( - doc_matters.src.image_dir_path, "/", image, " -> ", - pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename), "/", image - ); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + if (doc_matters.opt.action.very_verbose) { + writeln( + doc_matters.src.image_dir_path, "/", image, " -> ", + pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename), "/", image + ); + } + if (exists(doc_matters.src.image_dir_path ~ "/" ~ image)) { + (doc_matters.src.image_dir_path ~ "/" ~ image) + .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename)) ~ "/" ~ image); + } } } auto fn_src = doc_matters.src.image_dir_path ~ "/" ~ image; @@ -745,9 +791,11 @@ template outputEPub3() { } { /+ OEBPS/epub.css +/ auto css = DocReformCss(); - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.src.filename); - File(fn_dbg, "w").writeln(css.epub_css); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.src.filename); + File(fn_dbg, "w").writeln(css.epub_css); + } } fn = pth_epub3.fn_oebps_css(doc_matters.src.filename); auto zip_arc_member_file = new ArchiveMember(); |