From 0d4715a0ed5c2f9fa4b4772b8c79b4bd5044819a Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 28 Apr 2020 14:13:54 -0400 Subject: markup conversion - document header and body - .sst .ssm split into header and body - .ssi body only, (no document header) - change tracking of code blocks --- .../endnotes_inline_from_binary.d | 24 +- ...arkup_conversion_from_sisu_ruby_to_sisu_spine.d | 379 +++++++++---------- org/util_spine_markup_conversion_from_sisu.org | 403 +++++++++++---------- 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"^@(?Ptitle):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@(?Psubtitle):(?:[ ]+(?P.+)|$)"))) { - 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"^@(?Ptitle):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@(?Psubtitle):(?:[ ]+(?P.+)|$)"))) { + 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+:(?Pmain):(?:[ ]+(?P.+)|$)", "m"))) { _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); } + if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P.+)|$)", "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.+)|\n)"))) { + _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pauthor):(?:[ ]+(?P.+)|$)", "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"^@(?Prights):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcopyright):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P.+)|$)", "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"^@(?Pdate):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Ppublished):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pavailable):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pmodified):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcreated):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pissued):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pvalid):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pavailable):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pmodified):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pcreated):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pissued):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pvalid):[ ]+(?P.+)$"))) { + _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+:(?Ptopic_register):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P.+)|$)", "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+:(?Poclc):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pisbn):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pdewey):(?:[ ]+(?P.+)|$)", "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.+)$"))) { + _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+:(?Pbreaks):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pnum_top):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pheadings):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pitalics):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pbold):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pemphasis):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Psubstitute):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Ptexpdf_font):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Phome_button_text):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Phome_button_image):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcover_image):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pfooter):(?:[ ]+(?P.+)|$)", "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\s+:\w+:.*)"))) { + _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; + } } - if (auto m = h_.match(regex(r"^\s+:(?Pmain):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P.+)|$)", "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.+)|\n)"))) { - _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pauthor):(?:[ ]+(?P.+)|$)", "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"^@(?Prights):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcopyright):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P.+)|$)", "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"^@(?Pdate):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Ppublished):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pavailable):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pmodified):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcreated):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pissued):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pvalid):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pavailable):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pmodified):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pcreated):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pissued):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pvalid):[ ]+(?P.+)$"))) { - _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+:(?Ptopic_register):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P.+)|$)", "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+:(?Poclc):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pisbn):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pdewey):(?:[ ]+(?P.+)|$)", "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.+)$"))) { - _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+:(?Pbreaks):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pnum_top):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pheadings):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pitalics):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pbold):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pemphasis):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Ptexpdf_font):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Phome_button_text):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Phome_button_image):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcover_image):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pfooter):(?:[ ]+(?P.+)|$)", "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\s+:\w+:.*)"))) { - _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; - } - } - if (h_.match(regex(r"^#", "m"))) { - if (auto m = h_.match(regex(r"^(?P#.*)", "m"))) { - _tmp_header ~= m.captures["g"] ~ "\n"; + if (h_.match(regex(r"^#", "m"))) { + if (auto m = h_.match(regex(r"^(?P#.*)", "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"^@(?Ptitle):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@(?Psubtitle):(?:[ ]+(?P.+)|$)"))) { - 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"^@(?Ptitle):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "main", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@(?Psubtitle):(?:[ ]+(?P.+)|$)"))) { + 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+:(?Pmain):(?:[ ]+(?P.+)|$)", "m"))) { _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); } + if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P.+)|$)", "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.+)|\n)"))) { + _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pauthor):(?:[ ]+(?P.+)|$)", "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"^@(?Prights):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcopyright):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P.+)|$)", "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"^@(?Pdate):(?:[ ]+(?P.+)|\n)"))) { + _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Ppublished):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pavailable):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pmodified):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcreated):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pissued):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pvalid):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pavailable):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pmodified):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pcreated):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pissued):[ ]+(?P.+)$"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^@date\.(?Pvalid):[ ]+(?P.+)$"))) { + _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+:(?Ptopic_register):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P.+)|$)", "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+:(?Poclc):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pisbn):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pdewey):(?:[ ]+(?P.+)|$)", "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.+)$"))) { + _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+:(?Pbreaks):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pnum_top):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pheadings):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pitalics):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pbold):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pemphasis):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Psubstitute):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Ptexpdf_font):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Phome_button_text):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Phome_button_image):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pcover_image):(?:[ ]+(?P.+)|$)", "m"))) { + _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); + } + if (auto m = h_.match(regex(r"^\s+:(?Pfooter):(?:[ ]+(?P.+)|$)", "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\s+:\w+:.*)"))) { + _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; + } } - if (auto m = h_.match(regex(r"^\s+:(?Pmain):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:sub(?:title)?:(?:[ ]+(?P.+)|$)", "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.+)|\n)"))) { - _tmp_header ~= format_main_header("creator", "author", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pauthor):(?:[ ]+(?P.+)|$)", "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"^@(?Prights):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "copyright", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcopyright):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:licen[cs]e:(?:[ ]+(?P.+)|$)", "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"^@(?Pdate):(?:[ ]+(?P.+)|\n)"))) { - _tmp_header ~= format_main_header(m.captures["h"], "published", m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Ppublished):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pavailable):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pmodified):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcreated):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pissued):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pvalid):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pavailable):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pmodified):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pcreated):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pissued):[ ]+(?P.+)$"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^@date\.(?Pvalid):[ ]+(?P.+)$"))) { - _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+:(?Ptopic_register):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:type:(?:[ ]+(?P.+)|$)", "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+:(?Poclc):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pisbn):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pdewey):(?:[ ]+(?P.+)|$)", "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.+)$"))) { - _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+:(?Pbreaks):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pnum_top):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pheadings):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pitalics):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pbold):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pemphasis):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Ptexpdf_font):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Phome_button_text):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Phome_button_image):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pcover_image):(?:[ ]+(?P.+)|$)", "m"))) { - _tmp_header ~= format_sub_header(m.captures["h"], m.captures["c"]); - } - if (auto m = h_.match(regex(r"^\s+:(?Pfooter):(?:[ ]+(?P.+)|$)", "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\s+:\w+:.*)"))) { - _tmp_header ~= "# " ~ m.captures["g"] ~ "\n"; - } - } - if (h_.match(regex(r"^#", "m"))) { - if (auto m = h_.match(regex(r"^(?P#.*)", "m"))) { - _tmp_header ~= m.captures["g"] ~ "\n"; + if (h_.match(regex(r"^#", "m"))) { + if (auto m = h_.match(regex(r"^(?P#.*)", "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 { -- cgit v1.2.3