From d28ce48b155a11bf4f313982139f4697120e2df1 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 28 Feb 2017 15:26:52 -0500 Subject: work on outputs --- src/sdp/abstraction_summary.d | 3 - src/sdp/ao_abstract_doc_source.d | 245 ++++++++++++++++++++++----------------- src/sdp/ao_rgx.d | 32 +++-- src/sdp/output_rgx.d | 25 ++++ src/sdp/output_xhtmls.d | 34 +++++- 5 files changed, 217 insertions(+), 122 deletions(-) (limited to 'src/sdp') diff --git a/src/sdp/abstraction_summary.d b/src/sdp/abstraction_summary.d index 4a9fc80..ab32249 100644 --- a/src/sdp/abstraction_summary.d +++ b/src/sdp/abstraction_summary.d @@ -32,15 +32,12 @@ template SiSUabstractionSummary() { } } } - // auto char_repeat_number = doc_matters.source_filename.length; - // char_repeat_number = (char_repeat_number > 33) auto min_repeat_number = 66; auto char_repeat_number = (doc_matters.dochead_meta["title"]["full"].length + doc_matters.dochead_meta["creator"]["author"].length + 4); char_repeat_number = (char_repeat_number > min_repeat_number) ? char_repeat_number : min_repeat_number; - // writeln(char_repeat_number); writefln( "%s\n\"%s\", %s\n%s\n%s\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n(%s: %s)\n%s", markup.repeat_character_by_number_provided("-", char_repeat_number), diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 6690a9f..066ef3a 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -3015,6 +3015,7 @@ template SiSUdocAbstraction() { } auto rgx = Rgx(); if (line_occur["para"] == State.off) { + line = font_faces_line(line); /+ para matches +/ type["para"] = State.on; an_object[an_object_key] ~= line; // body_nugget @@ -3055,6 +3056,19 @@ template SiSUdocAbstraction() { ++line_occur["para"]; } } + auto font_faces_line(T)( + return ref T textline, + ) { + auto rgx = Rgx(); + if (match(textline, rgx.inline_faces_line)) { + textline = (textline) + .replaceFirst(rgx.inline_emphasis_line, ("*{$1}*$2")) + .replaceFirst(rgx.inline_bold_line, ("!{$1}!$2")) + .replaceFirst(rgx.inline_underscore_line, ("_{$1}_$2")) + .replaceFirst(rgx.inline_italics_line, ("/{$1}/$2")); + } + return textline; + } /+ abstraction functions ↑ +/ /+ ↓ abstraction function emitters +/ struct OCNemitter { @@ -3304,7 +3318,8 @@ template SiSUdocAbstraction() { } } body { - obj_txt["munge"]=obj_txt_in; + obj_txt_in = (obj_txt_in).replaceAll(rgx.two_spaces, mkup.nbsp ~ mkup.nbsp); + obj_txt["munge"] = obj_txt_in; return obj_txt["munge"]; } invariant() { @@ -3503,7 +3518,7 @@ template SiSUdocAbstraction() { ObjGenericComposite comp_obj_toc; mixin InternalMarkup; auto mkup = InlineMarkup(); - char[] heading_toc_ = to!(char[])(obj_["body_nugget"].dup.strip); + char[] heading_toc_ = (obj_["substantive"].dup.strip.to!(char[])).replaceAll(rgx.inline_notes_al, ""); heading_toc_ = _clean_heading_toc_(heading_toc_); auto attrib=""; string toc_txt_, subtoc_txt_; @@ -3621,7 +3636,8 @@ template SiSUdocAbstraction() { heading_toc_, _anchor_tag, ); - lev4_subtoc[segment_anchor_tag_that_object_belongs_to] ~= obj_["lev_markup_number"] ~ "~ " ~ to!string(subtoc_txt_).strip; + lev4_subtoc[segment_anchor_tag_that_object_belongs_to] + ~= obj_["lev_markup_number"] ~ "~ " ~ to!string(subtoc_txt_).strip; toc_txt_= munge.url_links(toc_txt_); indent=[ "hang_position" : to!int(obj_["lev_markup_number"]), @@ -3652,113 +3668,128 @@ template SiSUdocAbstraction() { static assert(is(typeof(dochead_make_aa) == string[string][string])); } if (dochead_make_aa["make"]["num_top"].length > 0) { - if (!(match(munge_, rgx.heading_anchor_tag))) { - static __gshared int heading_num_top_level=9; - static __gshared int heading_num_depth=2; - static __gshared int heading_num_0 = 0; - static __gshared int heading_num_1 = 0; - static __gshared int heading_num_2 = 0; - static __gshared int heading_num_3 = 0; - static __gshared string heading_number_auto_composite = ""; - if (heading_num_top_level==9) { - if (dochead_make_aa["make"]["num_depth"].length > 0) { - heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); - } - switch (dochead_make_aa["make"]["num_top"]) { - case "A": - break; - case "B": - heading_num_top_level=1; - break; - case "C": - heading_num_top_level=2; - break; - case "D": - heading_num_top_level=3; - break; - case "1": - heading_num_top_level=4; - break; - case "2": - heading_num_top_level=5; - break; - case "3": - heading_num_top_level=6; - break; - case "4": - heading_num_top_level=7; - break; - default: - break; - } - } - /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ - if (heading_num_top_level > to!uint(obj_["lev_markup_number"])) { - heading_num_0 = 0; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == to!uint(obj_["lev_markup_number"])) { - heading_num_0 ++; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 1)) { - heading_num_1 ++; - heading_num_2 = 0; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 2)) { - heading_num_2 ++; - heading_num_3 = 0; - } else if (heading_num_top_level == (to!uint(obj_["lev_markup_number"]) - 3)) { - heading_num_3 ++; - } - if (heading_num_3 > 0) { - heading_number_auto_composite = - (heading_num_depth == 3) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) ~ "." ~ - to!string(heading_num_3) - ) - : ""; - } else if (heading_num_2 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 2) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) ~ "." ~ - to!string(heading_num_2) - ) - : ""; - } else if (heading_num_1 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 1) - && (heading_num_depth <= 3)) - ? ( to!string(heading_num_0) ~ "." ~ - to!string(heading_num_1) - ) - : ""; - } else if (heading_num_0 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 0) - && (heading_num_depth <= 3)) - ? (to!string(heading_num_0)) - : ""; - } else { - heading_number_auto_composite = ""; - } - debug(heading_number_auto) { - writeln(heading_number_auto_composite); + // if (!(match(munge_, rgx.heading_anchor_tag))) { + static __gshared int heading_num_top_level=9; + static __gshared int heading_num_depth=2; + static __gshared int heading_num_0 = 0; + static __gshared int heading_num_1 = 0; + static __gshared int heading_num_2 = 0; + static __gshared int heading_num_3 = 0; + static __gshared string heading_number_auto_composite = ""; + if (heading_num_top_level==9) { + if (dochead_make_aa["make"]["num_depth"].length > 0) { + heading_num_depth = to!uint(dochead_make_aa["make"]["num_depth"]); } - if (!empty(heading_number_auto_composite)) { - munge_=(munge_) - .replaceFirst(rgx.heading, - "$1~$2 " ~ heading_number_auto_composite ~ ". ") - .replaceFirst(rgx.heading_marker_missing_tag, - "$1~" ~ heading_number_auto_composite ~ " "); + switch (dochead_make_aa["make"]["num_top"]) { + case "A": + break; + case "B": + heading_num_top_level=1; + break; + case "C": + heading_num_top_level=2; + break; + case "D": + heading_num_top_level=3; + break; + case "1": + heading_num_top_level=4; + break; + case "2": + heading_num_top_level=5; + break; + case "3": + heading_num_top_level=6; + break; + case "4": + heading_num_top_level=7; + break; + default: + break; } } + /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ + if ( + heading_num_top_level + > to!uint(obj_["lev_markup_number"]) + ) { + heading_num_0 = 0; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == to!uint(obj_["lev_markup_number"]) + ) { + heading_num_0 ++; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (to!uint(obj_["lev_markup_number"]) - 1) + ) { + heading_num_1 ++; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (to!uint(obj_["lev_markup_number"]) - 2) + ) { + heading_num_2 ++; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (to!uint(obj_["lev_markup_number"]) - 3) + ) { + heading_num_3 ++; + } + if (heading_num_3 > 0) { + heading_number_auto_composite = + (heading_num_depth == 3) + ? ( to!string(heading_num_0) ~ "." + ~ to!string(heading_num_1) ~ "." + ~ to!string(heading_num_2) ~ "." + ~ to!string(heading_num_3) + ) + : ""; + } else if (heading_num_2 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 2) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." + ~ to!string(heading_num_1) ~ "." + ~ to!string(heading_num_2) + ) + : ""; + } else if (heading_num_1 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 1) + && (heading_num_depth <= 3)) + ? ( to!string(heading_num_0) ~ "." + ~ to!string(heading_num_1) + ) + : ""; + } else if (heading_num_0 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 0) + && (heading_num_depth <= 3)) + ? (to!string(heading_num_0)) + : ""; + } else { + heading_number_auto_composite = ""; + } + debug(heading_number_auto) { + writeln(heading_number_auto_composite); + } + if (!(match(munge_, rgx.heading_anchor_tag)) + && !empty(heading_number_auto_composite)) { + munge_=(munge_) + .replaceFirst(rgx.heading, + "$1~$2 " ~ heading_number_auto_composite ~ ". ") + .replaceFirst(rgx.heading_marker_missing_tag, + "$1~" ~ heading_number_auto_composite ~ " "); + } } return munge_; } diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index 7d47608..20535d0 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -105,15 +105,6 @@ template SiSUrgxInit() { static block_curly_quote_close = ctRegex!(`^([}]quote)`); static block_curly_table_open = ctRegex!(`^(table[{].*?$)`); static block_curly_table_close = ctRegex!(`^([}]table)`); - /+ inline markup font face mod +/ - static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`); - static inline_bold = ctRegex!(`!\{(?P.+?)\}!`); - static inline_italics = ctRegex!(`/\{(?P.+?)\}/`); - static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`); - static inline_subscript = ctRegex!(`,\{(?P.+?)\},`); - static inline_strike = ctRegex!(`-\{(?P.+?)\}-`); - static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`); - static inline_mono = ctRegex!(`#\{(?P.+?)\}#`); /+ inline markup footnotes endnotes +/ static inline_notes_curly_gen = ctRegex!(`~\{.+?\}~`, "m"); static inline_notes_curly = ctRegex!(`~\{\s*(.+?)\}~`, "mg"); @@ -134,7 +125,7 @@ template SiSUrgxInit() { static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); static inline_text_and_note_curly = ctRegex!(`(?P.+?)(?:(?:[~])[{][*+ ]*)(?P.+?)(?:[}][~])`, "mg"); static note_ref = ctRegex!(`^\S+?noteref_([0-9]+)`, "mg"); // {^{73.}^}#noteref_73 - static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]`, "mg"); + static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_#]`, "mg"); static inline_url = ctRegex!(`((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]\S*)`, "mg"); static inline_link_naked_url = ctRegex!(`(?P^|[ ])(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!'"]?(?:[ ]|$))`, "mg"); static inline_link_markup_regular = ctRegex!(`(?P^|[ ])\{\s*(?P.+?)\s*\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); @@ -178,6 +169,10 @@ template SiSUrgxInit() { ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); auto language_code_and_filename = ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); + static newline = ctRegex!("\n", "mg"); + static space = ctRegex!(`[ ]`, "mg"); + static two_spaces = ctRegex!(`[ ]{2}`, "mg"); + static nbsp_char = ctRegex!(`░`, "mg"); static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); static src_fn = ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); @@ -207,5 +202,22 @@ template SiSUrgxInit() { static inline_link_fn_suffix = ctRegex!(`¤(.+?)(\.fnSuffix)`, "mg"); static inline_seg_link = ctRegex!(`(¤)(?:.+?)\.fnSuffix`, "mg"); static mark_internal_site_lnk = ctRegex!(`¤`, "mg"); + /+ inline markup font face mod +/ + static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); + static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); + static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); + static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); + static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); + static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); + static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); + static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); + static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); + static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); + static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); + static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); } } diff --git a/src/sdp/output_rgx.d b/src/sdp/output_rgx.d index 5a9a47e..e056b70 100644 --- a/src/sdp/output_rgx.d +++ b/src/sdp/output_rgx.d @@ -4,6 +4,10 @@ template SiSUoutputRgxInit() { private import defaults; struct Rgx { + static newline = ctRegex!("\n", "mg"); + static space = ctRegex!(`[ ]`, "mg"); + static two_spaces = ctRegex!(`[ ]{2}`, "mg"); + static nbsp_char = ctRegex!(`░`, "mg"); static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); static src_fn = ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); @@ -33,5 +37,26 @@ template SiSUoutputRgxInit() { static inline_link_fn_suffix = ctRegex!(`¤(.+?)(\.fnSuffix)`, "mg"); static inline_seg_link = ctRegex!(`(¤)(?:.+?)\.fnSuffix`, "mg"); static mark_internal_site_lnk = ctRegex!(`¤`, "mg"); + /+ inline markup font face mod +/ + static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); + static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); + static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); + static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); + static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); + static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); + static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); + static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); + static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); + static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); + static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); + static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static xhtml_ampersand = ctRegex!(`[&]`); // & + static xhtml_less_than = ctRegex!(`[<]`); // < + static xhtml_greater_than = ctRegex!(`[>]`); // > + static xhtml_line_break = ctRegex!(` [\\]{2}`); //
} } diff --git a/src/sdp/output_xhtmls.d b/src/sdp/output_xhtmls.d index de5236d..d39298c 100644 --- a/src/sdp/output_xhtmls.d +++ b/src/sdp/output_xhtmls.d @@ -25,6 +25,28 @@ template outputXHTMLs() { mixin SiSUoutputRgxInit; struct outputXHTMLs { auto rgx = Rgx(); + string special_characters(string _txt){ + _txt = (_txt) + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.xhtml_line_break, "
"); + return _txt; + } + string font_face(string _txt){ + _txt = (_txt) + .replaceAll(rgx.inline_emphasis, ("$1")) + .replaceAll(rgx.inline_bold, ("$1")) + .replaceAll(rgx.inline_underscore, ("$1")) + .replaceAll(rgx.inline_italics, ("$1")) + .replaceAll(rgx.inline_superscript, ("$1")) + .replaceAll(rgx.inline_subscript, ("$1")) + .replaceAll(rgx.inline_strike, ("$1")) + .replaceAll(rgx.inline_insert, ("$1")) + .replaceAll(rgx.inline_mono, ("$1")) + .replaceAll(rgx.inline_cite, ("$1")); + return _txt; + } string _xhtml_anchor_tags(const(string[]) anchor_tags) { string tags=""; if (anchor_tags.length > 0) { @@ -241,6 +263,7 @@ template outputXHTMLs() { string _suffix = ".html", ) { string _txt = obj.text; + _txt = special_characters(_txt); _txt = inline_links(obj, _txt, _suffix, "scroll"); _txt = inline_notes_scroll(obj, _txt); return _txt; @@ -250,6 +273,7 @@ template outputXHTMLs() { string _suffix = ".html", ) { string _txt = obj.text; + _txt = special_characters(_txt); _txt = inline_links(obj, _txt, _suffix, "seg"); auto t = inline_notes_seg(obj, _txt); return t; @@ -338,7 +362,9 @@ template outputXHTMLs() { string _txt, ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); + _txt = font_face(_txt); string o; + _txt = (obj.bullet) ? ("●  " ~ _txt) : _txt; if (obj.obj_cite_number.empty) { o = format(q"¶

%s @@ -439,6 +465,10 @@ template outputXHTMLs() { auto code(O)( auto return ref const O obj, ) { + string _txt = obj.text; + _txt = (_txt) + .replaceAll(rgx.newline, "
\n") + .replaceAll(rgx.nbsp_char, " "); string o; if (obj.obj_cite_number.empty) { o = format(q"¶

@@ -447,7 +477,7 @@ template outputXHTMLs() {

¶", obj.is_a, - obj.text + _txt ); } else { o = format(q"¶
@@ -460,7 +490,7 @@ template outputXHTMLs() { obj.obj_cite_number, obj.is_a, obj.obj_cite_number, - obj.text + _txt ); } return o; -- cgit v1.2.3