From f163bae9496feff1ef5bc299ca54ffcc497b12f7 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 17 Oct 2016 21:07:55 -0400 Subject: 0.7.3 provide associated segment name for endnotes section and book index --- src/sdp/ao_abstract_doc_source.d | 208 +++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 108 deletions(-) (limited to 'src/sdp/ao_abstract_doc_source.d') diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 17ffa35..143040f 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -20,6 +20,7 @@ template SiSUdocAbstraction() { ObjComposite[] contents_the_objects; string[string] an_object, processing; string[] anchor_tags; + string segment_object_belongs_to; auto set_abstract_object = ObjectAbstractSet(); auto note_section = NotesSection(); /+ enum +/ @@ -68,40 +69,8 @@ template SiSUdocAbstraction() { return bookindex_extract_hash.bookindex_nugget_hash(bookindex_section, obj_cite_number); } /+ node +/ - string node; + string _node; auto node_construct = NodeStructureMetadata(); - string node_jstr( - string lev_markup_number, - int obj_cite_number_, - long counter, - int heading_pointer, - string is_ - ) { - return node_construct.node_emitter( - lev_markup_number, - obj_cite_number_, - counter, - heading_pointer, - is_ - ); - } - string node_jstr_heading( - string lev_markup_number, - string lev_collapsed_number, - int obj_cite_number_, - long counter, - int heading_pointer, - string is_ - ) { - return node_construct.node_emitter_heading( - lev_markup_number, - lev_collapsed_number, - obj_cite_number_, - counter, - heading_pointer, - is_ - ); - } /+ ↓ abstract marked up document +/ auto abstract_doc_source( char[][] markup_sourcefile_content, @@ -351,7 +320,7 @@ template SiSUdocAbstraction() { } } else if (type["blocks"] == TriState.closing) { /+ line empty, with blocks flag +/ - _block_flag_line_empty_(line, an_object, contents_the_objects, bookindex_unordered_hashes, obj_cite_number, node, counter, type, obj_cite_number_poem, dochead_make_aa); // watch + _block_flag_line_empty_(line, an_object, contents_the_objects, bookindex_unordered_hashes, obj_cite_number, _node, counter, type, obj_cite_number_poem, dochead_make_aa); // watch } else { /+ line empty +/ /+ line.empty, post contents, empty variables: +/ @@ -372,22 +341,32 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "heading"; - node = - node_jstr_heading( + auto substantive_object_and_anchor_tags_tuple = + obj_im.obj_inline_markup_and_anchor_tags(an_object, dochead_make_aa); // tuple this with anchor tags? + an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; + anchor_tags = substantive_object_and_anchor_tags_tuple[1]; + if (to!int(an_object["lev_markup_number"]) == 4) { + segment_object_belongs_to = anchor_tags[0]; + } else if (to!int(an_object["lev_markup_number"]) < 4) { + segment_object_belongs_to = ""; + } + _node = + node_construct.node_emitter_heading( an_object["lev_markup_number"], an_object["lev_collapsed_number"], + segment_object_belongs_to, obj_cite_number, counter, heading_pointer, an_object["is"] ); // heading - auto substantive_object_and_anchor_tags_tuple = - obj_im.obj_inline_markup_and_anchor_tags(an_object, dochead_make_aa); // tuple this with anchor tags? - an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; - anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); ++heading_pointer; + debug(segments) { + writeln(an_object["lev_markup_number"]); + writeln(segment_object_belongs_to); + } contents_the_objects ~= set_abstract_object.contents_heading( an_object["substantive"], @@ -419,9 +398,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "para"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -432,7 +412,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_para( an_object["is"], @@ -472,16 +452,12 @@ template SiSUdocAbstraction() { && (counter-1 > previous_count)) { if (match(contents_the_objects[$-1].object, rgx.inline_notes_delimiter_al_regular_number_note)) { - // endnotes/ footnotes for - // doc objects other than paragraphs & headings - // various forms of grouped text previous_count=contents_the_objects.length -1; note_section.gather_notes_for_endnote_section( contents_the_objects, + segment_object_belongs_to, contents_the_objects.length -1 ); - // notes[notepoint]=note_section.notes_section(contents_the_objects, counter-1); - // notepoint +=1; } } } @@ -489,10 +465,6 @@ template SiSUdocAbstraction() { /+ ↓ post loop markup document/text +/ debug(objectrelated2) { // check writeln(line); - // writeln(__FILE__, ":", __LINE__); - // writeln(counter); - // // contents_am[0..counter] - // writeln(contents_am.length); } /+ Backmatter: @@ -525,7 +497,7 @@ template SiSUdocAbstraction() { biblio._bibliography_(biblio_unsorted_incomplete, bib_arr_json); auto bi = BookIndexReportSection(); auto bi_tuple = - bi.bookindex_build_section(bookindex_unordered_hashes, obj_cite_number); + bi.bookindex_build_section(bookindex_unordered_hashes, obj_cite_number, segment_object_belongs_to); static assert(!isTypeTuple!(bi_tuple)); auto bookindex_section = bi_tuple[0]; obj_cite_number = bi_tuple[1]; @@ -971,7 +943,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1010,8 +982,9 @@ template SiSUdocAbstraction() { } processing.remove("verse"); an_object["is"] = "verse"; - node = node_jstr( + _node = node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1022,7 +995,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1059,7 +1032,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1097,9 +1070,10 @@ template SiSUdocAbstraction() { } processing.remove("verse"); an_object["is"] = "verse"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1110,7 +1084,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1271,7 +1245,7 @@ template SiSUdocAbstraction() { ref ObjComposite[] contents_the_objects, ref string[][string][string] bookindex_unordered_hashes, ref int obj_cite_number, - ref string node, + ref string _node, ref long counter, ref int[string] type, string[string] obj_cite_number_poem, @@ -1295,9 +1269,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "code"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1308,7 +1283,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block_code( an_object["is"], @@ -1328,9 +1303,10 @@ template SiSUdocAbstraction() { bkidx_hash(an_object["bookindex"], obj_cite_number); // obj_cite_number = obj_cite_number_emit(type["obj_cite_number_status"]); an_object["is"] = "verse"; // check also - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1342,7 +1318,7 @@ template SiSUdocAbstraction() { "poem", "", (obj_cite_number_poem["start"], obj_cite_number_poem["end"]), - node + _node ); // bookindex object_reset(an_object); processing.remove("verse"); @@ -1357,9 +1333,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "table"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1370,7 +1347,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1391,9 +1368,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "group"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1404,7 +1382,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1424,9 +1402,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "block"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1437,7 +1416,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -1458,9 +1437,10 @@ template SiSUdocAbstraction() { bookindex_unordered_hashes = bkidx_hash(an_object["bookindex"], obj_cite_number); an_object["is"] = "quote"; - node = - node_jstr( + _node = + node_construct.node_emitter( content_non_header, + segment_object_belongs_to, obj_cite_number, counter, heading_pointer-1, @@ -1471,7 +1451,7 @@ template SiSUdocAbstraction() { an_object["substantive"] = substantive_object_and_anchor_tags_tuple[0]; anchor_tags = substantive_object_and_anchor_tags_tuple[1]; an_object["attrib"] = - obj_att.obj_attributes(an_object["is"], an_object["obj"], node); + obj_att.obj_attributes(an_object["is"], an_object["obj"], _node); contents_the_objects ~= set_abstract_object.contents_block( an_object["is"], @@ -2318,13 +2298,13 @@ template SiSUdocAbstraction() { } struct ObjAttributes { string[string] _obj_attrib; - string obj_attributes(string obj_is_, string obj_raw, string node) + string obj_attributes(string obj_is_, string obj_raw, string _node) in { } body { scope(exit) { - // destroy(obj_is_); + destroy(obj_is_); destroy(obj_raw); - destroy(node); + destroy(_node); } _obj_attrib.remove("json"); _obj_attrib["json"] ="{"; @@ -2364,12 +2344,12 @@ template SiSUdocAbstraction() { break; } _obj_attrib["json"] ~=" }"; - _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, node); + _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, _node); debug(structattrib) { if (oa_j["is"].str() == "heading") { // writeln(__LINE__); writeln(_obj_attrib["json"]); - // writeln(node); + // writeln(_node); writeln( "is: ", oa_j["is"].str(), "; obj_cite_number: ", oa_j["obj_cite_number"].integer() @@ -2499,9 +2479,9 @@ template SiSUdocAbstraction() { } invariant() { } - string _set_additional_values_parse_as_json(string _obj_attrib, string obj_is_, string node) { + string _set_additional_values_parse_as_json(string _obj_attrib, string obj_is_, string _node) { JSONValue oa_j = parseJSON(_obj_attrib); - JSONValue node_j = parseJSON(node); + JSONValue node_j = parseJSON(_node); assert( (oa_j.type == JSON_TYPE.OBJECT) && (node_j.type == JSON_TYPE.OBJECT) @@ -2649,7 +2629,8 @@ template SiSUdocAbstraction() { } auto bookindex_build_section( string[][string][string] bookindex_unordered_hashes, - int obj_cite_number + int obj_cite_number, + string segment_object_belongs_to, ) { string type; string lev, lev_markup_number, lev_collapsed_number; @@ -2700,7 +2681,9 @@ template SiSUdocAbstraction() { // bi_tmp = "_0_1 !{" ~ mainkey ~ "}! "; foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + bi_tmp ~= (segment_object_belongs_to.empty) + ? (" {" ~ ref_ ~ "}#" ~ go ~ ", ") + : (" {" ~ ref_ ~ "}[../" ~ segment_object_belongs_to ~ ".fn_suffix]#" ~ go ~ ", "); } bi_tmp ~= " \\\\\n "; bookindex_unordered_hashes[mainkey].remove("_a"); @@ -2710,7 +2693,9 @@ template SiSUdocAbstraction() { bi_tmp ~= subkey ~ ", "; foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { auto go = replaceAll(ref_, rgx.book_index_go, "$1"); - bi_tmp ~= " {" ~ ref_ ~ "}#" ~ go ~ ", "; + bi_tmp ~= (segment_object_belongs_to.empty) + ? (" {" ~ ref_ ~ "}#" ~ go ~ ", ") + : (" {" ~ ref_ ~ "}[../" ~ segment_object_belongs_to ~ ".fn_suffix]#" ~ go ~ ", "); } bi_tmp ~= " \\\\\n "; ++skn; @@ -2751,6 +2736,7 @@ template SiSUdocAbstraction() { auto rgx = Rgx(); private auto gather_notes_for_endnote_section( ObjComposite[] contents_am, + string segment_object_belongs_to, ulong counter ) in { @@ -2772,13 +2758,15 @@ template SiSUdocAbstraction() { rgx.inline_notes_delimiter_al_regular_number_note)) { debug(endnotes_build) { writeln( - "{^{", m.captures[1], ".}^}#noteref_", m.captures[1], " ", + "{^{", m.captures[1], ".}^}[../", segment_object_belongs_to, ".fn_suffix]#noteref_\n ", m.captures[1], " ", m.captures[2]); // sometimes need segment name (segmented html & epub) // writeln("{^{", m.captures[1], ".}^}#", contents_am[counter]["obj_cite_number"], " ", m.captures[2]); } - object_notes ~= - "{^{" ~ m.captures[1] ~ ".}^}#noteref_" ~ - m.captures[1] ~ " " ~ m.captures[2] ~ "』"; + object_notes ~= (segment_object_belongs_to.empty) + ? ("{^{" ~ m.captures[1] ~ ".}^}#noteref_" ~ + m.captures[1] ~ " " ~ m.captures[2] ~ "』") + : ("{^{" ~ m.captures[1] ~ ".}^}[../" ~ segment_object_belongs_to ~ ".fn_suffix]#noteref_" ~ + m.captures[1] ~ " " ~ m.captures[2] ~ "』"); } return object_notes; } @@ -2943,9 +2931,10 @@ template SiSUdocAbstraction() { int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; int obj_cite_number; int[string] p_; // p_ parent_ - string node; + string _node; string node_emitter( string lev_markup_number, + string segment_anchor_tag, int obj_cite_number_, long counter_, int pointer_, @@ -2960,7 +2949,7 @@ template SiSUdocAbstraction() { // scope(failure) { // writeln(__FILE__, ":", __LINE__, " failed here:"); // writeln(" is : ", is_); - // writeln(" node: ", node); + // writeln(" node: ", _node); // } assert(is_ != "heading"); // should not be necessary assert(to!int(obj_cite_number_) >= 0); // should not be necessary @@ -2978,33 +2967,35 @@ template SiSUdocAbstraction() { p_["lev_markup_number"] = DocStructMarkupHeading.h_text_1; p_["obj_cite_number"] = lv4; } - node=("{ " ~ + _node=("{ " ~ "\"is\": \"" ~ is_ ~ "\"" ~ ", \"heading_pointer\": " ~ to!string(pointer_) ~ ", \"doc_object_pointer\": " ~ to!string(counter_) ~ ", \"obj_cite_number\": " ~ to!string(obj_cite_number_) ~ + ", \"segment_anchor_tag\": \"" ~ segment_anchor_tag ~ "\"" ~ ", \"parent_obj_cite_number\": " ~ to!string(p_["obj_cite_number"]) ~ ", \"parent_lev_markup_number\": " ~ to!string(p_["lev_markup_number"]) ~ " }" ); debug(node) { if (match(lev_markup_number, rgx.levels_numbered_headings)) { - writeln("* ", to!string(node)); + writeln("* ", to!string(_node)); } else { - writeln("* ", to!string(node)); + writeln("* ", to!string(_node)); } } - JSONValue j = parseJSON(node); + JSONValue j = parseJSON(_node); assert(j["parent_lev_markup_number"].integer >= 4); assert(j["parent_lev_markup_number"].integer <= 7); assert(j["parent_obj_cite_number"].integer >= 0); - return node; + return _node; } invariant() { } string node_emitter_heading( string lev_markup_number, string lev_collapsed_number, + string segment_anchor_tag, int obj_cite_number_, long counter_, int pointer_, @@ -3030,7 +3021,7 @@ template SiSUdocAbstraction() { // scope(failure) { // writeln(__FILE__, ":", __LINE__, " failed here:"); // writeln(" is : ", is_); - // writeln(" node: ", node); + // writeln(" node: ", _node); // } auto rgx = Rgx(); int obj_cite_number = to!int(obj_cite_number_); @@ -3123,30 +3114,31 @@ template SiSUdocAbstraction() { // } break; } - node=("{ " ~ + _node=("{ " ~ "\"is\": \"" ~ is_ ~ "\"" ~ ", \"heading_pointer\": " ~ to!string(pointer_) ~ ", \"doc_object_pointer\": " ~ to!string(counter_) ~ ", \"obj_cite_number\": " ~ to!string(obj_cite_number_) ~ ", \"lev_markup_number\": " ~ to!string(lev_markup_number) ~ ", \"lev_collapsed_number\": " ~ to!string(lev_collapsed_number) ~ + ", \"segment_anchor_tag\": \"" ~ segment_anchor_tag ~ "\"" ~ ", \"parent_obj_cite_number\": " ~ to!string(p_["obj_cite_number"]) ~ ", \"parent_lev_markup_number\": " ~ to!string(p_["lev_markup_number"]) ~ " }" ); debug(heading) { if (match(lev_markup_number, rgx.levels_numbered_headings)) { - writeln("* ", to!string(node)); + writeln("* ", to!string(_node)); } } debug(node) { if (match(lev_markup_number, rgx.levels_numbered_headings)) { - writeln("* ", to!string(node)); + writeln("* ", to!string(_node)); } else { - writeln("* ", to!string(node)); + writeln("* ", to!string(_node)); } } - JSONValue j = parseJSON(node); + JSONValue j = parseJSON(_node); assert(j["parent_lev_markup_number"].integer <= 7); assert(j["parent_obj_cite_number"].integer >= 0); if (match(lev_markup_number, rgx.levels_numbered_headings)) { @@ -3180,7 +3172,7 @@ template SiSUdocAbstraction() { // assert(j["parent_lev_markup_number"].integer <= 7); } } - return node; + return _node; } invariant() { } -- cgit v1.2.3