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/default_paths.org | 9 ++ org/default_regex.org | 4 +- org/meta_abstraction.org | 29 +++++ org/output_sqlite.org | 230 ++++++++++++++++++++++++++++++++- org/output_xmls.org | 8 +- src/doc_reform/meta/metadoc_from_src.d | 22 ++++ src/doc_reform/meta/rgx.d | 4 +- src/doc_reform/output/paths_output.d | 9 ++ src/doc_reform/output/rgx.d | 1 + src/doc_reform/output/sqlite.d | 197 +++++++++++++++++++++++++++- src/doc_reform/output/xmls.d | 8 +- 11 files changed, 499 insertions(+), 22 deletions(-) diff --git a/org/default_paths.org b/org/default_paths.org index 932b034..806b0f7 100644 --- a/org/default_paths.org +++ b/org/default_paths.org @@ -1054,6 +1054,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/org/default_regex.org b/org/default_regex.org index 65d7cf6..02f5c0d 100644 --- a/org/default_regex.org +++ b/org/default_regex.org @@ -144,7 +144,7 @@ static heading_a = ctRegex!(`^:?[A][~] `, " static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); static heading_seg_and_above = ctRegex!(`^:?([A-D1])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); -static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~]([a-z0-9_.-]+) `,"i"); +static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~](?P[a-z0-9_.-]+) `,"i"); static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9]+))`,"i"); static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+((?:[0-9]+[.:])*[0-9]+)(?=[.:;, ]|$)`,"i"); static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+((?:[0-9]+.)*[0-9]+)(?=[.:;, ]|$)`); @@ -165,6 +165,7 @@ static para_bullet_indent = ctRegex!(`^_([1-9])[*] ` static para_indent = ctRegex!(`^_([1-9]) `); static para_indent_hang = ctRegex!(`^_([0-9])_([0-9]) `); static para_attribs = ctRegex!(`^_(?:(?:[0-9])(?:_([0-9]))?|(?:[1-9])?[*]) `); +static para_inline_link_anchor = ctRegex!(`\*[~](?P[a-z0-9_.-]+)(?= |$)`,"i"); #+END_SRC ** blocked markup @@ -493,6 +494,7 @@ static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+] /+ 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_image_without_dimensions                = ctRegex!(`(?P
┥)☼(?P(?P\S+?\.(?:jpg|gif|png)),w(?P0)h(?P0))\s*(?P.*?┝┤.+?├)`, "mg");
+static inline_link_anchor                             = ctRegex!(`┋(?P\S+?)┋`, "mg");
 static inline_link                                    = ctRegex!(`┥(?P.+?)┝┤(?P\S+?)├`, "mg");
 static inline_link_hash                               = ctRegex!(`┥(?P.+?)┝┤(?P#(?P\S+?))├`, "mg");
 static inline_link_clean                              = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
diff --git a/org/meta_abstraction.org b/org/meta_abstraction.org
index 2a447bc..1b98b2e 100644
--- a/org/meta_abstraction.org
+++ b/org/meta_abstraction.org
@@ -34,6 +34,7 @@ template DocReformDocAbstraction() {
   <>
   /+ ↓ abstraction struct init +/
   <>
+  <>
   /+ ↓ abstract marked up document +/
   auto DocReformDocAbstraction(Src,CMM,Opt,Mfst)(
     Src                  markup_sourcefile_content,
@@ -418,6 +419,23 @@ auto node_construct = NodeStructureMetadata();
 enum sObj { content, anchor_tag, notes_reg, notes_star, links, image_no_dimensions }
 #+END_SRC
 
+*** inline para tag associations
+
+#+name: abs_inline_para_tag_associations
+#+BEGIN_SRC d
+auto inline_para_link_anchor(O,St,TA)(O an_object, St segment_anchor_tag_that_object_belongs_to, TA tag_assoc) {
+  static auto rgx = Rgx();
+  if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) {
+    if (m.captures[1] !in tag_assoc) {
+      tag_assoc[(m.captures[1])] = [segment_anchor_tag_that_object_belongs_to]; // follow figure out how to use for text inline anchor tags
+    } else {
+      writeln("a tag named  already exists, check text line\n    ", an_object["substantive"]);
+    }
+  }
+  return tag_assoc;
+}
+#+END_SRC
+
 *** scope
 
 #+name: abs_init_rest
@@ -1294,6 +1312,7 @@ if ((obj_type_status["heading"] == State.on)
     = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
   an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
   anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+  tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
   comp_obj_para                                             = comp_obj_para.init;
   comp_obj_para.metainfo.is_of_part                         = "body";
   comp_obj_para.metainfo.is_of_section                      = "body";
@@ -3782,6 +3801,7 @@ void _poem_block_(L,O,T,C,N,CMM,Ts)(
             = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
           an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
           anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+          tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
           comp_obj_block                               = comp_obj_block.init;
           comp_obj_block.metainfo.is_of_part           = "body";
           comp_obj_block.metainfo.is_of_section        = "body";
@@ -3842,6 +3862,7 @@ void _poem_block_(L,O,T,C,N,CMM,Ts)(
           = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
         an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
         anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+        tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
         comp_obj_block                               = comp_obj_block.init;
         comp_obj_block.metainfo.is_of_part           = "body";
         comp_obj_block.metainfo.is_of_section        = "body";
@@ -3885,6 +3906,7 @@ void _poem_block_(L,O,T,C,N,CMM,Ts)(
           = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
         an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
         anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+        tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
         comp_obj_block                               = comp_obj_block.init;
         comp_obj_block.metainfo.is_of_part           = "body";
         comp_obj_block.metainfo.is_of_section        = "body";
@@ -3945,6 +3967,7 @@ void _poem_block_(L,O,T,C,N,CMM,Ts)(
           = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
         an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
         anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+        tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
         comp_obj_block                               = comp_obj_block.init;
         comp_obj_block.metainfo.is_of_part           = "body";
         comp_obj_block.metainfo.is_of_section        = "body";
@@ -4167,6 +4190,7 @@ void _block_flag_line_empty_(B,N,CMM,Ts)(
       = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
     an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
     anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+    tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
     comp_obj_block                               = comp_obj_block.init;
     comp_obj_block.metainfo.is_of_part           = "body";
     comp_obj_block.metainfo.is_of_section        = "body";
@@ -4219,6 +4243,7 @@ void _block_flag_line_empty_(B,N,CMM,Ts)(
       = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false);
     an_object["substantive"] = substantive_obj_misc_tuple[sObj.content];
     anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag];
+    tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc);
     comp_obj_block                               = comp_obj_block.init;
     comp_obj_block.metainfo.is_of_part           = "body";
     comp_obj_block.metainfo.is_of_section        = "body";
@@ -5433,6 +5458,10 @@ static struct ObjInlineMarkupMunge {
       urls = true;
       obj_txt_in = url_links(obj_txt_in);
     }
+    if (auto m = obj_txt_in.match(rgx.para_inline_link_anchor)) {
+      obj_txt_in = (obj_txt_in)
+        .replaceAll(rgx.para_inline_link_anchor, "┋$1┋");
+    }
     auto ftn = footnotes_endnotes_markup_and_number_or_stars(obj_txt_in, reset_note_numbers);
     obj_txt_out = ftn[0];
     debug(footnotes) {
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

¶", diff --git a/org/output_xmls.org b/org/output_xmls.org index cb7830a..a1b166e 100644 --- a/org/output_xmls.org +++ b/org/output_xmls.org @@ -466,7 +466,7 @@ auto inline_links(M,O)( "$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( @@ -770,7 +770,6 @@ auto heading(M,O)( string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj); - string seg_anchor_tag; string heading_lev_anchor_tag; string _horizontal_rule = "
"; if ((_xml_type != "html") @@ -779,9 +778,6 @@ auto heading(M,O)( } _txt = font_face(_txt); string o; - seg_anchor_tag = (obj.tags.segment_anchor_tag.empty) - ? "" - : ""; heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) ? "" : ""; @@ -879,6 +875,8 @@ auto para(M,O)( _txt = font_face(_txt); string o; _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = _txt.replaceFirst(rgx.inline_link_anchor, + ""); if (obj.metainfo.object_number.empty) { o = format(q"¶

%s diff --git a/src/doc_reform/meta/metadoc_from_src.d b/src/doc_reform/meta/metadoc_from_src.d index 6d04725..aefb5ea 100644 --- a/src/doc_reform/meta/metadoc_from_src.d +++ b/src/doc_reform/meta/metadoc_from_src.d @@ -238,6 +238,17 @@ template DocReformDocAbstraction() { ObjGenericComposite comp_obj_heading, comp_obj_location, comp_obj_block, comp_obj_code, comp_obj_poem_ocn, comp_obj_comment; auto node_construct = NodeStructureMetadata(); enum sObj { content, anchor_tag, notes_reg, notes_star, links, image_no_dimensions } + auto inline_para_link_anchor(O,St,TA)(O an_object, St segment_anchor_tag_that_object_belongs_to, TA tag_assoc) { + static auto rgx = Rgx(); + if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) { + if (m.captures[1] !in tag_assoc) { + tag_assoc[(m.captures[1])] = [segment_anchor_tag_that_object_belongs_to]; // follow figure out how to use for text inline anchor tags + } else { + writeln("a tag named already exists, check text line\n ", an_object["substantive"]); + } + } + return tag_assoc; + } /+ ↓ abstract marked up document +/ auto DocReformDocAbstraction(Src,CMM,Opt,Mfst)( Src markup_sourcefile_content, @@ -966,6 +977,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_para = comp_obj_para.init; comp_obj_para.metainfo.is_of_part = "body"; comp_obj_para.metainfo.is_of_section = "body"; @@ -2788,6 +2800,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -2848,6 +2861,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -2891,6 +2905,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -2951,6 +2966,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -3316,6 +3332,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -3362,6 +3379,7 @@ template DocReformDocAbstraction() { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, false); an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + tag_assoc = inline_para_link_anchor(an_object, segment_anchor_tag_that_object_belongs_to, tag_assoc); comp_obj_block = comp_obj_block.init; comp_obj_block.metainfo.is_of_part = "body"; comp_obj_block.metainfo.is_of_section = "body"; @@ -4435,6 +4453,10 @@ template DocReformDocAbstraction() { urls = true; obj_txt_in = url_links(obj_txt_in); } + if (auto m = obj_txt_in.match(rgx.para_inline_link_anchor)) { + obj_txt_in = (obj_txt_in) + .replaceAll(rgx.para_inline_link_anchor, "┋$1┋"); + } auto ftn = footnotes_endnotes_markup_and_number_or_stars(obj_txt_in, reset_note_numbers); obj_txt_out = ftn[0]; debug(footnotes) { diff --git a/src/doc_reform/meta/rgx.d b/src/doc_reform/meta/rgx.d index 00221de..5be26a8 100644 --- a/src/doc_reform/meta/rgx.d +++ b/src/doc_reform/meta/rgx.d @@ -70,7 +70,7 @@ static template DocReformRgxInit() { static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); static heading_seg_and_above = ctRegex!(`^:?([A-D1])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); - static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~]([a-z0-9_.-]+) `,"i"); + static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~](?P[a-z0-9_.-]+) `,"i"); static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9]+))`,"i"); static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+((?:[0-9]+[.:])*[0-9]+)(?=[.:;, ]|$)`,"i"); static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+((?:[0-9]+.)*[0-9]+)(?=[.:;, ]|$)`); @@ -91,6 +91,7 @@ static template DocReformRgxInit() { static para_indent = ctRegex!(`^_([1-9]) `); static para_indent_hang = ctRegex!(`^_([0-9])_([0-9]) `); static para_attribs = ctRegex!(`^_(?:(?:[0-9])(?:_([0-9]))?|(?:[1-9])?[*]) `); + static para_inline_link_anchor = ctRegex!(`\*[~](?P[a-z0-9_.-]+)(?= |$)`,"i"); /+ blocked markup +/ static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); @@ -253,6 +254,7 @@ static template DocReformRgxInit() { /+ 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_image_without_dimensions                = ctRegex!(`(?P
┥)☼(?P(?P\S+?\.(?:jpg|gif|png)),w(?P0)h(?P0))\s*(?P.*?┝┤.+?├)`, "mg");
+    static inline_link_anchor                             = ctRegex!(`┋(?P\S+?)┋`, "mg");
     static inline_link                                    = ctRegex!(`┥(?P.+?)┝┤(?P\S+?)├`, "mg");
     static inline_link_hash                               = ctRegex!(`┥(?P.+?)┝┤(?P#(?P\S+?))├`, "mg");
     static inline_link_clean                              = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
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
┥)☼(?P(?P\S+?\.(?:jpg|gif|png)),w(?P\d+)h(?P\d+))\s*(?P.*?┝┤.+?├)`, "mg");
     static inline_image_without_dimensions                = ctRegex!(`(?P
┥)☼(?P(?P\S+?\.(?:jpg|gif|png)),w(?P0)h(?P0))\s*(?P.*?┝┤.+?├)`, "mg");
+    static inline_link_anchor                             = ctRegex!(`┋(?P\S+?)┋`, "mg");
     static inline_link                                    = ctRegex!(`┥(?P.+?)┝┤(?P\S+?)├`, "mg");
     static inline_link_hash                               = ctRegex!(`┥(?P.+?)┝┤(?P#(?P\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, "$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;
         }
@@ -249,11 +244,202 @@ template SQLiteFormatAndLoadObject() {
           .replaceAll(rgx.inline_cite,        "$1");
         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 $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,
+              ("$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;
+      }
+      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;
+      }
+      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; + } + 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"¶

%s

¶", @@ -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"¶

%s

¶", 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 = "
"; 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) - ? "" - : ""; heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) ? "" : ""; @@ -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, + ""); if (obj.metainfo.object_number.empty) { o = format(q"¶

%s -- cgit v1.2.3