From 6dc360909c0d0d082fd1fd2f0c1e254bf1f86d8b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 21 Jan 2024 01:12:23 -0500 Subject: org, ocda (ongoing) --- org/ocda.org | 3811 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 1852 insertions(+), 1959 deletions(-) (limited to 'org/ocda.org') diff --git a/org/ocda.org b/org/ocda.org index 2cd51a3..ca0e928 100644 --- a/org/ocda.org +++ b/org/ocda.org @@ -31,7 +31,6 @@ Process markup document, create document abstraction. // metadoc_from_src.d module doc_reform.meta.metadoc_from_src; template docAbstraction() { - // ↓ abstraction imports <> @system auto docAbstraction(CMM,Opt,Mf) ( char[][] markup_sourcefile_content, @@ -54,6 +53,7 @@ template docSectKeysSeq() { #+NAME: docInitialize #+HEADER: :noweb yes #+BEGIN_SRC d +// ↓ abstraction imports import std.algorithm, std.container, @@ -70,59 +70,6 @@ import mixin ObjectSetter; mixin InternalMarkup; mixin spineRgxIn; -// ↓ abstraction struct init -@safe static auto eN() { - struct _e { - enum bi { - off, - on, - } - enum ocn { - off, - on, - closing, - bkidx, - reset, - } - enum sect { - unset, - head, - toc, - substantive, - bibliography, - glossary, - book_index, - blurb, - } - enum txt_is { - off, - para, - heading, - } - enum blk_is { - off, - code, - poem, - block, - group, - table, - quote, - } - enum blk_state { - off, - on, - closing, - } - enum blk_delim { - off, - curly, - tic, - curly_special, - tic_special, - } - } - return _e(); -} // initialize ObjGenericComposite[] the_document_toc_section, the_document_head_section, the_document_body_section, the_document_endnotes_section, the_document_bibliography_section, the_document_bookindex_section, the_document_glossary_section, the_document_blurb_section, the_document_xml_dom_tail_section; struct _theDoc { @@ -198,10 +145,27 @@ struct ST_bookindex { ObjGenericComposite[] bookindex; OCNset ocn; } +struct ST_biblio_section { + ObjGenericComposite[] bibliography_section; + string[string][string] tag_assoc; +} int[] dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; int[] dom_structure_markedup_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; int[] dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; int[] dom_structure_collapsed_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +struct ST_ancestors { + ObjGenericComposite[] the_document_body_section; + ObjGenericComposite[] the_document_endnotes_section; + ObjGenericComposite[] the_document_glossary_section; + ObjGenericComposite[] the_document_bibliography_section; + ObjGenericComposite[] the_document_bookindex_section; + ObjGenericComposite[] the_document_blurb_section; +} +struct ST_segnames { + string[][string] segnames; + int html_segnames_ptr_cntr; + int html_segnames_ptr; +} struct ST_txtPlusHasFootnotes { string obj_txt; bool has_notes_reg; @@ -225,208 +189,18 @@ struct ST_txtAndAnchorTagPlusHasFootnotesUrlsImages { bool has_links; // use same name bool has_images_without_dimensions; } -enum DomTags { none, open, close, close_and_open, open_still, } -@safe pure ObjGenericComposite obj_heading_ancestors()( - ObjGenericComposite obj, - string[] lv_ancestors_txt, -) { - switch (obj.metainfo.heading_lev_markup) { - case 0: - lv_ancestors_txt[0] = obj.text.to!string; - foreach(k; 1..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 1: - lv_ancestors_txt[1] = obj.text.to!string; - foreach(k; 2..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 2: - lv_ancestors_txt[2] = obj.text.to!string; - foreach(k; 3..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 3: - lv_ancestors_txt[3] = obj.text.to!string; - foreach(k; 4..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 4: - lv_ancestors_txt[4] = obj.text.to!string; - foreach(k; 5..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 5: - lv_ancestors_txt[5] = obj.text.to!string; - foreach(k; 6..8) { lv_ancestors_txt[k] = ""; } - goto default; - case 6: - lv_ancestors_txt[6] = obj.text.to!string; - lv_ancestors_txt[7] = ""; - goto default; - case 7: - lv_ancestors_txt[7] = obj.text.to!string; - goto default; - default: - obj.tags.heading_ancestors_text = lv_ancestors_txt.dup; - } - return obj; -} -@safe pure ObjGenericComposite obj_dom_structure_set_markup_tags()( - ObjGenericComposite obj, - int[] dom, - int lev -) { - foreach (i; 0 .. 8) { - if (i < lev) { - if (dom[i] == DomTags.open - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.open_still; - } else if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } - } else if (i == lev) { - if (lev == 0 - && dom[i] == DomTags.open_still - ) { - dom[i] = DomTags.close; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close_and_open; - } else { - dom[i] = DomTags.open; - } - } else if (i > lev) { - if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close; - } - } - } - debug(dom_magic_numbers) { writeln("marked up: ", lev, ": ", dom); } - obj.metainfo.dom_structure_markedup_tags_status = dom.dup; - return obj; -} -@safe pure ObjGenericComposite obj_dom_set_collapsed_tags()( - ObjGenericComposite obj, - int[] dom, - int lev -) { - foreach (i; 0 .. 8) { - if (i < lev) { - if (dom[i] == DomTags.open - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.open_still; - } else if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } - } else if (i == lev) { - if (lev == 0 - && dom[i] == DomTags.open_still - ) { - dom[i] = DomTags.close; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close_and_open; - } else { - dom[i] = DomTags.open; - } - } else if (i > lev) { - if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close; - } - } - } - debug(dom_magic_numbers) { writeln("collapsed: ", lev, ": ", dom); } - obj.metainfo.dom_structure_collapsed_tags_status = dom.dup; - return obj; -} -@safe static OCNset ocn_emit(int ocn_status_flag) { - return object_citation_number.ocn_emitter(ocn_status_flag); -} -@safe auto inline_markup_faces(L)(L line) { - static auto rgx = RgxI(); - static auto mkup = InlineMarkup(); - line = replaceAll!(m => mkup.quote_o ~ m[1] ~ mkup.quote_c)(line, rgx.within_quotes); - line = replaceAll!(m => mkup.ff_i ~ mkup.mono ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); - line = replaceAll!(m => mkup.ff_i ~ mkup.cite ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); - foreach (regx; [rgx.inline_mark_emphasis, rgx.inline_mark_bold, rgx.inline_mark_underscore, rgx.inline_mark_italics, rgx.inline_mark_superscript, rgx.inline_mark_subscript, rgx.inline_mark_strike, rgx.inline_mark_insert]) { - line = replaceAll!(m => mkup.ff_i ~ m["mark"] ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ m["mark"])(line, regx); - } - return line; -} -@safe static string links_and_images()(string obj_txt) { - static auto rgx = RgxI(); - static auto mkup = InlineMarkup(); - if (obj_txt.match(rgx.smid_inline_url_generic)) { - if ( - obj_txt.match(rgx.smid_inline_link_endnote_url_helper) - || obj_txt.match(rgx.smid_inline_link_endnote_url_helper_punctuated) - ) { - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s%s", - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_o, - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_c, - m[3] - ))(obj_txt, rgx.smid_inline_link_endnote_url_helper_punctuated); - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s", - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_o, - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_c - ))(obj_txt, rgx.smid_inline_link_endnote_url_helper); - } else { - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m["pre"], - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c - ))(obj_txt, rgx.smid_inline_link_markup_regular); - } - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m["pre"], - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c - ))(obj_txt, rgx.smid_inline_link_naked_url); // - } - return obj_txt; +struct ST_the_section { + ObjGenericComposite[] comp_section_obj; // array: the heading has 2 members inserted, paras just 1 + uint[string] pith; + string[string][string] tag_assoc; // only for headings: html & epub } +enum DomTags { none, open, close, close_and_open, open_still, } // book index variables string book_idx_tmp; string[][string][string] bookindex_unordered_hashes; // node -ObjGenericComposite comp_obj_heading, comp_obj_location, comp_obj_block, comp_obj_code, comp_obj_poem_ocn, comp_obj_comment; +ObjGenericComposite comp_obj_, comp_obj_location, comp_obj_poem_ocn, comp_obj_comment; auto node_construct = NodeStructureMetadata(); -@safe string[string][string] inline_para_link_anchor()( - string[string] an_object, - string[string] tag_in_seg, - string[string][string] tag_assoc -) { - static auto rgx = RgxI(); - if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) { - if (m.captures[1] !in tag_assoc) { - tag_assoc[(m.captures[1])]["seg_lv4"] = tag_in_seg["seg_lv4"]; - tag_assoc[(m.captures[1])]["seg_lv1to4"] = tag_in_seg["seg_lv1to4"]; - } else { - writeln("a tag named already exists, check text line\n ", an_object["substantive"]); - } - } - return tag_assoc; -} struct ST_txt_by_line_common_reset { int[string] line_occur; string[string] this_object; @@ -492,7 +266,7 @@ struct ST_flow_table_closed_make_special_notation_table { string[string] this_object; ObjGenericComposite[] the_document_body_section; OCNset obj_cite_digits; - ObjGenericComposite _comp_obj_heading; + ObjGenericComposite comp_obj_; int cntr; uint[string] pith; } @@ -501,7 +275,7 @@ struct ST_flow_block_flag_line_empty { ObjGenericComposite[] the_document_body_section; string[][string][string] bookindex_unordered_hashes; OCNset obj_cite_digits; - ObjGenericComposite comp_obj_heading; + ObjGenericComposite comp_obj_; int cntr; uint[string] pith; } @@ -554,7 +328,7 @@ scope(exit) { mixin spineNode; auto node_para_int_ = node_metadata_para_int; auto node_para_str_ = node_metadata_para_str; -ObjGenericComposite comp_obj_heading_, comp_obj_para, comp_obj_toc; +ObjGenericComposite comp_obj_; line_occur = [ "heading" : 0, "para" : 0, @@ -637,31 +411,19 @@ string _anchor_tag; string toc_txt_; an_object["glossary_nugget"] = ""; an_object["blurb_nugget"] = ""; -comp_obj_heading_ = comp_obj_heading_.init; -comp_obj_heading_.metainfo.is_of_part = "frontmatter"; -comp_obj_heading_.metainfo.is_of_section = "toc"; -comp_obj_heading_.metainfo.is_of_type = "para"; -comp_obj_heading_.metainfo.is_a = "heading"; -comp_obj_heading_.text = "Table of Contents"; -comp_obj_heading_.metainfo.ocn = 0; -comp_obj_heading_.metainfo.identifier = ""; -comp_obj_heading_.metainfo.dummy_heading = false; -comp_obj_heading_.metainfo.object_number_off = true; -comp_obj_heading_.metainfo.object_number_type = 0; -comp_obj_heading_.tags.segment_anchor_tag_epub = "toc"; -comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; -comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; -comp_obj_heading_.metainfo.heading_lev_markup = 4; -comp_obj_heading_.metainfo.heading_lev_collapsed = 1; -comp_obj_heading_.metainfo.parent_ocn = 1; -comp_obj_heading_.metainfo.parent_lev_markup = 0; -comp_obj_heading_.ptr.html_segnames = html_segnames_ptr; -comp_obj_heading_.tags.anchor_tags = ["toc"]; -comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; -comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; -tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; -tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; -auto toc_head = comp_obj_heading_; +comp_obj_ = set_object_heading("lev4", "frontmatter", "toc", "Table of Contents"); +comp_obj_.metainfo.identifier = ""; +comp_obj_.metainfo.dummy_heading = false; +comp_obj_.metainfo.object_number_off = true; +comp_obj_.metainfo.object_number_type = 0; +comp_obj_.tags.segment_anchor_tag_epub = "toc"; +comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; +comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; +comp_obj_.ptr.html_segnames = html_segnames_ptr; +comp_obj_.tags.anchor_tags = ["toc"]; +tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; +tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; +auto toc_head = comp_obj_; html_segnames_ptr_cntr++; the_document_toc_section = [toc_head]; static auto mkup = InlineMarkup(); @@ -794,95 +556,13 @@ auto loopMarkupSrcByLine( debug(glossary) { writeln(__LINE__); writeln(line); } pith["section"] = eN.sect.glossary; if (opt_action.backmatter && opt_action.section_glossary) { - indent = [ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - pith["txt_is"] = eN.txt_is.para; - line_occur["para"] = eN.bi.off; - an_object_key = "glossary_nugget"; - if (line.matchFirst(rgx.heading_glossary)) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "glossary"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_glossary"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "glossary"; - comp_obj_heading_.tags.anchor_tags = ["section_glossary"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - the_document_glossary_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "glossary"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "glossary"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; - comp_obj_heading_.tags.anchor_tags = ["glossary"]; - the_document_glossary_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - } else { - { - auto _get = line.flow_para_match_(an_object, an_object_key, indent, bullet, pith, line_occur); - { - an_object = _get.this_object; - an_object_key = _get.this_object_key; - pith = _get.pith; - indent = _get.indent; - bullet = _get.bullet; - line_occur = _get.line_occur; - } - } - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "glossary"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "glossary"; - comp_obj_para.text = links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""); - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.attrib.bullet = bullet; - the_document_glossary_section ~= comp_obj_para; + ST_the_section add_to_glossary_sect = line.build_the_glossary_section(pith, tag_assoc); + the_document_glossary_section ~= add_to_glossary_sect.comp_section_obj[0]; + if (add_to_glossary_sect.comp_section_obj.length > 1) { // heading + the_document_glossary_section ~= add_to_glossary_sect.comp_section_obj[1]; } - pith["ocn"] = eN.ocn.on; + pith = add_to_glossary_sect.pith; + tag_assoc = add_to_glossary_sect.tag_assoc; } continue; } else if (line.matchFirst(rgx.heading_blurb) @@ -894,141 +574,14 @@ auto loopMarkupSrcByLine( ) { pith["section"] = eN.sect.blurb; debug(blurb) { writeln(__LINE__); writeln(line); } - if (opt_action.backmatter && opt_action.section_blurb) { - indent = [ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - if (auto m = line.matchFirst(rgx.para_indent)) { - debug(paraindent) { writeln(line); } - indent["hang_position"] = (m["indent"]).to!int; - indent["base_position"] = (m["indent"]).to!int; - } else if (line.matchFirst(rgx.para_bullet)) { - debug(parabullet) { writeln(line); } - bullet = true; - } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { - debug(paraindenthang) { writeln(line); } - indent = [ - "hang_position" : (m["hang"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { - debug(parabulletindent) { writeln(line); } - indent = [ - "hang_position" : (m["indent"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - bullet = true; - } - pith["txt_is"] = eN.txt_is.para; - line_occur["para"] = eN.bi.off; - an_object_key = "blurb_nugget"; - if (line.matchFirst(rgx.heading_blurb)) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "blurb"; - comp_obj_heading_.tags.anchor_tags = ["section_blurb"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - the_document_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.tags.anchor_tags = ["blurb"]; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; - the_document_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - } else if (line.matchFirst(rgx.headings) - && (opt_action.backmatter && opt_action.section_blurb)) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = line.to!string; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv - comp_obj_heading_.metainfo.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } else if (!(line.empty)) { - { - auto _get = line.flow_para_match_(an_object, an_object_key, indent, bullet, pith, line_occur); - { - an_object = _get.this_object; - an_object_key = _get.this_object_key; - pith = _get.pith; - indent = _get.indent; - bullet = _get.bullet; - line_occur = _get.line_occur; - } - } - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "blurb"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "blurb"; - comp_obj_para.text = links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""); - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.has.inline_links = true; - comp_obj_para.attrib.bullet = bullet; - the_document_blurb_section ~= comp_obj_para; + if ((opt_action.backmatter && opt_action.section_blurb) && !(line.empty)) { + ST_the_section add_to_blurb_sect = line.build_the_blurb_section(pith, tag_assoc, opt_action); + the_document_blurb_section ~= add_to_blurb_sect.comp_section_obj[0]; + if (add_to_blurb_sect.comp_section_obj.length > 1) { // heading + the_document_blurb_section ~= add_to_blurb_sect.comp_section_obj[1]; } - pith["ocn"] = eN.ocn.on; + pith = add_to_blurb_sect.pith; + tag_assoc = add_to_blurb_sect.tag_assoc; } continue; } else if (pith["block_state"] == eN.blk_state.on) { @@ -1266,7 +819,7 @@ auto loopMarkupSrcByLine( the_document_body_section, bookindex_unordered_hashes, obj_cite_digits, - comp_obj_heading, + comp_obj_, cntr, pith, object_number_poem, @@ -1278,7 +831,7 @@ auto loopMarkupSrcByLine( the_document_body_section = _get.the_document_body_section; bookindex_unordered_hashes = _get.bookindex_unordered_hashes; obj_cite_digits = _get.obj_cite_digits; - comp_obj_heading = _get.comp_obj_heading; + comp_obj_ = _get.comp_obj_; cntr = _get.cntr; pith = _get.pith; } @@ -1397,11 +950,8 @@ auto loopMarkupSrcByLine( if (an_object["lev_markup_number"].to!int <= 4) { segnames["epub"] ~= tag_in_seg["seg_lv1to4"]; } - auto comp_obj_heading = node_construct.node_emitter_heading( - an_object["substantive"], - an_object["lev_markup_number"], - an_object["lev_collapsed_number"], - an_object["dummy_heading_status"], + auto comp_obj_ = node_construct.node_emitter_heading( + an_object, tag_in_seg, lev_anchor_tag, tag_assoc, @@ -1409,11 +959,8 @@ auto loopMarkupSrcByLine( cntr, // int heading_ptr, // int lv_ancestors_txt, // string[] - an_object["is"], // string html_segnames_ptr, // int - substantive_object_and_anchor_tags_struct.has_notes_reg, - substantive_object_and_anchor_tags_struct.has_notes_star, - substantive_object_and_anchor_tags_struct.has_links, + substantive_object_and_anchor_tags_struct, ); ++heading_ptr; debug(segments) { @@ -1421,7 +968,7 @@ auto loopMarkupSrcByLine( writeln(tag_in_seg["seg_lv4"]); writeln(tag_in_seg["seg_lv1to4"]); } - the_document_body_section ~= comp_obj_heading; + the_document_body_section ~= comp_obj_; debug(objectrelated1) { writeln(line); } // check { auto _get = txt_by_line_common_reset_(line_occur, an_object, pith); @@ -1445,7 +992,7 @@ auto loopMarkupSrcByLine( an_object["bookindex_nugget"] = ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; bookindex_unordered_hashes = bookindex_extract_hash.bookindex_nugget_hash(an_object["bookindex_nugget"], obj_cite_digits, tag_in_seg); an_object["is"] = "para"; - auto comp_obj_heading = node_construct.node_location_emitter( + auto comp_obj_ = node_construct.node_location_emitter( content_non_header, tag_in_seg, lev_anchor_tag, @@ -1459,28 +1006,22 @@ auto loopMarkupSrcByLine( = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "body"; - comp_obj_para.metainfo.is_of_section = "body"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "para"; - comp_obj_para.text = an_object["substantive"].to!string.strip; - comp_obj_para.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_para.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_para.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_para.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_para.metainfo.object_number_off = (obj_cite_digits.off == 0) ? true : false; // TODO - comp_obj_para.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_para.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.attrib.bullet = bullet; - comp_obj_para.tags.anchor_tags = [anchor_tag]; anchor_tag=""; - comp_obj_para.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_para.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_para.has.inline_links = substantive_obj_misc_struct.has_links; - comp_obj_para.has.image_without_dimensions = substantive_obj_misc_struct.has_images_without_dimensions; - the_document_body_section ~= comp_obj_para; + comp_obj_ = set_object_generic("body", "body", "para", "para", an_object["substantive"].to!string.strip, obj_cite_digits.object_number); + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = (obj_cite_digits.off == 0) ? true : false; // TODO + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.attrib.indent_hang = indent["hang_position"]; + comp_obj_.attrib.indent_base = indent["base_position"]; + comp_obj_.attrib.bullet = bullet; + comp_obj_.tags.anchor_tags = [anchor_tag]; anchor_tag=""; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + comp_obj_.has.image_without_dimensions = substantive_obj_misc_struct.has_images_without_dimensions; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); { auto _get = txt_by_line_common_reset_(line_occur, an_object, pith); @@ -1583,9 +1124,6 @@ auto loopMarkupSrcByLine( <> <> <> -<> -<> -<> <> <> <> @@ -1594,7 +1132,7 @@ auto loopMarkupSrcByLine( <> <> <> -// the_dom_tail_section ~= comp_obj_heading_; // remove tail for now, decide on later +// the_dom_tail_section ~= comp_obj_; // remove tail for now, decide on later <> <> <> @@ -1626,30 +1164,20 @@ return ret; #+HEADER: :noweb yes #+BEGIN_SRC d { // EOF backMatter - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "tail"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = ""; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_eof"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "tail"; - comp_obj_heading_.tags.anchor_tags = ["section_eof"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0]; - the_document_xml_dom_tail_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_ = set_object_heading("lev1", "backmatter", "tail", ""); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_eof"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "tail"; + comp_obj_.tags.anchor_tags = ["section_eof"]; + comp_obj_.metainfo.dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0]; + comp_obj_.metainfo.dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0]; + the_document_xml_dom_tail_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; } #+END_SRC @@ -1677,22 +1205,12 @@ ST_endnotes en_st = note_section.backmatter_endnote_objects(obj_cite_digits, opt #+BEGIN_SRC d { // glossary if (an_object["glossary_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Glossary section"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_glossary_section ~= comp_obj_heading_; + comp_obj_ = set_object_heading("lev1", "empty", "empty", "(skip) there is no Glossary section"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + the_document_glossary_section ~= comp_obj_; } debug(glossary) { foreach (gloss; the_document_glossary_section) { writeln(gloss.text); } } } @@ -1705,119 +1223,9 @@ ST_endnotes en_st = note_section.backmatter_endnote_objects(obj_cite_digits, opt #+BEGIN_SRC d { // bibliography string[] biblio_unsorted_incomplete = biblio_arr_json.dup; - Bibliography biblio = Bibliography(); - JSONValue[] biblio_ordered; - ST_flow_bibliography _get = biblio.flow_bibliography_(biblio_unsorted_incomplete, bib_arr_json); - { - biblio_ordered = _get.biblio_sorted; - bib_arr_json = _get.bib_arr_json; - biblio_unsorted_incomplete = _get.biblio_unsorted_incomplete; - } - if (biblio_ordered.length > 0) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bibliography"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_bibliography"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "bibliography"; - comp_obj_heading_.tags.anchor_tags = ["section_bibliography"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - the_document_bibliography_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bibliography"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "bibliography"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; - comp_obj_heading_.tags.anchor_tags = ["bibliography"]; - the_document_bibliography_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - string out_; - foreach (entry; biblio_ordered) { - out_ = format("%s \"%s\"%s%s%s%s%s%s%s%s%s.", - ((entry["author"].str.empty) ? entry["editor"].str : entry["author"].str), - entry["fulltitle"].str, - ((entry["journal"].str.empty) ? "" : ", " ~ mkup.ff_i ~ mkup.italic ~ mkup.ff_o ~ entry["journal"].str ~ mkup.ff_c ~ mkup.italic), - ((entry["volume"].str.empty) ? "" : ", " ~ entry["volume"].str), - ((entry["in"].str.empty) ? "" : ", " ~ entry["in"].str), - ((!(entry["author"].str.empty) && (!(entry["editor"].str.empty))) ? entry["editor"].str : ""), - ", " ~ entry["year"].str, - ((entry["pages"].str.empty) ? "" : ", " ~ entry["pages"].str), - ((entry["publisher"].str.empty) ? "" : ", " ~ entry["publisher"].str), - ((entry["place"].str.empty) ? "" : ", " ~ entry["place"].str), - ((entry["url"].str.empty) ? "" : ", [" ~ entry["url"].str ~ "]"), - ); - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "bibliography"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "bibliography"; - comp_obj_para.text = out_.to!string.strip; - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = 0; - comp_obj_para.attrib.indent_base = 1; - comp_obj_para.attrib.bullet = bullet; - comp_obj_para.tags.anchor_tags = [anchor_tag]; - the_document_bibliography_section ~= comp_obj_para; - } - } - } else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_bibliography_section ~= comp_obj_heading_; - } - debug(bibliosection) { foreach (o; the_document_bibliography_section) { writeln(o.text); } } + ST_biblio_section biblio_section = backmatter_make_the_bibliography_section(biblio_unsorted_incomplete, bib_arr_json); + the_document_bibliography_section = biblio_section.bibliography_section; + tag_assoc = biblio_section.tag_assoc; } #+END_SRC @@ -1844,24 +1252,14 @@ ST_endnotes en_st = note_section.backmatter_endnote_objects(obj_cite_digits, opt #+BEGIN_SRC d { // blurb if (an_object["blurb_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Blurb section"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = ""; - comp_obj_heading_.tags.anchor_tag_html = ""; - comp_obj_heading_.tags.in_segment_html = ""; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_blurb_section ~= comp_obj_heading_; + comp_obj_ = set_object_heading("lev1", "empty", "empty", "(skip) there is no Blurb section"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = ""; + comp_obj_.tags.anchor_tag_html = ""; + comp_obj_.tags.in_segment_html = ""; + the_document_blurb_section ~= comp_obj_; } debug(blurb) { foreach (blurb; the_document_blurb_section) { writeln(blurb.text); } } } @@ -1873,98 +1271,7 @@ ST_endnotes en_st = note_section.backmatter_endnote_objects(obj_cite_digits, opt #+HEADER: :noweb yes #+BEGIN_SRC d { // toc gather backmatter - indent = [ - "hang_position" : 1, - "base_position" : 1, - ]; - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.metainfo.is_of_part = "frontmatter"; - comp_obj_toc.metainfo.is_of_section = "toc"; - comp_obj_toc.metainfo.is_of_type = "para"; - comp_obj_toc.metainfo.is_a = "toc"; - comp_obj_toc.metainfo.ocn = 0; - comp_obj_toc.metainfo.identifier = ""; - comp_obj_toc.metainfo.object_number_off = true; - comp_obj_toc.metainfo.object_number_type = 0; - comp_obj_toc.attrib.indent_hang = indent["hang_position"]; - comp_obj_toc.attrib.indent_base = indent["base_position"]; - comp_obj_toc.attrib.bullet = false; - if (the_document_endnotes_section.length > 1) { - toc_txt_ = format("%s%s%s%s#%s%s", - mkup.lnk_o, - "Endnotes", - mkup.lnk_c, - mkup.url_o, - "endnotes", - mkup.url_c, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_document_toc_section ~= comp_obj_toc; - } - if (the_document_glossary_section.length > 1) { - toc_txt_ = format("%s%s%s%s#%s%s", - mkup.lnk_o, - "Glossary", - mkup.lnk_c, - mkup.url_o, - "glossary", - mkup.url_c, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_document_toc_section ~= comp_obj_toc; - } - if (the_document_bibliography_section.length > 1){ - toc_txt_ = format("%s%s%s%s#%s%s", - mkup.lnk_o, - "Bibliography", - mkup.lnk_c, - mkup.url_o, - "bibliography", - mkup.url_c, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_document_toc_section ~= comp_obj_toc; - } - if (the_document_bookindex_section.length > 1) { - toc_txt_ = format("%s%s%s%s#%s%s", - mkup.lnk_o, - "Book Index", - mkup.lnk_c, - mkup.url_o, - "bookindex", - mkup.url_c, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_document_toc_section ~= comp_obj_toc; - } - if (the_document_blurb_section.length > 1) { - toc_txt_ = format("%s%s%s%s#%s%s", - mkup.lnk_o, - "Blurb", - mkup.lnk_c, - mkup.url_o, - "blurb", - mkup.url_c, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.has.inline_links = true; - comp_obj_toc.text = toc_txt_.to!string.strip; - the_document_toc_section ~= comp_obj_toc; - } - debug(toc) { - writefln( "%s %s", __LINE__,); - foreach (toc_linked_heading; the_document_toc_section) { - writeln(mkup.indent_by_spaces_provided(toc_linked_heading.attrib.indent_hang), toc_linked_heading.text); - } - } + the_document_toc_section ~= backmatter_gather_table_of_contents(the_document_endnotes_section, the_document_glossary_section, the_document_bibliography_section, the_document_bookindex_section, the_document_blurb_section); // } #+END_SRC @@ -1985,454 +1292,158 @@ ST_endnotes en_st = note_section.backmatter_endnote_objects(obj_cite_digits, opt #+NAME: docAbstractionAncestors #+HEADER: :noweb yes #+BEGIN_SRC d -// document ancestors -@safe int[] _get_ancestors_markup(O)(O obj, ref int[] _ancestors_markup) { +{ // document ancestors + ST_ancestors get_ancestors; + get_ancestors = the_document_body_section.after_doc_determine_ancestors(the_document_endnotes_section, the_document_glossary_section, the_document_bibliography_section, the_document_bookindex_section, the_document_blurb_section); + the_document_body_section = get_ancestors.the_document_body_section; + the_document_endnotes_section = get_ancestors.the_document_endnotes_section; + the_document_glossary_section = get_ancestors.the_document_glossary_section; + the_document_bibliography_section = get_ancestors.the_document_bibliography_section; + the_document_bookindex_section = get_ancestors.the_document_bookindex_section; + the_document_blurb_section = get_ancestors.the_document_blurb_section; +} +#+END_SRC + +**** SegNames + +#+NAME: docAbstractionSegNames +#+HEADER: :noweb yes +#+BEGIN_SRC d +{ // document segnames + ST_segnames get_segnames; + get_segnames = the_document_body_section.after_doc_determine_segnames(the_document_endnotes_section, the_document_glossary_section, the_document_bibliography_section, the_document_bookindex_section, the_document_blurb_section, segnames, html_segnames_ptr_cntr, html_segnames_ptr); // + segnames = get_segnames.segnames; + html_segnames_ptr_cntr = get_segnames.html_segnames_ptr_cntr; + html_segnames_ptr = get_segnames.html_segnames_ptr; +} +#+END_SRC + +**** SegNames with links & images + +#+NAME: docAbstractionSegNamesLinkedAndImages +#+HEADER: :noweb yes +#+BEGIN_SRC d +// document head +string[] segnames_0_to_4; +foreach (ref obj; the_document_head_section) { if (obj.metainfo.is_a == "heading") { debug(dom) { writeln(obj.text); } - if (obj.metainfo.heading_lev_markup == 1) { - _ancestors_markup = [ - _ancestors_markup[0], - 0,0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 2) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - 0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 3) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - 0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 4) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - 0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 5) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - 0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 6) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - 0,0 - ]; + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; } - if (obj.metainfo.heading_lev_markup == 7) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - _ancestors_markup[6], - 0 - ]; + if (obj.metainfo.heading_lev_markup == 0) { + // TODO second hit (of two) with same assertion failure, check, fix and reinstate + // assert( obj.metainfo.ocn == 1, + // "Title OCN should be 1 not: " ~ obj.metainfo.ocn.to!string); // bug introduced 0.18.1 + obj.metainfo.ocn = 1; + obj.metainfo.identifier = "1"; + obj.metainfo.object_number_type = OCNtype.ocn; } - if (obj.metainfo.heading_lev_markup == 8) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - _ancestors_markup[6], - _ancestors_markup[7] - ]; + // dom structure (marked up & collapsed) + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); } - _ancestors_markup[obj.metainfo.heading_lev_markup] = obj.metainfo.ocn; + obj = obj.obj_heading_ancestors(lv_ancestors_txt); } - debug(ancestor_markup) { writeln("marked up: ", _ancestors_markup); } - return _ancestors_markup; + obj = _links(obj); } -@safe int[] _get_ancestors_collapsed(O)(O obj, ref int[] _ancestors_collapsed) { - if (obj.metainfo.is_a == "heading") { - if (obj.metainfo.heading_lev_collapsed == 1) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - 0,0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 2) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - 0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 3) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - 0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 4) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - 0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 5) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - 0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 6) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - 0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 7) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - _ancestors_collapsed[6], - 0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 8) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - _ancestors_collapsed[6], - _ancestors_collapsed[7] - ]; +if (the_document_toc_section.length > 1) { + // scroll + dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; + dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; + foreach (ref obj; the_document_toc_section) { + if (obj.metainfo.is_a == "heading") { + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + // dom structure (marked up & collapsed) + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); } - _ancestors_collapsed[obj.metainfo.heading_lev_collapsed] = obj.metainfo.ocn; + obj = _links(obj); } - debug(ancestor_collapsed) { writeln("collapsed: ", _ancestors_collapsed); } - return _ancestors_collapsed; } +// images +string[] _images; // multiple 1~ levels, loop through document body if (the_document_body_section.length > 1) { - int[] _ancestors_markup = [0,0,0,0,0,0,0,0]; - int[][] _ancestors_markup_; - _ancestors_markup = [1,0,0,0,0,0,0,0]; - _ancestors_markup_ ~= _ancestors_markup; - int[] _ancestors_collapsed = [0,0,0,0,0,0,0,0]; - int[][] _ancestors_collapsed_; - _ancestors_collapsed = [1,0,0,0,0,0,0,0]; - _ancestors_collapsed_ ~= _ancestors_collapsed; foreach (ref obj; the_document_body_section) { + if (!(obj.metainfo.identifier.empty)) { + if (!(((obj.metainfo.identifier) in tag_assoc) + && ("seg_lv4" in tag_assoc[(obj.metainfo.identifier)])) + ) { + tag_assoc[(obj.metainfo.identifier)]["seg_lv4"] + = obj.tags.html_segment_anchor_tag_is; + } + tag_assoc[(obj.metainfo.identifier)]["seg_lv1to4"] + = obj.tags.epub_segment_anchor_tag_is; + } if (obj.metainfo.is_a == "heading") { - obj.metainfo.markedup_ancestors = _get_ancestors_markup(obj, _ancestors_markup); - obj.metainfo.collapsed_ancestors = _get_ancestors_collapsed(obj, _ancestors_collapsed); - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + debug(dom) { writeln(obj.text); } + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.lev4_subtoc = lev4_subtoc[obj.tags.anchor_tag_html]; + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + // dom structure (marked up & collapsed) + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "para") { + _images ~= extract_images(obj.text); + obj = _image_dimensions(obj, manifested); } - } - debug(ancestors) { - writeln("ancestors markup o_n: ", obj.metainfo.markedup_ancestors); - writeln("ancestors collapsed o_n: ", obj.metainfo.markedup_ancestors); + obj = _links(obj); } } +auto image_list = (_images.sort()).uniq; #+END_SRC -**** SegNames +*** Level 1~ +**** Endnotes -#+NAME: docAbstractionSegNames +#+NAME: docAbstractionEndnotes #+HEADER: :noweb yes #+BEGIN_SRC d -// segnames +// endnotes optional only one 1~ level if (the_document_endnotes_section.length > 1) { - segnames["html"] ~= "endnotes"; - segnames["epub"] ~= "endnotes"; - html_segnames_ptr = html_segnames_ptr_cntr; + dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; + dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; + dom_structure_markedup_tags_status = dom_structure_markedup_tags_status_buffer.dup; + dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status_buffer.dup; foreach (ref obj; the_document_endnotes_section) { if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -if (the_document_glossary_section.length > 1) { - segnames["html"] ~= "glossary"; - segnames["epub"] ~= "glossary"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_document_glossary_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -if (the_document_bibliography_section.length > 1) { - segnames["html"] ~= "bibliography"; - segnames["epub"] ~= "bibliography"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_document_bibliography_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -if (the_document_bookindex_section.length > 1) { - segnames["html"] ~= "bookindex"; - segnames["epub"] ~= "bookindex"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_document_bookindex_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -if (the_document_blurb_section.length > 1) { - segnames["html"] ~= "blurb"; - segnames["epub"] ~= "blurb"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_document_blurb_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -**** Decendants - -#+NAME: docAbstractionDecendants -#+HEADER: :noweb yes -#+BEGIN_SRC d -// decendants -@safe auto get_decendants()(ObjGenericComposite[] document_sections) { - int[string] _heading_ocn_decendants; - string[] _ocn_open_key = ["","","","","","","",""]; - auto _doc_sect_length = document_sections.length - 1; - int _last_ocn; - foreach (_lg, ref obj; document_sections) { - if (obj.metainfo.is_a == "heading") { - foreach (_dts_lv, dom_tag_status; obj.metainfo.dom_structure_markedup_tags_status) { - switch (dom_tag_status) with (DomTags) { - case none: break; - case open: - _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; - break; - case close: - if (_ocn_open_key[_dts_lv].empty) { - _ocn_open_key[_dts_lv] = "0"; - } - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; - _ocn_open_key[_dts_lv] = (0).to!string; - break; - case close_and_open: - if (_ocn_open_key[_dts_lv].empty) { - _ocn_open_key[_dts_lv] = "0"; - } - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; - _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; - break; - case open_still: break; - default: break; - } - } - } - if (obj.metainfo.ocn > 0) { - _last_ocn = obj.metainfo.ocn; - } - if (_lg == _doc_sect_length) { - _heading_ocn_decendants["1"] = _last_ocn; // close existing o_n key - } - } - Tuple!(int, int)[] pairs; - foreach (pair; _heading_ocn_decendants.byPair) { - pairs ~= tuple(pair[0].to!int, pair[1]); - } - return pairs.sort; -} -#+END_SRC - -**** Images - -#+NAME: docAbstractionRelatedFunctionsImages -#+HEADER: :noweb yes -#+BEGIN_SRC d -// images -string[] _images; -@safe string[] extract_images()(string content_block) { - string[] images_; - if (auto m = content_block.matchAll(rgx.image)) { - images_ ~= m.captures[1]; - } - return images_; -} -@system auto _image_dimensions(O,M)(O obj, M manifested) { - if (obj.has.image_without_dimensions) { - import std.math; - import imageformats; - int w, h, chans; - real _w, _h; - int max_width = 640; - foreach (img; obj.text.matchAll(rgx.inline_image_without_dimensions)) { - try { - read_image_info(manifested.src.image_dir_path ~ "/" ~ img["img"], w, h, chans); - } catch (Exception ex) { - writeln("WARNING, image not found: ", img["img"], "\n ", manifested.src.image_dir_path ~ "/" ~ img["img"]); - } - // calculate, decide max width and proportionally reduce to keep w & h within it - debug(images) { writeln("width: ", w, ", height: ", h); } - if (w > max_width) { - _w = max_width; - _h = round((max_width / w.to!real) * h.to!real); - } else { - _w = w; - _h = h; - } - obj.text = obj.text.replaceFirst( - rgx.inline_image_without_dimensions, - format(q"┃%s☼%s,w%sh%s %s┃", - "$1", - "$3", - _w.to!string, - _h.to!string, - "$6", - ) - ); - } - debug(images) { writeln("image without dimensions: ", obj.text); } - } - return obj; -} -#+END_SRC - -**** Links - -#+NAME: docAbstractionLinks -#+HEADER: :noweb yes -#+BEGIN_SRC d -// links -@safe auto _links(O)(O obj) { - if (auto m = obj.text.match(rgx.inline_link_stow_uri)) { - debug(links) { - writeln("number of link matches to stow: ", (obj.text.match(rgx.inline_link_stow_uri)).count); - writeln("links to stow: ", (obj.text.match(rgx.inline_link_stow_uri))); - } - int _n_matches = (obj.text.match(rgx.inline_link_stow_uri)).count.to!int; - for(int i = 0; i < _n_matches; ++i) { - if (obj.text.match(rgx.inline_link_stow_uri)) { - obj.stow.link ~= obj.text.matchFirst(rgx.inline_link_stow_uri)[2]; - obj.text = obj.text.replaceFirst( - rgx.inline_link_stow_uri, - format(q"┃┥%s┝┤%s├┃", "$1", i) - ); + debug(dom) { writeln(obj.text); } + if (obj.metainfo.heading_lev_markup == 1) { + obj_cite_digits = ocn_emit(eN.ocn.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; } - } - } - return obj; -} -#+END_SRC - -**** SegNames with links and Images - -#+NAME: docAbstractionSegNamesLinkedAndImages -#+HEADER: :noweb yes -#+BEGIN_SRC d -// document head -string[] segnames_0_to_4; -foreach (ref obj; the_document_head_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { writeln(obj.text); } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - } - if (obj.metainfo.heading_lev_markup == 0) { - // TODO second hit (of two) with same assertion failure, check, fix and reinstate - // assert( obj.metainfo.ocn == 1, - // "Title OCN should be 1 not: " ~ obj.metainfo.ocn.to!string); // bug introduced 0.18.1 - obj.metainfo.ocn = 1; - obj.metainfo.identifier = "1"; - obj.metainfo.object_number_type = OCNtype.ocn; - } - // dom structure (marked up & collapsed) - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } - obj = _links(obj); -} -if (the_document_toc_section.length > 1) { - // scroll - dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; - dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; - foreach (ref obj; the_document_toc_section) { - if (obj.metainfo.is_a == "heading") { if (obj.metainfo.heading_lev_markup <= 4) { segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); } @@ -2447,25 +1458,26 @@ if (the_document_toc_section.length > 1) { obj = _links(obj); } } -// multiple 1~ levels, loop through document body -if (the_document_body_section.length > 1) { - foreach (ref obj; the_document_body_section) { - if (!(obj.metainfo.identifier.empty)) { - if (!(((obj.metainfo.identifier) in tag_assoc) - && ("seg_lv4" in tag_assoc[(obj.metainfo.identifier)])) - ) { - tag_assoc[(obj.metainfo.identifier)]["seg_lv4"] - = obj.tags.html_segment_anchor_tag_is; - } - tag_assoc[(obj.metainfo.identifier)]["seg_lv1to4"] - = obj.tags.epub_segment_anchor_tag_is; - } +#+END_SRC + +**** Glossary + +#+NAME: docAbstractionGlossary +#+HEADER: :noweb yes +#+BEGIN_SRC d +// glossary optional only one 1~ level +if (the_document_glossary_section.length > 1) { + foreach (ref obj; the_document_glossary_section) { if (obj.metainfo.is_a == "heading") { debug(dom) { writeln(obj.text); } + if (obj.metainfo.heading_lev_markup == 1) { + obj_cite_digits = ocn_emit(eN.ocn.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + } if (obj.metainfo.heading_lev_markup <= 4) { segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.lev4_subtoc = lev4_subtoc[obj.tags.anchor_tag_html]; obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; if (segnames["html"].length > obj.ptr.html_segnames + 1) { obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; @@ -2480,29 +1492,24 @@ if (the_document_body_section.length > 1) { obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); } obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "para") { - _images ~= extract_images(obj.text); - obj = _image_dimensions(obj, manifested); + } else if (obj.metainfo.is_a == "glossary" && !(obj.text.empty)) { + obj_cite_digits = ocn_emit(eN.ocn.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; } obj = _links(obj); } } -auto image_list = (_images.sort()).uniq; #+END_SRC -*** Level 1~ -**** Endnotes +**** Bibliography -#+NAME: docAbstractionEndnotes +#+NAME: docAbstractionBibliography #+HEADER: :noweb yes #+BEGIN_SRC d -// endnotes optional only one 1~ level -if (the_document_endnotes_section.length > 1) { - dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; - dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; - dom_structure_markedup_tags_status = dom_structure_markedup_tags_status_buffer.dup; - dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status_buffer.dup; - foreach (ref obj; the_document_endnotes_section) { +// bibliography optional only one 1~ level +if (the_document_bibliography_section.length > 1) { + foreach (ref obj; the_document_bibliography_section) { if (obj.metainfo.is_a == "heading") { debug(dom) { writeln(obj.text); } if (obj.metainfo.heading_lev_markup == 1) { @@ -2527,90 +1534,10 @@ if (the_document_endnotes_section.length > 1) { obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); } obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } - obj = _links(obj); - } -} -#+END_SRC - -**** Glossary - -#+NAME: docAbstractionGlossary -#+HEADER: :noweb yes -#+BEGIN_SRC d -// glossary optional only one 1~ level -if (the_document_glossary_section.length > 1) { - foreach (ref obj; the_document_glossary_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { writeln(obj.text); } - if (obj.metainfo.heading_lev_markup == 1) { - obj_cite_digits = ocn_emit(eN.ocn.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - // dom structure (marked up & collapsed) - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "glossary" && !(obj.text.empty)) { - obj_cite_digits = ocn_emit(eN.ocn.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - } - obj = _links(obj); - } -} -#+END_SRC - -**** Bibliography - -#+NAME: docAbstractionBibliography -#+HEADER: :noweb yes -#+BEGIN_SRC d -// bibliography optional only one 1~ level -if (the_document_bibliography_section.length > 1) { - foreach (ref obj; the_document_bibliography_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { writeln(obj.text); } - if (obj.metainfo.heading_lev_markup == 1) { - obj_cite_digits = ocn_emit(eN.ocn.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - // dom structure (marked up & collapsed) - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "bibliography") { - obj_cite_digits = ocn_emit(eN.ocn.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; + } else if (obj.metainfo.is_a == "bibliography") { + obj_cite_digits = ocn_emit(eN.ocn.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; } obj = _links(obj); } @@ -2719,7 +1646,7 @@ if (the_document_blurb_section.length > 1) { #+BEGIN_SRC d // get decendants if (the_document_body_section.length > 1) { - auto pairs = get_decendants( + auto pairs = after_doc_get_decendants( the_document_head_section ~ the_document_body_section ~ the_document_endnotes_section ~ @@ -2834,30 +1761,25 @@ if (the_document_body_section.length > 1) { // sort out: // - obj.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status; // - obj.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status; -comp_obj_heading_ = comp_obj_heading_.init; -comp_obj_heading_.metainfo.is_of_part = "empty"; -comp_obj_heading_.metainfo.is_of_section = "empty"; -comp_obj_heading_.metainfo.is_of_type = "para"; -comp_obj_heading_.metainfo.is_a = "heading"; -comp_obj_heading_.metainfo.ocn = 0; -comp_obj_heading_.metainfo.identifier = ""; -comp_obj_heading_.metainfo.dummy_heading = true; -comp_obj_heading_.metainfo.object_number_off = true; -comp_obj_heading_.metainfo.object_number_type = 0; -comp_obj_heading_.tags.segment_anchor_tag_epub = ""; -comp_obj_heading_.tags.anchor_tag_html = ""; -comp_obj_heading_.tags.in_segment_html = ""; -comp_obj_heading_.tags.html_segment_anchor_tag_is = ""; -comp_obj_heading_.tags.epub_segment_anchor_tag_is = ""; -comp_obj_heading_.metainfo.heading_lev_markup = 9; -comp_obj_heading_.metainfo.heading_lev_collapsed = 9; -comp_obj_heading_.metainfo.parent_ocn = 0; -comp_obj_heading_.metainfo.parent_lev_markup = 0; -comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status.dup; -comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status.dup; -comp_obj_heading_ = comp_obj_heading_.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, 0); -comp_obj_heading_ = comp_obj_heading_.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, 0); -comp_obj_heading_ = comp_obj_heading_.obj_heading_ancestors(lv_ancestors_txt); +comp_obj_ = set_object_heading("lev1", "empty", "empty", ""); +comp_obj_.metainfo.identifier = ""; +comp_obj_.metainfo.dummy_heading = true; +comp_obj_.metainfo.object_number_off = true; +comp_obj_.metainfo.object_number_type = 0; +comp_obj_.tags.segment_anchor_tag_epub = ""; +comp_obj_.tags.anchor_tag_html = ""; +comp_obj_.tags.in_segment_html = ""; +comp_obj_.tags.html_segment_anchor_tag_is = ""; +comp_obj_.tags.epub_segment_anchor_tag_is = ""; +comp_obj_.metainfo.heading_lev_markup = 9; +comp_obj_.metainfo.heading_lev_collapsed = 9; +comp_obj_.metainfo.parent_ocn = 0; +comp_obj_.metainfo.parent_lev_markup = 0; +comp_obj_.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status.dup; +comp_obj_.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status.dup; +comp_obj_ = comp_obj_.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, 0); +comp_obj_ = comp_obj_.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, 0); +comp_obj_ = comp_obj_.obj_heading_ancestors(lv_ancestors_txt); #+END_SRC *** The Doc @@ -3028,58 +1950,515 @@ struct DocHas_ { #+NAME: docAbstractionRelatedFunctions #+HEADER: :noweb yes #+BEGIN_SRC d -@system ST_txt_by_line_common_reset txt_by_line_common_reset_()( - int[string] line_occur, - string[string] an_object, - uint[string] pith, +@safe pure ObjGenericComposite obj_heading_ancestors()( + ObjGenericComposite obj, + string[] lv_ancestors_txt, ) { - line_occur["heading"] = eN.bi.off; - line_occur["para"] = eN.bi.off; - pith["txt_is"] = eN.txt_is.off; - an_object = an_object.object_reset; - ST_txt_by_line_common_reset ret; - { - ret.line_occur = line_occur; - ret.this_object = an_object; - ret.pith = pith; + switch (obj.metainfo.heading_lev_markup) { + case 0: + lv_ancestors_txt[0] = obj.text.to!string; + foreach(k; 1..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 1: + lv_ancestors_txt[1] = obj.text.to!string; + foreach(k; 2..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 2: + lv_ancestors_txt[2] = obj.text.to!string; + foreach(k; 3..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 3: + lv_ancestors_txt[3] = obj.text.to!string; + foreach(k; 4..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 4: + lv_ancestors_txt[4] = obj.text.to!string; + foreach(k; 5..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 5: + lv_ancestors_txt[5] = obj.text.to!string; + foreach(k; 6..8) { lv_ancestors_txt[k] = ""; } + goto default; + case 6: + lv_ancestors_txt[6] = obj.text.to!string; + lv_ancestors_txt[7] = ""; + goto default; + case 7: + lv_ancestors_txt[7] = obj.text.to!string; + goto default; + default: + obj.tags.heading_ancestors_text = lv_ancestors_txt.dup; } - return ret; + return obj; } -@safe ST_txt_by_line_block_start txt_by_line_block_start()( - char[] line, - uint[string] pith, - uint[string] dochas, - string[string] object_number_poem +@safe pure ObjGenericComposite obj_dom_structure_set_markup_tags()( + ObjGenericComposite obj, + int[] dom, + int lev +) { + foreach (i; 0 .. 8) { + if (i < lev) { + if (dom[i] == DomTags.open + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.open_still; + } else if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } + } else if (i == lev) { + if (lev == 0 + && dom[i] == DomTags.open_still + ) { + dom[i] = DomTags.close; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close_and_open; + } else { + dom[i] = DomTags.open; + } + } else if (i > lev) { + if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close; + } + } + } + debug(dom_magic_numbers) { writeln("marked up: ", lev, ": ", dom); } + obj.metainfo.dom_structure_markedup_tags_status = dom.dup; + return obj; +} +@safe pure ObjGenericComposite obj_dom_set_collapsed_tags()( + ObjGenericComposite obj, + int[] dom, + int lev ) { + foreach (i; 0 .. 8) { + if (i < lev) { + if (dom[i] == DomTags.open + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.open_still; + } else if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } + } else if (i == lev) { + if (lev == 0 + && dom[i] == DomTags.open_still + ) { + dom[i] = DomTags.close; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close_and_open; + } else { + dom[i] = DomTags.open; + } + } else if (i > lev) { + if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close; + } + } + } + debug(dom_magic_numbers) { writeln("collapsed: ", lev, ": ", dom); } + obj.metainfo.dom_structure_collapsed_tags_status = dom.dup; + return obj; +} +@safe static OCNset ocn_emit(int ocn_status_flag) { + return object_citation_number.ocn_emitter(ocn_status_flag); +} +@safe auto inline_markup_faces(L)(L line) { static auto rgx = RgxI(); - if (auto m = line.matchFirst(rgx.block_curly_code_open)) { - dochas["codeblock"]++; - an_object["lang"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; - debug(codecurly) { writefln( "* [code curly] %s", line); } // code (curly) open - pith["block_is"] = eN.blk_is.code; - pith["block_state"] = eN.blk_state.on; - pith["block_delim"] = eN.blk_delim.curly; - } else if (auto m = line.matchFirst(rgx.block_curly_poem_open)) { - dochas["poem"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(poem) { writefln( "* [poem curly] %s", line); } // poem (curly) open - object_number_poem["start"] = obj_cite_digits.object_number.to!string; - pith["block_is"] = eN.blk_is.poem; - pith["block_state"] = eN.blk_state.on; - pith["block_delim"] = eN.blk_delim.curly; - pith["verse_new"] = eN.bi.on; - } else if (auto m = line.matchFirst(rgx.block_curly_group_open)) { - dochas["group"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(group) { writefln( "* [group curly] %s", line); } // group (curly) open - pith["block_is"] = eN.blk_is.group; - pith["block_state"] = eN.blk_state.on; + static auto mkup = InlineMarkup(); + line = replaceAll!(m => mkup.quote_o ~ m[1] ~ mkup.quote_c)(line, rgx.within_quotes); + line = replaceAll!(m => mkup.ff_i ~ mkup.mono ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); + line = replaceAll!(m => mkup.ff_i ~ mkup.cite ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); + foreach (regx; [rgx.inline_mark_emphasis, rgx.inline_mark_bold, rgx.inline_mark_underscore, rgx.inline_mark_italics, rgx.inline_mark_superscript, rgx.inline_mark_subscript, rgx.inline_mark_strike, rgx.inline_mark_insert]) { + line = replaceAll!(m => mkup.ff_i ~ m["mark"] ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ m["mark"])(line, regx); + } + return line; +} +@safe static string links_and_images()(string obj_txt) { + static auto rgx = RgxI(); + static auto mkup = InlineMarkup(); + if (obj_txt.match(rgx.smid_inline_url_generic)) { + if ( + obj_txt.match(rgx.smid_inline_link_endnote_url_helper) + || obj_txt.match(rgx.smid_inline_link_endnote_url_helper_punctuated) + ) { + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s%s", + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_o, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_c, + m[3] + ))(obj_txt, rgx.smid_inline_link_endnote_url_helper_punctuated); + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s", + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_o, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_c + ))(obj_txt, rgx.smid_inline_link_endnote_url_helper); + } else { + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", + m["pre"], + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c + ))(obj_txt, rgx.smid_inline_link_markup_regular); + } + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", + m["pre"], + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c + ))(obj_txt, rgx.smid_inline_link_naked_url); // + } + return obj_txt; +} +// ↓ abstraction struct init +@safe static auto eN() { + struct _e { + enum bi { + off, + on, + } + enum ocn { + off, + on, + closing, + bkidx, + reset, + } + enum sect { + unset, + head, + toc, + substantive, + bibliography, + glossary, + book_index, + blurb, + } + enum txt_is { + off, + para, + heading, + } + enum blk_is { + off, + code, + poem, + block, + group, + table, + quote, + } + enum blk_state { + off, + on, + closing, + } + enum blk_delim { + off, + curly, + tic, + curly_special, + tic_special, + } + } + return _e(); +} +@safe string[string][string] inline_para_link_anchor()( + string[string] an_object, + string[string] tag_in_seg, + string[string][string] tag_assoc +) { + static auto rgx = RgxI(); + if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) { + if (m.captures[1] !in tag_assoc) { + tag_assoc[(m.captures[1])]["seg_lv4"] = tag_in_seg["seg_lv4"]; + tag_assoc[(m.captures[1])]["seg_lv1to4"] = tag_in_seg["seg_lv1to4"]; + } else { + writeln("a tag named already exists, check text line\n ", an_object["substantive"]); + } + } + return tag_assoc; +} +@system ST_txt_by_line_common_reset txt_by_line_common_reset_()( + int[string] line_occur, + string[string] an_object, + uint[string] pith, +) { + line_occur["heading"] = eN.bi.off; + line_occur["para"] = eN.bi.off; + pith["txt_is"] = eN.txt_is.off; + an_object = an_object.object_reset; + ST_txt_by_line_common_reset ret; + { + ret.line_occur = line_occur; + ret.this_object = an_object; + ret.pith = pith; + } + return ret; +} +ST_the_section build_the_glossary_section( + char[] line, // line is immutable, not necessary to return unchanged + uint[string] pith, + string[string][string] tag_assoc, // only for headings: html & epub +) { + static auto rgx = RgxI(); + ObjGenericComposite comp_obj_; + ObjGenericComposite[] add_to_current_document_section; + indent = [ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + pith["txt_is"] = eN.txt_is.para; + line_occur["para"] = eN.bi.off; + an_object_key = "glossary_nugget"; + ST_the_section ret; + if (line.matchFirst(rgx.heading_glossary)) { + { + comp_obj_ = set_object_heading("lev1", "backmatter", "glossary", "Glossary"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_glossary"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "glossary"; + comp_obj_.tags.anchor_tags = ["section_glossary"]; + comp_obj_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + comp_obj_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + add_to_current_document_section ~= comp_obj_; // + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } { + comp_obj_ = set_object_heading("lev4", "backmatter", "glossary", "Glossary"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "glossary"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.metainfo.heading_lev_collapsed = 2; + comp_obj_.tags.anchor_tags = ["glossary"]; + add_to_current_document_section ~= comp_obj_; // + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + pith["ocn"] = eN.ocn.on; + } + { + ret.comp_section_obj ~= add_to_current_document_section; + ret.pith = pith; + ret.tag_assoc = tag_assoc; // only for headings: html & epub + } + } else { // para + { + auto _get = line.flow_para_match_(an_object, an_object_key, indent, bullet, pith, line_occur); + { + an_object = _get.this_object; + an_object_key = _get.this_object_key; + pith = _get.pith; + indent = _get.indent; + bullet = _get.bullet; + line_occur = _get.line_occur; + } + } + comp_obj_ = set_object_generic("backmatter", "glossary", "para", "glossary", links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""), 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.attrib.indent_hang = indent["hang_position"]; + comp_obj_.attrib.indent_base = indent["base_position"]; + comp_obj_.attrib.bullet = bullet; + add_to_current_document_section ~= comp_obj_; // + pith["ocn"] = eN.ocn.on; + { + ret.comp_section_obj = add_to_current_document_section; + ret.pith = pith; + ret.tag_assoc = tag_assoc; // NO CHANGE here, only for headings: html & epub + } + } + return ret; +} +ST_the_section build_the_blurb_section(Opt) ( + char[] line, // line is immutable, not necessary to return unchanged + uint[string] pith, + string[string][string] tag_assoc, // only for headings: html & epub + Opt opt_action, +) { + static auto rgx = RgxI(); + ObjGenericComposite comp_obj_; + ObjGenericComposite[] add_to_current_document_section; + // assert (opt_action.backmatter && opt_action.section_blurb); + indent = [ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + if (auto m = line.matchFirst(rgx.para_indent)) { + debug(paraindent) { writeln(line); } + indent["hang_position"] = (m["indent"]).to!int; + indent["base_position"] = (m["indent"]).to!int; + } else if (line.matchFirst(rgx.para_bullet)) { + debug(parabullet) { writeln(line); } + bullet = true; + } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { + debug(paraindenthang) { writeln(line); } + indent = [ + "hang_position" : (m["hang"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { + debug(parabulletindent) { writeln(line); } + indent = [ + "hang_position" : (m["indent"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + bullet = true; + } + pith["txt_is"] = eN.txt_is.para; + line_occur["para"] = eN.bi.off; + an_object_key = "blurb_nugget"; + ST_the_section ret; + if (line.matchFirst(rgx.heading_blurb) + && (opt_action.backmatter && opt_action.section_blurb)) { + { + comp_obj_ = set_object_heading("lev1", "backmatter", "blurb", "Blurb"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_blurb"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "blurb"; + comp_obj_.tags.anchor_tags = ["section_blurb"]; + comp_obj_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + comp_obj_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + add_to_current_document_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } + { + comp_obj_ = set_object_heading("lev4", "backmatter", "blurb", "Blurb"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "blurb"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.metainfo.heading_lev_collapsed = 2; + comp_obj_.tags.anchor_tags = ["blurb"]; + add_to_current_document_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } + } else if (line.matchFirst(rgx.headings) + && (opt_action.backmatter && opt_action.section_blurb)) { + comp_obj_ = comp_obj_.init; + comp_obj_.metainfo.is_of_part = "backmatter"; + comp_obj_.metainfo.is_of_section = "blurb"; + comp_obj_.metainfo.is_of_type = "para"; + comp_obj_.metainfo.is_a = "heading"; + comp_obj_.text = line.to!string; + comp_obj_.metainfo.ocn = 0; + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "blurb"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.metainfo.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv + comp_obj_.metainfo.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv + comp_obj_.metainfo.parent_ocn = 1; + comp_obj_.metainfo.parent_lev_markup = 0; + add_to_current_document_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } else if (!(line.empty)) { + { + auto _get = line.flow_para_match_(an_object, an_object_key, indent, bullet, pith, line_occur); + { + an_object = _get.this_object; + an_object_key = _get.this_object_key; + pith = _get.pith; + indent = _get.indent; + bullet = _get.bullet; + line_occur = _get.line_occur; + } + } + comp_obj_ = set_object_generic("backmatter", "blurb", "para", "blurb", links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""), 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.attrib.indent_hang = indent["hang_position"]; + comp_obj_.attrib.indent_base = indent["base_position"]; + comp_obj_.has.inline_links = true; + comp_obj_.attrib.bullet = bullet; + add_to_current_document_section ~= comp_obj_; + } + pith["ocn"] = eN.ocn.on; + { + ret.comp_section_obj = add_to_current_document_section; + ret.pith = pith; + ret.tag_assoc = tag_assoc; // NO CHANGE here, only for headings: html & epub + } + return ret; +} +@safe ST_txt_by_line_block_start txt_by_line_block_start()( + char[] line, + uint[string] pith, + uint[string] dochas, + string[string] object_number_poem +) { + static auto rgx = RgxI(); + if (auto m = line.matchFirst(rgx.block_curly_code_open)) { + dochas["codeblock"]++; + an_object["lang"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; + debug(codecurly) { writefln( "* [code curly] %s", line); } // code (curly) open + pith["block_is"] = eN.blk_is.code; + pith["block_state"] = eN.blk_state.on; + pith["block_delim"] = eN.blk_delim.curly; + } else if (auto m = line.matchFirst(rgx.block_curly_poem_open)) { + dochas["poem"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(poem) { writefln( "* [poem curly] %s", line); } // poem (curly) open + object_number_poem["start"] = obj_cite_digits.object_number.to!string; + pith["block_is"] = eN.blk_is.poem; + pith["block_state"] = eN.blk_state.on; + pith["block_delim"] = eN.blk_delim.curly; + pith["verse_new"] = eN.bi.on; + } else if (auto m = line.matchFirst(rgx.block_curly_group_open)) { + dochas["group"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(group) { writefln( "* [group curly] %s", line); } // group (curly) open + pith["block_is"] = eN.blk_is.group; + pith["block_state"] = eN.blk_state.on; pith["block_delim"] = eN.blk_delim.curly; } else if (auto m = line.matchFirst(rgx.block_curly_block_open)) { dochas["block"]++; @@ -3324,23 +2703,17 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "verse", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); } object_reset(an_object); @@ -3386,23 +2759,17 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "verse", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); object_reset(an_object); processing.remove("verse"); @@ -3424,23 +2791,17 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "verse", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); object_number_poem["end"] = obj_cite_digits.object_number.to!string; object_reset(an_object); @@ -3486,23 +2847,17 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "verse", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); object_reset(an_object); processing.remove("verse"); @@ -3589,7 +2944,7 @@ struct DocHas_ { an_object, the_document_body_section, obj_cite_digits, - comp_obj_heading, + comp_obj_, cntr, pith, conf_make_meta, @@ -3598,7 +2953,7 @@ struct DocHas_ { an_object = _get.this_object; the_document_body_section = _get.the_document_body_section; obj_cite_digits = _get.obj_cite_digits; - comp_obj_heading = _get._comp_obj_heading; + comp_obj_ = _get.comp_obj_; cntr = _get.cntr; pith = _get.pith; } @@ -3869,12 +3224,12 @@ struct DocHas_ { string[string] an_object, ObjGenericComposite[] the_document_body_section, OCNset obj_cite_digits, - ObjGenericComposite _comp_obj_heading, + ObjGenericComposite comp_obj_, int cntr, uint[string] pith, CMM conf_make_meta ) { - comp_obj_block = comp_obj_block.init; + comp_obj_ = comp_obj_.init; obj_cite_digits = ocn_emit(pith["ocn"]); auto comp_obj_location = node_construct.node_location_emitter( content_non_header, @@ -3890,22 +3245,22 @@ struct DocHas_ { ST_txtAndAnchorTagPlusHasFootnotesUrlsImages substantive_obj_misc_struct = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, "body_nugget", conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); + comp_obj_.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_ = comp_obj_.flow_table_instructions(an_object["table_head"]); { - auto _get = comp_obj_block.flow_table_substantive_munge_special(an_object["substantive"]); + auto _get = comp_obj_.flow_table_substantive_munge_special(an_object["substantive"]); { - comp_obj_block = _get.table_object; + comp_obj_ = _get.table_object; an_object["substantive"] = _get.table_substantive; } } - the_document_body_section ~= comp_obj_block; + the_document_body_section ~= comp_obj_; object_reset(an_object); processing.remove("verse"); ++cntr; @@ -3914,7 +3269,7 @@ struct DocHas_ { ret.this_object = an_object; ret.the_document_body_section = the_document_body_section; ret.obj_cite_digits = obj_cite_digits; - ret._comp_obj_heading = _comp_obj_heading; + ret.comp_obj_ = comp_obj_; ret.cntr = cntr; ret.pith = pith; } @@ -3927,7 +3282,7 @@ struct DocHas_ { ObjGenericComposite[] the_document_body_section, string[][string][string] bookindex_unordered_hashes, OCNset obj_cite_digits, - ObjGenericComposite _comp_obj_heading, + ObjGenericComposite comp_obj_, int cntr, uint[string] pith, string[string] object_number_poem, @@ -3971,25 +3326,19 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "quote"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "quote", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digit_type; + comp_obj_.metainfo.lang = an_object["lang"]; + comp_obj_.metainfo.attrib = an_object["attrib"]; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); pith["block_is"] = eN.blk_is.quote; pith["block_state"] = eN.blk_state.off; @@ -4023,25 +3372,19 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "group"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "group", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.metainfo.lang = an_object["lang"]; + comp_obj_.metainfo.attrib = an_object["attrib"]; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); pith["block_is"] = eN.blk_is.poem; pith["block_state"] = eN.blk_state.off; @@ -4075,25 +3418,19 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; // anchor_tag = substantive_obj_misc_struct.anchor_tag; // check - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "block"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_block.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_block; + comp_obj_ = set_object_generic("body", "body", "block", "block", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digit_type; + comp_obj_.metainfo.lang = an_object["lang"]; + comp_obj_.metainfo.attrib = an_object["attrib"]; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; pith["block_is"] = eN.blk_is.block; pith["block_state"] = eN.blk_state.off; pith["block_delim"] = eN.blk_delim.off; @@ -4121,17 +3458,11 @@ struct DocHas_ { heading_ptr-1, an_object["is"] ); - comp_obj_poem_ocn = comp_obj_poem_ocn.init; - comp_obj_poem_ocn.metainfo.is_of_part = "body"; - comp_obj_poem_ocn.metainfo.is_of_section = "body"; - comp_obj_poem_ocn.metainfo.is_of_type = "block"; - comp_obj_poem_ocn.metainfo.is_a = "poem"; - comp_obj_poem_ocn.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_poem_ocn = set_object_generic("body", "body", "block", "poem", "", obj_cite_digits.object_number); comp_obj_poem_ocn.metainfo.identifier = obj_cite_digits.identifier; comp_obj_poem_ocn.metainfo.object_number_off = obj_cite_digits.off; comp_obj_poem_ocn.metainfo.o_n_book_index = obj_cite_digits.bkidx; comp_obj_poem_ocn.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_poem_ocn.text = ""; the_document_body_section ~= comp_obj_poem_ocn; pith["block_is"] = eN.blk_is.poem; pith["block_state"] = eN.blk_state.off; @@ -4164,26 +3495,20 @@ struct DocHas_ { = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; anchor_tag = substantive_obj_misc_struct.anchor_tag; - comp_obj_code = comp_obj_code.init; - comp_obj_code.metainfo.is_of_part = "body"; - comp_obj_code.metainfo.is_of_section = "body"; - comp_obj_code.metainfo.is_of_type = "block"; - comp_obj_code.metainfo.is_a = "code"; - comp_obj_code.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_code.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_code.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_code.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_code.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_code.metainfo.syntax = an_object["syntax"]; - comp_obj_code.metainfo.attrib = an_object["attrib"]; - comp_obj_code.code_block.linenumbers = (an_object["attrib"].match(rgx.code_numbering)) ? true : false; - comp_obj_code.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_code.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_code.text = an_object["substantive"]; - comp_obj_code.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; - comp_obj_code.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; - comp_obj_code.has.inline_links = substantive_obj_misc_struct.has_links; - the_document_body_section ~= comp_obj_code; + comp_obj_ = set_object_generic("body", "body", "block", "code", an_object["substantive"], obj_cite_digits.object_number); + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.metainfo.syntax = an_object["syntax"]; + comp_obj_.metainfo.attrib = an_object["attrib"]; + comp_obj_.code_block.linenumbers = (an_object["attrib"].match(rgx.code_numbering)) ? true : false; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.has.inline_notes_reg = substantive_obj_misc_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_obj_misc_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_obj_misc_struct.has_links; + the_document_body_section ~= comp_obj_; pith["block_is"] = eN.blk_is.code; pith["block_state"] = eN.blk_state.off; pith["block_delim"] = eN.blk_delim.off; @@ -4191,7 +3516,7 @@ struct DocHas_ { processing.remove("verse"); ++cntr; } else if (pith["block_is"] == eN.blk_is.table) { - comp_obj_block = comp_obj_block.init; + comp_obj_ = comp_obj_.init; obj_cite_digits = ocn_emit(pith["ocn"]); an_object["bookindex_nugget"] = ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; @@ -4216,23 +3541,23 @@ struct DocHas_ { ST_txtAndAnchorTagPlusHasFootnotesUrlsImages substantive_obj_misc_struct = obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, conf_make_meta, No._new_doc); an_object["substantive"] = substantive_obj_misc_struct.obj_txt; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); + comp_obj_ = comp_obj_.init; + comp_obj_.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_ = comp_obj_.flow_table_instructions(an_object["table_head"]); { - auto _get = comp_obj_block.flow_table_substantive_munge(an_object["substantive"]); + auto _get = comp_obj_.flow_table_substantive_munge(an_object["substantive"]); { - comp_obj_block = _get.table_object; + comp_obj_ = _get.table_object; an_object["substantive"] = _get.table_substantive; } } - the_document_body_section ~= comp_obj_block; + the_document_body_section ~= comp_obj_; pith["block_is"] = eN.blk_is.table; pith["block_state"] = eN.blk_state.off; pith["block_delim"] = eN.blk_delim.off; @@ -4247,7 +3572,7 @@ struct DocHas_ { ret.the_document_body_section = the_document_body_section; ret.bookindex_unordered_hashes = bookindex_unordered_hashes; ret.obj_cite_digits = obj_cite_digits; - ret.comp_obj_heading = _comp_obj_heading; // + ret.comp_obj_ = comp_obj_; // ret.cntr = cntr; ret.pith = pith; } @@ -4938,6 +4263,53 @@ struct DocHas_ { invariant() { } } +@safe ObjGenericComposite set_object_heading()( + string level, + string part, + string section, + string text, +) { + ObjGenericComposite comp_obj; + comp_obj = comp_obj.init; + comp_obj.metainfo.is_of_part = part; + comp_obj.metainfo.is_of_section = section; + comp_obj.metainfo.is_of_type = "para"; + comp_obj.metainfo.is_a = "heading"; + comp_obj.text = text; + comp_obj.metainfo.ocn = 0; + if (level == "lev1") { + comp_obj.metainfo.heading_lev_markup = 1; + comp_obj.metainfo.heading_lev_collapsed = 1; + comp_obj.metainfo.parent_ocn = 1; + comp_obj.metainfo.parent_lev_markup = 0; + } else if (level == "lev4") { + comp_obj.metainfo.heading_lev_markup = 4; + comp_obj.metainfo.heading_lev_collapsed = 1; + comp_obj.metainfo.parent_ocn = 1; + comp_obj.metainfo.parent_lev_markup = 0; + comp_obj.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; // KEEP + comp_obj.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; // KEEP + } + return comp_obj; +} +@safe ObjGenericComposite set_object_generic()( + string part, + string section, + string type, + string is_a, + string text, + int ocn, +) { + ObjGenericComposite comp_obj; + comp_obj = comp_obj.init; + comp_obj.metainfo.is_of_part = part; + comp_obj.metainfo.is_of_section = section; + comp_obj.metainfo.is_of_type = type; + comp_obj.metainfo.is_a = is_a; + comp_obj.text = text; + comp_obj.metainfo.ocn = ocn; + return comp_obj; +} @safe static struct ObjInlineMarkupMunge { string[string] obj_txt; int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; @@ -5304,7 +4676,7 @@ static struct ObjInlineMarkup { string[][string] lev4_subtoc, ObjGenericComposite[] the_document_toc_section, ) { - ObjGenericComposite comp_obj_toc; + ObjGenericComposite comp_obj_; mixin InternalMarkup; static auto mkup = InlineMarkup(); char[] heading_toc_ = (obj_["substantive"].dup.strip.to!(char[])) @@ -5327,35 +4699,29 @@ static struct ObjInlineMarkup { mkup.url_c, ); toc_txt_= toc_txt_.links_and_images; - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.metainfo.is_of_part = "frontmatter"; - comp_obj_toc.metainfo.is_of_section = "toc"; - comp_obj_toc.metainfo.is_of_type = "para"; - comp_obj_toc.metainfo.is_a = "toc"; - comp_obj_toc.metainfo.ocn = 0; - comp_obj_toc.metainfo.identifier = ""; - comp_obj_toc.metainfo.object_number_off = true; - comp_obj_toc.metainfo.object_number_type = 0; - comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; - comp_obj_toc.attrib.indent_hang = indent["hang_position"]; - comp_obj_toc.attrib.indent_base = indent["base_position"]; - comp_obj_toc.attrib.bullet = false; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_document_toc_section ~= comp_obj_toc; - } - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.metainfo.is_of_part = "frontmatter"; - comp_obj_toc.metainfo.is_of_section = "toc"; - comp_obj_toc.metainfo.is_of_type = "para"; - comp_obj_toc.metainfo.is_a = "toc"; - comp_obj_toc.metainfo.ocn = 0; - comp_obj_toc.metainfo.identifier = ""; - comp_obj_toc.metainfo.object_number_off = true; - comp_obj_toc.metainfo.object_number_type = 0; - comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; - comp_obj_toc.attrib.bullet = false; - comp_obj_toc.has.inline_links = true; + comp_obj_ = set_object_generic("frontmatter", "toc", "para", "toc", toc_txt_.to!string.strip, 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; + comp_obj_.attrib.indent_hang = indent["hang_position"]; + comp_obj_.attrib.indent_base = indent["base_position"]; + comp_obj_.attrib.bullet = false; + comp_obj_.has.inline_links = true; + the_document_toc_section ~= comp_obj_; + } + comp_obj_ = comp_obj_.init; + comp_obj_.metainfo.is_of_part = "frontmatter"; + comp_obj_.metainfo.is_of_section = "toc"; + comp_obj_.metainfo.is_of_type = "para"; + comp_obj_.metainfo.is_a = "toc"; + comp_obj_.metainfo.ocn = 0; + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; + comp_obj_.attrib.bullet = false; + comp_obj_.has.inline_links = true; switch (obj_["lev_markup_number"].to!int) { case 0: .. case 3: break; @@ -5574,12 +4940,12 @@ struct ObjAttributes { @safe string obj_attributes()( string obj_is_, string obj_raw, - ObjGenericComposite _comp_obj_heading, + ObjGenericComposite comp_obj_, ) { scope(exit) { destroy(obj_is_); destroy(obj_raw); - destroy(_comp_obj_heading); + destroy(comp_obj_); } _obj_attrib["json"] ="{"; switch (obj_is_) { @@ -5618,7 +4984,7 @@ struct ObjAttributes { break; } _obj_attrib["json"] ~= " }"; - _obj_attrib["json"] = _set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, _comp_obj_heading); + _obj_attrib["json"] = _set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, comp_obj_); debug(structattrib) { if (oa_j["is"].str() == "heading") { writeln(_obj_attrib["json"]); @@ -5733,21 +5099,21 @@ struct ObjAttributes { @safe string _set_additional_values_parse_as_json()( string _obj_attrib, string obj_is_, - ObjGenericComposite _comp_obj_heading, + ObjGenericComposite comp_obj_, ) { JSONValue oa_j = parseJSON(_obj_attrib); assert( (oa_j.type == JSON_TYPE.OBJECT) ); if (obj_is_ == "heading") { - oa_j.object["object_number"] = _comp_obj_heading.metainfo.ocn; - oa_j.object["lev_markup_number"] = _comp_obj_heading.metainfo.heading_lev_markup; - oa_j.object["lev_collapsed_number"] = _comp_obj_heading.metainfo.heading_lev_collapsed; - oa_j.object["heading_ptr"] = _comp_obj_heading.ptr.heading; - oa_j.object["doc_object_ptr"] = _comp_obj_heading.ptr.doc_object; - } - oa_j.object["parent_object_number"] = _comp_obj_heading.metainfo.parent_ocn; - oa_j.object["parent_lev_markup_number"] = _comp_obj_heading.metainfo.parent_lev_markup; + oa_j.object["object_number"] = comp_obj_.metainfo.ocn; + oa_j.object["lev_markup_number"] = comp_obj_.metainfo.heading_lev_markup; + oa_j.object["lev_collapsed_number"] = comp_obj_.metainfo.heading_lev_collapsed; + oa_j.object["heading_ptr"] = comp_obj_.ptr.heading; + oa_j.object["doc_object_ptr"] = comp_obj_.ptr.doc_object; + } + oa_j.object["parent_object_number"] = comp_obj_.metainfo.parent_ocn; + oa_j.object["parent_lev_markup_number"] = comp_obj_.metainfo.parent_lev_markup; _obj_attrib = oa_j.toString(); return _obj_attrib; } @@ -5899,7 +5265,7 @@ struct BookIndexReportSection { bookindex_unordered_hashes.byKey.array .sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable).release; ObjGenericComposite[] bookindex_section; - ObjGenericComposite comp_obj_heading_, comp_obj_para; + ObjGenericComposite comp_obj_; auto node_para_int_ = node_metadata_para_int; auto node_para_str_ = node_metadata_para_str; if ((mainkeys.length > 0) @@ -5908,55 +5274,36 @@ struct BookIndexReportSection { string bi_tmp; string[] bi_tmp_tags; { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bookindex"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Book Index"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_book_index"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "bookindex"; - comp_obj_heading_.tags.anchor_tags = ["section_bookindex"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading.has.inline_links = true; - bookindex_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_ = set_object_heading("lev1", "backmatter", "bookindex", "Book Index"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_book_index"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "bookindex"; + comp_obj_.tags.anchor_tags = ["section_bookindex"]; + comp_obj_.has.inline_links = true; + bookindex_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; ++mkn; } { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bookindex"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Index"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "bookindex"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading.has.inline_links = false; - comp_obj_heading_.tags.anchor_tags = ["bookindex"]; - bookindex_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_ = set_object_heading("lev4", "backmatter", "bookindex", "Index"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "bookindex"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.metainfo.heading_lev_collapsed = 2; + comp_obj_.has.inline_links = false; + comp_obj_.tags.anchor_tags = ["bookindex"]; + bookindex_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; ++mkn; } import std.array : appender; @@ -5996,39 +5343,26 @@ struct BookIndexReportSection { bi_tmp ~= " \\\\\n "; ++skn; } - bi_tmp = bi_tmp.replaceFirst(rgx.trailing_linebreak, ""); - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "bookindex"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "bookindex"; - comp_obj_para.text = bi_tmp.to!string.strip; - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.tags.anchor_tags = bi_tmp_tags; - comp_obj_para.attrib.indent_hang = 0; - comp_obj_para.attrib.indent_base = 1; - comp_obj_para.attrib.bullet = false; - comp_obj_para.has.inline_links = true; - comp_obj_para.text = bi_tmp.to!string.strip; - bookindex_section ~= comp_obj_para; + bi_tmp = bi_tmp.replaceFirst(rgx.trailing_linebreak, ""); + comp_obj_ = set_object_generic("backmatter", "bookindex", "para", "bookindex", bi_tmp.to!string.strip, 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.anchor_tags = bi_tmp_tags; + comp_obj_.attrib.indent_hang = 0; + comp_obj_.attrib.indent_base = 1; + comp_obj_.attrib.bullet = false; + comp_obj_.has.inline_links = true; + comp_obj_.text = bi_tmp.to!string.strip; + bookindex_section ~= comp_obj_; ++mkn; } } else { // no book index, (figure out what to do here) - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.text = "(skip) there is no Book Index"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - bookindex_section ~= comp_obj_heading_; + comp_obj_ = set_object_heading("lev1", "backmatter", "bookindex", "(skip) there is no Book Index"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + bookindex_section ~= comp_obj_; } ST_bookindex ret; { @@ -6119,213 +5453,773 @@ struct NotesSection { ~ m["note"] ~ "』" ); } - return object_notes; + return object_notes; + } + @safe private auto gathered_notes() { + string[][string] endnotes_; + if (object_notes.length > 1) { + endnotes_["notes"] = (object_notes["notes"].split(rgx.break_string))[0..$-1]; + endnotes_["anchor"] = (object_notes["anchor"].split(rgx.break_string))[0..$-1]; + } else { + endnotes_["notes"] = []; + endnotes_["anchor"] = []; + } + return endnotes_; + } + @safe private ST_endnotes backmatter_endnote_objects(O)( + OCNset obj_cite_digits, + O opt_action, + ) { + mixin spineNode; + ObjGenericComposite[] the_document_endnotes_section; + auto endnotes_ = gathered_notes(); + string type_is; + string lev, lev_markup_number, lev_collapsed_number; + string attrib; + int[string] indent; + ObjGenericComposite comp_obj_; + if ((endnotes_["notes"].length > 0) + && (opt_action.backmatter && opt_action.section_endnotes)) { + { + comp_obj_ = set_object_heading("lev1", "backmatter", "endnotes", "Endnotes"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_endnotes"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "endnotes"; + comp_obj_.tags.anchor_tags = ["section_endnotes"]; + the_document_endnotes_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + ++mkn; + } + { + comp_obj_ = set_object_heading("lev4", "backmatter", "endnotes", "Endnotes"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "endnotes"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.tags.anchor_tags = ["endnotes"]; + the_document_endnotes_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + ++mkn; + } + } else { + comp_obj_ = set_object_heading("lev1", "empty", "empty", "(skip) there are no Endnotes"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + the_document_endnotes_section ~= comp_obj_; + } + if (opt_action.backmatter && opt_action.section_endnotes) { + ObjGenericComposite comp_obj_endnote_; + comp_obj_endnote_ = set_object_generic("backmatter", "endnotes", "para", "endnote", "", 0); + comp_obj_endnote_.metainfo.identifier = ""; + // comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_endnote_.attrib.indent_hang = 0; + comp_obj_endnote_.attrib.indent_base = 0; + comp_obj_endnote_.attrib.bullet = false; + foreach (i, endnote; endnotes_["notes"]) { + auto m = endnote.matchFirst(rgx.note_ref); + string notenumber = m["ref"].to!string; + string anchor_tag = "note_" ~ notenumber; + comp_obj_endnote_.tags.anchor_tags = [ endnotes_["anchor"][i] ]; + comp_obj_endnote_.has.inline_links = true; + comp_obj_endnote_.text = endnote.inline_markup_faces.strip; + the_document_endnotes_section ~= comp_obj_endnote_; + } + } + ST_endnotes ret; + { + ret.endnotes = the_document_endnotes_section; + ret.ocn = obj_cite_digits; + } + return ret; + } +} +@system public ST_biblio_section backmatter_make_the_bibliography_section()( + string[] biblio_unsorted_incomplete, + JSONValue[] bib_arr_json, +) { + Bibliography biblio = Bibliography(); + ObjGenericComposite comp_obj_; + static auto mkup = InlineMarkup(); + ST_flow_bibliography _get = biblio.flow_bibliography_(biblio_unsorted_incomplete, bib_arr_json); + JSONValue[] biblio_ordered; + biblio_ordered = _get.biblio_sorted; + if (biblio_ordered.length > 0) { + { + comp_obj_ = set_object_heading("lev1", "backmatter", "bibliography", "Bibliography"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = false; + comp_obj_.metainfo.object_number_off = false; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "_part_bibliography"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = "bibliography"; + comp_obj_.tags.anchor_tags = ["section_bibliography"]; + comp_obj_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + comp_obj_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + the_document_bibliography_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } + { + comp_obj_ = set_object_heading("lev4", "backmatter", "bibliography", "Bibliography"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.tags.segment_anchor_tag_epub = "bibliography"; + comp_obj_.tags.anchor_tag_html = comp_obj_.tags.segment_anchor_tag_epub; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.tags.anchor_tags = ["bibliography"]; + the_document_bibliography_section ~= comp_obj_; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; + } + { + string out_; + foreach (entry; biblio_ordered) { + out_ = format("%s \"%s\"%s%s%s%s%s%s%s%s%s.", + ((entry["author"].str.empty) ? entry["editor"].str : entry["author"].str), + entry["fulltitle"].str, + ((entry["journal"].str.empty) ? "" : ", " ~ mkup.ff_i ~ mkup.italic ~ mkup.ff_o ~ entry["journal"].str ~ mkup.ff_c ~ mkup.italic), + ((entry["volume"].str.empty) ? "" : ", " ~ entry["volume"].str), + ((entry["in"].str.empty) ? "" : ", " ~ entry["in"].str), + ((!(entry["author"].str.empty) && (!(entry["editor"].str.empty))) ? entry["editor"].str : ""), + ", " ~ entry["year"].str, + ((entry["pages"].str.empty) ? "" : ", " ~ entry["pages"].str), + ((entry["publisher"].str.empty) ? "" : ", " ~ entry["publisher"].str), + ((entry["place"].str.empty) ? "" : ", " ~ entry["place"].str), + ((entry["url"].str.empty) ? "" : ", [" ~ entry["url"].str ~ "]"), + ); + comp_obj_ = set_object_generic("backmatter", "bibliography", "para", "bibliography", out_.to!string.strip, 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.attrib.indent_hang = 0; + comp_obj_.attrib.indent_base = 1; + comp_obj_.attrib.bullet = bullet; + comp_obj_.tags.anchor_tags = [anchor_tag]; + the_document_bibliography_section ~= comp_obj_; + } + } + } else { + comp_obj_ = set_object_heading("lev1", "empty", "empty", "(skip) there is no Bibliography"); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.dummy_heading = true; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + the_document_bibliography_section ~= comp_obj_; + } + debug(bibliosection) { foreach (o; the_document_bibliography_section) { writeln(o.text); } } + ST_biblio_section ret; + { + ret.bibliography_section = the_document_bibliography_section; + ret.tag_assoc = tag_assoc; // + } + return ret; +} +struct Bibliography { + @system public ST_flow_bibliography flow_bibliography_()( + string[] biblio_unsorted_incomplete, + JSONValue[] bib_arr_json + ) { + JSONValue[] biblio_unsorted + = biblio_make_unsorted_array_of_json_objects(biblio_unsorted_incomplete, bib_arr_json); // TODO lookat returns + biblio_arr_json = []; + biblio_unsorted_incomplete = []; + JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); + debug(biblio0) { + biblio_debug(biblio_sorted__); + writeln("---"); + writeln("unsorted incomplete: ", biblio_unsorted_incomplete.length); + writeln("json: ", bib_arr_json.length); + writeln("unsorted: ", biblio_unsorted.length); + writeln("sorted: ", biblio_sorted__.length); + int cntr; + int[7] x; + while (cntr < x.length) { + writeln(cntr, ": ", biblio_sorted__[cntr]["fulltitle"]); + cntr++; + } + } + ST_flow_bibliography ret; + { + ret.biblio_sorted = biblio_sorted__; + ret.bib_arr_json = bib_arr_json; + ret.biblio_unsorted_incomplete = biblio_unsorted_incomplete; + } + return ret; + } + @system final private JSONValue[] biblio_make_unsorted_array_of_json_objects()( + string[] biblio_unordered, + JSONValue[] bib_arr_json + ) { + foreach (bibent; biblio_unordered) { + // update bib to include deemed_author, needed for: + // sort_bibliography_array_by_deemed_author_year_title + // either: sort on multiple fields, or; create such sort field + JSONValue j = parseJSON(bibent); + if (!empty(j["fulltitle"].str)) { + if (!empty(j["author_raw"].str)) { + j["deemed_author"] = j["author_arr"][0]; + } else if (!empty(j["editor_raw"].str)) { + j["deemed_author"] = j["editor_arr"][0]; + } + j["sortby_deemed_author_year_title"] = ( + j["deemed_author"].str ~ + "; " ~ + j["year"].str ~ + "; " ~ + j["fulltitle"].str + ); + } + bib_arr_json ~= j; + } + return bib_arr_json.dup; + } + @system final private JSONValue[] biblio_sort()(JSONValue[] biblio_unordered) { + JSONValue[] biblio_sorted_; + biblio_sorted_ + = sort!((a, b){ + return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); + })(biblio_unordered).array; + debug(bibliosorted) { + foreach (j; biblio_sorted_) { + if (!empty(j["fulltitle"].str)) { writeln(j["sortby_deemed_author_year_title"]); } + } + } + return biblio_sorted_; + } + @system void biblio_debug()(JSONValue[] biblio_sorted) { + debug(biblio0) { + foreach (j; biblio_sorted) { + if (!empty(j["fulltitle"].str)) { writeln(j["sortby_deemed_author_year_title"]); } + } + } + } +} +@system public ObjGenericComposite[] backmatter_gather_table_of_contents( + ObjGenericComposite[] the_document_endnotes_section, + ObjGenericComposite[] the_document_glossary_section, + ObjGenericComposite[] the_document_bibliography_section, + ObjGenericComposite[] the_document_bookindex_section, + ObjGenericComposite[] the_document_blurb_section, +) { + ObjGenericComposite[] toc_section_backmatter; + string toc_txt_; + static auto mkup = InlineMarkup(); + ObjGenericComposite comp_obj_; + int[string] indent = [ + "hang_position" : 1, + "base_position" : 1, + ]; + comp_obj_ = set_object_generic("frontmatter", "toc", "para", "toc", "", 0); + comp_obj_.metainfo.identifier = ""; + comp_obj_.metainfo.object_number_off = true; + comp_obj_.metainfo.object_number_type = 0; + comp_obj_.attrib.indent_hang = indent["hang_position"]; + comp_obj_.attrib.indent_base = indent["base_position"]; + comp_obj_.attrib.bullet = false; + if (the_document_endnotes_section.length > 1) { + toc_txt_ = format("%s%s%s%s#%s%s", + mkup.lnk_o, + "Endnotes", + mkup.lnk_c, + mkup.url_o, + "endnotes", + mkup.url_c, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_.text = toc_txt_.to!string.strip; + comp_obj_.has.inline_links = true; + toc_section_backmatter ~= comp_obj_; + } + if (the_document_glossary_section.length > 1) { + toc_txt_ = format("%s%s%s%s#%s%s", + mkup.lnk_o, + "Glossary", + mkup.lnk_c, + mkup.url_o, + "glossary", + mkup.url_c, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_.text = toc_txt_.to!string.strip; + comp_obj_.has.inline_links = true; + toc_section_backmatter ~= comp_obj_; + } + if (the_document_bibliography_section.length > 1){ + toc_txt_ = format("%s%s%s%s#%s%s", + mkup.lnk_o, + "Bibliography", + mkup.lnk_c, + mkup.url_o, + "bibliography", + mkup.url_c, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_.text = toc_txt_.to!string.strip; + comp_obj_.has.inline_links = true; + toc_section_backmatter ~= comp_obj_; + } + if (the_document_bookindex_section.length > 1) { + toc_txt_ = format("%s%s%s%s#%s%s", + mkup.lnk_o, + "Book Index", + mkup.lnk_c, + mkup.url_o, + "bookindex", + mkup.url_c, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_.text = toc_txt_.to!string.strip; + comp_obj_.has.inline_links = true; + toc_section_backmatter ~= comp_obj_; + } + if (the_document_blurb_section.length > 1) { + toc_txt_ = format("%s%s%s%s#%s%s", + mkup.lnk_o, + "Blurb", + mkup.lnk_c, + mkup.url_o, + "blurb", + mkup.url_c, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_.has.inline_links = true; + comp_obj_.text = toc_txt_.to!string.strip; + toc_section_backmatter ~= comp_obj_; + } + debug(toc) { + writefln( "%s %s", __LINE__,); + foreach (toc_linked_heading; toc_section_backmatter) { + writeln(mkup.indent_by_spaces_provided(toc_linked_heading.attrib.indent_hang), toc_linked_heading.text); + } + } + return toc_section_backmatter; +} +@system public ST_ancestors after_doc_determine_ancestors( + ObjGenericComposite[] the_document_body_section, + ObjGenericComposite[] the_document_endnotes_section, + ObjGenericComposite[] the_document_glossary_section, + ObjGenericComposite[] the_document_bibliography_section, + ObjGenericComposite[] the_document_bookindex_section, + ObjGenericComposite[] the_document_blurb_section, +) { + @safe int[] _get_ancestors_markup(ObjGenericComposite obj, int[] _ancestors_markup) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { writeln(obj.text); } + if (obj.metainfo.heading_lev_markup == 1) { + _ancestors_markup = [ + _ancestors_markup[0], + 0,0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 2) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + 0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 3) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + 0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 4) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + 0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 5) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + 0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 6) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + 0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 7) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + _ancestors_markup[6], + 0 + ]; + } + if (obj.metainfo.heading_lev_markup == 8) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + _ancestors_markup[6], + _ancestors_markup[7] + ]; + } + _ancestors_markup[obj.metainfo.heading_lev_markup] = obj.metainfo.ocn; + } + debug(ancestor_markup) { writeln("marked up: ", _ancestors_markup); } + return _ancestors_markup; + } + @safe int[] _get_ancestors_collapsed(ObjGenericComposite obj, int[] _ancestors_collapsed) { + if (obj.metainfo.is_a == "heading") { + if (obj.metainfo.heading_lev_collapsed == 1) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + 0,0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 2) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + 0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 3) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + 0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 4) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + 0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 5) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + 0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 6) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + 0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 7) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + _ancestors_collapsed[6], + 0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 8) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + _ancestors_collapsed[6], + _ancestors_collapsed[7] + ]; + } + _ancestors_collapsed[obj.metainfo.heading_lev_collapsed] = obj.metainfo.ocn; + } + debug(ancestor_collapsed) { writeln("collapsed: ", _ancestors_collapsed); } + return _ancestors_collapsed; } - @safe private auto gathered_notes() { - string[][string] endnotes_; - if (object_notes.length > 1) { - endnotes_["notes"] = (object_notes["notes"].split(rgx.break_string))[0..$-1]; - endnotes_["anchor"] = (object_notes["anchor"].split(rgx.break_string))[0..$-1]; - } else { - endnotes_["notes"] = []; - endnotes_["anchor"] = []; + // multiple 1~ levels, loop through document body + if (the_document_body_section.length > 1) { + int[] _ancestors_markup = [0,0,0,0,0,0,0,0]; + int[][] _ancestors_markup_; + _ancestors_markup = [1,0,0,0,0,0,0,0]; + _ancestors_markup_ ~= _ancestors_markup; + int[] _ancestors_collapsed = [0,0,0,0,0,0,0,0]; + int[][] _ancestors_collapsed_; + _ancestors_collapsed = [1,0,0,0,0,0,0,0]; + _ancestors_collapsed_ ~= _ancestors_collapsed; + foreach (ref obj; the_document_body_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.markedup_ancestors = _get_ancestors_markup(obj, _ancestors_markup); + obj.metainfo.collapsed_ancestors = _get_ancestors_collapsed(obj, _ancestors_collapsed); + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + } + debug(ancestors) { + writeln("ancestors markup o_n: ", obj.metainfo.markedup_ancestors); + writeln("ancestors collapsed o_n: ", obj.metainfo.markedup_ancestors); } - return endnotes_; } - @safe private ST_endnotes backmatter_endnote_objects(O)( - OCNset obj_cite_digits, - O opt_action, - ) { - mixin spineNode; - ObjGenericComposite[] the_document_endnotes_section; - auto endnotes_ = gathered_notes(); - string type_is; - string lev, lev_markup_number, lev_collapsed_number; - string attrib; - int[string] indent; - ObjGenericComposite comp_obj_heading_; - if ((endnotes_["notes"].length > 0) - && (opt_action.backmatter && opt_action.section_endnotes)) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "endnotes"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = false; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_endnotes"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "endnotes"; - comp_obj_heading_.tags.anchor_tags = ["section_endnotes"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_endnotes_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; + ST_ancestors ret; + ret.the_document_body_section = the_document_body_section; + ret.the_document_endnotes_section = the_document_endnotes_section; + ret.the_document_glossary_section = the_document_glossary_section; + ret.the_document_bibliography_section = the_document_bibliography_section; + ret.the_document_bookindex_section = the_document_bookindex_section; + ret.the_document_blurb_section = the_document_blurb_section; + return ret; +} +@system public ST_segnames after_doc_determine_segnames( + ObjGenericComposite[] the_document_body_section, + ObjGenericComposite[] the_document_endnotes_section, + ObjGenericComposite[] the_document_glossary_section, + ObjGenericComposite[] the_document_bibliography_section, + ObjGenericComposite[] the_document_bookindex_section, + ObjGenericComposite[] the_document_blurb_section, + string[][string] segnames, + int html_segnames_ptr_cntr, + int html_segnames_ptr, +) { + if (the_document_endnotes_section.length > 1) { + segnames["html"] ~= "endnotes"; + segnames["epub"] ~= "endnotes"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_document_endnotes_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "endnotes"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "endnotes"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.tags.anchor_tags = ["endnotes"]; - the_document_endnotes_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; } - } else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there are no Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_document_endnotes_section ~= comp_obj_heading_; } - if (opt_action.backmatter && opt_action.section_endnotes) { - ObjGenericComposite comp_obj_endnote_; - comp_obj_endnote_ = comp_obj_endnote_.init; - comp_obj_endnote_.metainfo.is_of_part = "backmatter"; - comp_obj_endnote_.metainfo.is_of_section = "endnotes"; - comp_obj_endnote_.metainfo.is_of_type = "para"; - comp_obj_endnote_.metainfo.is_a = "endnote"; - comp_obj_endnote_.metainfo.ocn = 0; - comp_obj_endnote_.metainfo.identifier = ""; - // comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_endnote_.attrib.indent_hang = 0; - comp_obj_endnote_.attrib.indent_base = 0; - comp_obj_endnote_.attrib.bullet = false; - foreach (i, endnote; endnotes_["notes"]) { - auto m = endnote.matchFirst(rgx.note_ref); - string notenumber = m["ref"].to!string; - string anchor_tag = "note_" ~ notenumber; - comp_obj_endnote_.tags.anchor_tags = [ endnotes_["anchor"][i] ]; - comp_obj_endnote_.has.inline_links = true; - comp_obj_endnote_.text = endnote.inline_markup_faces.strip; - the_document_endnotes_section ~= comp_obj_endnote_; + html_segnames_ptr_cntr++; + } + if (the_document_glossary_section.length > 1) { + segnames["html"] ~= "glossary"; + segnames["epub"] ~= "glossary"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_document_glossary_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; } } - ST_endnotes ret; - { - ret.endnotes = the_document_endnotes_section; - ret.ocn = obj_cite_digits; + html_segnames_ptr_cntr++; + } + if (the_document_bibliography_section.length > 1) { + segnames["html"] ~= "bibliography"; + segnames["epub"] ~= "bibliography"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_document_bibliography_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } } - return ret; + html_segnames_ptr_cntr++; } -} -struct Bibliography { - @system public ST_flow_bibliography flow_bibliography_()( - string[] biblio_unsorted_incomplete, - JSONValue[] bib_arr_json - ) { - JSONValue[] biblio_unsorted - = biblio_make_unsorted_array_of_json_objects(biblio_unsorted_incomplete, bib_arr_json); // TODO lookat returns - biblio_arr_json = []; - biblio_unsorted_incomplete = []; - JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); - debug(biblio0) { - biblio_debug(biblio_sorted__); - writeln("---"); - writeln("unsorted incomplete: ", biblio_unsorted_incomplete.length); - writeln("json: ", bib_arr_json.length); - writeln("unsorted: ", biblio_unsorted.length); - writeln("sorted: ", biblio_sorted__.length); - int cntr; - int[7] x; - while (cntr < x.length) { - writeln(cntr, ": ", biblio_sorted__[cntr]["fulltitle"]); - cntr++; + if (the_document_bookindex_section.length > 1) { + segnames["html"] ~= "bookindex"; + segnames["epub"] ~= "bookindex"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_document_bookindex_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; } } - ST_flow_bibliography ret; - { - ret.biblio_sorted = biblio_sorted__; - ret.bib_arr_json = bib_arr_json; - ret.biblio_unsorted_incomplete = biblio_unsorted_incomplete; + html_segnames_ptr_cntr++; + } + if (the_document_blurb_section.length > 1) { + segnames["html"] ~= "blurb"; + segnames["epub"] ~= "blurb"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_document_blurb_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } } - return ret; + html_segnames_ptr_cntr++; } - @system final private JSONValue[] biblio_make_unsorted_array_of_json_objects()( - string[] biblio_unordered, - JSONValue[] bib_arr_json - ) { - foreach (bibent; biblio_unordered) { - // update bib to include deemed_author, needed for: - // sort_bibliography_array_by_deemed_author_year_title - // either: sort on multiple fields, or; create such sort field - JSONValue j = parseJSON(bibent); - if (!empty(j["fulltitle"].str)) { - if (!empty(j["author_raw"].str)) { - j["deemed_author"] = j["author_arr"][0]; - } else if (!empty(j["editor_raw"].str)) { - j["deemed_author"] = j["editor_arr"][0]; + ST_segnames ret; + ret.segnames = segnames; + ret.html_segnames_ptr_cntr = html_segnames_ptr_cntr; + ret.html_segnames_ptr = html_segnames_ptr; + return ret; +} +// decendants +@safe auto after_doc_get_decendants()(ObjGenericComposite[] document_sections) { + int[string] _heading_ocn_decendants; + string[] _ocn_open_key = ["","","","","","","",""]; + auto _doc_sect_length = document_sections.length - 1; + int _last_ocn; + foreach (_lg, ref obj; document_sections) { + if (obj.metainfo.is_a == "heading") { + foreach (_dts_lv, dom_tag_status; obj.metainfo.dom_structure_markedup_tags_status) { + switch (dom_tag_status) with (DomTags) { + case none: break; + case open: + _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; + break; + case close: + if (_ocn_open_key[_dts_lv].empty) { + _ocn_open_key[_dts_lv] = "0"; + } + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; + _ocn_open_key[_dts_lv] = (0).to!string; + break; + case close_and_open: + if (_ocn_open_key[_dts_lv].empty) { + _ocn_open_key[_dts_lv] = "0"; + } + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; + _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; + break; + case open_still: break; + default: break; } - j["sortby_deemed_author_year_title"] = ( - j["deemed_author"].str ~ - "; " ~ - j["year"].str ~ - "; " ~ - j["fulltitle"].str - ); } - bib_arr_json ~= j; } - return bib_arr_json.dup; + if (obj.metainfo.ocn > 0) { + _last_ocn = obj.metainfo.ocn; + } + if (_lg == _doc_sect_length) { + _heading_ocn_decendants["1"] = _last_ocn; // close existing o_n key + } } - @system final private JSONValue[] biblio_sort()(JSONValue[] biblio_unordered) { - JSONValue[] biblio_sorted_; - biblio_sorted_ - = sort!((a, b){ - return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); - })(biblio_unordered).array; - debug(bibliosorted) { - foreach (j; biblio_sorted_) { - if (!empty(j["fulltitle"].str)) { writeln(j["sortby_deemed_author_year_title"]); } + Tuple!(int, int)[] pairs; + foreach (pair; _heading_ocn_decendants.byPair) { + pairs ~= tuple(pair[0].to!int, pair[1]); + } + return pairs.sort; +} +@safe string[] extract_images()(string content_block) { + static auto rgx = RgxI(); + string[] images_; + if (auto m = content_block.matchAll(rgx.image)) { + images_ ~= m.captures[1]; + } + return images_; +} +@system auto _image_dimensions(O,M)(O obj, M manifested) { + static auto rgx = RgxI(); + if (obj.has.image_without_dimensions) { + import std.math; + import imageformats; + int w, h, chans; + real _w, _h; + int max_width = 640; + foreach (img; obj.text.matchAll(rgx.inline_image_without_dimensions)) { + try { + read_image_info(manifested.src.image_dir_path ~ "/" ~ img["img"], w, h, chans); + } catch (Exception ex) { + writeln("WARNING, image not found: ", img["img"], "\n ", manifested.src.image_dir_path ~ "/" ~ img["img"]); + } + // calculate, decide max width and proportionally reduce to keep w & h within it + debug(images) { writeln("width: ", w, ", height: ", h); } + if (w > max_width) { + _w = max_width; + _h = round((max_width / w.to!real) * h.to!real); + } else { + _w = w; + _h = h; } + obj.text = obj.text.replaceFirst( + rgx.inline_image_without_dimensions, + format(q"┃%s☼%s,w%sh%s %s┃", + "$1", + "$3", + _w.to!string, + _h.to!string, + "$6", + ) + ); } - return biblio_sorted_; + debug(images) { writeln("image without dimensions: ", obj.text); } } - @system void biblio_debug()(JSONValue[] biblio_sorted) { - debug(biblio0) { - foreach (j; biblio_sorted) { - if (!empty(j["fulltitle"].str)) { writeln(j["sortby_deemed_author_year_title"]); } + return obj; +} +// links +@safe auto _links(O)(O obj) { + static auto rgx = RgxI(); + if (auto m = obj.text.match(rgx.inline_link_stow_uri)) { + debug(links) { + writeln("number of link matches to stow: ", (obj.text.match(rgx.inline_link_stow_uri)).count); + writeln("links to stow: ", (obj.text.match(rgx.inline_link_stow_uri))); + } + int _n_matches = (obj.text.match(rgx.inline_link_stow_uri)).count.to!int; + for(int i = 0; i < _n_matches; ++i) { + if (obj.text.match(rgx.inline_link_stow_uri)) { + obj.stow.link ~= obj.text.matchFirst(rgx.inline_link_stow_uri)[2]; + obj.text = obj.text.replaceFirst( + rgx.inline_link_stow_uri, + format(q"┃┥%s┝┤%s├┃", "$1", i) + ); } } } + return obj; } struct NodeStructureMetadata { int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; @@ -6381,11 +6275,8 @@ struct NodeStructureMetadata { } invariant() { } - @safe ObjGenericComposite node_emitter_heading(Hd,TaL,TA,fNr,fNs,fL)( - string _text, - string lev_markup_number, - string lev_collapsed_number, - Hd dummy_heading_status, + @safe ObjGenericComposite node_emitter_heading(O,TaL,TA,SOAT)( + O an_object, string[string] tag_in_seg, TaL lev_anchor_tag, TA tag_assoc, @@ -6393,12 +6284,14 @@ struct NodeStructureMetadata { int cntr_, int ptr_, string[] lv_ancestors_txt, - string is_, int html_segnames_ptr, - fNr flag_notes_reg, - fNs flag_notes_star, - fL flag_links, + SOAT substantive_object_and_anchor_tags_struct, ) { + string _text = an_object["substantive"]; + string lev_markup_number = an_object["lev_markup_number"]; + string lev_collapsed_number = an_object["lev_collapsed_number"]; + string dummy_heading_status = an_object["dummy_heading_status"]; + string is_ = an_object["is"]; debug(asserts) { static assert(is(typeof(lev) == string)); static assert(is(typeof(obj_cite_digits.object_number) == int)); @@ -6500,75 +6393,75 @@ struct NodeStructureMetadata { default: break; } - ObjGenericComposite _comp_obj_heading_; - _comp_obj_heading_ = _comp_obj_heading_.init; - _comp_obj_heading_.metainfo.is_of_part = "body"; - _comp_obj_heading_.metainfo.is_of_section = "body"; - _comp_obj_heading_.metainfo.is_of_type = "para"; - _comp_obj_heading_.metainfo.is_a = "heading"; - _comp_obj_heading_.text = _text.to!string.strip; - _comp_obj_heading_.metainfo.ocn = obj_cite_digits.object_number; - _comp_obj_heading_.metainfo.identifier = obj_cite_digits.identifier; - _comp_obj_heading_.metainfo.dummy_heading = (dummy_heading_status == "t") ? true: false; - _comp_obj_heading_.metainfo.object_number_off = obj_cite_digits.off; - // _comp_obj_heading_.metainfo.o_n_book_index = obj_cite_digits.bkidx; - _comp_obj_heading_.metainfo.object_number_type = obj_cite_digits.type; - _comp_obj_heading_.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1to4"]; - _comp_obj_heading_.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; - _comp_obj_heading_.tags.in_segment_html = _comp_obj_heading_.tags.anchor_tag_html; - _comp_obj_heading_.tags.heading_lev_anchor_tag = lev_anchor_tag; - _comp_obj_heading_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - _comp_obj_heading_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; - _comp_obj_heading_.metainfo.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); - _comp_obj_heading_.metainfo.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); - _comp_obj_heading_.metainfo.parent_ocn = p_["object_number"]; - _comp_obj_heading_.metainfo.parent_lev_markup = p_["lev_markup_number"]; - _comp_obj_heading_.tags.heading_ancestors_text = lv_ancestors_txt; - _comp_obj_heading_.ptr.doc_object = cntr_; - _comp_obj_heading_.ptr.html_segnames = ((lev_markup_number == "4") ? html_segnames_ptr : 0); - _comp_obj_heading_.ptr.heading = ptr_; - _comp_obj_heading_.has.inline_notes_reg = flag_notes_reg; - _comp_obj_heading_.has.inline_notes_star = flag_notes_star; - _comp_obj_heading_.has.inline_links = flag_links; - tag_assoc[_comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = _comp_obj_heading_.tags.in_segment_html; - tag_assoc[_comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = _comp_obj_heading_.tags.segment_anchor_tag_epub; + ObjGenericComposite comp_obj_; + comp_obj_ = comp_obj_.init; + comp_obj_.metainfo.is_of_part = "body"; + comp_obj_.metainfo.is_of_section = "body"; + comp_obj_.metainfo.is_of_type = "para"; + comp_obj_.metainfo.is_a = "heading"; + comp_obj_.text = _text.to!string.strip; + comp_obj_.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_.metainfo.dummy_heading = (dummy_heading_status == "t") ? true: false; + comp_obj_.metainfo.object_number_off = obj_cite_digits.off; + // comp_obj_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1to4"]; + comp_obj_.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; + comp_obj_.tags.in_segment_html = comp_obj_.tags.anchor_tag_html; + comp_obj_.tags.heading_lev_anchor_tag = lev_anchor_tag; + comp_obj_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1to4"]; + comp_obj_.metainfo.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); + comp_obj_.metainfo.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); + comp_obj_.metainfo.parent_ocn = p_["object_number"]; + comp_obj_.metainfo.parent_lev_markup = p_["lev_markup_number"]; + comp_obj_.tags.heading_ancestors_text = lv_ancestors_txt; + comp_obj_.ptr.doc_object = cntr_; + comp_obj_.ptr.html_segnames = ((lev_markup_number == "4") ? html_segnames_ptr : 0); + comp_obj_.ptr.heading = ptr_; + comp_obj_.has.inline_notes_reg = substantive_object_and_anchor_tags_struct.has_notes_reg; + comp_obj_.has.inline_notes_star = substantive_object_and_anchor_tags_struct.has_notes_star; + comp_obj_.has.inline_links = substantive_object_and_anchor_tags_struct.has_links; + tag_assoc[comp_obj_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_.tags.in_segment_html; + tag_assoc[comp_obj_.tags.segment_anchor_tag_epub]["seg_lv1to4"] = comp_obj_.tags.segment_anchor_tag_epub; debug(_node) { if (lev_markup_number.match(rgx.levels_numbered_headings)) { writeln("* ", _node.to!string); } } debug(nodeheading) { if (lev_markup_number.match(rgx.levels_numbered_headings)) { writeln("* ", _node.to!string); } } - assert(_comp_obj_heading_.metainfo.parent_lev_markup <= 7); - assert(_comp_obj_heading_.metainfo.parent_ocn >= 0); + assert(comp_obj_.metainfo.parent_lev_markup <= 7); + assert(comp_obj_.metainfo.parent_ocn >= 0); if (lev_markup_number.match(rgx.levels_numbered_headings)) { - assert(_comp_obj_heading_.metainfo.heading_lev_markup <= 7); - assert(_comp_obj_heading_.metainfo.ocn >= 0); - if (_comp_obj_heading_.metainfo.parent_lev_markup > 0) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup < _comp_obj_heading_.metainfo.heading_lev_markup); - if (_comp_obj_heading_.metainfo.ocn != 0) { - assert(_comp_obj_heading_.metainfo.parent_ocn < _comp_obj_heading_.metainfo.ocn); + assert(comp_obj_.metainfo.heading_lev_markup <= 7); + assert(comp_obj_.metainfo.ocn >= 0); + if (comp_obj_.metainfo.parent_lev_markup > 0) { + assert(comp_obj_.metainfo.parent_lev_markup < comp_obj_.metainfo.heading_lev_markup); + if (comp_obj_.metainfo.ocn != 0) { + assert(comp_obj_.metainfo.parent_ocn < comp_obj_.metainfo.ocn); } } - if (_comp_obj_heading_.metainfo.heading_lev_markup == 0) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_B); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_C); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_1) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_2) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_1); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_3) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_2); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_4) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_3); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_5) { - } - } - return _comp_obj_heading_; + if (comp_obj_.metainfo.heading_lev_markup == 0) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_B); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_C); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_1) { + assert(comp_obj_.metainfo.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_2) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_1); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_3) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_2); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_4) { + assert(comp_obj_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_3); + } else if (comp_obj_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_5) { + } + } + return comp_obj_; } invariant() { } -- cgit v1.2.3