From 49f6c45c3d60fe0251843cc23ce289ec23b3501b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 9 Oct 2018 13:10:49 -0400 Subject: internal links --- org/output_sqlite.org | 230 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 225 insertions(+), 5 deletions(-) (limited to 'org/output_sqlite.org') diff --git a/org/output_sqlite.org b/org/output_sqlite.org index 566b960..e456fe7 100644 --- a/org/output_sqlite.org +++ b/org/output_sqlite.org @@ -420,11 +420,6 @@ auto munge_html(M,O)( } _txt = _txt.replaceAll(rgx.inline_notes_al_gen_ref, "$1 "); } - 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; } @@ -486,6 +481,229 @@ string html_font_face(string _txt){ } #+END_SRC +****** inline markup +******* images + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +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 $6")); + } + return _txt; +} +#+END_SRC + +******* links +******** scroll, seg, epub + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +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, + ("$1")) + .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; +} +#+END_SRC + +******* notes +******** scroll + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +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, + (" $1 ") + ); + } + 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; +} +#+END_SRC + +******** seg + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +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", + "

", + "", + " ", + m.captures[1], + ".", + m.captures[2], + "

" + ); + } + _txt = (_txt).replaceAll( + rgx.inline_notes_delimiter_al_regular_number_note, + (" $1 ") + ); + } 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; +} +#+END_SRC + +******* inline markup + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +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; +} +#+END_SRC + ***** objects ****** heading @@ -496,6 +714,7 @@ auto html_heading(M,O)( auto ref const O obj, ) { string _txt = munge_html(doc_matters, obj); + _txt = inline_markup(doc_matters, obj, _txt); string o = format(q"¶

%s

¶", @@ -538,6 +757,7 @@ auto html_para(M,O)( ) { string _txt = munge_html(doc_matters, obj); _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = inline_markup(doc_matters, obj, _txt); string o = format(q"¶

%s

¶", -- cgit v1.2.3