diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2020-04-28 14:13:54 -0400 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2020-05-20 11:27:26 -0400 |
commit | 0d4715a0ed5c2f9fa4b4772b8c79b4bd5044819a (patch) | |
tree | 18394573a84c0c4acec19b77b3e253c87fd7b602 | |
parent | rename & house utils; work on markup conversion (diff) |
markup conversiondoc-reform_v0.10.0
- document header and body
- .sst .ssm split into header and body
- .ssi body only, (no document header)
- change tracking of code blocks
3 files changed, 412 insertions, 394 deletions
diff --git a/misc/util/d/tools/markup_conversion/endnotes_inline_from_binary.d b/misc/util/d/tools/markup_conversion/endnotes_inline_from_binary.d index abd4e45..b084052 100755 --- a/misc/util/d/tools/markup_conversion/endnotes_inline_from_binary.d +++ b/misc/util/d/tools/markup_conversion/endnotes_inline_from_binary.d @@ -48,31 +48,27 @@ void main(string[] args) { string text = filename.readText; string[] paragraphs = text.split("\n\n"); int endnote_ref_count = 0; - int[string] type = [ - "curly_code" : 0, - "tic_code" : 0, - ]; + int code_block_status = 0; + enum codeBlock { off, curly, tic, } foreach (paragraph; paragraphs) { /+ loop to gather binary endnotes +/ - if ( !( type["curly_code"] == 1 || type["tic_code"] == 1) + if (code_block_status == codeBlock.off && paragraph.match(rgx_endnote) ) { endnotes ~= replaceAll!(m => m[1]) (paragraph, rgx_endnote); } else { - if ( type["curly_code"] == 1 - && paragraph.matchFirst(block_curly_code_close) + if ((code_block_status == codeBlock.curly + && paragraph.matchFirst(block_curly_code_close)) + || ((code_block_status == codeBlock.tic + && paragraph.matchFirst(block_tic_close)) ) { - type["curly_code"] = 0; - } else if (type["tic_code"] == 1 - && paragraph.matchFirst(block_tic_close) - ) { - type["tic_code"] = 0; + code_block_status = codeBlock.off; } else if ( type["curly_code"] == 1 || type["tic_code"] == 1) { // skip, prevent search for endnotes } else if (paragraph.matchFirst(block_curly_code_open)) { - type["curly_code"] = 1; + code_block_status = codeBlock.curly; } else if (paragraph.matchFirst(block_tic_code_open)) { - type["tic_code"] = 1; + code_block_status = codeBlock.tic; } else if (auto m = paragraph.matchAll(rgx_endnote_ref)) { foreach (n; m) { endnote_ref_count++; // endnote_refs ~= (n.captures[1]); diff --git a/misc/util/d/tools/markup_conversion/markup_conversion_from_sisu_ruby_to_sisu_spine.d b/misc/util/d/tools/markup_conversion/markup_conversion_from_sisu_ruby_to_sisu_spine.d index 94e8718..0ec541d 100755 --- a/misc/util/d/tools/markup_conversion/markup_conversion_from_sisu_ruby_to_sisu_spine.d +++ b/misc/util/d/tools/markup_conversion/markup_conversion_from_sisu_ruby_to_sisu_spine.d @@ -93,204 +93,215 @@ void main(string[] args) { string filename = arg; try { string[] munged_header, munged_contents, munged_endnotes, endnote_refs; - string text = filename.readText; - char[][] hc = header0Content1(text); - char[] src_header = hc[0]; - string[] headers = src_header.to!string.split("\n\n"); - char[] src_txt = hc[1]; - string[] paragraphs = src_txt.to!string.split("\n\n"); - int endnote_ref_count = 0; - int[string] type = [ - "curly_code" : 0, - "tic_code" : 0, - ]; + char[][] hc; + char[] src_header; + string[] headers; + char[] src_txt; + string[] paragraphs; + enum codeBlock { off, curly, tic, } string _tmp_header; - headers[0] = headers[0].replaceFirst(regex(r"^%\s+SiSU.+", "i"), "# SiSU 8.0 spine (auto-conversion)"); - foreach (h_; headers) { - _tmp_header = ""; - if (auto m = h_.match(regex(r"^%\s*", "m"))) { - h_ = h_.replaceAll(regex(r"^%\s*", "m"), "# ") ~ "\n"; - } - if (h_.match(regex(r"^@title:|@subtitle"))) { - if (auto m = h_.match(regex(r"^@(?P<h>title):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@(?P<h>subtitle):(?:[ ]+(?P<c>.+)|$)"))) { - if (m.captures["c"].length == 0) { - } else { + int endnote_ref_count = 0; + int code_block_status = codeBlock.off; + string text = filename.readText; + if (arg.match(regex(r"\w+?\.ss[tm]"))) { + hc = header0Content1(text); + src_header = hc[0]; + headers = src_header.to!string.split("\n\n"); + src_txt = hc[1]; + paragraphs = src_txt.to!string.split("\n\n"); + } else if (arg.match(regex(r"\w+?\.ssi"))) { + headers = []; + paragraphs = text.split("\n\n"); + } + if (headers.length > 0) { + headers[0] = headers[0].replaceFirst(regex(r"^%\s+SiSU.+", "i"), "# SiSU 8.0 spine (auto-conversion)"); + foreach (h_; headers) { + _tmp_header = ""; + if (auto m = h_.match(regex(r"^%\s*", "m"))) { + h_ = h_.replaceAll(regex(r"^%\s*", "m"), "# ") ~ "\n"; + } + if (h_.match(regex(r"^@title:|@subtitle"))) { + if (auto m = h_.match(regex(r"^@(?P<h>title):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@(?P<h>subtitle):(?:[ ]+(?P<c>.+)|$)"))) { + if (m.captures["c"].length == 0) { + } else { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>main):(?:[ ]+(?P<c>.+)|$)", "m"))) { _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); } + if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header("subtitle", m.captures["c"]); + } + } else if (h_.match(regex(r"^@creator:|@author:"))) { + if (auto m = h_.match(regex(r"^(?:@creator:|@author:)(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>author):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@rights:"))) { + if (auto m = h_.match(regex(r"^@(?P<h>rights):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>copyright):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header("license", m.captures["c"]); + } + } else if (h_.match(regex(r"^@date:|@date\."))) { + if (auto m = h_.match(regex(r"^@(?P<h>date):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>published):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>available):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>modified):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>created):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>issued):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>valid):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>available):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>modified):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>created):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>issued):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>valid):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@classify:"))) { + if (auto m = h_.match(regex(r"^@classify:"))) { + _tmp_header ~= "classify:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>topic_register):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= "# type: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; + } + } else if (h_.match(regex(r"^(?:@identifier:|@identify:)"))) { + if (auto m = h_.match(regex(r"^(?:@identifier:|@idenfify)"))) { + _tmp_header ~= "identify:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>oclc):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>isbn):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>dewey):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@publisher:"))) { + if (auto m = h_.match(regex(r"^@publisher:[ ]+(?P<c>.+)$"))) { + _tmp_header ~= "publisher: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; + } + } else if (h_.match(regex(r"^@make:"))) { + // writeln(h_); + if (auto m = h_.match(regex(r"^@make:"))) { + _tmp_header ~= "make:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>breaks):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>num_top):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>headings):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>italics):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>bold):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>emphasis):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>substitute):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>texpdf_font):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_text):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>cover_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>footer):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + // writeln(_tmp_header); + } else if (h_.match(regex(r"^@\w+:"))) { + _tmp_header ~= "# " ~ h_.split("\n").join("\n# ") ~ "\n"; + } else if (h_.match(regex(r"^\s+:\w+:", "m"))) { + if (auto m = h_.match(regex(r"^(?P<g>\s+:\w+:.*)"))) { + _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; + } } - if (auto m = h_.match(regex(r"^\s+:(?P<h>main):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header("subtitle", m.captures["c"]); - } - } else if (h_.match(regex(r"^@creator:|@author:"))) { - if (auto m = h_.match(regex(r"^(?:@creator:|@author:)(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>author):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@rights:"))) { - if (auto m = h_.match(regex(r"^@(?P<h>rights):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>copyright):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header("license", m.captures["c"]); - } - } else if (h_.match(regex(r"^@date:|@date\."))) { - if (auto m = h_.match(regex(r"^@(?P<h>date):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>published):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>available):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>modified):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>created):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>issued):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>valid):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>available):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>modified):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>created):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>issued):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>valid):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@classify:"))) { - if (auto m = h_.match(regex(r"^@classify:"))) { - _tmp_header ~= "classify:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>topic_register):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= "# type: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; - } - } else if (h_.match(regex(r"^(?:@identifier:|@identify:)"))) { - if (auto m = h_.match(regex(r"^(?:@identifier:|@idenfify)"))) { - _tmp_header ~= "identify:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>oclc):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>isbn):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>dewey):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@publisher:"))) { - if (auto m = h_.match(regex(r"^@publisher:[ ]+(?P<c>.+)$"))) { - _tmp_header ~= "publisher: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; - } - } else if (h_.match(regex(r"^@make:"))) { - // writeln(h_); - if (auto m = h_.match(regex(r"^@make:"))) { - _tmp_header ~= "make:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>breaks):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>num_top):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>headings):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>italics):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>bold):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>emphasis):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>texpdf_font):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_text):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>cover_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>footer):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - // writeln(_tmp_header); - } else if (h_.match(regex(r"^@\w+:"))) { - _tmp_header ~= "# " ~ h_.split("\n").join("\n# ") ~ "\n"; - } else if (h_.match(regex(r"^\s+:\w+:", "m"))) { - if (auto m = h_.match(regex(r"^(?P<g>\s+:\w+:.*)"))) { - _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; - } - } - if (h_.match(regex(r"^#", "m"))) { - if (auto m = h_.match(regex(r"^(?P<g>#.*)", "m"))) { - _tmp_header ~= m.captures["g"] ~ "\n"; + if (h_.match(regex(r"^#", "m"))) { + if (auto m = h_.match(regex(r"^(?P<g>#.*)", "m"))) { + _tmp_header ~= m.captures["g"] ~ "\n"; + } + } + if (_tmp_header.length > 0) { + munged_header ~= _tmp_header.split("\n\n"); + } else if (h_.length > 0) { + writeln("munging required: ", h_); + h_ = h_.replaceAll((regex(r"\n\n\n+", "m")), "\n\n"); + munged_header ~= h_; } - } - if (_tmp_header.length > 0) { - munged_header ~= _tmp_header.split("\n\n"); - } else if (h_.length > 0) { - writeln("munging required: ", h_); - h_ = h_.replaceAll((regex(r"\n\n\n+", "m")), "\n\n"); - munged_header ~= h_; } + // writeln(munged_header.join("\n")); } - // writeln(munged_header.join("\n")); foreach (paragraph; paragraphs) { /+ loop to gather binary endnotes +/ - if ( !( type["curly_code"] == 1 || type["tic_code"] == 1) + if (code_block_status == codeBlock.off && paragraph.match(rgx_endnote) ) { munged_endnotes ~= replaceAll!(m => m[1]) (paragraph, rgx_endnote); } else { - if ( type["curly_code"] == 1 || type["tic_code"] == 1 + if ( code_block_status != codeBlock.off || paragraph.matchFirst(block_curly_code_open) || paragraph.matchFirst(block_tic_code_open) ) { /+ code blocks identified, no munging +/ - if ( type["curly_code"] == 1 - && paragraph.matchFirst(block_curly_code_close) - ) { - type["curly_code"] = 0; - } else if (type["tic_code"] == 1 - && paragraph.matchFirst(block_tic_close) + if ((code_block_status == codeBlock.curly + && paragraph.matchFirst(block_curly_code_close)) + || (code_block_status == codeBlock.tic + && paragraph.matchFirst(block_tic_close)) ) { - type["tic_code"] = 0; + code_block_status = codeBlock.off; } else if (paragraph.matchFirst(block_curly_code_open)) { - type["curly_code"] = 1; + code_block_status = codeBlock.curly; } else if (paragraph.matchFirst(block_tic_code_open)) { - type["tic_code"] = 1; + code_block_status = codeBlock.tic; } munged_contents ~= paragraph; } else { /+ regular content, not a code block +/ @@ -309,15 +320,17 @@ void main(string[] args) { { import std.outbuffer; auto buffer = new OutBuffer(); - foreach (header; munged_header) { /+ loop to inline endnotes +/ - buffer.write(header ~ "\n"); + if (munged_header.length > 0) { + foreach (header; munged_header) { /+ loop to inline endnotes +/ + buffer.write(header ~ "\n"); + } } if (munged_endnotes.length == endnote_ref_count) { int endnote_count = -1; - foreach (content; munged_contents) { /+ loop to inline endnotes +/ + foreach (k, content; munged_contents) { /+ loop to inline endnotes +/ content = replaceAll!(m => "~{ " ~ munged_endnotes[++endnote_count] ~ " }~" ~ m["tail"] ) (content, rgx_endnote_ref); // endnote_ref cannot occur in a code block or else fail - buffer.write(content ~ "\n\n"); + buffer.write(content ~ ((k == munged_contents.length - 1) ? "" : "\n\n")); } if (buffer) { try { diff --git a/org/util_spine_markup_conversion_from_sisu.org b/org/util_spine_markup_conversion_from_sisu.org index 8053bcf..21a5ffb 100644 --- a/org/util_spine_markup_conversion_from_sisu.org +++ b/org/util_spine_markup_conversion_from_sisu.org @@ -108,10 +108,8 @@ try { string text = filename.readText; string[] paragraphs = text.split("\n\n"); int endnote_ref_count = 0; - int[string] type = [ - "curly_code" : 0, - "tic_code" : 0, - ]; + int code_block_status = 0; + enum codeBlock { off, curly, tic, } #+END_SRC *** loop doc body @@ -119,26 +117,24 @@ try { #+NAME: inline_notes_loop_doc_body #+BEGIN_SRC d foreach (paragraph; paragraphs) { /+ loop to gather binary endnotes +/ - if ( !( type["curly_code"] == 1 || type["tic_code"] == 1) + if (code_block_status == codeBlock.off && paragraph.match(rgx_endnote) ) { endnotes ~= replaceAll!(m => m[1]) (paragraph, rgx_endnote); } else { - if ( type["curly_code"] == 1 - && paragraph.matchFirst(block_curly_code_close) + if ((code_block_status == codeBlock.curly + && paragraph.matchFirst(block_curly_code_close)) + || ((code_block_status == codeBlock.tic + && paragraph.matchFirst(block_tic_close)) ) { - type["curly_code"] = 0; - } else if (type["tic_code"] == 1 - && paragraph.matchFirst(block_tic_close) - ) { - type["tic_code"] = 0; + code_block_status = codeBlock.off; } else if ( type["curly_code"] == 1 || type["tic_code"] == 1) { // skip, prevent search for endnotes } else if (paragraph.matchFirst(block_curly_code_open)) { - type["curly_code"] = 1; + code_block_status = codeBlock.curly; } else if (paragraph.matchFirst(block_tic_code_open)) { - type["tic_code"] = 1; + code_block_status = codeBlock.tic; } else if (auto m = paragraph.matchAll(rgx_endnote_ref)) { foreach (n; m) { endnote_ref_count++; // endnote_refs ~= (n.captures[1]); @@ -363,187 +359,200 @@ writeln(arg); string filename = arg; try { string[] munged_header, munged_contents, munged_endnotes, endnote_refs; - string text = filename.readText; - char[][] hc = header0Content1(text); - char[] src_header = hc[0]; - string[] headers = src_header.to!string.split("\n\n"); - char[] src_txt = hc[1]; - string[] paragraphs = src_txt.to!string.split("\n\n"); - int endnote_ref_count = 0; - int[string] type = [ - "curly_code" : 0, - "tic_code" : 0, - ]; + char[][] hc; + char[] src_header; + string[] headers; + char[] src_txt; + string[] paragraphs; + enum codeBlock { off, curly, tic, } string _tmp_header; + int endnote_ref_count = 0; + int code_block_status = codeBlock.off; + string text = filename.readText; + if (arg.match(regex(r"\w+?\.ss[tm]"))) { + hc = header0Content1(text); + src_header = hc[0]; + headers = src_header.to!string.split("\n\n"); + src_txt = hc[1]; + paragraphs = src_txt.to!string.split("\n\n"); + } else if (arg.match(regex(r"\w+?\.ssi"))) { + headers = []; + paragraphs = text.split("\n\n"); + } #+END_SRC *** loop doc header #+NAME: from_sisu_rb_loop_doc_header #+BEGIN_SRC d -headers[0] = headers[0].replaceFirst(regex(r"^%\s+SiSU.+", "i"), "# SiSU 8.0 spine (auto-conversion)"); -foreach (h_; headers) { - _tmp_header = ""; - if (auto m = h_.match(regex(r"^%\s*", "m"))) { - h_ = h_.replaceAll(regex(r"^%\s*", "m"), "# ") ~ "\n"; - } - if (h_.match(regex(r"^@title:|@subtitle"))) { - if (auto m = h_.match(regex(r"^@(?P<h>title):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@(?P<h>subtitle):(?:[ ]+(?P<c>.+)|$)"))) { - if (m.captures["c"].length == 0) { - } else { +if (headers.length > 0) { + headers[0] = headers[0].replaceFirst(regex(r"^%\s+SiSU.+", "i"), "# SiSU 8.0 spine (auto-conversion)"); + foreach (h_; headers) { + _tmp_header = ""; + if (auto m = h_.match(regex(r"^%\s*", "m"))) { + h_ = h_.replaceAll(regex(r"^%\s*", "m"), "# ") ~ "\n"; + } + if (h_.match(regex(r"^@title:|@subtitle"))) { + if (auto m = h_.match(regex(r"^@(?P<h>title):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@(?P<h>subtitle):(?:[ ]+(?P<c>.+)|$)"))) { + if (m.captures["c"].length == 0) { + } else { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>main):(?:[ ]+(?P<c>.+)|$)", "m"))) { _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); } + if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header("subtitle", m.captures["c"]); + } + } else if (h_.match(regex(r"^@creator:|@author:"))) { + if (auto m = h_.match(regex(r"^(?:@creator:|@author:)(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>author):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@rights:"))) { + if (auto m = h_.match(regex(r"^@(?P<h>rights):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>copyright):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header("license", m.captures["c"]); + } + } else if (h_.match(regex(r"^@date:|@date\."))) { + if (auto m = h_.match(regex(r"^@(?P<h>date):(?:[ ]+(?P<c>.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>published):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>available):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>modified):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>created):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>issued):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>valid):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>available):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>modified):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>created):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>issued):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?P<h>valid):[ ]+(?P<c>.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@classify:"))) { + if (auto m = h_.match(regex(r"^@classify:"))) { + _tmp_header ~= "classify:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>topic_register):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= "# type: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; + } + } else if (h_.match(regex(r"^(?:@identifier:|@identify:)"))) { + if (auto m = h_.match(regex(r"^(?:@identifier:|@idenfify)"))) { + _tmp_header ~= "identify:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>oclc):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>isbn):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>dewey):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + } else if (h_.match(regex(r"^@publisher:"))) { + if (auto m = h_.match(regex(r"^@publisher:[ ]+(?P<c>.+)$"))) { + _tmp_header ~= "publisher: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; + } + } else if (h_.match(regex(r"^@make:"))) { + // writeln(h_); + if (auto m = h_.match(regex(r"^@make:"))) { + _tmp_header ~= "make:\n"; + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>breaks):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>num_top):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>headings):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>italics):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>bold):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>emphasis):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>substitute):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>texpdf_font):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_text):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>cover_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?P<h>footer):(?:[ ]+(?P<c>.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + // writeln(_tmp_header); + } else if (h_.match(regex(r"^@\w+:"))) { + _tmp_header ~= "# " ~ h_.split("\n").join("\n# ") ~ "\n"; + } else if (h_.match(regex(r"^\s+:\w+:", "m"))) { + if (auto m = h_.match(regex(r"^(?P<g>\s+:\w+:.*)"))) { + _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; + } } - if (auto m = h_.match(regex(r"^\s+:(?P<h>main):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header("subtitle", m.captures["c"]); - } - } else if (h_.match(regex(r"^@creator:|@author:"))) { - if (auto m = h_.match(regex(r"^(?:@creator:|@author:)(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>author):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@rights:"))) { - if (auto m = h_.match(regex(r"^@(?P<h>rights):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>copyright):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header("license", m.captures["c"]); - } - } else if (h_.match(regex(r"^@date:|@date\."))) { - if (auto m = h_.match(regex(r"^@(?P<h>date):(?:[ ]+(?P<c>.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>published):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>available):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>modified):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>created):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>issued):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>valid):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>available):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>modified):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>created):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>issued):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?P<h>valid):[ ]+(?P<c>.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@classify:"))) { - if (auto m = h_.match(regex(r"^@classify:"))) { - _tmp_header ~= "classify:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>topic_register):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= "# type: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; - } - } else if (h_.match(regex(r"^(?:@identifier:|@identify:)"))) { - if (auto m = h_.match(regex(r"^(?:@identifier:|@idenfify)"))) { - _tmp_header ~= "identify:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>oclc):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>isbn):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>dewey):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - } else if (h_.match(regex(r"^@publisher:"))) { - if (auto m = h_.match(regex(r"^@publisher:[ ]+(?P<c>.+)$"))) { - _tmp_header ~= "publisher: " ~ "\"" ~ m.captures["c"] ~ "\"\n"; - } - } else if (h_.match(regex(r"^@make:"))) { - // writeln(h_); - if (auto m = h_.match(regex(r"^@make:"))) { - _tmp_header ~= "make:\n"; - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>breaks):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>num_top):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>headings):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>italics):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>bold):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>emphasis):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>texpdf_font):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_text):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>home_button_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>cover_image):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?P<h>footer):(?:[ ]+(?P<c>.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - // writeln(_tmp_header); - } else if (h_.match(regex(r"^@\w+:"))) { - _tmp_header ~= "# " ~ h_.split("\n").join("\n# ") ~ "\n"; - } else if (h_.match(regex(r"^\s+:\w+:", "m"))) { - if (auto m = h_.match(regex(r"^(?P<g>\s+:\w+:.*)"))) { - _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; - } - } - if (h_.match(regex(r"^#", "m"))) { - if (auto m = h_.match(regex(r"^(?P<g>#.*)", "m"))) { - _tmp_header ~= m.captures["g"] ~ "\n"; + if (h_.match(regex(r"^#", "m"))) { + if (auto m = h_.match(regex(r"^(?P<g>#.*)", "m"))) { + _tmp_header ~= m.captures["g"] ~ "\n"; + } + } + if (_tmp_header.length > 0) { + munged_header ~= _tmp_header.split("\n\n"); + } else if (h_.length > 0) { + writeln("munging required: ", h_); + h_ = h_.replaceAll((regex(r"\n\n\n+", "m")), "\n\n"); + munged_header ~= h_; } - } - if (_tmp_header.length > 0) { - munged_header ~= _tmp_header.split("\n\n"); - } else if (h_.length > 0) { - writeln("munging required: ", h_); - h_ = h_.replaceAll((regex(r"\n\n\n+", "m")), "\n\n"); - munged_header ~= h_; } + // writeln(munged_header.join("\n")); } -// writeln(munged_header.join("\n")); #+END_SRC *** loop doc body (identify & ignore code blocks) @@ -551,28 +560,26 @@ foreach (h_; headers) { #+NAME: from_sisu_rb_loop_doc_body #+BEGIN_SRC d foreach (paragraph; paragraphs) { /+ loop to gather binary endnotes +/ - if ( !( type["curly_code"] == 1 || type["tic_code"] == 1) + if (code_block_status == codeBlock.off && paragraph.match(rgx_endnote) ) { munged_endnotes ~= replaceAll!(m => m[1]) (paragraph, rgx_endnote); } else { - if ( type["curly_code"] == 1 || type["tic_code"] == 1 + if ( code_block_status != codeBlock.off || paragraph.matchFirst(block_curly_code_open) || paragraph.matchFirst(block_tic_code_open) ) { /+ code blocks identified, no munging +/ - if ( type["curly_code"] == 1 - && paragraph.matchFirst(block_curly_code_close) + if ((code_block_status == codeBlock.curly + && paragraph.matchFirst(block_curly_code_close)) + || (code_block_status == codeBlock.tic + && paragraph.matchFirst(block_tic_close)) ) { - type["curly_code"] = 0; - } else if (type["tic_code"] == 1 - && paragraph.matchFirst(block_tic_close) - ) { - type["tic_code"] = 0; + code_block_status = codeBlock.off; } else if (paragraph.matchFirst(block_curly_code_open)) { - type["curly_code"] = 1; + code_block_status = codeBlock.curly; } else if (paragraph.matchFirst(block_tic_code_open)) { - type["tic_code"] = 1; + code_block_status = codeBlock.tic; } munged_contents ~= paragraph; } else { /+ regular content, not a code block +/ @@ -597,15 +604,17 @@ foreach (paragraph; paragraphs) { { import std.outbuffer; auto buffer = new OutBuffer(); - foreach (header; munged_header) { /+ loop to inline endnotes +/ - buffer.write(header ~ "\n"); + if (munged_header.length > 0) { + foreach (header; munged_header) { /+ loop to inline endnotes +/ + buffer.write(header ~ "\n"); + } } if (munged_endnotes.length == endnote_ref_count) { int endnote_count = -1; - foreach (content; munged_contents) { /+ loop to inline endnotes +/ + foreach (k, content; munged_contents) { /+ loop to inline endnotes +/ content = replaceAll!(m => "~{ " ~ munged_endnotes[++endnote_count] ~ " }~" ~ m["tail"] ) (content, rgx_endnote_ref); // endnote_ref cannot occur in a code block or else fail - buffer.write(content ~ "\n\n"); + buffer.write(content ~ ((k == munged_contents.length - 1) ? "" : "\n\n")); } if (buffer) { try { |