From 60f70c541879cccfd379c7f75ed6aff62e793caf Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 7 Oct 2018 12:12:33 -0400 Subject: xmls segmented heading inline links --- src/doc_reform/output/epub3.d | 32 +++++++++++------------ src/doc_reform/output/xmls.d | 60 ++++++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 34 deletions(-) (limited to 'src/doc_reform/output') diff --git a/src/doc_reform/output/epub3.d b/src/doc_reform/output/epub3.d index 19c7934..18d9e03 100644 --- a/src/doc_reform/output/epub3.d +++ b/src/doc_reform/output/epub3.d @@ -160,7 +160,7 @@ template outputEPub3() { if (obj.metainfo.heading_lev_markup < 4) { toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "
  • " ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "" + ~ "" ~ _txt ~ "" ~ "\n"; } else { @@ -169,7 +169,7 @@ template outputEPub3() { : ("#" ~ obj.metainfo.ocn.to!string); toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "
  • " ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "" + ~ "" ~ _txt ~ "" ~ "\n"; } @@ -179,7 +179,7 @@ template outputEPub3() { if (obj.metainfo.heading_lev_markup < 4) { toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "
  • " ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "" + ~ "" ~ _txt ~ "" ~ "\n"; } else { @@ -188,7 +188,7 @@ template outputEPub3() { : ("#" ~ obj.metainfo.ocn.to!string); toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "
  • " ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "" + ~ "" ~ _txt ~ "" ~ "\n"; } @@ -262,7 +262,7 @@ template outputEPub3() { ¶", counter, _txt, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, hashtag, ); break; @@ -276,7 +276,7 @@ template outputEPub3() { ¶", counter, _txt, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, hashtag, ); break; @@ -512,41 +512,41 @@ template outputEPub3() { oepbs_content_parts["manifest_documents"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, + obj.tags.segment_anchor_tag_is, ); oepbs_content_parts["spine"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, ); oepbs_content_parts["guide"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, + obj.tags.segment_anchor_tag_is, ); } else if (obj.metainfo.heading_lev_markup > 4) { oepbs_content_parts["manifest_documents"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, ); oepbs_content_parts["spine"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, ); oepbs_content_parts["guide"] ~= format(q"¶ ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, ); } diff --git a/src/doc_reform/output/xmls.d b/src/doc_reform/output/xmls.d index 7a1a812..47053f3 100644 --- a/src/doc_reform/output/xmls.d +++ b/src/doc_reform/output/xmls.d @@ -89,7 +89,8 @@ template outputXHTMLs() { .replaceAll(rgx.inline_cite, ("$1")); return _txt; } - string _xhtml_anchor_tags(const(string[]) anchor_tags) { + string _xhtml_anchor_tags(O)(O obj) { + const(string[]) anchor_tags = obj.tags.anchor_tags; string tags=""; if (anchor_tags.length > 0) { foreach (tag; anchor_tags) { @@ -351,13 +352,28 @@ template outputXHTMLs() { } if (_xml_type == "seg" || _xml_type == "epub") { if (auto m = _txt.match(rgx.inline_link_hash)) { - foreach (segname; doc_matters.xml.segnames) { - if (auto n = segname.match(m.captures[3])) { + 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┝┤$3" ~ _suffix ~ "├"); - break; + "┥$1┝┤$3" ~ _suffix ~ "├" + ); + } else { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.xml.tag_associations[(m.captures[3])][0] + ~ _suffix + ~ "#" ~ "$3" + ~ "├" + ); } + } else { + writeln( + "WARNING on internal document links, anchor to link not found in document, " + ~ "anchor: " ~ m.captures[3] + ~ " document: " ~ doc_matters.src.filename + ); } } } @@ -592,7 +608,9 @@ template outputXHTMLs() { string _txt, string _xml_type = "html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); + string seg_anchor_tag; + string heading_lev_anchor_tag; string _horizontal_rule = "
    "; if ((_xml_type != "html") || (obj.metainfo.heading_lev_markup == 0 || obj.metainfo.heading_lev_markup > 4)) { @@ -600,10 +618,16 @@ 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) + ? "" + : ""; if (obj.metainfo.object_number.empty) { o = format(q"¶%s
    - %s + %s%s %s
    ¶", @@ -611,7 +635,7 @@ template outputXHTMLs() { obj.metainfo.heading_lev_markup, obj.metainfo.is_a, tags, - obj.tags.segment_anchor_tag, + heading_lev_anchor_tag, _txt, obj.metainfo.heading_lev_markup, ); @@ -619,7 +643,7 @@ template outputXHTMLs() { o = format(q"¶%s
    - %s + %s%s %s
    ¶", @@ -631,7 +655,7 @@ template outputXHTMLs() { obj.metainfo.object_number, obj.metainfo.object_number, tags, - obj.tags.segment_anchor_tag, + heading_lev_anchor_tag, _txt, obj.metainfo.heading_lev_markup, ); @@ -644,7 +668,7 @@ template outputXHTMLs() { string _txt, string _suffix = ".html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = heading(doc_matters, obj, _txt); return o; @@ -671,7 +695,7 @@ template outputXHTMLs() { const O obj, string _txt, ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = font_face(_txt); string o; _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; @@ -712,7 +736,7 @@ template outputXHTMLs() { string _txt, string _suffix = ".html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = para(doc_matters, obj, _txt); return o; @@ -772,7 +796,7 @@ template outputXHTMLs() { string _txt, string _suffix = ".html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = quote(doc_matters, obj, _txt); return o; @@ -833,7 +857,7 @@ template outputXHTMLs() { string _suffix = ".html", string _xml_type = "html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = group(doc_matters, obj, _txt); return o; @@ -890,7 +914,7 @@ template outputXHTMLs() { string _suffix = ".html", string _xml_type = "html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = block(doc_matters, obj, _txt); return o; @@ -947,7 +971,7 @@ template outputXHTMLs() { string _suffix = ".html", string _xml_type = "html", ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = verse(doc_matters, obj, _txt); return o; @@ -1008,7 +1032,7 @@ template outputXHTMLs() { const O obj, string _txt, ) { - auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); + auto tags = _xhtml_anchor_tags(obj); _txt = font_face(_txt); auto t = tablarize(doc_matters, obj, _txt); _txt = t[0]; -- cgit v1.2.3