From 48ba380760b306077afa7a156a21d3ff98d26775 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 4 May 2018 21:22:39 -0400 Subject: html & epub images in place (dimensions not & other issues) --- src/sdp/output/defaults.d | 1 + src/sdp/output/epub3.d | 28 +++++++++---------- src/sdp/output/html.d | 51 ++++++++++++++++++++++++---------- src/sdp/output/hub.d | 3 ++ src/sdp/output/paths_source.d | 32 ++++++++++++++++----- src/sdp/output/rgx.d | 1 + src/sdp/output/source_sisupod.d | 5 +--- src/sdp/output/xmls.d | 61 ++++++++++++++++++++++++++++++++--------- 8 files changed, 130 insertions(+), 52 deletions(-) (limited to 'src/sdp/output') diff --git a/src/sdp/output/defaults.d b/src/sdp/output/defaults.d index 418a334..0d215c7 100644 --- a/src/sdp/output/defaults.d +++ b/src/sdp/output/defaults.d @@ -24,6 +24,7 @@ template InternalMarkup() { auto tc_c = "┚"; auto tc_p = "┆"; auto mono = "■"; + auto img = "☼"; static string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { _indent_spaces = replicate(_indent_spaces, indent); return _indent_spaces; diff --git a/src/sdp/output/epub3.d b/src/sdp/output/epub3.d index 321ef9b..eb55593 100644 --- a/src/sdp/output/epub3.d +++ b/src/sdp/output/epub3.d @@ -375,7 +375,7 @@ template outputEPub3() { case "para": switch (obj.is_a) { case "toc": - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -398,7 +398,7 @@ template outputEPub3() { case "para": switch (obj.is_a) { case "para": - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -412,24 +412,24 @@ template outputEPub3() { case "block": switch (obj.is_a) { case "quote": - auto t = xhtml_format.quote_seg(obj, _txt, suffix); + auto t = xhtml_format.quote_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0].to!string; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "group": - auto t = xhtml_format.group_seg(obj, _txt, suffix); + auto t = xhtml_format.group_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0].to!string; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "block": - auto t = xhtml_format.block_seg(obj, _txt, suffix); + auto t = xhtml_format.block_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0].to!string; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "poem": break; case "verse": - auto t = xhtml_format.verse_seg(obj, _txt, suffix); + auto t = xhtml_format.verse_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0].to!string; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -460,26 +460,26 @@ template outputEPub3() { case "para": switch (obj.is_a) { case "endnote": assert(part == "endnotes"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; break; case "glossary": assert(part == "glossary"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "bibliography": assert(part == "bibliography"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "bookindex": assert(part == "bookindex_seg"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "blurb": assert(part == "blurb"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "epub"); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -723,13 +723,13 @@ template outputEPub3() { debug(epub_output) { debug(epub_images) { writeln( - doc_matters.src_path_info.image_root, image, " -> ", + doc_matters.src_path_info.src_image_root_with_path, "/", image, " -> ", pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename), "/", image ); } } - auto fn_src = doc_matters.src_path_info.image_root ~ image; - auto fn_out = pth_epub3.doc_oebps_image(doc_matters.src.filename).to!string ~ "/" ~ image; + auto fn_src = doc_matters.src_path_info.src_image_root_with_path ~ "/" ~ image; + auto fn_out = pth_epub3.doc_oebps_image(doc_matters.src.filename.to!string) ~ "/" ~ image; if (exists(fn_src)) { { auto zip_arc_member_file = new ArchiveMember(); diff --git a/src/sdp/output/html.d b/src/sdp/output/html.d index 35e3027..3db534b 100644 --- a/src/sdp/output/html.d +++ b/src/sdp/output/html.d @@ -225,7 +225,7 @@ template outputHTML() { top_level_headings[3] = ""; goto default; default: - auto t = xhtml_format.heading_seg(obj, _txt, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "seg"); top_level_headings[obj.heading_lev_markup] = t[0]; break; } @@ -240,13 +240,13 @@ template outputHTML() { // writeln(top_level_heading); doc_html[segment_filename] ~= top_level_heading; } - auto t = xhtml_format.heading_seg(obj, _txt, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html[segment_filename] ~= xhtml_format.lev4_heading_subtoc(obj); doc_html_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, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -270,7 +270,7 @@ template outputHTML() { case "para": switch (obj.is_a) { case "toc": - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; break; default: @@ -292,7 +292,7 @@ template outputHTML() { case "para": switch (obj.is_a) { case "para": - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -306,24 +306,24 @@ template outputHTML() { case "block": switch (obj.is_a) { case "quote": - auto t = xhtml_format.quote_seg(obj, _txt, suffix); + auto t = xhtml_format.quote_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; case "group": - auto t = xhtml_format.group_seg(obj, _txt, suffix); + auto t = xhtml_format.group_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; case "block": - auto t = xhtml_format.block_seg(obj, _txt, suffix); + auto t = xhtml_format.block_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; case "poem": break; case "verse": - auto t = xhtml_format.verse_seg(obj, _txt, suffix); + auto t = xhtml_format.verse_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0].to!string; doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -354,26 +354,26 @@ template outputHTML() { case "para": switch (obj.is_a) { case "endnote": assert(part == "endnotes"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0]; break; case "glossary": assert(part == "glossary"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "bibliography": assert(part == "bibliography"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "bookindex": assert(part == "bookindex_seg"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "blurb": assert(part == "blurb"); - auto t = xhtml_format.para_seg(obj, _txt, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix, "seg"); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -455,4 +455,27 @@ template outputHTML() { // Handle error } } + void images_cp(M)( + auto return ref M doc_matters, + ) { + { /+ (copy html images) +/ + + auto pth_html = SiSUpathsHTML!()(doc_matters.output_path, doc_matters.src.language); + if (!exists(pth_html.image)) { + pth_html.image.mkdirRecurse; + } + foreach (image; doc_matters.srcs.image_list) { + auto fn_src_in = doc_matters.src_path_info.src_image_root_with_path ~ "/" ~ image; + auto fn_src_out = pth_html.image ~ "/" ~ image; + debug(images_html) { + writeln(fn_src_in, " -> ", fn_src_out); + } + if (exists(fn_src_in)) { + fn_src_in.copy(fn_src_out); + } else { + writeln("WARNING image not found: ", fn_src_in); + } + } + } + } } diff --git a/src/sdp/output/hub.d b/src/sdp/output/hub.d index d395269..b86d30d 100644 --- a/src/sdp/output/hub.d +++ b/src/sdp/output/hub.d @@ -93,6 +93,7 @@ template outputHub() { writeln("html seg done"); } outputHTML!().css(doc_matters); + outputHTML!().images_cp(doc_matters); } else if (doc_matters.opt.action.html_seg) { if ((doc_matters.opt.action.verbose)) { writeln("html seg processing... "); @@ -103,6 +104,7 @@ template outputHub() { writeln("html seg done"); } outputHTML!().css(doc_matters); + outputHTML!().images_cp(doc_matters); } else if (doc_matters.opt.action.html_scroll) { if ((doc_matters.opt.action.verbose)) { writeln("html scroll processing... "); @@ -113,6 +115,7 @@ template outputHub() { writeln("html scroll done"); } outputHTML!().css(doc_matters); + outputHTML!().images_cp(doc_matters); } if (doc_matters.opt.action.epub) { if ((doc_matters.opt.action.verbose)) { diff --git a/src/sdp/output/paths_source.d b/src/sdp/output/paths_source.d index ac5e703..9f377bc 100644 --- a/src/sdp/output/paths_source.d +++ b/src/sdp/output/paths_source.d @@ -30,7 +30,7 @@ template PodManifest() { _manifest_path = _pth; } else if (_pth.match(rgx.src_pth_contents) && exists(_pth)!=0 && _pth.isFile) { - _manifest_path = dirName(_pth); + _manifest_path = _pth.dirName; } else if (_pth.match(rgx.src_pth_pod_sst_or_ssm) && exists(_pth)!=0 && (_pth.isFile)) { if (auto m = _pth.match(rgx.src_pth_pod_sst_or_ssm)) { @@ -480,7 +480,7 @@ template SiSUpathsSRC() { static auto rgx = Rgx(); auto SiSUpathsSRC(D,Fn)( D _pwd, - Fn _fn_src_and_relative_path, + Fn _fn_src_and_path, ) { struct SisuSrcPaths { auto pwd() { @@ -489,7 +489,7 @@ template SiSUpathsSRC() { auto language() { // use command line info as well? string _k; - if (auto m = _fn_src_and_relative_path.match(rgx.language_code_and_filename)) { + if (auto m = _fn_src_and_path.match(rgx.language_code_and_filename)) { _k = m.captures[1]; } else { /+ unknown until doc_meta read, (could provide & use command line info?) +/ _k = "xx"; // original default was "en" but is not known @@ -514,11 +514,29 @@ template SiSUpathsSRC() { auto doc_src_fn_with_path_for_text_root_and_lng() { return asNormalizedPath(text_root.chainPath(language)).array; } - auto doc_src_with_relative_path() { - return asNormalizedPath(pwd.chainPath(_fn_src_and_relative_path)).array; - } auto doc_src_fn() { - return asNormalizedPath(_fn_src_and_relative_path.baseName).array; + return asNormalizedPath(_fn_src_and_path.baseName).array; + } + auto doc_src_with_path() { + return asNormalizedPath(pwd.chainPath(_fn_src_and_path)).array; + } + auto src_image_root_with_path() { + string[] _possible_img_pth = [ + asNormalizedPath(pwd.chainPath((_fn_src_and_path).dirName ~ "/image")).array, + asNormalizedPath(pwd.chainPath((_fn_src_and_path).dirName ~ "/../image")).array, + asNormalizedPath(pwd.chainPath((_fn_src_and_path).dirName ~ "/../../image")).array, + ]; + string _img_pth_found = ""; + foreach(_img_pth; _possible_img_pth) { + if (exists(_img_pth)) { + _img_pth_found = _img_pth; + break; + } + } + if (_img_pth_found.empty) { + writeln("WARNING not image path found, searched: ", _possible_img_pth); + } + return _img_pth_found; } } return SisuSrcPaths(); diff --git a/src/sdp/output/rgx.d b/src/sdp/output/rgx.d index 0227902..60f15cf 100644 --- a/src/sdp/output/rgx.d +++ b/src/sdp/output/rgx.d @@ -61,6 +61,7 @@ static template SiSUoutputRgxInit() { static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); /+ inline markup footnotes endnotes +/ + static inline_image = ctRegex!(`(?P
┥)☼(?P(?P\S+?\.(?:jpg|gif|png)),w(?P\d+)h(?P\d+))\s*(?P.*?┝┤.+?├)`, "mg");
     static inline_link                                    = ctRegex!(`┥(?P.+?)┝┤(?P.+?)├`, "mg");
     static inline_link_clean                              = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
     static inline_a_url                                   = ctRegex!(`(┤)(\S+?)(├)`, "mg");
diff --git a/src/sdp/output/source_sisupod.d b/src/sdp/output/source_sisupod.d
index 50b37b0..a92d087 100644
--- a/src/sdp/output/source_sisupod.d
+++ b/src/sdp/output/source_sisupod.d
@@ -65,10 +65,7 @@ template SiSUpod() {
               pths_sisupod.image_root(doc_matters.src.filename).zpod, "/", image
             );
           }
-          auto fn_src_in = ((doc_matters.src.is_pod)
-            ? doc_matters.src.image_dir_path
-            : pth_sisudoc_src.image_root).to!string
-            ~ "/" ~ image;
+          auto fn_src_in = doc_matters.src_path_info.src_image_root_with_path ~ "/" ~ image;
           auto fn_src_out_sisupod_zip_base
             = pths_sisupod.image_root(doc_matters.src.filename).zpod.to!string
             ~ "/" ~ image;
diff --git a/src/sdp/output/xmls.d b/src/sdp/output/xmls.d
index 7dd6a60..1621732 100644
--- a/src/sdp/output/xmls.d
+++ b/src/sdp/output/xmls.d
@@ -311,15 +311,39 @@ template outputXHTMLs() {
     ¶");
       return o;
     }
+    auto inline_images(O)(
+      auto return ref const O obj,
+      string                  _txt,
+      string                  _suffix    = ".html",
+      string                  _xml_type = "seg",
+    ) {
+      string _img_pth;
+      if (_xml_type == "epub") {
+        _img_pth = "image/";
+      } else if (_xml_type == "scroll") {
+        _img_pth = "../../image/";
+      } else if (_xml_type == "seg") {
+        _img_pth = "../../../image/";
+      }
+      if (_txt.match(rgx.inline_image)) {
+        _txt = (_txt)
+          .replaceAll( // TODO bug where image dimensions (w or h) not given & consequently set to 0; should not be used (calculate earlier, abstraction)
+            rgx.inline_image,
+            ("$1 $6"));
+      }
+      return _txt;
+    }
     auto inline_links(O)(
       auto return ref const O obj,
       string                  _txt,
       string                  _suffix    = ".html",
-      string                  seg_scroll = "seg",
+      string                  _xml_type = "seg",
     ) {
       if (obj.inline_links) {
         if ((_txt.match(rgx.mark_internal_site_lnk))
-        && (seg_scroll == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault
+        && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault
           _txt = (_txt).replaceAll(
             rgx.inline_seg_link,
             "$1");
@@ -424,6 +448,7 @@ template outputXHTMLs() {
       string                   _txt,
       string                   _suffix = ".html",
     ) {
+      _txt = inline_images(obj, _txt, _suffix, "scroll");
       _txt = inline_links(obj, _txt, _suffix, "scroll");
       _txt = inline_notes_scroll(obj, _txt);
       return _txt;
@@ -432,8 +457,10 @@ template outputXHTMLs() {
       auto return ref const O  obj,
       string                   _txt,
       string                   _suffix = ".html",
+      string                   _xml_type = "seg",
     ) {
-      _txt = inline_links(obj, _txt, _suffix, "seg");
+      _txt = inline_images(obj, _txt, _suffix, _xml_type);
+      _txt = inline_links(obj, _txt, _suffix, _xml_type);
       auto t = inline_notes_seg(obj, _txt);
       return t;
     }
@@ -543,11 +570,11 @@ template outputXHTMLs() {
     auto heading(O)(
       auto return ref const O    obj,
       string                     _txt,
-      string                     _type="html",
+      string                     _xml_type = "html",
     ) {
       auto tags = _xhtml_anchor_tags(obj.anchor_tags);
       string _horizontal_rule = "
"; - if ((_type != "html") + if ((_xml_type != "html") || (obj.heading_lev_markup == 0 || obj.heading_lev_markup > 4)) { _horizontal_rule = ""; } @@ -603,12 +630,12 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", - string _type = "html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0]; string[] _endnotes = t[1]; - string o = heading(obj, _txt, _type); + string o = heading(obj, _txt, _xml_type); auto u = tuple( o, _endnotes, @@ -668,8 +695,9 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = para(obj, _txt); @@ -724,8 +752,9 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = quote(obj, _txt); @@ -770,6 +799,7 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); _txt = inline_markup_scroll(obj, _txt, _suffix); @@ -780,8 +810,9 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = group(obj, _txt); @@ -822,6 +853,7 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); _txt = inline_markup_scroll(obj, _txt, _suffix); @@ -832,8 +864,9 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = block(obj, _txt); @@ -874,6 +907,7 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); _txt = inline_markup_scroll(obj, _txt, _suffix); @@ -884,8 +918,9 @@ template outputXHTMLs() { auto return ref const O obj, string _txt, string _suffix = ".html", + string _xml_type = "html", ) { - auto t = inline_markup_seg(obj, _txt, _suffix); + auto t = inline_markup_seg(obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = verse(obj, _txt); -- cgit v1.2.3