From 4bf61c31fac50313753246e76993739fff3bfa14 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 3 Feb 2017 15:42:31 -0500 Subject: doc_matters, add image list --- org/ao_defaults.org | 7 ++++ org/ao_doc_abstraction.org | 12 +++++++ org/sdp.org | 8 +++-- src/sdp/abstraction.d | 8 +++-- src/sdp/ao_abstract_doc_source.d | 72 +++++++++++++++++++++++++++++----------- src/sdp/ao_rgx.d | 1 + 6 files changed, 84 insertions(+), 24 deletions(-) diff --git a/org/ao_defaults.org b/org/ao_defaults.org index b2604ac..a798763 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -1003,6 +1003,13 @@ static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(.+?) static inline_a_url = ctRegex!(`(┤)(\S+?)(├)`, "mg"); #+END_SRC +** images :images: + +#+name: ao_rgx +#+BEGIN_SRC d +static image = ctRegex!(`([a-zA-Z._-]+?\.(?:png|gif|jpg))`, "mg"); +#+END_SRC + ** inline markup book index :inline:bookindex: #+name: ao_rgx diff --git a/org/ao_doc_abstraction.org b/org/ao_doc_abstraction.org index 6911b63..33ebea3 100644 --- a/org/ao_doc_abstraction.org +++ b/org/ao_doc_abstraction.org @@ -1667,6 +1667,14 @@ next are not yet known for backmatter during the second pass #+name: abs_post #+BEGIN_SRC d +string[] _images; +auto extract_images(S)(S content_block) { + string[] images_; + if (auto m = matchAll(content_block, rgx.image)) { + images_ ~= m.captures[1]; + } + return images_; +} foreach (ref obj; the_document_head_section) { if (obj.is_a == "heading") { debug(dom) { @@ -1754,9 +1762,12 @@ if (the_document_body_section.length > 1) { dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); + } else if (obj.is_a == "para") { + _images ~= extract_images(obj.text); } } } +auto images=uniq(_images.sort()); /+ optional only one 1~ level +/ if (the_endnotes_section.length > 1) { dom_markedup_buffer = dom_markedup.dup; @@ -2033,6 +2044,7 @@ auto t = tuple( document_the, document_section_keys_sequenced, html_segnames, + images, ); return t; #+END_SRC diff --git a/org/sdp.org b/org/sdp.org index cafb5d9..9cb677b 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -501,10 +501,11 @@ auto da = SiSUdocAbstraction!()( opts ); static assert(!isTypeTuple!(da)); -static assert(da.length==3); +static assert(da.length==4); auto doc_abstraction = da[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; string[][string] _document_section_keys_sequenced = da[1]; string[] _doc_html_segnames = da[2]; +auto _images = da[3]; #+END_SRC ** 4. _document matters_ (compiled from various sources) @@ -540,6 +541,10 @@ struct DocumentMatters { string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2]; return _k; } + auto image_list() { + auto _k = _images; + return _k; + } auto opt_action_bool() { bool[string] _k = opts; return _k; @@ -548,7 +553,6 @@ struct DocumentMatters { auto _k = env; return _k; } - /+ add a list of images +/ } auto doc_matters = DocumentMatters(); #+END_SRC diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d index c799fb7..d358f33 100644 --- a/src/sdp/abstraction.d +++ b/src/sdp/abstraction.d @@ -70,10 +70,11 @@ template SiSUabstraction() { opts ); static assert(!isTypeTuple!(da)); - static assert(da.length==3); + static assert(da.length==4); auto doc_abstraction = da[0]; // head ~ toc ~ contents ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb; string[][string] _document_section_keys_sequenced = da[1]; string[] _doc_html_segnames = da[2]; + auto _images = da[3]; struct DocumentMatters { string[] keys_seq_seg() { string[] _k = _document_section_keys_sequenced["seg"]; @@ -103,6 +104,10 @@ template SiSUabstraction() { string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2]; return _k; } + auto image_list() { + auto _k = _images; + return _k; + } auto opt_action_bool() { bool[string] _k = opts; return _k; @@ -111,7 +116,6 @@ template SiSUabstraction() { auto _k = env; return _k; } - /+ add a list of images +/ } auto doc_matters = DocumentMatters(); auto t = tuple(doc_abstraction, doc_matters); diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index cd1c266..12bbd71 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -1211,6 +1211,14 @@ template SiSUdocAbstraction() { } html_segnames_ptr_cntr++; } + string[] _images; + auto extract_images(S)(S content_block) { + string[] images_; + if (auto m = matchAll(content_block, rgx.image)) { + images_ ~= m.captures[1]; + } + return images_; + } foreach (ref obj; the_document_head_section) { if (obj.is_a == "heading") { debug(dom) { @@ -1220,8 +1228,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1239,8 +1249,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1260,8 +1272,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1286,13 +1300,18 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); + } else if (obj.is_a == "para") { + _images ~= extract_images(obj.text); } } } + auto images=uniq(_images.sort()); /+ optional only one 1~ level +/ if (the_endnotes_section.length > 1) { dom_markedup_buffer = dom_markedup.dup; @@ -1315,8 +1334,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1340,8 +1361,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1365,8 +1388,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1392,8 +1417,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1416,8 +1443,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1441,8 +1470,10 @@ template SiSUdocAbstraction() { || (opt_action_bool["html_scroll"]) || (opt_action_bool["html_seg"]) || (opt_action_bool["epub"])) { - obj.dom_markedup = dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; } heading_ancestors(obj, lv_ancestors); } @@ -1525,6 +1556,7 @@ template SiSUdocAbstraction() { document_the, document_section_keys_sequenced, html_segnames, + images, ); return t; /+ post loop markup document/text ↑ +/ diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index f99e542..2d83d06 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -155,6 +155,7 @@ template SiSUrgxInit() { static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(.+?)\}((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|#)\S+?)([.,;:?!]?(?:[ ]|$))`, "mg"); static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(.+?)\}((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|#)\S+)`, "mg"); static inline_a_url = ctRegex!(`(┤)(\S+?)(├)`, "mg"); + static image = ctRegex!(`([a-zA-Z._-]+?\.(?:png|gif|jpg))`, "mg"); /+ inline markup book index +/ static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); -- cgit v1.2.3