/+ - Name: SisuDoc Spine - Description: part of SiSU spine (Doc Reform): for document structuring, processing, publishing and search - Author: Ralph Amissah [ralph.amissah@gmail.com] - Copyright: (C) 2015 (continuously updated, current 2026) Ralph Amissah, All Rights Reserved. - License: AGPL 3 or later, for everything in this repository unless a file or a directory specifies otherwise. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License (AGPLv3) as published by the Free Software Foundation (FSF), either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see [https://www.gnu.org/licenses/]. If you have Internet connection, the latest version of the AGPL should be available at: [https://www.gnu.org/licenses/agpl-3.0.html] - Spine (by Doc Reform, related to SiSU) uses standard: - docReform markup syntax - standard SiSU markup syntax with modified headers and minor modifications - docReform object numbering - standard SiSU object citation numbering & system - Homepages: [https://www.sisudoc.org] [https://www.doc-reform.org] - Git [https://git.sisudoc.org/] +/ module sisudoc.outputs.io_out.xmls; @safe: template outputXHTMLs() { import std.file; import std.outbuffer; import std.uri; import std.conv : to; import sisudoc.outputs.io_out; import sisudoc.outputs.io_out.rgx; import sisudoc.ocda.meta.rgx_files; import sisudoc.outputs.io_out.rgx_xhtml; import sisudoc.outputs.io_out.zip_pod; import sisudoc.outputs.io_out.xmls; import sisudoc.outputs.io_out.xmls_css; mixin spineRgxOut; mixin spineRgxXHTML; struct outputXHTMLs { static auto rgx = RgxO(); static auto rgx_xhtml = RgxXHTML(); string div_delimit( string section, return ref string previous_section ) { string delimit = ""; string delimit_ = ""; if (section != previous_section) { switch (section) { case "head": delimit_ ~= "\n
\n" ; break; case "toc": delimit_ ~= "\n
\n" ; break; case "bookindex": delimit_ ~= "\n
\n" ; break; default: delimit_ ~= "\n
\n" ; break; } if (previous_section.length > 0) { delimit ~= "\n
"; } previous_section = section; delimit ~= delimit_; } // you also need to close the last div, introduce a footer? return delimit; } /+ ↓ the DPUB-ARIA role for a document section. spine has always known what these sections are; the output never said so, and "doc_endnotes" as a class name means something to a stylesheet and nothing to a reading system or a screen reader. These roles are what carry that structure across. They are plain ARIA, valid in html as well as in the epub, so both get them. . A section with no role of its own returns nothing rather than an invented one. +/ /+ ↓ and the role of an individual object, where it has one of its own. A gathered endnote is a note body, whatever the section around it says; the reference to it carries doc-noteref at the other end. . Not doc-biblioentry for a bibliography entry: DPUB-ARIA 1.1 deprecated it, and the entries sit inside doc-bibliography, which is what a reader needs. +/ string _para_role(O)(O obj) { switch (obj.metainfo.is_a) { case "endnote": return " role=\"doc-footnote\""; default: return ""; } } string _section_role(string _section) { switch (_section) { case "toc": return " role=\"doc-toc\""; case "endnotes": return " role=\"doc-endnotes\""; case "bibliography": return " role=\"doc-bibliography\""; case "glossary": return " role=\"doc-glossary\""; case "bookindex": return " role=\"doc-index\""; default: return ""; } } string special_characters_text(string _txt) { _txt = _txt .replaceAll(rgx_xhtml.ampersand, "&") // "&" .replaceAll(rgx_xhtml.quotation, """) // """ .replaceAll(rgx_xhtml.less_than, "<") // "<" .replaceAll(rgx_xhtml.greater_than, ">") // ">" .replaceAll(rgx.br_line, "
") .replaceAll(rgx.br_line_inline, "
") .replaceAll(rgx.br_line_spaced, "
\n
") .replaceAll(rgx.nbsp_char, " "); return _txt; } /+ the same escaping for where markup cannot go. +/ string special_characters_plain(string _txt) { _txt = _txt .replaceAll(rgx.br_line, " ") .replaceAll(rgx.br_line_inline, " ") .replaceAll(rgx.br_line_spaced, " ") .replaceAll(rgx_xhtml.ampersand, "&") .replaceAll(rgx_xhtml.quotation, """) .replaceAll(rgx_xhtml.less_than, "<") .replaceAll(rgx_xhtml.greater_than, ">") .replaceAll(rgx.nbsp_char, " "); return _txt; } /+ ↓ a date for an attribute value: the same trimming, no markup +/ string special_characters_plain_date(string _txt) { _txt = _txt .replaceAll(regex(r"(?:-00)+"), "") .replaceAll(rgx.br_line, " ") .replaceAll(rgx.br_line_inline, " ") .replaceAll(rgx.br_line_spaced, " ") .replaceAll(rgx.nbsp_char, " "); return _txt; } string special_characters_date(string _txt) { _txt = _txt .replaceAll(regex(r"(?:-00)+"), "") .replaceAll(rgx.br_line, "
") .replaceAll(rgx.br_line_inline, "
") .replaceAll(rgx.br_line_spaced, "
\n
") .replaceAll(rgx.nbsp_char, " "); return _txt; } /+ ↓ a group's line-leading indent and bullet markers ("_1 ", "_* ", "_2* ", "_0_1 "), then the escaping and the line breaks. . The markers are anchored to the start of a line, so they must be read while the text still has lines: special_characters_text turns the line separator into
and takes the newlines with it, after which "^" matches only at the start of the object and every later marker is printed as text. So the markers go first, into a private-use codepoint that the escaping leaves alone, and that becomes a no-break space after it. U+E003, beside the U+E000 to U+E002 the markdown and typst writers use for their own protection. Written   rather than  , because the epub is xml, and xml defines no   entity: in an epub it is a fatal error. +/ string special_characters_breaks_indents_bullets(O)( const O obj, ) { import std.array : replace, replicate; import std.regex : Captures, replaceAll; enum _sp = ""; string _txt = obj.text; if (obj.metainfo.is_a == "group") { _txt = (_txt) .replaceAll(rgx.grouped_para_indent_hang, _sp.replicate(2)) .replaceAll!((Captures!string m) => _sp.replicate(2 * m["indent"].to!int) ~ "●" ~ _sp.replicate(2)) (rgx.grouped_para_bullet_indent) .replaceAll(rgx.grouped_para_bullet, "●" ~ _sp.replicate(2)) .replaceAll!((Captures!string m) => _sp.replicate(2 * m["indent"].to!int)) (rgx.grouped_para_indent); } _txt = special_characters_text(_txt).replace(_sp, " "); if (!(obj.metainfo.is_a == "code")) { _txt = (_txt) .replaceAll(rgx_xhtml.line_break, "
"); } return _txt; } string font_face(string _txt) { _txt = _txt .replaceAll(rgx.inline_emphasis, ("$1")) .replaceAll(rgx.inline_bold, ("$1")) .replaceAll(rgx.inline_underscore, ("$1")) .replaceAll(rgx.inline_italics, ("$1")) .replaceAll(rgx.inline_superscript, ("$1")) .replaceAll(rgx.inline_subscript, ("$1")) .replaceAll(rgx.inline_strike, ("$1")) .replaceAll(rgx.inline_insert, ("$1")) .replaceAll(rgx.inline_mono, ("$1")) .replaceAll(rgx.inline_cite, ("$1")); return _txt; } /+ ↓ the heading element for a markup level. Markup goes to level 7; HTML stops at h6, and an is simply not an element, so the deepest three markup levels share h6 and are told apart by the "heading" class and their ocn. Level 0 is the document title, which is h1 in a segment of its own, in html as in epub: there is no element. +/ int _heading_element_level(O)(O obj, string _xml_type) { int _lev = obj.metainfo.heading_lev_markup.to!int; if (_lev < 1) { return 1; } return (_lev > 6) ? 6 : _lev; } /+ ↓ the class a heading carries. The title (level A) shares

with level B, having no element of its own since bespoke is not recognized and no longer used, so it is told apart by class: "heading title", which the stylesheets size a step above h1, as h0 was. Shifting every level down one instead would give the title alone h1, and would further compress the limited html heading range (h1 - h6). +/ string _heading_class(O)(O obj) { return (obj.metainfo.heading_lev_markup == 0) ? obj.metainfo.is_a ~ " title" : obj.metainfo.is_a; } /+ ↓ the anchors an object carries. "name" on an is obsolete; "id" is what a link target is. The two are not interchangeable here, because these tags are not all link targets. A gathered endnote carries exactly one, "note_", which is unique in the document and is what every reference to it points at, so that one becomes an id. . A book index entry carries the same marker on every object the entry names - "loc" appears 296 times in one document - and those are markers of where a term occurs, not distinct targets. Making them ids would put the same id in a document hundreds of times, so they stay as they are until the book index gives them something unique to be. +/ string _xhtml_anchor_tags(O)(O obj) { string tags=""; bool _is_a_unique_target = (obj.metainfo.is_a == "endnote"); if (obj.tags.anchor_tags.length > 0) { foreach (tag; obj.tags.anchor_tags) { if (!(tag.empty)) { tags ~= (_is_a_unique_target) ? "" : ""; } } } return tags; } /+ ↓ Dublin Core metas, shared by the html and epub head. A meta is written only where there is a value for it. +/ string dc_metadata(M)( M doc_matters, string _indent, bool _generator, ) { auto _meta = doc_matters.conf_make_meta.meta; string o; void _dc(string _name, string _content) { if (!(_content.empty)) { o ~= _indent ~ "\n"; } } _dc("dc.title", special_characters_plain(_meta.title_full)); _dc("dc.author", special_characters_plain(_meta.creator_author)); _dc("dc.publisher", special_characters_plain(_meta.publisher)); _dc("dc.date", special_characters_plain_date(_meta.date_published)); _dc("dc.date.created", special_characters_plain_date(_meta.date_created)); _dc("dc.date.issued", special_characters_plain_date(_meta.date_issued)); _dc("dc.date.available", special_characters_plain_date(_meta.date_available)); _dc("dc.date.valid", special_characters_plain_date(_meta.date_valid)); _dc("dc.date.modified", special_characters_plain_date(_meta.date_modified)); _dc("dc.language", doc_matters.src.language_tag); _dc("dc.rights", special_characters_plain(_meta.rights_copyright)); if (_generator) { _dc("generator", special_characters_plain(doc_matters.generator_program.name_and_version)); } o ~= _indent ~ ""; return o; } string header_metadata(M)( M doc_matters, ) { return "\n" ~ " \n" ~ dc_metadata(doc_matters, " ", doc_matters.opt.action.generated_by) ~ "\n" ~ " "; } string site_info_button(M)( M doc_matters, ) { string _locations; if (doc_matters.conf_make_meta.make.home_button_text.length > 0) { _locations = (doc_matters.conf_make_meta.make.home_button_text) .replaceAll( rgx.inline_link, ("

$1

")) .replaceAll( rgx.br_line, "") .replaceAll( rgx.br_line_inline, ""); } else { _locations = "

spine

\n

sources / git

\n

www.sisudoc.org

"; } string o; o = format(q"┃
%s
┃", _locations, ); return o; } string inline_search_form(M)( M doc_matters, ) { string o; string _form; if (doc_matters.opt.action.html_link_search) { o = format(q"┃
  %s %s
   %s
┃", doc_matters.conf_make_meta.conf.w_srv_cgi_action, (doc_matters.conf_make_meta.conf.w_srv_db_sqlite_filename.empty) ? "" : "\n 🔎 ", (doc_matters.conf_make_meta.conf.w_srv_db_sqlite_filename.empty) ? "" : "\n ", doc_matters.src.filename_base, doc_matters.conf_make_meta.conf.w_srv_cgi_action, (doc_matters.conf_make_meta.conf.w_srv_db_sqlite_filename.empty) ? "" : "\n ", doc_matters.src.filename_base, ); } else { o = ""; } return o; } string html_head(M)( M doc_matters, string type, ) { string o; string metadata_links = ((doc_matters.opt.action.html_link_curate) ? format(q"┃

⟰  [ %s  ◆ %s%s ℹ ]   ≅ | 🖋 | ⌘ |

┃", (doc_matters.opt.action.webserver_url_doc_root.length > 0) ? doc_matters.opt.action.webserver_url_doc_root : doc_matters.conf_make_meta.conf.w_srv_data_root_url , // HOME index.html equivalent _cfg.www_url_doc_root, (type == "seg") ? "../" ~ doc_matters.src.filename_base ~ ".html" : "./" ~ doc_matters.src.filename_base ~ "/toc.html", (type == "seg") ? "▤" : "※", (type == "seg") ? "../../" : "../", doc_matters.src.filename_base, doc_matters.src.lng, (doc_matters.opt.action.html_link_pdf || doc_matters.opt.action.html_link_pdf_a4) ? (" □ ") : "", (doc_matters.opt.action.html_link_pdf || doc_matters.opt.action.html_link_pdf_letter) ? (" □ ") : "", (type == "seg") ? "../" : "", doc_matters.src.filename_base, (type == "seg") ? "../" : "", (type == "seg") ? "../" : "", (type == "seg") ? "../" : "", ) : ""); o = format(q"┃ %s%s %s
%s
%s
%s
┃", special_characters_text(doc_matters.conf_make_meta.meta.title_full), (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : ", " ~ special_characters_text(doc_matters.conf_make_meta.meta.creator_author), header_metadata(doc_matters), ((type == "seg") ? "../" : ""), ((type == "seg") ? "../../../css/html_seg.css" : "../../css/html_scroll.css"), doc_matters.src.language_tag, site_info_button(doc_matters), metadata_links, inline_search_form(doc_matters), ); return o; } string epub3_seg_head(M)( M doc_matters, ) { string html_simple = format(q"┃ ┃", doc_matters.src.language_tag, doc_matters.src.language_tag, ); string o; o = format(q"┃%s %s%s %s ┃", html_simple, special_characters_plain(doc_matters.conf_make_meta.meta.title_full), (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : ", " ~ special_characters_plain(doc_matters.conf_make_meta.meta.creator_author), dc_metadata(doc_matters, " ", true), doc_matters.src.language_tag, ); return o; } string dom_close() { string o; o = format(q"┃

┃"); return o; } string tail(M)(M doc_matters) { string o; o = format(q"┃
%s

≅ SiSU Spine ፨ (object numbering & object search)

(web 1993, object numbering 1997, object search 2002 ...) 2026

┃", special_characters_text(doc_matters.conf_make_meta.meta.rights_copyright), ((doc_matters.conf_make_meta.meta.rights_license).empty) ? "" : "
", ((doc_matters.conf_make_meta.meta.rights_license).empty) ? "" : "License: " ~ special_characters_text(doc_matters.conf_make_meta.meta.rights_license) ); return o; } string inline_images(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "seg", ) { string _img_pth; switch (_xml_type) { case "epub": _img_pth = "image/"; break; case "scroll": _img_pth = format(q"┃%s/image/┃", "../.."); break; case "seg": _img_pth = format(q"┃%s/image/┃", "../../.."); break; default: break; } if (_txt.match(rgx.inline_image)) { _txt = replaceAll!(m => m["pre"].to!string ~ _img_element(_img_pth ~ m["img"].to!string, m["width"].to!string, m["height"].to!string, _image_alt(m["post"].to!string)) ~ " " ~ _image_rest(m["post"].to!string) )(_txt, rgx.inline_image); _txt = _txt.replaceAll(rgx.inline_link_empty, ("$1")); } return _txt; } /+ ↓ an image's alt text, which markup carries and every writer was throwing away: { tux.png 64x80 "a better way" }image. The project's own markup reference calls it alt text, and it was being left in the visible flow as a quoted string beside the image instead, so no spine wrote had an alt at all. +/ string _image_alt(string _post) { if (auto m = _post.matchFirst(rgx.inline_image_alt)) { return m["alt"].to!string; } return ""; } /+ ↓ and what is left of the markup once the alt text is taken out of it +/ string _image_rest(string _post) { if (auto m = _post.matchFirst(rgx.inline_image_alt)) { return m.post.to!string; } return _post; } /+ ↓ the itself. alt is required, and an image with nothing to say for itself takes alt="", which is the way to say "decorative, skip me". No alt at all is not that, it is an omission, and a reader has to announce the file name instead. . width and height are dropped when there are none. They were written as width="0" height="0", which is a perfectly valid pair of HTML integers meaning zero by zero, so the image did not appear at all; max-width in the stylesheet caps a width and cannot raise one. +/ string _img_element(string _src, string _w, string _h, string _alt) { string _dim = (_w == "0" && _h == "0") ? "" : " width=\"" ~ _w ~ "\" height=\"" ~ _h ~ "\""; return "\"""; } string inline_links(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "seg", ) { string seg_lvs; if (obj.has.inline_links) { if (obj.metainfo.is_a != "code") { _txt = replaceAll!(m => m[1] ~ "┤" ~ (replaceAll!(n => n["type"] ~ n["path"] ~ (n["file"].encodeComponent) )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) ~ "├" )(_txt, rgx.inline_link_number_only); } 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"); } if (_xml_type == "seg" || _xml_type == "epub") { seg_lvs = (_xml_type == "epub") ? "seg_lv1to4" : "seg_lv4"; foreach (m; _txt.match(rgx.inline_link_hash)) { if ((m.captures["hash"] in doc_matters.has.tag_associations) && (seg_lvs in doc_matters.has.tag_associations[(m.captures["hash"])]) ) { if ( m.captures["hash"] == doc_matters.has.tag_associations[(m.captures["hash"])][seg_lvs] ) { _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤$3" ~ _suffix ~ "├" ); } else { _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" ~ doc_matters.has.tag_associations[(m.captures["hash"])][seg_lvs] ~ _suffix ~ "#" ~ "$3" ~ "├" ); } } else { if (doc_matters.opt.action.vox_gt_1) { writeln( "WARNING on internal document links, anchor to link <<" ~ m.captures["hash"] ~ ">> not found in document, " ~ "anchor: " ~ m.captures["hash"] ~ " document: " ~ doc_matters.src.filename ); } } } } _txt = _txt .replaceAll( rgx.inline_link_fn_suffix, ("$1" ~ _suffix)) .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; } string inline_notes_scroll(O,M)( string _txt, const O obj, M doc_matters, ) { if (obj.has.inline_notes_reg) { _txt = font_face(_txt); _txt = _txt.replaceAll( rgx.inline_notes_al_regular_number_note, (" $1 ") ); } if (obj.has.inline_notes_star) { _txt = font_face(_txt); _txt = _txt.replaceAll( rgx.inline_notes_al_special_char_note, (" $1 ") ); } debug(markup_endnotes) { if (_txt.match(rgx.inline_notes_al_regular_number_note)) { writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); } } debug(markup) { if (_txt.match(rgx.inline_notes_al_regular_number_note)) { writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); } } return _txt; } Tuple!(string, string[]) inline_notes_seg(O,M)( string _txt, const O obj, M doc_matters, ) { string[] _endnotes; if (obj.has.inline_notes_star) { _txt = font_face(_txt); /+ need markup for text, and separated footnote +/ foreach(m; _txt.matchAll(rgx.inline_notes_al_special_char_note)) { _endnotes ~= format( "%s%s%s%s\n %s%s%s%s%s %s\n%s", "

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

" ); } _txt = _txt.replaceAll( rgx.inline_notes_al_special_char_note, (" $1 ") ); } if (obj.has.inline_notes_reg) { _txt = font_face(_txt); /+ need markup for text, and separated footnote +/ foreach(m; _txt.matchAll(rgx.inline_notes_al_regular_number_note)) { _endnotes ~= format( "%s%s%s%s\n %s%s%s%s%s %s\n%s", "

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

" ); } _txt = _txt.replaceAll( rgx.inline_notes_al_regular_number_note, (" $1 ") ); } else if (_txt.match(rgx.inline_notes_al_regular_number_note)) { debug(markup) { writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); } } Tuple!(string, string[]) t = tuple( _txt, _endnotes, ); return t; } string inline_markup_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", ) { if (obj.metainfo.dummy_heading && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { _txt = ""; } else { _txt = inline_images(_txt, obj, doc_matters, _suffix, "scroll"); _txt = inline_links(_txt, obj, doc_matters, _suffix, "scroll"); _txt = inline_notes_scroll(_txt, obj, doc_matters); } return _txt; } Tuple!(string, string[]) inline_markup_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "seg", ) { if (obj.metainfo.dummy_heading && ((_xml_type == "epub" && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) || obj.metainfo.is_a == "heading") ) { _txt = ""; } else { _txt = inline_images(_txt, obj, doc_matters, _suffix, _xml_type); // TODO _txt = inline_links(_txt, obj, doc_matters, _suffix, _xml_type); // TODO } Tuple!(string, string[]) t = inline_notes_seg(_txt, obj, doc_matters); return t; } string lev4_heading_subtoc(O,M)( const O obj, M doc_matters, ) { char[] lev4_subtoc; lev4_subtoc ~= "
\n"; foreach (subtoc; obj.tags.lev4_subtoc) { if (auto m = subtoc.match(rgx.inline_link_subtoc)) { auto indent = (m.captures[1].to!int - 3).to!string; // css assumptions based on use of em for left margin & indent auto text = m.captures[2].to!string; text = font_face(text); auto link = m.captures[3].to!string; lev4_subtoc ~= subtoc.replaceFirst(rgx.inline_link_subtoc, format(q"┃

۰ %s

┃", indent, indent, link, text, )); } } lev4_subtoc ~= "
\n"; return lev4_subtoc.to!string; } auto nav_pre_next_svg(O,M)( const O obj, M doc_matters, ) { string prev, next, toc; if (obj.tags.segment_anchor_tag_epub == "toc") { toc = ""; prev = ""; } else { toc = format(q"┃ ┃", ); } if (obj.tags.segname_prev == "") { prev = ""; } else { prev = format(q"┃ ┃", obj.tags.segname_prev, ); } if (obj.tags.segname_next == "") { next = ""; } else { next = format(q"┃ ┃", obj.tags.segname_next, ); } string _toc_pre_next = format(q"┃ ┃", toc, prev, next, ); string _pre_next = format(q"┃ ┃", prev, next, ); struct bar { string toc_pre_next() { return _toc_pre_next; } string pre_next() { return _pre_next; } } return bar(); } string heading(O,M)( string _txt, const O obj, M doc_matters, string _xml_type = "html", ) { assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "para"); assert(obj.metainfo.is_a == "heading"); string tags = _xhtml_anchor_tags(obj); string heading_lev_anchor_tag; string _horizontal_rule = "
"; if ((_xml_type != "html") || (obj.metainfo.heading_lev_markup == 0 || obj.metainfo.heading_lev_markup > 4)) { _horizontal_rule = ""; } _txt = font_face(_txt); string o; heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) ? "" : ""; if (_txt.empty) { o = format(q"┃%s ┃", _horizontal_rule, ); } else { o = ""; if (obj.metainfo.is_of_section == "toc") { o ~= format(q"┃
┃", special_characters_text(doc_matters.conf_make_meta.meta.rights_copyright), special_characters_text(doc_matters.conf_make_meta.meta.rights_license) ); } } if (!(obj.metainfo.identifier.empty)) { o ~= format(q"┃%s
%s%s %s
┃", _horizontal_rule, obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), _heading_element_level(obj, _xml_type), _heading_class(obj), obj.metainfo.identifier, tags, heading_lev_anchor_tag, _txt, _heading_element_level(obj, _xml_type), ); } else { o ~= format(q"┃%s
%s%s %s
┃", _horizontal_rule, _heading_element_level(obj, _xml_type), _heading_class(obj), tags, heading_lev_anchor_tag, _txt, _heading_element_level(obj, _xml_type), ); } return o; } string heading_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", ) { _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = heading(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) heading_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0]; string[] _endnotes = t[1]; string o = heading(_txt, obj, doc_matters, _xml_type); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } string para(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "para"); assert(obj.metainfo.is_a == "para" || "toc" || "endnote" || "glossary" || "bibliography" || "bookindex" || "blurb"); string tags = _xhtml_anchor_tags(obj); _txt = font_face(_txt); string o; _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; _txt = _txt.replaceFirst(rgx.inline_link_anchor, ""); if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s %s

┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.attrib.indent_hang, obj.attrib.indent_base, obj.metainfo.identifier, _para_role(obj), tags, _txt ); } else { o = format(q"┃

%s %s

┃", obj.metainfo.is_a, obj.attrib.indent_hang, obj.attrib.indent_base, _para_role(obj), tags, _txt ); } return o; } string para_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", ) { if (obj.metainfo.is_a == "toc" && _txt.match(rgx.inline_link_toc_to_backmatter)) { _txt = _txt.replaceAll(rgx.inline_link_toc_to_backmatter, "┤#section_$1├"); } _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = para(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) para_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = para(_txt, obj, doc_matters); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } string quote(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "quote"); _txt = font_face(_txt); string o; if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s

┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.identifier, _txt ); } else { o = format(q"┃

%s

┃", obj.metainfo.is_a, _txt ); } return o; } string quote_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", ) { _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = quote(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) quote_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = quote(_txt, obj, doc_matters); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } string group(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "group"); _txt = font_face(_txt); string o; if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s

┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.identifier, _txt ); } else { o = format(q"┃

%s

┃", obj.metainfo.is_a, _txt ); } return o; } string group_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = group(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) group_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = group(_txt, obj, doc_matters); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } string block(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "block"); _txt = font_face(_txt); string o; if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s

┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.identifier, _txt.stripRight ); } else { o = format(q"┃

%s

┃", obj.metainfo.is_a, _txt.stripRight ); } return o; } string block_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = block(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) block_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = block(_txt, obj, doc_matters); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } string verse(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "verse"); _txt = font_face(_txt); string o; if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s

┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.identifier, _txt ); } else { o = format(q"┃

%s

┃", obj.metainfo.is_a, _txt ); } return o; } string verse_scroll(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); string o = verse(_txt, obj, doc_matters); return o; } Tuple!(string, string[]) verse_seg(O,M)( string _txt, const O obj, M doc_matters, string _suffix = ".html", string _xml_type = "html", ) { Tuple!(string, string[]) t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = verse(_txt, obj, doc_matters); Tuple!(string, string[]) u = tuple( o, _endnotes, ); return u; } /+ ↓ column widths as a , not a width attribute on every cell +/ string _table_colgroup(O)(const O obj) { if (obj.table.column_widths.length == 0) { return ""; } string _cols; foreach(w; obj.table.column_widths) { _cols ~= (w > 0) ? "" : ""; } return "" ~ _cols ~ ""; } Tuple!(string, string) tablarize(O)( string _txt, const O obj, ) { string[] _table_rows = (_txt).split(rgx.table_delimiter_row); string[] _table_cols; string _table; string _tablenote; bool _in_head = false; bool _in_body = false; foreach(row_idx, row; _table_rows) { _table_cols = row.split(rgx.table_delimiter_col); if ((_table_cols.length == 1) && (_table_rows.length <= row_idx+2)) { _tablenote ~= _table_cols[0]; continue; } /+ ↓ a heading row goes in , the rest in +/ if (row_idx == 0 && obj.table.heading) { _table ~= ""; _in_head = true; } else if (!_in_body) { if (_in_head) { _table ~= ""; _in_head = false; } _table ~= ""; _in_body = true; } _table ~= ""; foreach(col_idx, cell; _table_cols) { bool _is_th = (row_idx == 0 && obj.table.heading); string _col_is = _is_th ? "th" : "td"; string _class = (col_idx < obj.table.column_aligns.length && obj.table.column_aligns[col_idx] == "l") ? "left" : "right"; _table ~= "<" ~ _col_is ~ (_is_th ? " scope=\"col\"" : "") ~ " class=\"" ~ _class ~ "\">"; _table ~= cell; _table ~= ""; } _table ~= ""; } if (_in_head) { _table ~= ""; } else if (_in_body) { _table ~= ""; } Tuple!(string, string) t = tuple( (_table_colgroup(obj) ~ _table), _tablenote, ); return t; } string table(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "table"); string tags = _xhtml_anchor_tags(obj); _txt = font_face(_txt); auto t = tablarize(_txt, obj); _txt = t[0]; string _note = t[1]; string o; o = format(q"┃
%s %s
%s
┃", obj.metainfo.object_number, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.object_number, tags, _txt, (_note.strip.empty) ? "" : ("

" ~ _note.strip ~ "

") ); return o; } string code(O,M)( string _txt, const O obj, M doc_matters, ) { assert(obj.metainfo.is_of_part == "body"); assert(obj.metainfo.is_of_section == "body"); assert(obj.metainfo.is_of_type == "block"); assert(obj.metainfo.is_a == "code"); string o; string codelines(string _txt) { string _codelines; if (obj.code_block.linenumbers) { string[] _block_lines = (_txt).split(rgx.br_linebreaks_newlines); _codelines = "
\n";
          foreach (k, _line; _block_lines) {
            if (k == 1) {
              _codelines ~= format(q"┃    %s
    ┃",
                _line,
              );
            } else {
              _codelines ~= format(q"┃    %s
    ┃",
                _line,
              );
            }
          }
          _codelines ~= "  
"; } else { _codelines = "
\n";
          _codelines ~= _txt;
          _codelines ~= "  
"; } return _codelines; } /+ ↓ a code block is wrapped in a
, not a

+/ if (!(obj.metainfo.identifier.empty)) { o = format(q"┃

%s
┃", obj.metainfo.identifier, (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), obj.metainfo.is_a, obj.metainfo.identifier, codelines(_txt) ); } else { o = format(q"┃
%s
┃", obj.metainfo.is_a, codelines(_txt) ); } return o; } } }