diff options
author | Ralph Amissah <ralph@amissah.com> | 2017-04-28 12:00:37 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2019-04-10 15:14:14 -0400 |
commit | f5320e4c3a9b21209ad7fd7c089bf144cfb60971 (patch) | |
tree | 236ee8570415e312d1686b80665cb8bb0770d91b /org/output_xmls.org | |
parent | xml family css (diff) |
xml family, special characters, deal with once
Diffstat (limited to 'org/output_xmls.org')
-rw-r--r-- | org/output_xmls.org | 248 |
1 files changed, 129 insertions, 119 deletions
diff --git a/org/output_xmls.org b/org/output_xmls.org index 08f32bb..017c346 100644 --- a/org/output_xmls.org +++ b/org/output_xmls.org @@ -25,7 +25,7 @@ template outputXHTMLs() { struct outputXHTMLs { auto rgx = Rgx(); <<xhtml_format_objects>> -<<xhtml_format_objects_code>> + <<xhtml_format_objects_code>> } } #+END_SRC @@ -70,12 +70,20 @@ import #+name: xhtml_format_objects #+BEGIN_SRC d -string special_characters(string _txt){ +string special_characters(O)( + auto return ref const O obj, + string _txt +){ _txt = (_txt) - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.xhtml_line_break, "<br />"); + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_quotation, """) + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.nbsp_char, " "); + if (!(obj.is_a == "code")) { + _txt = (_txt) + .replaceAll(rgx.xhtml_line_break, "<br />"); + } return _txt; } #+END_SRC @@ -414,10 +422,9 @@ auto inline_notes_seg(O)( #+BEGIN_SRC d auto inline_markup_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - string _txt = obj.text; - _txt = special_characters(_txt); _txt = inline_links(obj, _txt, _suffix, "scroll"); _txt = inline_notes_scroll(obj, _txt); return _txt; @@ -430,10 +437,9 @@ auto inline_markup_scroll(O)( #+BEGIN_SRC d auto inline_markup_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - string _txt = obj.text; - _txt = special_characters(_txt); _txt = inline_links(obj, _txt, _suffix, "seg"); auto t = inline_notes_seg(obj, _txt); return t; @@ -444,8 +450,9 @@ auto inline_markup_seg(O)( #+name: xhtml_format_objects #+BEGIN_SRC d -auto toc(O)( +auto toc_seg(O)( auto return ref const O obj, + string _txt, ) { string o; o = format(q"¶ <div class="substance"> @@ -456,7 +463,7 @@ auto toc(O)( obj.is_a, obj.indent_hang, obj.indent_base, - obj.text + _txt, ); return o; } @@ -521,10 +528,11 @@ auto heading(O)( #+BEGIN_SRC d auto heading_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = heading(obj, _txt); return o; } @@ -536,10 +544,11 @@ auto heading_scroll(O)( #+BEGIN_SRC d auto heading_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = t[0]; + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = t[0]; string[] _endnotes = t[1]; string o = heading(obj, _txt); auto u = tuple( @@ -602,10 +611,11 @@ auto para(O)( #+BEGIN_SRC d auto para_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = para(obj, _txt); return o; } @@ -617,10 +627,11 @@ auto para_scroll(O)( #+BEGIN_SRC d auto para_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = to!string(t[0]); string[] _endnotes = t[1]; string o = para(obj, _txt); auto u = tuple( @@ -675,10 +686,11 @@ auto quote(O)( #+BEGIN_SRC d auto quote_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = quote(obj, _txt); return o; } @@ -690,10 +702,11 @@ auto quote_scroll(O)( #+BEGIN_SRC d auto quote_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = to!string(t[0]); string[] _endnotes = t[1]; string o = quote(obj, _txt); auto u = tuple( @@ -748,10 +761,11 @@ auto group(O)( #+BEGIN_SRC d auto group_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = group(obj, _txt); return o; } @@ -763,10 +777,11 @@ auto group_scroll(O)( #+BEGIN_SRC d auto group_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = to!string(t[0]); string[] _endnotes = t[1]; string o = group(obj, _txt); auto u = tuple( @@ -817,10 +832,11 @@ auto block(O)( #+BEGIN_SRC d auto block_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = block(obj, _txt); return o; } @@ -832,10 +848,11 @@ auto block_scroll(O)( #+BEGIN_SRC d auto block_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = to!string(t[0]); string[] _endnotes = t[1]; string o = block(obj, _txt); auto u = tuple( @@ -856,11 +873,6 @@ auto verse(O)( // using code from code block, review string _txt, ) { _txt = font_face(_txt); - _txt = (_txt) - .replaceAll(rgx.newline, "<br />\n") - .replaceAll(rgx.two_spaces, " " ~ " " ~ " " ~ " ") - .replaceAll(rgx.nbsp_and_space, " " ~ " ") - .replaceAll(rgx.strip_br, ""); string o; if (obj.obj_cite_number.empty) { o = format(q"¶ <div class="substance"> @@ -891,10 +903,11 @@ auto verse(O)( // using code from code block, review #+BEGIN_SRC d auto verse_scroll(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue + _txt = inline_markup_scroll(obj, _txt, _suffix); // issue string o = verse(obj, _txt); return o; } @@ -906,10 +919,11 @@ auto verse_scroll(O)( #+BEGIN_SRC d auto verse_seg(O)( auto return ref const O obj, + string _txt, string _suffix = ".html", ) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = to!string(t[0]); string[] _endnotes = t[1]; string o = verse(obj, _txt); auto u = tuple( @@ -924,40 +938,32 @@ auto verse_seg(O)( #+name: xhtml_format_objects_code #+BEGIN_SRC d - auto code(O)( - auto return ref const O obj, - ) { - string _txt = obj.text; - _txt = (_txt) - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_quotation, """) - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.nbsp_char, " "); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶ <div class="substance"> - <p class="%s">%s</p> - </div>¶", - obj.is_a, - _txt - ); - } else { - o = format(q"¶ <div class="substance"> - <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <p class="%s" id="%s"> -%s - </p> - </div>¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; - } +auto code(O)( + auto return ref const O obj, + string _txt, +) { + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶ <div class="substance"> + <p class="%s">%s</p> +</div>¶", + obj.is_a, + _txt + ); + } else { + o = format(q"¶ <div class="substance"> + <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> + <p class="%s" id="%s">%s</p> +</div>¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; +} #+END_SRC *** table @@ -1014,8 +1020,8 @@ auto tablarize(O)( #+BEGIN_SRC d auto table(O)( auto return ref const O obj, + string _txt, ) { - string _txt = obj.text; auto tags = _xhtml_anchor_tags(obj.anchor_tags); _txt = font_face(_txt); auto t = tablarize(obj, _txt); @@ -1049,6 +1055,7 @@ auto table(O)( #+BEGIN_SRC d auto endnote(O)( auto return ref const O obj, + string _txt, ) { string o; o = format(q"¶ <p class="%s" indent="h%si%s"> @@ -1057,7 +1064,7 @@ auto endnote(O)( obj.is_a, obj.indent_hang, obj.indent_base, - obj.text + _txt ); return o; } @@ -1094,16 +1101,17 @@ void scroll(D,I)( string suffix = ".html"; foreach (part; doc_matters.keys_seq.scroll) { foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); switch (obj.use) { case "frontmatter": switch (obj.is_of) { case "para": switch (obj.is_a) { case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, suffix); + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); break; case "toc": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -1124,10 +1132,10 @@ void scroll(D,I)( case "para": switch (obj.is_a) { case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, suffix); + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); break; case "para": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -1139,24 +1147,24 @@ void scroll(D,I)( case "block": switch (obj.is_a) { case "quote": - doc_html ~= xhtml_format.quote_scroll(obj); + doc_html ~= xhtml_format.quote_scroll(obj, _txt); break; case "group": - doc_html ~= xhtml_format.group_scroll(obj); + doc_html ~= xhtml_format.group_scroll(obj, _txt); break; case "block": - doc_html ~= xhtml_format.block_scroll(obj); + doc_html ~= xhtml_format.block_scroll(obj, _txt); break; case "poem": break; case "verse": - doc_html ~= xhtml_format.verse_scroll(obj, suffix); + doc_html ~= xhtml_format.verse_scroll(obj, _txt, suffix); break; case "code": - doc_html ~= xhtml_format.code(obj); + doc_html ~= xhtml_format.code(obj, _txt); break; case "table": - doc_html ~= xhtml_format.table(obj); + doc_html ~= xhtml_format.table(obj, _txt); break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -1177,22 +1185,22 @@ void scroll(D,I)( case "para": switch (obj.is_a) { case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, suffix); + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); break; case "endnote": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; case "glossary": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; case "bibliography": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; case "bookindex": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; case "blurb": - doc_html ~= xhtml_format.para_scroll(obj, suffix); + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -1276,6 +1284,7 @@ void seg(D,I)( string suffix = ".html"; foreach (part; doc_matters.keys_seq.seg) { foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); if (obj.is_a == "heading") { // all headings: frontmatter, body & backmatter switch (obj.heading_lev_markup) { case 0: .. case 3: @@ -1300,8 +1309,8 @@ void seg(D,I)( top_level_headings[3] = ""; goto default; default: - auto t = xhtml_format.heading_seg(obj, suffix); - top_level_headings[obj.heading_lev_markup] = t[0]; + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + top_level_headings[obj.heading_lev_markup] = t[0]; // should probably have different css tagging (fontsize etc) break; } break; @@ -1312,12 +1321,12 @@ void seg(D,I)( // writeln(top_level_heading); doc_html[segment_filename] ~= top_level_heading; } - auto t = xhtml_format.heading_seg(obj, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; case 5: .. case 7: - auto t = xhtml_format.heading_seg(obj, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -1340,7 +1349,7 @@ void seg(D,I)( case "para": switch (obj.is_a) { case "toc": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); break; default: @@ -1362,7 +1371,7 @@ void seg(D,I)( case "para": switch (obj.is_a) { case "para": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -1376,32 +1385,32 @@ void seg(D,I)( case "block": switch (obj.is_a) { case "quote": - auto t = xhtml_format.quote_seg(obj, suffix); + auto t = xhtml_format.quote_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; case "group": - auto t = xhtml_format.group_seg(obj, suffix); + auto t = xhtml_format.group_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; case "block": - auto t = xhtml_format.block_seg(obj, suffix); + auto t = xhtml_format.block_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; break; case "poem": break; case "verse": - auto t = xhtml_format.verse_seg(obj, suffix); + auto t = xhtml_format.verse_seg(obj, _txt, suffix); doc_html[segment_filename] ~= to!string(t[0]); doc_html_endnotes[segment_filename] ~= t[1]; // work on break; case "code": - doc_html[segment_filename] ~= xhtml_format.code(obj); + doc_html[segment_filename] ~= xhtml_format.code(obj, _txt); break; case "table": - doc_html[segment_filename] ~= xhtml_format.table(obj); + doc_html[segment_filename] ~= xhtml_format.table(obj, _txt); doc_html_endnotes[segment_filename] ~= ""; break; default: @@ -1423,26 +1432,26 @@ void seg(D,I)( case "para": switch (obj.is_a) { case "endnote": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= t[0]; break; case "glossary": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "bibliography": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "bookindex": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; case "blurb": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_html[segment_filename] ~= t[0]; doc_html_endnotes[segment_filename] ~= t[1]; break; @@ -1864,6 +1873,7 @@ void outputEPub3(D,I)( string suffix = ".xhtml"; foreach (part; doc_matters.keys_seq.seg) { foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); if (obj.is_a == "heading") { switch (obj.heading_lev_markup) { case 0: .. case 3: @@ -1899,12 +1909,12 @@ void outputEPub3(D,I)( foreach (top_level_heading; top_level_headings) { doc_epub3[segment_filename] ~= top_level_heading; } - auto t = xhtml_format.heading_seg(obj, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case 5: .. case 7: - auto t = xhtml_format.heading_seg(obj, suffix); + auto t = xhtml_format.heading_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -1927,7 +1937,7 @@ void outputEPub3(D,I)( case "para": switch (obj.is_a) { case "toc": - doc_epub3[segment_filename] ~= xhtml_format.toc(obj); + doc_epub3[segment_filename] ~= xhtml_format.toc_seg(obj, _txt); break; default: if ((doc_matters.opt_action_bool["debug"])) { @@ -1948,7 +1958,7 @@ void outputEPub3(D,I)( case "para": switch (obj.is_a) { case "para": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -1962,32 +1972,32 @@ void outputEPub3(D,I)( case "block": switch (obj.is_a) { case "quote": - auto t = xhtml_format.quote_seg(obj, suffix); + auto t = xhtml_format.quote_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= to!string(t[0]); doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "group": - auto t = xhtml_format.group_seg(obj, suffix); + auto t = xhtml_format.group_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= to!string(t[0]); doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "block": - auto t = xhtml_format.block_seg(obj, suffix); + auto t = xhtml_format.block_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= to!string(t[0]); doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "poem": // double check why both poem & verse break; case "verse": - auto t = xhtml_format.verse_seg(obj, suffix); + auto t = xhtml_format.verse_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= to!string(t[0]); doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "code": - doc_epub3[segment_filename] ~= xhtml_format.code(obj); + doc_epub3[segment_filename] ~= xhtml_format.code(obj, _txt); break; case "table": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; @@ -2010,26 +2020,26 @@ void outputEPub3(D,I)( case "para": switch (obj.is_a) { case "endnote": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; break; case "glossary": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "bibliography": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "bookindex": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; case "blurb": - auto t = xhtml_format.para_seg(obj, suffix); + auto t = xhtml_format.para_seg(obj, _txt, suffix); doc_epub3[segment_filename] ~= t[0]; doc_epub3_endnotes[segment_filename] ~= t[1]; break; |