diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2018-10-09 13:10:49 -0400 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2019-04-10 15:14:15 -0400 |
commit | 49f6c45c3d60fe0251843cc23ce289ec23b3501b (patch) | |
tree | 70604d0b0a09ca0ec96949bada9f8ec6f0082baa /src/doc_reform/output | |
parent | xmls segmented heading inline links (diff) |
internal links
Diffstat (limited to 'src/doc_reform/output')
-rw-r--r-- | src/doc_reform/output/paths_output.d | 9 | ||||
-rw-r--r-- | src/doc_reform/output/rgx.d | 1 | ||||
-rw-r--r-- | src/doc_reform/output/sqlite.d | 197 | ||||
-rw-r--r-- | src/doc_reform/output/xmls.d | 8 |
4 files changed, 205 insertions, 10 deletions
diff --git a/src/doc_reform/output/paths_output.d b/src/doc_reform/output/paths_output.d index 451c40d..11232a9 100644 --- a/src/doc_reform/output/paths_output.d +++ b/src/doc_reform/output/paths_output.d @@ -117,6 +117,15 @@ template DocReformPathsHTML() { string fn_seg(string fn_src, string seg_filename) { return asNormalizedPath(seg(fn_src).chainPath(seg_filename ~ suffix)).array; } + string tail_seg(string fn_src) { + return lng ~ "/html/" ~ base_filename(fn_src); + } + string tail_fn_scroll(string fn_src) { + return lng ~ "/html/" ~ base_filename(fn_src) ~ suffix; + } + string tail_fn_seg(string fn_src, string seg_filename) { + return lng ~ "/html/" ~ seg(fn_src) ~ "/" ~ seg_filename ~ suffix; + } } return _PathsStruct(); } diff --git a/src/doc_reform/output/rgx.d b/src/doc_reform/output/rgx.d index f352732..6896237 100644 --- a/src/doc_reform/output/rgx.d +++ b/src/doc_reform/output/rgx.d @@ -63,6 +63,7 @@ static template DocReformOutputRgxInit() { /+ inline markup footnotes endnotes +/ static inline_image = ctRegex!(`(?P<pre>┥)☼(?P<imginf>(?P<img>\S+?\.(?:jpg|gif|png)),w(?P<width>\d+)h(?P<height>\d+))\s*(?P<post>.*?┝┤.+?├)`, "mg"); static inline_image_without_dimensions = ctRegex!(`(?P<pre>┥)☼(?P<imginf>(?P<img>\S+?\.(?:jpg|gif|png)),w(?P<width>0)h(?P<height>0))\s*(?P<post>.*?┝┤.+?├)`, "mg"); + static inline_link_anchor = ctRegex!(`┋(?P<anchor>\S+?)┋`, "mg"); static inline_link = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>\S+?)├`, "mg"); static inline_link_hash = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>#(?P<segname>\S+?))├`, "mg"); static inline_link_clean = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg"); diff --git a/src/doc_reform/output/sqlite.d b/src/doc_reform/output/sqlite.d index b317dc0..0d31e2f 100644 --- a/src/doc_reform/output/sqlite.d +++ b/src/doc_reform/output/sqlite.d @@ -203,11 +203,6 @@ template SQLiteFormatAndLoadObject() { } _txt = _txt.replaceAll(rgx.inline_notes_al_gen_ref, "<sup>$1</sup> "); } - if (_txt.matchFirst(rgx.inline_link)) { - foreach (m; _txt.matchAll(rgx.inline_link)) { - } - _txt = _txt.replaceAll(rgx.inline_link_clean, ""); - } if (_notes.length > 0) { _txt ~= _notes; } @@ -249,11 +244,202 @@ template SQLiteFormatAndLoadObject() { .replaceAll(rgx.inline_cite, "<cite>$1</cite>"); return _txt; } + auto inline_images(M,O)( + M doc_matters, + 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<img src=\"" + ~ _img_pth + ~ "$3\" width=\"$4\" height=\"$5\" naturalsizeflag=\"0\" align=\"bottom\" border=\"0\" /> $6")); + } + return _txt; + } + auto inline_links(M,O)( + M doc_matters, + const O obj, + string _txt, + string _xml_type = "seg", + ) { + if (obj.has.inline_links) { + if ((_txt.match(rgx.mark_internal_site_lnk)) + && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault + _txt = (_txt).replaceAll( + rgx.inline_seg_link, + "$1"); + } + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + if (_xml_type == "seg") { + foreach (m; _txt.match(rgx.inline_link_hash)) { + if (m.captures[3] in doc_matters.xml.tag_associations) { + if (m.captures[3] == doc_matters.xml.tag_associations[(m.captures[3])][0]) { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ pth_html.tail_fn_seg(doc_matters.src.filename, "$3.html") + ~ "├" + ); + } else { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ doc_matters.xml.tag_associations[(m.captures[3])][0] + ~ ".html" + ~ "#" ~ "$3" + ~ "├" + ); + } + } else { + writeln( + "WARNING on internal document links, anchor to link not found in document, " + ~ "anchor: " ~ m.captures[3] + ~ " document: " ~ doc_matters.src.filename + ); + } + } + } else { + if (auto m = _txt.match(rgx.inline_link_hash)) { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ pth_html.tail_fn_scroll(doc_matters.src.filename) + ~ "#" ~ "$3" + ~ "├" + ); + } + } + _txt = (_txt) + .replaceAll( + rgx.inline_link_fn_suffix, + ("$1.html")) + .replaceAll( + rgx.inline_link, + ("<a href=\"$2\">$1</a>")) + .replaceAll( + rgx.mark_internal_site_lnk, + ""); + } + debug(markup_links) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + debug(markup) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + return _txt; + } + auto inline_notes_scroll(M,O)( + M doc_matters, + const O obj, + string _txt, + ) { + if (obj.has.inline_notes_reg) { + // _txt = font_face(_txt); + _txt = (_txt).replaceAll( + rgx.inline_notes_delimiter_al_regular_number_note, + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ); + } + debug(markup_endnotes) { + if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + debug(markup) { + if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + return _txt; + } + auto inline_notes_seg(M,O)( + M doc_matters, + const O obj, + string _txt, + ) { + string[] _endnotes; + if (obj.has.inline_notes_reg) { + /+ need markup for text, and separated footnote +/ + foreach(m; _txt.matchAll(rgx.inline_notes_delimiter_al_regular_number_note)) { + _endnotes ~= format( + "%s%s%s%s\n %s%s%s%s%s\n %s\n%s", + "<p class=\"endnote\">", + "<a href=\"#noteref_", + m.captures[1], + "\">", + "<note id=\"note_", + m.captures[1], + "\"> <sup>", + m.captures[1], + ".</sup></note></a>", + m.captures[2], + "</p>" + ); + } + _txt = (_txt).replaceAll( + rgx.inline_notes_delimiter_al_regular_number_note, + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ); + } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + debug(markup) { + writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + auto t = tuple( + _txt, + _endnotes, + ); + return t; + } + string xml_type="seg"; /+ set html document type to be linked to here (seg|scroll) +/ + auto inline_markup(M,O)( + M doc_matters, + const O obj, + string _txt, + ) { + _txt = inline_images(doc_matters, obj, _txt, xml_type); + _txt = inline_links(doc_matters, obj, _txt, xml_type); + _txt = inline_notes_scroll(doc_matters, obj, _txt); + return _txt; + } auto html_heading(M,O)( M doc_matters, auto ref const O obj, ) { string _txt = munge_html(doc_matters, obj); + _txt = inline_markup(doc_matters, obj, _txt); string o = format(q"¶<p class="%s"><b> %s </b></p>¶", @@ -268,6 +454,7 @@ template SQLiteFormatAndLoadObject() { ) { string _txt = munge_html(doc_matters, obj); _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = inline_markup(doc_matters, obj, _txt); string o = format(q"¶<p class="%s" indent="h%si%s"> %s </p>¶", diff --git a/src/doc_reform/output/xmls.d b/src/doc_reform/output/xmls.d index 47053f3..571c1af 100644 --- a/src/doc_reform/output/xmls.d +++ b/src/doc_reform/output/xmls.d @@ -351,7 +351,7 @@ template outputXHTMLs() { "$1"); } if (_xml_type == "seg" || _xml_type == "epub") { - if (auto m = _txt.match(rgx.inline_link_hash)) { + foreach (m; _txt.match(rgx.inline_link_hash)) { if (m.captures[3] in doc_matters.xml.tag_associations) { if (m.captures[3] == doc_matters.xml.tag_associations[(m.captures[3])][0]) { _txt = _txt.replaceFirst( @@ -609,7 +609,6 @@ template outputXHTMLs() { string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj); - string seg_anchor_tag; string heading_lev_anchor_tag; string _horizontal_rule = "<hr />"; if ((_xml_type != "html") @@ -618,9 +617,6 @@ template outputXHTMLs() { } _txt = font_face(_txt); string o; - seg_anchor_tag = (obj.tags.segment_anchor_tag.empty) - ? "" - : "<a name=\"" ~ obj.tags.segment_anchor_tag ~ "\"></a>"; heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) ? "" : "<a name=\"" ~ obj.tags.heading_lev_anchor_tag ~ "\"></a>"; @@ -699,6 +695,8 @@ template outputXHTMLs() { _txt = font_face(_txt); string o; _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = _txt.replaceFirst(rgx.inline_link_anchor, + "<a name=\"$1\"></a>"); if (obj.metainfo.object_number.empty) { o = format(q"¶ <div class="substance"> <p class="%s" indent="h%si%s">%s |