diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2018-10-07 12:12:33 -0400 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2019-04-10 15:14:15 -0400 |
commit | 60f70c541879cccfd379c7f75ed6aff62e793caf (patch) | |
tree | 0914c4410eabe2794d901bc95c2c14363724eebb /src/doc_reform/output | |
parent | output xmls, work on internal links (diff) |
xmls segmented heading inline links
Diffstat (limited to 'src/doc_reform/output')
-rw-r--r-- | src/doc_reform/output/epub3.d | 32 | ||||
-rw-r--r-- | src/doc_reform/output/xmls.d | 60 |
2 files changed, 58 insertions, 34 deletions
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), " ") ~ "<li>" ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "<a href=\"" ~ obj.tags.segment_anchor_tag ~ ".xhtml" ~ "\">" + ~ "<a href=\"" ~ obj.tags.segment_anchor_tag_is ~ ".xhtml" ~ "\">" ~ _txt ~ "</a>" ~ "\n"; } else { @@ -169,7 +169,7 @@ template outputEPub3() { : ("#" ~ obj.metainfo.ocn.to!string); toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "<li>" ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "<a href=\"" ~ obj.tags.segment_anchor_tag ~ ".xhtml" ~ hashtag ~ "\">" + ~ "<a href=\"" ~ obj.tags.segment_anchor_tag_is ~ ".xhtml" ~ hashtag ~ "\">" ~ _txt ~ "</a>" ~ "\n"; } @@ -179,7 +179,7 @@ template outputEPub3() { if (obj.metainfo.heading_lev_markup < 4) { toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "<li>" ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "<a href=\"" ~ obj.tags.segment_anchor_tag ~ ".xhtml" ~ "\">" + ~ "<a href=\"" ~ obj.tags.segment_anchor_tag_is ~ ".xhtml" ~ "\">" ~ _txt ~ "</a>" ~ "\n"; } else { @@ -188,7 +188,7 @@ template outputEPub3() { : ("#" ~ obj.metainfo.ocn.to!string); toc ~= markup.indent_by_spaces_provided((n + 1), " ") ~ "<li>" ~ "\n" ~ markup.indent_by_spaces_provided((n + 2), " ") - ~ "<a href=\"" ~ obj.tags.segment_anchor_tag ~ ".xhtml" ~ hashtag ~ "\">" + ~ "<a href=\"" ~ obj.tags.segment_anchor_tag_is ~ ".xhtml" ~ hashtag ~ "\">" ~ _txt ~ "</a>" ~ "\n"; } @@ -262,7 +262,7 @@ template outputEPub3() { <content src="%s.xhtml%s" />¶", counter, _txt, - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, hashtag, ); break; @@ -276,7 +276,7 @@ template outputEPub3() { <content src="%s.xhtml%s" />¶", 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"¶ <item id="%s.xhtml" href="%s.xhtml" media-type="application/xhtml+xml" /> ¶", - 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"¶ <itemref idref="%s.xhtml" linear="yes" /> ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, ); oepbs_content_parts["guide"] ~= format(q"¶ <reference type="%s" href="%s" /> ¶", - 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"¶ <item id="%s.xhtml#%s" href="%s.xhtml#%s" media-type="application/xhtml+xml" /> ¶", - 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"¶ <itemref idref="%s.xhtml#%s" linear="yes" /> ¶", - obj.tags.segment_anchor_tag, + obj.tags.segment_anchor_tag_is, obj.metainfo.object_number, ); oepbs_content_parts["guide"] ~= format(q"¶ <reference type="%s#%s" href="%s#%s" /> ¶", - 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, ("<cite>$1</cite>")); 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 = "<hr />"; 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) + ? "" + : "<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>"; if (obj.metainfo.object_number.empty) { o = format(q"¶%s <div class="substance"> - <h%s class="%s">%s<a name="%s"></a> + <h%s class="%s">%s%s %s </h%s> </div>¶", @@ -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 <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <h%s class="%s" id="%s"><a name="%s"></a>%s<a name="%s"></a> + <h%s class="%s" id="%s"><a name="%s"></a>%s%s %s </h%s> </div>¶", @@ -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]; |