From af1765cd7b2f3b1309eea5bcdb91780176518c88 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 28 Nov 2016 20:54:26 -0500 Subject: 0.9.2 backmatter: control processing, possible to omit sections --- org/ao_abstract_doc_source.org | 316 +++++++++++++++++++++------------------ org/ao_defaults.org | 3 + org/sdp.org | 106 +++++++------ src/sdp.d | 104 +++++++------ src/sdp/ao_abstract_doc_source.d | 316 +++++++++++++++++++++------------------ src/sdp/ao_rgx.d | 3 + views/version.txt | 2 +- 7 files changed, 472 insertions(+), 378 deletions(-) diff --git a/org/ao_abstract_doc_source.org b/org/ao_abstract_doc_source.org index 690c029..c5535fd 100644 --- a/org/ao_abstract_doc_source.org +++ b/org/ao_abstract_doc_source.org @@ -266,17 +266,20 @@ continue; #+name: abs_in_loop_body_non_code_obj #+BEGIN_SRC d if ((matchFirst(line, rgx.heading_biblio) -|| (type["biblio_section"] == State.on)) +|| (type["biblio_section"] == State.on +&& (!matchFirst(line, rgx.heading_blurb_glossary)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): biblio +/ - _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); type["glossary_section"] = State.off; type["biblio_section"] = State.on; type["blurb_section"] = State.off; - debug(bibliobuild) { - writeln("- ", biblio_entry_str_json); - writeln("-> ", biblio_arr_json.length); + if (opt_action_bool["backmatter"] && opt_action_bool["section_biblio"]) { + _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); // + debug(bibliobuild) { + writeln("- ", biblio_entry_str_json); + writeln("-> ", biblio_arr_json.length); + } } continue; #+END_SRC @@ -293,7 +296,8 @@ if there is a glossary section you need to: #+name: abs_in_loop_body_non_code_obj #+BEGIN_SRC d } else if ((matchFirst(line, rgx.heading_glossary) -|| (type["glossary_section"] == State.on)) +|| (type["glossary_section"] == State.on +&& (!matchFirst(line, rgx.heading_biblio_blurb)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): glossary +/ @@ -305,50 +309,52 @@ if there is a glossary section you need to: type["glossary_section"] = State.on; type["biblio_section"] = State.off; type["blurb_section"] = State.off; - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="glossary_nugget"; // - if (matchFirst(line, rgx.heading_glossary)) { - the_glossary_section ~= - set_abstract_object.contents_heading( - "Glossary", // nugget/object - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - "B", // lev - 1, // lev_markup_number - 1, // lev_collapsed_number - ); - the_glossary_section ~= - set_abstract_object.contents_heading( - "Glossary", // nugget/object - "", // attrib - 0, // obj_cite_number - ["glossary"], // anchor tag - "1", // lev - 4, // lev_markup_number - 2, // lev_collapsed_number - ); - // } else if (matchFirst(line, rgx.heading)) { - // _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - the_glossary_section ~= - set_abstract_object.contents_para( - "para", // an_object["is"], - to!string(line), // an_object["substantive"], - "", // attrib - 0, // obj_cite_number, - indent, - bullet - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_glossary"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="glossary_nugget"; // + if (matchFirst(line, rgx.heading_glossary)) { + the_glossary_section ~= + set_abstract_object.contents_heading( + "Glossary", // nugget/object + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + "B", // lev + 1, // lev_markup_number + 1, // lev_collapsed_number + ); + the_glossary_section ~= + set_abstract_object.contents_heading( + "Glossary", // nugget/object + "", // attrib + 0, // obj_cite_number + ["glossary"], // anchor tag + "1", // lev + 4, // lev_markup_number + 2, // lev_collapsed_number + ); + // } else if (matchFirst(line, rgx.heading)) { + // _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + the_glossary_section ~= + set_abstract_object.contents_para( + "para", // an_object["is"], + to!string(line), // an_object["substantive"], + "", // attrib + 0, // obj_cite_number, + indent, + bullet + ); + } + type["obj_cite_number_status"] = TriState.off; } - type["obj_cite_number_status"] = TriState.off; continue; #+END_SRC @@ -364,7 +370,8 @@ if there is a blurb section you need to: #+name: abs_in_loop_body_non_code_obj #+BEGIN_SRC d } else if ((matchFirst(line, rgx.heading_blurb) -|| (type["blurb_section"] == State.on)) +|| (type["blurb_section"] == State.on +&& (!matchFirst(line, rgx.heading_biblio_glossary)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): blurb +/ @@ -376,60 +383,63 @@ if there is a blurb section you need to: type["glossary_section"] = State.off; type["biblio_section"] = State.off; type["blurb_section"] = State.on; - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="blurb_nugget"; - if (matchFirst(line, rgx.heading_blurb)) { - the_blurb_section ~= - set_abstract_object.contents_heading( - "Blurb", // nugget/object - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - "B", // lev - 1, // lev_markup_number - 1, // lev_collapsed_number - ); - the_blurb_section ~= - set_abstract_object.contents_heading( - "Blurb", // nugget/object - "", // attrib - 0, // obj_cite_number - ["blurb"], // anchor tag - "1", // lev - 4, // lev_markup_number - 2, // lev_collapsed_number - ); - } else if (matchFirst(line, rgx.heading)) { - _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); - the_blurb_section ~= - set_abstract_object.contents_heading( - to!string(line), // an_object["substantive"], - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - to!string(an_object["lev"]), - to!int(an_object["lev_markup_number"]), - to!int(an_object["lev_collapsed_number"]), - ); - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - the_blurb_section ~= - set_abstract_object.contents_para( - "para", // an_object["is"], - to!string(line), // an_object["substantive"], - "", // attrib - obj_cite_number, - indent, - bullet - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="blurb_nugget"; + if (matchFirst(line, rgx.heading_blurb)) { + the_blurb_section ~= + set_abstract_object.contents_heading( + "Blurb", // nugget/object + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + "B", // lev + 1, // lev_markup_number + 1, // lev_collapsed_number + ); + the_blurb_section ~= + set_abstract_object.contents_heading( + "Blurb", // nugget/object + "", // attrib + 0, // obj_cite_number + ["blurb"], // anchor tag + "1", // lev + 4, // lev_markup_number + 2, // lev_collapsed_number + ); + } else if ((matchFirst(line, rgx.heading)) + && (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"])) { + _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? + the_blurb_section ~= + set_abstract_object.contents_heading( + to!string(line), // an_object["substantive"], + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + to!string(an_object["lev"]), + to!int(an_object["lev_markup_number"]), + to!int(an_object["lev_collapsed_number"]), + ); + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + the_blurb_section ~= + set_abstract_object.contents_para( + "para", // an_object["is"], + to!string(line), // an_object["substantive"], + "", // attrib + obj_cite_number, + indent, + bullet + ); + } + type["obj_cite_number_status"] = TriState.off; } - type["obj_cite_number_status"] = TriState.off; continue; #+END_SRC @@ -549,7 +559,7 @@ if ((matchFirst(line, rgx.book_index)) || (matchFirst(line, rgx.book_index_open)) || (type["book_index"] == State.on )) { /+ book_index +/ - _book_index_(line, book_idx_tmp, an_object, type); + _book_index_(line, book_idx_tmp, an_object, type, opt_action_bool); #+END_SRC ******* not book index [+1] @@ -846,10 +856,11 @@ debug(objectrelated2) { // check } /+ Backmatter: - * endnotes - * glossary - * references / bibliography - * book index + - endnotes + - glossary + - bibliography / references + - book index + - blurb +/ // TODO FIGURE OUT, you need this possibility // obj_im.obj_inline_markup_and_anchor_tags("doc_end_reset", an_object_key, "", dochead_make_aa); @@ -861,7 +872,7 @@ debug(objectrelated2) { // check #+name: abs_post #+BEGIN_SRC d auto en_tuple = - note_section.endnote_objects(obj_cite_number); + note_section.endnote_objects(obj_cite_number, opt_action_bool); static assert(!isTypeTuple!(en_tuple)); auto the_endnotes_section = en_tuple[0]; obj_cite_number = en_tuple[1]; @@ -1033,7 +1044,8 @@ auto bi_tuple = bi.bookindex_build_section( bookindex_unordered_hashes, obj_cite_number, - segment_object_belongs_to + segment_object_belongs_to, + opt_action_bool, ); static assert(!isTypeTuple!(bi_tuple)); auto the_bookindex_section = bi_tuple[0]; @@ -2407,10 +2419,11 @@ void _block_flag_line_empty_( #+name: abs_functions_book_index #+BEGIN_SRC d auto _book_index_( - char[] line, - ref string book_idx_tmp, + char[] line, + ref string book_idx_tmp, ref string[string] an_object, - ref int[string] type + ref int[string] type, + bool[string] opt_action_bool, ) { if (auto m = match(line, rgx.book_index)) { /+ match book_index +/ @@ -2424,27 +2437,33 @@ auto _book_index_( } else if (auto m = match(line, rgx.book_index_open)) { /+ match open book_index +/ type["book_index"] = State.on; - book_idx_tmp = to!string(m.captures[1]); - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + book_idx_tmp = to!string(m.captures[1]); + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } } } else if (type["book_index"] == State.on ) { /+ book_index flag set +/ if (auto m = match(line, rgx.book_index_close)) { type["book_index"] = State.off; - an_object["bookindex_nugget"] = book_idx_tmp ~ to!string(m.captures[1]); - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + an_object["bookindex_nugget"] = book_idx_tmp ~ to!string(m.captures[1]); + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } } book_idx_tmp = ""; } else { - book_idx_tmp ~= line; + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + book_idx_tmp ~= line; + } } } } @@ -3974,8 +3993,9 @@ struct BookIndexReportSection { #+BEGIN_SRC d auto bookindex_build_section( string[][string][string] bookindex_unordered_hashes, - int obj_cite_number, - string segment_object_belongs_to, + int obj_cite_number, + string segment_object_belongs_to, + bool[string] opt_action_bool, ) { string type; string lev; @@ -3986,7 +4006,8 @@ struct BookIndexReportSection { auto mainkeys = bookindex_unordered_hashes.byKey.array.sort().release; ObjComposite[][string] bookindex_section; - if (mainkeys.length > 0) { + if ((mainkeys.length > 0) + && (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"])) { string bi_tmp_seg, bi_tmp_scroll; attrib=""; lev="B"; @@ -4150,8 +4171,8 @@ struct NotesSection { #+BEGIN_SRC d private auto gather_notes_for_endnote_section( ObjComposite[] contents_am, - string segment_object_belongs_to, - ulong counter + string segment_object_belongs_to, + ulong counter, ) in { // endnotes/ footnotes for @@ -4228,7 +4249,10 @@ struct NotesSection { #+name: ao_emitters_endnotes #+BEGIN_SRC d - private auto endnote_objects(int obj_cite_number) + private auto endnote_objects( + int obj_cite_number, + bool[string] opt_action_bool, + ) in { } body { @@ -4239,7 +4263,8 @@ struct NotesSection { string lev, lev_markup_number, lev_collapsed_number; string attrib; int[string] indent; - if (endnotes_["seg"].length > 0) { + if ((endnotes_["seg"].length > 0) + && (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"])) { attrib=""; lev="B"; lev_markup_number="1"; @@ -4314,15 +4339,17 @@ struct NotesSection { 1 ); } - foreach (i, endnote; endnotes_["seg"]) { - attrib=""; - the_endnotes_section["seg"] ~= - set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); - } - foreach (i, endnote; endnotes_["scroll"]) { - attrib=""; - the_endnotes_section["scroll"] ~= - set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + if (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"]) { + foreach (i, endnote; endnotes_["seg"]) { + attrib=""; + the_endnotes_section["seg"] ~= + set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + } + foreach (i, endnote; endnotes_["scroll"]) { + attrib=""; + the_endnotes_section["scroll"] ~= + set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + } } auto t = tuple(the_endnotes_section, obj_cite_number); return t; @@ -5198,9 +5225,10 @@ template SiSUdocAbstraction() { <> /+ ↓ abstract marked up document +/ auto abstract_doc_source( - char[][] markup_sourcefile_content, + char[][] markup_sourcefile_content, string[string][string] dochead_make_aa, - string[string][string] dochead_meta_aa + string[string][string] dochead_meta_aa, + bool[string] opt_action_bool, ) { /+ ↓ abstraction init +/ <> diff --git a/org/ao_defaults.org b/org/ao_defaults.org index b5ed652..067fe59 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -566,6 +566,9 @@ static heading_backmatter = ctRegex!(`^:?1[~][!](glo static heading_biblio = ctRegex!(`^:?(1)[~][!](biblio(?:graphy)?|references?)`); static heading_glossary = ctRegex!(`^:?(1)[~][!](glossary)`); static heading_blurb = ctRegex!(`^:?(1)[~][!](blurb)`); +static heading_biblio_glossary = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|glossary)|[A-D1][~])`); +static heading_biblio_blurb = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|blurb)|[A-D1][~])`); +static heading_blurb_glossary = ctRegex!(`^:?(?:(1)[~][!](?:blurb|glossary)|[A-D1][~])`); static para_bullet = ctRegex!(`^_[*] `); static para_bullet_indent = ctRegex!(`^_([1-9])[*] `); static para_indent = ctRegex!(`^_([1-9]) `); diff --git a/org/sdp.org b/org/sdp.org index afd2be5..a016400 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -24,7 +24,7 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 9, 1); +enum ver = Version(0, 9, 2); #+END_SRC * sdp.d sisu document parser :sdp.d: @@ -215,52 +215,68 @@ look into using getopt #+NAME: sdp_args #+BEGIN_SRC d bool[string] opt_action_bool = [ - "assertions" : false, - "concordance" : false, - "digest" : false, - "docbook" : false, - "epub" : false, - "html" : false, - "manifest" : false, - "no_ocn" : false, - "odt" : false, - "pdf" : false, - "postgresql" : false, - "qrcode" : false, - "sisupod" : false, - "source" : false, - "sqlite" : false, - "text" : false, - "verbose" : false, - "xhtml" : false, - "xml_dom" : false, - "xml_sax" : false, + "assertions" : false, + "concordance" : false, + "digest" : false, + "docbook" : false, + "epub" : false, + "html" : false, + "manifest" : false, + "ocn" : true, + "odt" : false, + "pdf" : false, + "postgresql" : false, + "qrcode" : false, + "sisupod" : false, + "source" : false, + "sqlite" : false, + "text" : false, + "verbose" : false, + "xhtml" : false, + "xml_dom" : false, + "xml_sax" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, ]; auto helpInfo = getopt(args, std.getopt.config.passThrough, - "assert", "--assert set optional assertions on", &opt_action_bool["assertions"], - "concordance", "--concordance file for document", &opt_action_bool["concordance"], - "digest", "--digest hash digest for each object", &opt_action_bool["digest"], - "docbook", "--docbook process docbook output", &opt_action_bool["docbook"], - "epub", "--epub process epub output", &opt_action_bool["epub"], - "html", "--html process html output", &opt_action_bool["html"], - "manifest", "--manifest process manifest output", &opt_action_bool["manifest"], - "no-ocn", "--no-ocn suppress object cite numbers", &opt_action_bool["no_ocn"], - "odf", "--odf process odf:odt output", &opt_action_bool["odt"], - "odt", "--odt process odf:odt output", &opt_action_bool["odt"], - "pdf", "--pdf process pdf output", &opt_action_bool["pdf"], - "pg", "--pg process postgresql output", &opt_action_bool["postgresql"], - "postgresql", "--postgresql process postgresql output", &opt_action_bool["postgresql"], - "qrcode", "--qrcode with document metadata", &opt_action_bool["qrcode"], - "sisupod", "--sisupod sisupod source content bundled", &opt_action_bool["sisupod"], - "source", "--source markup source text content", &opt_action_bool["source"], - "sqlite", "--sqlite process sqlite output", &opt_action_bool["sqlite"], - "text", "--text process text output", &opt_action_bool["text"], - "txt", "--txt process text output", &opt_action_bool["text"], - "verbose|v", "--verbose output to terminal", &opt_action_bool["verbose"], - "xhtml", "--xhtml process xhtml output", &opt_action_bool["xhtml"], - "xml-dom", "--xml-dom process xml dom output", &opt_action_bool["xml_dom"], - "xml-sax", "--xml-sax process xml sax output", &opt_action_bool["xml_sax"], + "assert", "--assert set optional assertions on", &opt_action_bool["assertions"], + "concordance", "--concordance file for document", &opt_action_bool["concordance"], + "digest", "--digest hash digest for each object", &opt_action_bool["digest"], + "docbook", "--docbook process docbook output", &opt_action_bool["docbook"], + "epub", "--epub process epub output", &opt_action_bool["epub"], + "html", "--html process html output", &opt_action_bool["html"], + "manifest", "--manifest process manifest output", &opt_action_bool["manifest"], + "ocn", "--ocn object cite numbers (default)", &opt_action_bool["ocn"], + "odf", "--odf process odf:odt output", &opt_action_bool["odt"], + "odt", "--odt process odf:odt output", &opt_action_bool["odt"], + "pdf", "--pdf process pdf output", &opt_action_bool["pdf"], + "pg", "--pg process postgresql output", &opt_action_bool["postgresql"], + "postgresql", "--postgresql process postgresql output", &opt_action_bool["postgresql"], + "qrcode", "--qrcode with document metadata", &opt_action_bool["qrcode"], + "sisupod", "--sisupod sisupod source content bundled", &opt_action_bool["sisupod"], + "source", "--source markup source text content", &opt_action_bool["source"], + "sqlite", "--sqlite process sqlite output", &opt_action_bool["sqlite"], + "text", "--text process text output", &opt_action_bool["text"], + "txt", "--txt process text output", &opt_action_bool["text"], + "verbose|v", "--verbose output to terminal", &opt_action_bool["verbose"], + "xhtml", "--xhtml process xhtml output", &opt_action_bool["xhtml"], + "xml-dom", "--xml-dom process xml dom output", &opt_action_bool["xml_dom"], + "xml-sax", "--xml-sax process xml sax output", &opt_action_bool["xml_sax"], + "section-toc", "--section-toc process table of contents (default)", &opt_action_bool["section_toc"], + "section-body", "--section-body process document body (default)", &opt_action_bool["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &opt_action_bool["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &opt_action_bool["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &opt_action_bool["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &opt_action_bool["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &opt_action_bool["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &opt_action_bool["backmatter"], ); if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); @@ -358,7 +374,7 @@ string[string][string] dochead_meta = header_make_and_meta_tuple[1]; #+NAME: sdp_each_file_do_document_abstraction #+BEGIN_SRC d /+ ↓ document abstraction: process document, return abstraction as tuple +/ -auto t = abs.abstract_doc_source(content_body, dochead_make, dochead_meta); +auto t = abs.abstract_doc_source(content_body, dochead_make, dochead_meta, opt_action_bool); static assert(!isTypeTuple!(t)); auto doc_ao_contents = t[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; auto doc_ao_bookindex_unordered_hashes = t[1]; // redundant? diff --git a/src/sdp.d b/src/sdp.d index 3cb555a..9f98716 100755 --- a/src/sdp.d +++ b/src/sdp.d @@ -88,52 +88,68 @@ void main(string[] args) { } } bool[string] opt_action_bool = [ - "assertions" : false, - "concordance" : false, - "digest" : false, - "docbook" : false, - "epub" : false, - "html" : false, - "manifest" : false, - "no_ocn" : false, - "odt" : false, - "pdf" : false, - "postgresql" : false, - "qrcode" : false, - "sisupod" : false, - "source" : false, - "sqlite" : false, - "text" : false, - "verbose" : false, - "xhtml" : false, - "xml_dom" : false, - "xml_sax" : false, + "assertions" : false, + "concordance" : false, + "digest" : false, + "docbook" : false, + "epub" : false, + "html" : false, + "manifest" : false, + "ocn" : true, + "odt" : false, + "pdf" : false, + "postgresql" : false, + "qrcode" : false, + "sisupod" : false, + "source" : false, + "sqlite" : false, + "text" : false, + "verbose" : false, + "xhtml" : false, + "xml_dom" : false, + "xml_sax" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, ]; auto helpInfo = getopt(args, std.getopt.config.passThrough, - "assert", "--assert set optional assertions on", &opt_action_bool["assertions"], - "concordance", "--concordance file for document", &opt_action_bool["concordance"], - "digest", "--digest hash digest for each object", &opt_action_bool["digest"], - "docbook", "--docbook process docbook output", &opt_action_bool["docbook"], - "epub", "--epub process epub output", &opt_action_bool["epub"], - "html", "--html process html output", &opt_action_bool["html"], - "manifest", "--manifest process manifest output", &opt_action_bool["manifest"], - "no-ocn", "--no-ocn suppress object cite numbers", &opt_action_bool["no_ocn"], - "odf", "--odf process odf:odt output", &opt_action_bool["odt"], - "odt", "--odt process odf:odt output", &opt_action_bool["odt"], - "pdf", "--pdf process pdf output", &opt_action_bool["pdf"], - "pg", "--pg process postgresql output", &opt_action_bool["postgresql"], - "postgresql", "--postgresql process postgresql output", &opt_action_bool["postgresql"], - "qrcode", "--qrcode with document metadata", &opt_action_bool["qrcode"], - "sisupod", "--sisupod sisupod source content bundled", &opt_action_bool["sisupod"], - "source", "--source markup source text content", &opt_action_bool["source"], - "sqlite", "--sqlite process sqlite output", &opt_action_bool["sqlite"], - "text", "--text process text output", &opt_action_bool["text"], - "txt", "--txt process text output", &opt_action_bool["text"], - "verbose|v", "--verbose output to terminal", &opt_action_bool["verbose"], - "xhtml", "--xhtml process xhtml output", &opt_action_bool["xhtml"], - "xml-dom", "--xml-dom process xml dom output", &opt_action_bool["xml_dom"], - "xml-sax", "--xml-sax process xml sax output", &opt_action_bool["xml_sax"], + "assert", "--assert set optional assertions on", &opt_action_bool["assertions"], + "concordance", "--concordance file for document", &opt_action_bool["concordance"], + "digest", "--digest hash digest for each object", &opt_action_bool["digest"], + "docbook", "--docbook process docbook output", &opt_action_bool["docbook"], + "epub", "--epub process epub output", &opt_action_bool["epub"], + "html", "--html process html output", &opt_action_bool["html"], + "manifest", "--manifest process manifest output", &opt_action_bool["manifest"], + "ocn", "--ocn object cite numbers (default)", &opt_action_bool["ocn"], + "odf", "--odf process odf:odt output", &opt_action_bool["odt"], + "odt", "--odt process odf:odt output", &opt_action_bool["odt"], + "pdf", "--pdf process pdf output", &opt_action_bool["pdf"], + "pg", "--pg process postgresql output", &opt_action_bool["postgresql"], + "postgresql", "--postgresql process postgresql output", &opt_action_bool["postgresql"], + "qrcode", "--qrcode with document metadata", &opt_action_bool["qrcode"], + "sisupod", "--sisupod sisupod source content bundled", &opt_action_bool["sisupod"], + "source", "--source markup source text content", &opt_action_bool["source"], + "sqlite", "--sqlite process sqlite output", &opt_action_bool["sqlite"], + "text", "--text process text output", &opt_action_bool["text"], + "txt", "--txt process text output", &opt_action_bool["text"], + "verbose|v", "--verbose output to terminal", &opt_action_bool["verbose"], + "xhtml", "--xhtml process xhtml output", &opt_action_bool["xhtml"], + "xml-dom", "--xml-dom process xml dom output", &opt_action_bool["xml_dom"], + "xml-sax", "--xml-sax process xml sax output", &opt_action_bool["xml_sax"], + "section-toc", "--section-toc process table of contents (default)", &opt_action_bool["section_toc"], + "section-body", "--section-body process document body (default)", &opt_action_bool["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &opt_action_bool["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &opt_action_bool["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &opt_action_bool["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &opt_action_bool["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &opt_action_bool["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &opt_action_bool["backmatter"], ); if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); @@ -194,7 +210,7 @@ void main(string[] args) { string[string][string] dochead_make = header_make_and_meta_tuple[0]; string[string][string] dochead_meta = header_make_and_meta_tuple[1]; /+ ↓ document abstraction: process document, return abstraction as tuple +/ - auto t = abs.abstract_doc_source(content_body, dochead_make, dochead_meta); + auto t = abs.abstract_doc_source(content_body, dochead_make, dochead_meta, opt_action_bool); static assert(!isTypeTuple!(t)); auto doc_ao_contents = t[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; auto doc_ao_bookindex_unordered_hashes = t[1]; // redundant? diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 51089cd..cc39ea1 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -75,9 +75,10 @@ template SiSUdocAbstraction() { auto node_construct = NodeStructureMetadata(); /+ ↓ abstract marked up document +/ auto abstract_doc_source( - char[][] markup_sourcefile_content, + char[][] markup_sourcefile_content, string[string][string] dochead_make_aa, - string[string][string] dochead_meta_aa + string[string][string] dochead_meta_aa, + bool[string] opt_action_bool, ) { /+ ↓ abstraction init +/ scope(success) { @@ -214,21 +215,25 @@ template SiSUdocAbstraction() { /+ object other than "code block" object (includes regular text paragraph, headings & blocks other than code) +/ if ((matchFirst(line, rgx.heading_biblio) - || (type["biblio_section"] == State.on)) + || (type["biblio_section"] == State.on + && (!matchFirst(line, rgx.heading_blurb_glossary)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): biblio +/ - _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); type["glossary_section"] = State.off; type["biblio_section"] = State.on; type["blurb_section"] = State.off; - debug(bibliobuild) { - writeln("- ", biblio_entry_str_json); - writeln("-> ", biblio_arr_json.length); + if (opt_action_bool["backmatter"] && opt_action_bool["section_biblio"]) { + _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); // + debug(bibliobuild) { + writeln("- ", biblio_entry_str_json); + writeln("-> ", biblio_arr_json.length); + } } continue; } else if ((matchFirst(line, rgx.heading_glossary) - || (type["glossary_section"] == State.on)) + || (type["glossary_section"] == State.on + && (!matchFirst(line, rgx.heading_biblio_blurb)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): glossary +/ @@ -240,53 +245,56 @@ template SiSUdocAbstraction() { type["glossary_section"] = State.on; type["biblio_section"] = State.off; type["blurb_section"] = State.off; - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="glossary_nugget"; // - if (matchFirst(line, rgx.heading_glossary)) { - the_glossary_section ~= - set_abstract_object.contents_heading( - "Glossary", // nugget/object - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - "B", // lev - 1, // lev_markup_number - 1, // lev_collapsed_number - ); - the_glossary_section ~= - set_abstract_object.contents_heading( - "Glossary", // nugget/object - "", // attrib - 0, // obj_cite_number - ["glossary"], // anchor tag - "1", // lev - 4, // lev_markup_number - 2, // lev_collapsed_number - ); - // } else if (matchFirst(line, rgx.heading)) { - // _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - the_glossary_section ~= - set_abstract_object.contents_para( - "para", // an_object["is"], - to!string(line), // an_object["substantive"], - "", // attrib - 0, // obj_cite_number, - indent, - bullet - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_glossary"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="glossary_nugget"; // + if (matchFirst(line, rgx.heading_glossary)) { + the_glossary_section ~= + set_abstract_object.contents_heading( + "Glossary", // nugget/object + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + "B", // lev + 1, // lev_markup_number + 1, // lev_collapsed_number + ); + the_glossary_section ~= + set_abstract_object.contents_heading( + "Glossary", // nugget/object + "", // attrib + 0, // obj_cite_number + ["glossary"], // anchor tag + "1", // lev + 4, // lev_markup_number + 2, // lev_collapsed_number + ); + // } else if (matchFirst(line, rgx.heading)) { + // _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + the_glossary_section ~= + set_abstract_object.contents_para( + "para", // an_object["is"], + to!string(line), // an_object["substantive"], + "", // attrib + 0, // obj_cite_number, + indent, + bullet + ); + } + type["obj_cite_number_status"] = TriState.off; } - type["obj_cite_number_status"] = TriState.off; continue; } else if ((matchFirst(line, rgx.heading_blurb) - || (type["blurb_section"] == State.on)) + || (type["blurb_section"] == State.on + && (!matchFirst(line, rgx.heading_biblio_glossary)))) && (!matchFirst(line, rgx.heading)) && (!matchFirst(line, rgx.comment))) { /+ within section (block object): blurb +/ @@ -298,60 +306,63 @@ template SiSUdocAbstraction() { type["glossary_section"] = State.off; type["biblio_section"] = State.off; type["blurb_section"] = State.on; - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="blurb_nugget"; - if (matchFirst(line, rgx.heading_blurb)) { - the_blurb_section ~= - set_abstract_object.contents_heading( - "Blurb", // nugget/object - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - "B", // lev - 1, // lev_markup_number - 1, // lev_collapsed_number - ); - the_blurb_section ~= - set_abstract_object.contents_heading( - "Blurb", // nugget/object - "", // attrib - 0, // obj_cite_number - ["blurb"], // anchor tag - "1", // lev - 4, // lev_markup_number - 2, // lev_collapsed_number - ); - } else if (matchFirst(line, rgx.heading)) { - _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); - the_blurb_section ~= - set_abstract_object.contents_heading( - to!string(line), // an_object["substantive"], - "", // attrib - 0, // obj_cite_number - [""], // anchor tag - to!string(an_object["lev"]), - to!int(an_object["lev_markup_number"]), - to!int(an_object["lev_collapsed_number"]), - ); - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - the_blurb_section ~= - set_abstract_object.contents_para( - "para", // an_object["is"], - to!string(line), // an_object["substantive"], - "", // attrib - obj_cite_number, - indent, - bullet - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="blurb_nugget"; + if (matchFirst(line, rgx.heading_blurb)) { + the_blurb_section ~= + set_abstract_object.contents_heading( + "Blurb", // nugget/object + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + "B", // lev + 1, // lev_markup_number + 1, // lev_collapsed_number + ); + the_blurb_section ~= + set_abstract_object.contents_heading( + "Blurb", // nugget/object + "", // attrib + 0, // obj_cite_number + ["blurb"], // anchor tag + "1", // lev + 4, // lev_markup_number + 2, // lev_collapsed_number + ); + } else if ((matchFirst(line, rgx.heading)) + && (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"])) { + _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); // levels? + the_blurb_section ~= + set_abstract_object.contents_heading( + to!string(line), // an_object["substantive"], + "", // attrib + 0, // obj_cite_number + [""], // anchor tag + to!string(an_object["lev"]), + to!int(an_object["lev_markup_number"]), + to!int(an_object["lev_collapsed_number"]), + ); + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + the_blurb_section ~= + set_abstract_object.contents_para( + "para", // an_object["is"], + to!string(line), // an_object["substantive"], + "", // attrib + obj_cite_number, + indent, + bullet + ); + } + type["obj_cite_number_status"] = TriState.off; } - type["obj_cite_number_status"] = TriState.off; continue; } else if (type["poem"] == TriState.on) { /+ within block object: poem +/ @@ -419,7 +430,7 @@ template SiSUdocAbstraction() { || (matchFirst(line, rgx.book_index_open)) || (type["book_index"] == State.on )) { /+ book_index +/ - _book_index_(line, book_idx_tmp, an_object, type); + _book_index_(line, book_idx_tmp, an_object, type, opt_action_bool); } else { /+ not book_index +/ an_object_key="body_nugget"; @@ -655,15 +666,16 @@ template SiSUdocAbstraction() { } /+ Backmatter: - * endnotes - * glossary - * references / bibliography - * book index + - endnotes + - glossary + - bibliography / references + - book index + - blurb +/ // TODO FIGURE OUT, you need this possibility // obj_im.obj_inline_markup_and_anchor_tags("doc_end_reset", an_object_key, "", dochead_make_aa); auto en_tuple = - note_section.endnote_objects(obj_cite_number); + note_section.endnote_objects(obj_cite_number, opt_action_bool); static assert(!isTypeTuple!(en_tuple)); auto the_endnotes_section = en_tuple[0]; obj_cite_number = en_tuple[1]; @@ -771,7 +783,8 @@ template SiSUdocAbstraction() { bi.bookindex_build_section( bookindex_unordered_hashes, obj_cite_number, - segment_object_belongs_to + segment_object_belongs_to, + opt_action_bool, ); static assert(!isTypeTuple!(bi_tuple)); auto the_bookindex_section = bi_tuple[0]; @@ -1945,10 +1958,11 @@ template SiSUdocAbstraction() { } } auto _book_index_( - char[] line, - ref string book_idx_tmp, + char[] line, + ref string book_idx_tmp, ref string[string] an_object, - ref int[string] type + ref int[string] type, + bool[string] opt_action_bool, ) { if (auto m = match(line, rgx.book_index)) { /+ match book_index +/ @@ -1962,27 +1976,33 @@ template SiSUdocAbstraction() { } else if (auto m = match(line, rgx.book_index_open)) { /+ match open book_index +/ type["book_index"] = State.on; - book_idx_tmp = to!string(m.captures[1]); - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + book_idx_tmp = to!string(m.captures[1]); + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } } } else if (type["book_index"] == State.on ) { /+ book_index flag set +/ if (auto m = match(line, rgx.book_index_close)) { type["book_index"] = State.off; - an_object["bookindex_nugget"] = book_idx_tmp ~ to!string(m.captures[1]); - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + an_object["bookindex_nugget"] = book_idx_tmp ~ to!string(m.captures[1]); + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } } book_idx_tmp = ""; } else { - book_idx_tmp ~= line; + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + book_idx_tmp ~= line; + } } } } @@ -3297,8 +3317,9 @@ template SiSUdocAbstraction() { } auto bookindex_build_section( string[][string][string] bookindex_unordered_hashes, - int obj_cite_number, - string segment_object_belongs_to, + int obj_cite_number, + string segment_object_belongs_to, + bool[string] opt_action_bool, ) { string type; string lev; @@ -3309,7 +3330,8 @@ template SiSUdocAbstraction() { auto mainkeys = bookindex_unordered_hashes.byKey.array.sort().release; ObjComposite[][string] bookindex_section; - if (mainkeys.length > 0) { + if ((mainkeys.length > 0) + && (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"])) { string bi_tmp_seg, bi_tmp_scroll; attrib=""; lev="B"; @@ -3455,8 +3477,8 @@ template SiSUdocAbstraction() { auto rgx = Rgx(); private auto gather_notes_for_endnote_section( ObjComposite[] contents_am, - string segment_object_belongs_to, - ulong counter + string segment_object_belongs_to, + ulong counter, ) in { // endnotes/ footnotes for @@ -3521,7 +3543,10 @@ template SiSUdocAbstraction() { } return endnotes_; } - private auto endnote_objects(int obj_cite_number) + private auto endnote_objects( + int obj_cite_number, + bool[string] opt_action_bool, + ) in { } body { @@ -3532,7 +3557,8 @@ template SiSUdocAbstraction() { string lev, lev_markup_number, lev_collapsed_number; string attrib; int[string] indent; - if (endnotes_["seg"].length > 0) { + if ((endnotes_["seg"].length > 0) + && (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"])) { attrib=""; lev="B"; lev_markup_number="1"; @@ -3607,15 +3633,17 @@ template SiSUdocAbstraction() { 1 ); } - foreach (i, endnote; endnotes_["seg"]) { - attrib=""; - the_endnotes_section["seg"] ~= - set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); - } - foreach (i, endnote; endnotes_["scroll"]) { - attrib=""; - the_endnotes_section["scroll"] ~= - set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + if (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"]) { + foreach (i, endnote; endnotes_["seg"]) { + attrib=""; + the_endnotes_section["seg"] ~= + set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + } + foreach (i, endnote; endnotes_["scroll"]) { + attrib=""; + the_endnotes_section["scroll"] ~= + set_abstract_object.contents_endnote(endnote, endnotes_["anchor"][i]); + } } auto t = tuple(the_endnotes_section, obj_cite_number); return t; diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index f320867..aa4cd58 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -74,6 +74,9 @@ template RgxInit() { static heading_biblio = ctRegex!(`^:?(1)[~][!](biblio(?:graphy)?|references?)`); static heading_glossary = ctRegex!(`^:?(1)[~][!](glossary)`); static heading_blurb = ctRegex!(`^:?(1)[~][!](blurb)`); + static heading_biblio_glossary = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|glossary)|[A-D1][~])`); + static heading_biblio_blurb = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|blurb)|[A-D1][~])`); + static heading_blurb_glossary = ctRegex!(`^:?(?:(1)[~][!](?:blurb|glossary)|[A-D1][~])`); static para_bullet = ctRegex!(`^_[*] `); static para_bullet_indent = ctRegex!(`^_([1-9])[*] `); static para_indent = ctRegex!(`^_([1-9]) `); diff --git a/views/version.txt b/views/version.txt index 5e919e9..58c4aa4 100644 --- a/views/version.txt +++ b/views/version.txt @@ -4,4 +4,4 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 9, 1); +enum ver = Version(0, 9, 2); -- cgit v1.2.3