From d8d34b0eaca6f847f6ac7b09d729ad1c38e5484f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 5 Oct 2016 15:23:01 -0400 Subject: segment auto naming (where no name provided) placed in function --- org/ao_abstract_doc_source.org | 48 ++++++++++++++++++++++++++++-------------- org/ao_defaults.org | 6 +++--- 2 files changed, 35 insertions(+), 19 deletions(-) (limited to 'org') diff --git a/org/ao_abstract_doc_source.org b/org/ao_abstract_doc_source.org index 5c78771..5677baa 100644 --- a/org/ao_abstract_doc_source.org +++ b/org/ao_abstract_doc_source.org @@ -2690,7 +2690,32 @@ struct ObjInlineMarkupMunge { struct ObjInlineMarkup { // struct ObjInlineMarkup : AssertObjInlineMarkup { auto munge = ObjInlineMarkupMunge(); +#+END_SRC + +***** make segment anchor tags if not provided :markup:inline:segment:anchor:tags: + +#+name: ao_emitters +#+BEGIN_SRC d string[string] obj_txt; + string make_segment_anchor_tags_if_none_provided(string munge_, string lev_) { + if (!(match(munge_, rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { + if (match(munge_, rgx.heading_identify_anchor_tag)) { + if (auto m = match(munge_, rgx.heading_extract_named_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); + } else if (auto m = match(munge_, rgx.heading_extract_unnamed_anchor_tag)) { + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "s" ~ m.captures[1] ~ " "); + } + } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" + static __gshared uint heading_num_lev1 = 0; + heading_num_lev1 ++; + munge_=replaceFirst(munge_, rgx.heading_marker_missing_tag, + "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); + } + } + return munge_; + } #+END_SRC ***** object inline markup and anchor tags :markup:inline: @@ -2818,22 +2843,7 @@ struct ObjInlineMarkup { } } // WORK ON, you still need to ensure that level 1 anchor_tags are unique - if (!(match(obj_txt["munge"], rgx.heading_anchor_tag))) { // if (anchor_tags_.length == 0) { - if (match(obj_txt["munge"], rgx.heading_identify_anchor_tag)) { - if (auto m = match(obj_txt["munge"], rgx.heading_extract_named_anchor_tag)) { - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading_marker_missing_tag, - "$1~" ~ toLower(m.captures[1]) ~ "_" ~ m.captures[2] ~ " "); - } else if (auto m = match(obj_txt["munge"], rgx.heading_extract_unnamed_anchor_tag)) { - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading_marker_missing_tag, - "$1~" ~ "s" ~ m.captures[1] ~ " "); - } - } else if (obj_["lev"] == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" - static __gshared uint heading_num_lev1 = 0; - heading_num_lev1 ++; - obj_txt["munge"]=replaceFirst(obj_txt["munge"], rgx.heading_marker_missing_tag, - "$1~" ~ "x" ~ to!string(heading_num_lev1) ~ " "); - } - } + obj_txt["munge"]=make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); if (auto m = match(obj_txt["munge"], rgx.heading_anchor_tag)) { anchor_tag = m.captures[1]; anchor_tags_ ~=anchor_tag; @@ -2881,6 +2891,12 @@ struct ObjInlineMarkup { } invariant() { } +#+END_SRC + +***** close + +#+name: ao_emitters +#+BEGIN_SRC d } #+END_SRC diff --git a/org/ao_defaults.org b/org/ao_defaults.org index c01ea41..1ba90fe 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -610,9 +610,9 @@ static heading_a = ctRegex!(`^:?[A][~] `, "m"); static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?) `); static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~]([a-z0-9_.-]+) `,"i"); -static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9.]+))`,"i"); // unless dob.obj =~/^:?[A-D1-4]~\s+(?:|(?:chapter|article|section|clause)\s+)([0-9.]+)/i -static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+([0-9.]+)`,"i"); -static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+([0-9.]+)`); +static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9]+))`,"i"); // unless dob.obj =~/^:?[A-D1-4]~\s+(?:|(?:chapter|article|section|clause)\s+)([0-9.]+)/i +static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`,"i"); +static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`); static heading_marker_missing_tag = ctRegex!(`^:?([A-D1-4])[~] `); static heading_title = ctRegex!(`^:?[A-D1-4][~][a-z0-9_.-]*[?]?\s+(.+?)$`); static heading_all = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+(.+?)$`); // test, particularly [2] name/hashtag which may or may not be, does this affect title [3] -- cgit v1.2.3