module doc_reform.output.xmls; template outputXHTMLs() { import doc_reform.output; import std.digest.sha, std.file, std.outbuffer, std.zip, std.conv : to; import doc_reform.output.create_zip_file, doc_reform.output.xmls, doc_reform.output.xmls_css; mixin DocReformOutputRgxInit; struct outputXHTMLs { static auto rgx = Rgx(); string div_delimit( string part, return ref string previous_part ){ string delimit = ""; string delimit_ = ""; if (part != previous_part) { switch (part) { case "head": delimit_ ~= "\n
\n" ; break; case "toc_seg": delimit_ ~= "\n
\n" ; break; case "toc_scroll": delimit_ ~= "\n
\n" ; break; case "bookindex_seg": delimit_ ~= "\n
\n" ; break; case "bookindex_scroll": delimit_ ~= "\n
\n" ; break; default: delimit_ ~= "\n
\n" ; break; } if (previous_part.length > 0) { delimit ~= "\n
"; } previous_part = part; delimit ~= delimit_; } // you also need to close the last div, introduce a footer? return delimit; } string special_characters(O)( const O obj, string _txt ){ _txt = (_txt) .replaceAll(rgx.xhtml_ampersand, "&") .replaceAll(rgx.xhtml_quotation, """) .replaceAll(rgx.xhtml_less_than, "<") .replaceAll(rgx.xhtml_greater_than, ">") .replaceAll(rgx.nbsp_char, " "); if (!(obj.metainfo.is_a == "code")) { _txt = (_txt) .replaceAll(rgx.xhtml_line_break, "
"); } return _txt; } string special_characters_text(string _txt){ _txt = (_txt) .replaceAll(rgx.xhtml_ampersand, "&") .replaceAll(rgx.xhtml_quotation, """) .replaceAll(rgx.xhtml_less_than, "<") .replaceAll(rgx.xhtml_greater_than, ">") .replaceAll(rgx.nbsp_char, " "); return _txt; } string font_face(string _txt){ _txt = (_txt) .replaceAll(rgx.inline_emphasis, ("$1")) .replaceAll(rgx.inline_bold, ("$1")) .replaceAll(rgx.inline_underscore, ("$1")) .replaceAll(rgx.inline_italics, ("$1")) .replaceAll(rgx.inline_superscript, ("$1")) .replaceAll(rgx.inline_subscript, ("$1")) .replaceAll(rgx.inline_strike, ("$1")) .replaceAll(rgx.inline_insert, ("$1")) .replaceAll(rgx.inline_mono, ("$1")) .replaceAll(rgx.inline_cite, ("$1")); return _txt; } string _xhtml_anchor_tags(const(string[]) anchor_tags) { string tags=""; if (anchor_tags.length > 0) { foreach (tag; anchor_tags) { if (!(tag.empty)) { tags ~= ""; } } } return tags; } auto header_metadata(M)( M doc_matters, ) { string _title="Title"; string _author="Author"; string _publisher="Publisher"; string _date="Date"; string _date_created="Date"; string _date_issued="Date"; string _date_available="Date"; string _date_valid="Date"; string _date_modified="Date"; string _language="en"; string _rights="Copyright: Copyright (C) year holder"; string _generator="doc_reform [DocReform 7.1.8 of 2016w08/5 (2016-02-26)] (n*x and D)"; string _generator_home="http://www.sisudoc.org"; string o; o = format(q"¶ ¶", _title, _author, _publisher, _date, _date_created, _date_issued, _date_available, _date_valid, _date_modified, _language, _rights, _generator, _generator_home, ); return o; } auto site_info_button(M)( M doc_matters, ) { string _locations; if (doc_matters.conf_make_meta.make.home_button_text.length > 0) { _locations = (doc_matters.conf_make_meta.make.home_button_text) .replaceAll( rgx.inline_link, ("

$1

")) .replaceAll( rgx.br_line, "") .replaceAll( rgx.br_nl, ""); } else { _locations = "

DocReform

\n

www.sisudoc.org

\n

sources / git

"; } string o; o = format(q"¶
%s
¶", _locations, ); return o; } auto inline_search_form(M)( M doc_matters, ) { string _action="http://www.sisudoc.org/cgi-bin/search.cgi"; string _db="DocReform.7a.manual"; string o; o = format(q"¶

¶", _action, _db, ); return o; } auto html_head(M)( M doc_matters, string type, ) { string o; o = format(q"¶ %s%s %s
%s %s%s¶", doc_matters.conf_make_meta.meta.title_full, (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : ", " ~ doc_matters.conf_make_meta.meta.creator_author, header_metadata(doc_matters), ((type == "seg") ? "../../../" : "../../") ~ "image/rb7.ico", ((type == "seg") ? "../../../css/html_seg.css" : "../../css/html_scroll.css"), doc_matters.src.language, site_info_button(doc_matters), inline_search_form(doc_matters), ((type == "seg") ? "" : "\n
"), ); return o; } auto epub3_seg_head(M)( M doc_matters, ) { string html_base = format(q"¶ ¶", ); string html_simple = format(q"¶ ¶", doc_matters.src.language, doc_matters.src.language, ); string html_strict = format(q"¶ ¶", doc_matters.src.language, doc_matters.src.language, ); string o; o = format(q"¶%s %s%s ¶", html_simple, doc_matters.conf_make_meta.meta.title_full, (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : ", " ~ doc_matters.conf_make_meta.meta.creator_author, doc_matters.conf_make_meta.meta.title_full, (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" : ", " ~ doc_matters.conf_make_meta.meta.creator_author, doc_matters.src.language, ); return o; } auto tail() { string o; o = format(q"¶
¶"); return o; } auto inline_images(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "seg", ) { string _img_pth; if (_xml_type == "epub") { _img_pth = "image/"; } else if (_xml_type == "scroll") { _img_pth = "../../image/"; } else if (_xml_type == "seg") { _img_pth = "../../../image/"; } if (_txt.match(rgx.inline_image)) { _txt = _txt.replaceAll( rgx.inline_image, ("$1 $6")); } return _txt; } auto inline_links(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "seg", ) { if (obj.has.inline_links) { if ((_txt.match(rgx.mark_internal_site_lnk)) && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault _txt = (_txt).replaceAll( rgx.inline_seg_link, "$1"); } _txt = (_txt) .replaceAll( rgx.inline_link_fn_suffix, ("$1" ~ _suffix)) .replaceAll( rgx.inline_link, ("$1")) .replaceAll( rgx.mark_internal_site_lnk, ""); } debug(markup_links) { if (_txt.match(rgx.inline_link)) { writeln(__LINE__, " (missed) markup link identified (", obj.has.inline_links, "): ", obj.metainfo.is_a, ": ", obj.text ); } } debug(markup) { if (_txt.match(rgx.inline_link)) { writeln(__LINE__, " (missed) markup link identified (", obj.has.inline_links, "): ", obj.metainfo.is_a, ": ", obj.text ); } } return _txt; } auto inline_notes_scroll(M,O)( M doc_matters, const O obj, string _txt, ) { if (obj.has.inline_notes_reg) { _txt = font_face(_txt); _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, (" $1 ") ); } debug(markup_endnotes) { if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); } } debug(markup) { if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); } } return _txt; } auto inline_notes_seg(M,O)( M doc_matters, const O obj, string _txt, ) { string[] _endnotes; if (obj.has.inline_notes_reg) { _txt = font_face(_txt); /+ need markup for text, and separated footnote +/ foreach(m; _txt.matchAll(rgx.inline_notes_delimiter_al_regular_number_note)) { _endnotes ~= format( "%s%s%s%s\n %s%s%s%s%s\n %s\n%s", "

", "", " ", m.captures[1], ".", m.captures[2], "

" ); } _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, (" $1 ") ); } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { debug(markup) { writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); } } auto t = tuple( _txt, _endnotes, ); return t; } auto inline_markup_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", ) { _txt = inline_images(doc_matters, obj, _txt, _suffix, "scroll"); _txt = inline_links(doc_matters, obj, _txt, _suffix, "scroll"); _txt = inline_notes_scroll(doc_matters, obj, _txt); return _txt; } auto inline_markup_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "seg", ) { _txt = inline_images(doc_matters, obj, _txt, _suffix, _xml_type); // TODO _txt = inline_links(doc_matters, obj, _txt, _suffix, _xml_type); // TODO auto t = inline_notes_seg(doc_matters, obj, _txt); return t; } string lev4_heading_subtoc(M,O)( M doc_matters, const O obj, ) { char[] lev4_subtoc; lev4_subtoc ~= "
\n"; foreach (subtoc; obj.tags.lev4_subtoc) { if (auto m = subtoc.match(rgx.inline_link_subtoc)) { auto indent = m.captures[1].to!string; auto text = m.captures[2].to!string; text = font_face(text); auto link = m.captures[3].to!string; lev4_subtoc ~= subtoc.replaceFirst(rgx.inline_link_subtoc, format(q"¶

%s

¶", indent, indent, link, text, )); } } lev4_subtoc ~= "
\n"; return lev4_subtoc.to!string; } auto nav_pre_next_svg(M,O)( M doc_matters, const O obj, ) { string prev, next, toc; if (obj.tags.segment_anchor_tag == "toc") { toc = ""; prev = ""; } else { toc = format(q"¶ ¶", ); } if (obj.tags.segname_prev == "") { prev = ""; } else { prev = format(q"¶ ¶", obj.tags.segname_prev, ); } if (obj.tags.segname_next == "") { next = ""; } else { next = format(q"¶ ¶", obj.tags.segname_next, ); } string _toc_pre_next = format(q"¶
¶", toc, prev, next, ); string _pre_next = format(q"¶
¶", prev, next, ); struct bar { string toc_pre_next() { return _toc_pre_next; } string pre_next() { return _pre_next; } } return bar(); } auto heading(M,O)( M doc_matters, const O obj, string _txt, string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); string _horizontal_rule = "
"; if ((_xml_type != "html") || (obj.metainfo.heading_lev_markup == 0 || obj.metainfo.heading_lev_markup > 4)) { _horizontal_rule = ""; } _txt = font_face(_txt); string o; if (obj.metainfo.object_number.empty) { o = format(q"¶%s
%s %s
¶", _horizontal_rule, obj.metainfo.heading_lev_markup, obj.metainfo.is_a, tags, _txt, obj.metainfo.heading_lev_markup, ); } else { o = format(q"¶%s
%s %s
¶", _horizontal_rule, obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.heading_lev_markup, obj.metainfo.is_a, obj.metainfo.object_number, obj.metainfo.object_number, tags, _txt, obj.metainfo.heading_lev_markup, ); } return o; } auto heading_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = heading(doc_matters, obj, _txt); return o; } auto heading_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html" ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0]; string[] _endnotes = t[1]; string o = heading(doc_matters, obj, _txt, _xml_type); auto u = tuple( o, _endnotes, ); return u; } auto para(M,O)( M doc_matters, const O obj, string _txt, ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = font_face(_txt); string o; _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s %s

¶", obj.metainfo.is_a, obj.attrib.indent_hang, obj.attrib.indent_base, tags, _txt ); } else { o = format(q"¶

%s %s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.attrib.indent_hang, obj.attrib.indent_base, obj.metainfo.object_number, tags, _txt ); } return o; } auto para_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = para(doc_matters, obj, _txt); return o; } auto para_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = para(doc_matters, obj, _txt); auto u = tuple( o, _endnotes, ); return u; } auto quote(M,O)( M doc_matters, const O obj, string _txt, ) { _txt = font_face(_txt); string o; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s

¶", obj.metainfo.is_a, _txt ); } else { o = format(q"¶

%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, _txt ); } return o; } auto quote_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = quote(doc_matters, obj, _txt); return o; } auto quote_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = quote(doc_matters, obj, _txt); auto u = tuple( o, _endnotes, ); return u; } auto group(M,O)( M doc_matters, const O obj, string _txt, ) { _txt = font_face(_txt); string o; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s

¶", obj.metainfo.is_a, _txt ); } else { o = format(q"¶

%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, _txt ); } return o; } auto group_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = group(doc_matters, obj, _txt); return o; } auto group_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = group(doc_matters, obj, _txt); auto u = tuple( o, _endnotes, ); return u; } auto block(M,O)( M doc_matters, const O obj, string _txt, ) { _txt = font_face(_txt); string o; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s

¶", obj.metainfo.is_a, _txt.stripRight ); } else { o = format(q"¶

%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, _txt.stripRight ); } return o; } auto block_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = block(doc_matters, obj, _txt); return o; } auto block_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = block(doc_matters, obj, _txt); auto u = tuple( o, _endnotes, ); return u; } auto verse(M,O)( M doc_matters, const O obj, string _txt, ) { _txt = font_face(_txt); string o; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s

¶", obj.metainfo.is_a, _txt ); } else { o = format(q"¶

%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, _txt ); } return o; } auto verse_scroll(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = inline_markup_scroll(doc_matters, obj, _txt, _suffix); string o = verse(doc_matters, obj, _txt); return o; } auto verse_seg(M,O)( M doc_matters, const O obj, string _txt, string _suffix = ".html", string _xml_type = "html", ) { auto t = inline_markup_seg(doc_matters, obj, _txt, _suffix, _xml_type); _txt = t[0].to!string; string[] _endnotes = t[1]; string o = verse(doc_matters, obj, _txt); auto u = tuple( o, _endnotes, ); return u; } auto tablarize(M,O)( M doc_matters, const O obj, string _txt, ) { string[] _table_rows = (_txt).split(rgx.table_delimiter_row); string[] _table_cols; string _table; string _tablenote; foreach(row_idx, row; _table_rows) { _table_cols = row.split(rgx.table_delimiter_col); _table ~= ""; foreach(col_idx, cell; _table_cols) { if ((_table_cols.length == 1) && (_table_rows.length <= row_idx+2)) { _tablenote ~= cell; } else { string _col_is = (row_idx == 0 && obj.table.heading) ? "th" : "td"; string _align = ("style=\"text-align:" ~ ((obj.table.column_aligns[col_idx] == "l") ? "left\"" : "right\"")); _table ~= "<" ~ _col_is ~ " width=\"" ~ obj.table.column_widths[col_idx].to!string ~ "%\" " ~ _align ~ ">"; _table ~= cell; _table ~= ""; } } _table ~= ""; } auto t = tuple( _table, _tablenote, ); return t; } auto table(M,O)( M doc_matters, const O obj, string _txt, ) { auto tags = _xhtml_anchor_tags(obj.tags.anchor_tags); _txt = font_face(_txt); auto t = tablarize(doc_matters, obj, _txt); _txt = t[0]; string _note = t[1]; string o; o = format(q"¶

%s %s
%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, tags, _txt, _note ); return o; } auto endnote(M,O)( M doc_matters, const O obj, string _txt, ) { string o; o = format(q"¶

%s

¶", obj.metainfo.is_a, obj.attrib.indent_hang, obj.attrib.indent_base, _txt ); return o; } auto code(M,O)( M doc_matters, const O obj, string _txt, ) { string o; if (obj.metainfo.object_number.empty) { o = format(q"¶

%s

¶", obj.metainfo.is_a, _txt ); } else { o = format(q"¶

%s

¶", obj.metainfo.object_number, obj.metainfo.object_number, obj.metainfo.is_a, obj.metainfo.object_number, _txt ); } return o; } } }