From 9cf470e69b2d579701ee607f796de612dc600565 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 20 Apr 2017 13:57:03 -0400 Subject: 0.14.0 reorganized files, and paths --- org/ao_doc_abstraction.org | 40 +- org/default_misc.org | 777 +++++++++ org/default_paths.org | 436 +++++ org/default_regex.org | 475 ++++++ org/defaults.org | 1471 ---------------- org/output.org | 3442 -------------------------------------- org/output_hub.org | 185 ++ org/output_sisupod.org | 280 ++++ org/output_xmls.org | 3116 ++++++++++++++++++++++++++++++++++ org/output_zip.org | 36 + org/sdp.org | 24 +- src/sdp.d | 3 +- src/sdp/abstraction.d | 8 +- src/sdp/ao_abstract_doc_source.d | 40 +- src/sdp/ao_defaults.d | 7 +- src/sdp/ao_rgx.d | 8 +- src/sdp/defaults.d | 186 -- src/sdp/output_epub3.d | 60 +- src/sdp/output_html.d | 24 +- src/sdp/output_hub.d | 44 +- src/sdp/output_xhtmls.d | 38 +- src/sdp/paths_output.d | 287 ++++ src/sdp/paths_source.d | 59 + src/sdp/source_sisupod.d | 103 +- views/version.txt | 2 +- 25 files changed, 5887 insertions(+), 5264 deletions(-) create mode 100644 org/default_misc.org create mode 100644 org/default_paths.org create mode 100644 org/default_regex.org delete mode 100644 org/defaults.org delete mode 100644 org/output.org create mode 100644 org/output_hub.org create mode 100644 org/output_sisupod.org create mode 100644 org/output_xmls.org create mode 100644 org/output_zip.org create mode 100644 src/sdp/paths_output.d create mode 100644 src/sdp/paths_source.d diff --git a/org/ao_doc_abstraction.org b/org/ao_doc_abstraction.org index e178575..93768c1 100644 --- a/org/ao_doc_abstraction.org +++ b/org/ao_doc_abstraction.org @@ -185,7 +185,6 @@ template SiSUdocAbstraction() { <> <> <> - // <> <> <> <> @@ -625,8 +624,9 @@ scope(failure) { ); } line = (line).replaceAll(rgx.true_dollar, "$$$$"); - // dollar represented as $$ needed to stop submatching on $ - // (substitutions using ${identifiers} must take into account (i.e. happen earlier)) + /+ dollar represented as $$ needed to stop submatching on $ + (substitutions using ${identifiers} must take into account (i.e. happen earlier)) + +/ debug(source) { // source lines writeln(line); } @@ -705,7 +705,6 @@ if there is a glossary section you need to: writeln(__LINE__); writeln(line); } - // _glossary_block_(line, type); type["glossary_section"] = State.on; type["biblio_section"] = State.off; type["blurb_section"] = State.off; @@ -967,7 +966,6 @@ assert( "code block status: none or closed" ); if (type["blocks"] == TriState.closing) { - // blocks closed, unless followed by book index debug(check) { // block writeln(__LINE__); writeln(line); @@ -1041,14 +1039,13 @@ if (line.matchFirst(rgx.book_index) && ((type["para"] == State.off) && (type["heading"] == State.off))) { /+ heading make set +/ - _heading_make_set_(line, line_occur, heading_match_rgx, type); + line = _heading_make_set_(line, line_occur, heading_match_rgx, type); } /+ TODO node info: all headings identified at this point, - extract node info here?? - how long can it wait? - should be incorporated in composite objects - should happen before endnote links set (they need to be moved down?) - // node_construct.node_emitter_heading segment anchor tag +/ if (line.matchFirst(rgx.heading)) { /+ heading match +/ @@ -1191,7 +1188,6 @@ if ((type["heading"] == State.on) writeln(segment_anchor_tag_that_object_belongs_to); } the_document_body_section ~= comp_obj_heading; - // track previous heading and make assertions debug(objectrelated1) { // check writeln(line); } @@ -1256,7 +1252,6 @@ if ((type["heading"] == State.on) line == null, "line variable should be empty, should not occur" ); - // check what happens when paragraph separated by 2 newlines } #+END_SRC @@ -1401,7 +1396,6 @@ if (biblio_ordered.length > 0) { comp_obj_heading_.parent_ocn = 1; comp_obj_heading_.parent_lev_markup = 0; the_bibliography_section ~= comp_obj_heading_; - // --- comp_obj_heading_ = comp_obj_heading_.init; comp_obj_heading_.use = "backmatter"; comp_obj_heading_.is_of = "para"; @@ -2008,7 +2002,6 @@ if (the_bookindex_section["scroll"].length > 1) { foreach (ref obj; the_bookindex_section["scroll"]) { if (obj.is_a == "heading") { debug(dom) { - // writeln(obj.text); } if (obj.heading_lev_markup == 4) { obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; @@ -2094,7 +2087,6 @@ if (the_blurb_section.length > 1) { comp_obj_heading_.use = "empty"; comp_obj_heading_.is_of = "para"; comp_obj_heading_.is_a = "heading"; - // comp_obj_heading_.text = "(skip) this is the DOM tail"; comp_obj_heading_.ocn = 0; comp_obj_para.obj_cite_number = ""; comp_obj_heading_.segment_anchor_tag = ""; @@ -2530,6 +2522,9 @@ void _code_block_(L,O,T)( debug(code) { // code (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; type["blocks"] = TriState.closing; type["code"] = TriState.closing; type["curly_code"] = TriState.off; @@ -2544,6 +2539,9 @@ void _code_block_(L,O,T)( debug(code) { // code (tic) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; type["blocks"] = TriState.closing; type["code"] = TriState.closing; type["tic_code"] = TriState.off; @@ -2794,6 +2792,7 @@ void _quote_block_(L,O,T)( debug(quote) { // quote (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["quote"] = TriState.closing; type["curly_quote"] = TriState.off; @@ -2808,6 +2807,7 @@ void _quote_block_(L,O,T)( debug(quote) { // quote (tic) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["quote"] = TriState.closing; type["tic_quote"] = TriState.off; @@ -2844,6 +2844,7 @@ void _group_block_(L,O,T)( debug(group) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["group"] = TriState.closing; type["curly_group"] = TriState.off; @@ -2858,6 +2859,7 @@ void _group_block_(L,O,T)( debug(group) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["group"] = TriState.closing; type["tic_group"] = TriState.off; @@ -2895,6 +2897,7 @@ void _block_block_(L,O,T)( debug(block) { // block (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["block"] = TriState.closing; type["curly_block"] = TriState.off; @@ -2909,6 +2912,7 @@ void _block_block_(L,O,T)( debug(block) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["block"] = TriState.closing; type["tic_block"] = TriState.off; @@ -3007,6 +3011,7 @@ void _poem_block_(L,O,T,C,N,Ma)( ocn_emit(type["ocn_status"]); type["verse_new"] = State.off; } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; verse_line = TriState.off; type["verse_new"] = State.on; } @@ -3099,6 +3104,7 @@ void _poem_block_(L,O,T,C,N,Ma)( ocn_emit(type["ocn_status"]); type["verse_new"] = State.off; } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; type["verse_new"] = State.on; verse_line = TriState.off; } @@ -3298,7 +3304,6 @@ void _block_flag_line_empty_(B)( string[string] obj_cite_number_poem, string[string][string] dochead_make_aa, ) { - // line.empty, post contents, empty variables --------------- assert( line.empty, "line should be empty" @@ -3812,6 +3817,7 @@ auto _heading_make_set_(L,C,R,T)( } } } + return line; } #+END_SRC @@ -4792,7 +4798,6 @@ struct ObjInlineMarkup { switch (obj_["is"]) { case "heading": static __gshared string anchor_tag = ""; - // TODO WORK ON, you still need to ensure that level 1 anchor_tags are unique obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, dochead_make_aa); obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); if (auto m = obj_txt["munge"].match(rgx.heading_anchor_tag)) { @@ -6215,9 +6220,10 @@ struct Bibliography { static assert(is(typeof(bib_arr_json) == JSONValue[])); } foreach (bibent; biblio_unordered) { - // update bib to include deemed_author, needed for: - // sort_bibliography_array_by_deemed_author_year_title - // either: sort on multiple fields, or; create such sort field + /+ update bib to include deemed_author, needed for: + sort_bibliography_array_by_deemed_author_year_title + either: sort on multiple fields, or; create such sort field + +/ JSONValue j = parseJSON(bibent); if (!empty(j["fulltitle"].str)) { if (!empty(j["author_raw"].str)) { diff --git a/org/default_misc.org b/org/default_misc.org new file mode 100644 index 0000000..4b835b1 --- /dev/null +++ b/org/default_misc.org @@ -0,0 +1,777 @@ +#+TITLE: sdp defaults misc +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* 0. ao defaults :defaults: +** 0. tangle template + +#+name: tangle_defaults +#+BEGIN_SRC d :tangle ../src/sdp/ao_defaults.d +/++ + default settings ++/ +template SiSUregisters() { + <> + <> +} +<> +<> +<> +<> +<> +#+END_SRC + +** imports + +#+name: ao_defaults_imports +#+BEGIN_SRC d +private import + std.algorithm, + std.array, + std.container, + std.exception, + std.file, + std.getopt, + std.json, + std.path, + std.process, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; +#+END_SRC + +** settings metadata associative array indexes :settings: +**** conf associative array + +#+name: ao_defaults_template_registers +#+BEGIN_SRC d +string[string][string] conf_aa() { + auto conf_ = [ + "webserv": [ + "url_root" : "", + "path" : "~/sdp_www" , + "images" : "" , + "cgi" : "/usr/local/lib/sdp-cgi" + ], + "webserv_cgi": [ + "host" : "localhost", + "base_path" : "", + "port" : "8081", + "user" : "", + "file_links" : "www.sisudoc.org" + ], + "processing": [ + "path" : "~", + "dir" : "_sisu_processing", + "concord_max" : "400000" + ], + "flag": [ + "act0" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --manifest --verbose", + "act1" : "--digest --text --html --manifest", + "act2" : "--digest --text --html --epub --pdf --manifest", + "act3" : "--digest --qrcode --text --html --epub --concordance --pdf --manifest", + "act4" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --manifest", + "act5" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --sqlite --manifest", + "act6" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --manifest", + "act7" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --source --sisupod --manifest", + "act8" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --pg --update --manifest", + "act9" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --pg --update --source --sisupod --manifest" + ], + "default": [ + "papersize" : "a4,letter", + "text_wrap" : "78", + "emphasis" : "bold", + "language" : "en", + "digest" : "sha256" + ], + "permission": [ + "share_source" : "" + ], + "program_select": [ + "editor" : "vim", + "epub_viewer" : "ebook-viewer", + "html_viewer" : "xombrero", + "odf_viewer" : "lowriter", + "pdf_viewer" : "evince", + "xml_viewer" : "xml-viewer" + ], + "search": [ + "flag" : "", + "action" : "", + "db" : "", + "title" : "" + ] + ]; + return conf_; +} +#+END_SRC + +**** make associative array + +#+name: ao_defaults_template_registers +#+BEGIN_SRC d +string[string][string] make_aa() { + auto make_ = [ + "make": [ + "bold" : "", + "breaks" : "", + "cover_image" : "", + "css" : "", + "emphasis" : "", + "footer" : "", + "headings" : "", + "home_button_image" : "", + "home_button_text" : "", + "italics" : "", + "num_top" : "", + "num_depth" : "", + "substitute" : "", + "texpdf_font" : "" + ] + ]; + return make_; +} +#+END_SRC + +**** meta (metadata) associative array + +#+name: ao_defaults_template_registers +#+BEGIN_SRC d +string[string][string] meta_aa() { + auto meta_ = [ + "classify": [ + "dewey" : "", + "keywords" : "", + "loc" : "", + "subject" : "", + "topic_register" : "" + ], + "creator": [ + "author" : "", + "author_email" : "", + "illustrator" : "", + "translator" : "" + ], + "date": [ + "added_to_site" : "", + "available" : "", + "created" : "", + "issued" : "", + "modified" : "", + "published" : "", + "valid" : "" + ], + "identifier": [ + "isbn" : "", + "oclc" : "", + "pg" : "" + ], + "links": [ + "link" : "" + ], + "notes": [ + "abstract" : "", + "description" : "" + ], + "original": [ + "language" : "", + "source" : "", + "title" : "" + ], + "publisher": [ + "name" : "" + ], + "rights": [ + "copyright" : "", + "cover" : "", + "illustrations" : "", + "license" : "" + ], + "title": [ + "edition" : "", + "full" : "", + "language" : "", + "main" : "", + "note" : "", + "sub" : "", + "subtitle" : "" + ] + ]; + return meta_; +} +#+END_SRC + +** metadata associative array indexes :header: + +#+name: ao_defaults_template_registers +#+BEGIN_SRC d +auto ptr_head_main = + [ + "classify", + "creator", + "date", + "identifier", + "links", + "make", /+ make +/ + "original", + "notes", + "rights", + "title" + ]; +auto ptr_head_sub_classify = + [ + "dewey", + "keywords", + "loc", + "subject", + "topic_register" + ]; +auto ptr_head_sub_creator = + [ + "author", + "author_email", + "cover", + "illustrator", + "translator" + ]; +auto ptr_head_sub_date = + [ + "added_to_site", + "available", + "created", + "issued", + "modified", + "published", + "valid" + ]; +auto ptr_head_sub_identifier = + [ + "isbn", + "oclc", + "pg" + ]; +/+ make +/ +auto ptr_head_sub_make = + [ + "cover_image", + "home_button_image", + "home_button_text", + "footer", "headings", + "num_top", "num_depth", + "breaks", + "substitute", + "bold", + "italics", + "emphasis", + "texpdf_font", + "css" + ]; +auto ptr_head_sub_notes = + [ + "abstract", + "description" + ]; +auto ptr_head_sub_original = + [ + "language", + "source", + "title" + ]; +auto ptr_head_sub_publisher = + [ "name" ]; +auto ptr_head_sub_rights = + [ + "copyright", + "cover", + "illustrations", + "license" + ]; +auto ptr_head_sub_title = + [ + "edition", + "full", + "language", + "main", + "note", + "sub" + ]; +auto config_jsonstr = `{ +}`; +#+END_SRC + +*** notes headers + +#+name: ao_defaults_template +#+BEGIN_SRC d +/+ + /+ + unify internal representation of header info for native & sdlang document headers + represent either using struct, hashes or possibly json + sdp internal representation should be identical for native & sdlang variants + +/ +header. + ├── make // make instructions + │   ├── bold + │   ├── breaks + │   ├── cover_image + │   ├── css + │   ├── emphasis + │   ├── footer + │   ├── headings + │   ├── home_button_image + │   ├── home_button_text + │   ├── italics + │   ├── num_top + │   ├── substitute + │   └── texpdf_font + └── meta // metadata +    ├── author // move author to creator:author +    ├── classify +    │   ├── dewey +    │   ├── keyword +    │   ├── loc +    │   ├── subject +    │   └── topic_register +    ├── creator +    │   ├── author + │ │ ├── [ [first_name: x0, last_name: y0], [first_name: x1, last_name: y1] ] + │ │ └── [ full_name0, full_name1 ] +    │   ├── author_email +    │   ├── illustrator +    │   └── translator +    ├── date +    │   ├── added_to_site +    │   ├── available +    │   ├── created +    │   ├── issued +    │   ├── modified +    │   ├── published +    │   └── valid +    ├── identifier +    │   ├── isbn +    │   ├── oclc +    │   └── pg +    ├── links +    ├── notes +    │   ├── abstract +    │   └── description +    ├── original +    │   ├── language +    │   ├── source +    │   └── title +    ├── publisher +    │   └── name +    ├── rights +    │   ├── copyright +    │   ├── cover +    │   ├── illustrations +    │   └── license +    └── title // move title: to title:main +    ├── edition +    ├── [ full (main + sub) ] +    ├── language +    ├── main +    ├── note +    ├── sub +    └── subtitle // move title:subtitle to title:sub + +61 leaves ++/ +#+END_SRC + +** template: flags regex initialize :regex_flags: + +#+name: ao_defaults_template_init_flags +#+BEGIN_SRC d +template SiSUrgxInitFlags() { + /+ regex flags +/ + int[string] flags_type_init() { + int[string] flags_type_init = [ + "make_headings" : 0, + "header_make" : 0, + "header_meta" : 0, + "heading" : 0, + "biblio_section" : 0, + "glossary_section" : 0, + "blurb_section" : 0, + "para" : 0, + "blocks" : 0, // 0..2 generic + "code" : 0, // 0..2 + "poem" : 0, // 0..2 + "table" : 0, // 0..2 + "group" : 0, // 0..2 + "block" : 0, // 0..2 + "quote" : 0, // 0..2 + "verse_new" : 0, + "curly_code" : 0, + "curly_poem" : 0, + "curly_group" : 0, + "curly_block" : 0, + "curly_quote" : 0, + "curly_table" : 0, + "curly_table_special_markup" : 0, + "tic_code" : 0, + "tic_poem" : 0, + "tic_group" : 0, + "tic_block" : 0, + "tic_quote" : 0, + "tic_table" : 0, + "ocn_status" : 0, // 0 obj_cite_number; 1 no obj_cite_number; 2 no obj_cite_number & dummy headings + "ocn_status_multi_obj" : 0, // 0 obj_cite_number; 1 no obj_cite_number; 2 no obj_cite_number & dummy headings + "book_index" : 0, + ]; + return flags_type_init; + } +} +#+END_SRC + +#+name: ao_defaults_template_node +#+BEGIN_SRC d +template SiSUnode() { + string[string] node_metadata_heading_str() { + auto _node = [ + "is" : "", + "ocn" : "", + "marked_up_lev" : "", + "segment_anchor_tag" : "", + "attrib" : "", + ]; + return _node; + } + int[string] node_metadata_heading_int() { + auto _node = [ + "ocn" : 0, // decide whether to use or keep? + "ptr_doc_object" : 0, + "ptr_html_segnames" : 0, + "ptr_heading" : 0, + "heading_lev_markup" : 9, + "heading_lev_collapsed" : 9, + "parent_ocn" : 0, + "parent_lev_markup" : 9, + ]; + return _node; + } + string[string] node_metadata_para_str() { + auto _node = [ + "is" : "", + "ocn" : "", + "attrib" : "", + // "segment_anchor_tag" : "", + ]; + return _node; + } + int[string] node_metadata_para_int() { + auto _node = [ + "ocn" : 0, + "indent_base" : 0, + "indent_hang" : 0, + "bullet" : 0, // bool (0|1) + // "ptr_doc_object" : 0, + // "ptr_html_segnames" : 0, + // "parent_ocn" : 0, + // "parent_lev_markup" : 9, + ]; + return _node; + } +} +#+END_SRC + +** template: bibliography :biblio: + +#+name: ao_defaults_template_biblio +#+BEGIN_SRC d +template SiSUbiblio() { + // required: deemed_author (author || editor); year; fulltitle; + struct BibJsnStr { + auto biblio_entry_tags_jsonstr() { + string x = `{ + "is" : "", + "sortby_deemed_author_year_title" : "", + "deemed_author" : "", + "author_raw" : "", + "author" : "", + "author_arr" : [ "" ], + "editor_raw" : "", + "editor" : "", + "editor_arr" : [ "" ], + "title" : "", + "subtitle" : "", + "fulltitle" : "", + "language" : "", + "trans" : "", + "src" : "", + "journal" : "", + "in" : "", + "volume" : "", + "edition" : "", + "year" : "", + "place" : "", + "publisher" : "", + "url" : "", + "pages" : "", + "note" : "", + "short_name" : "", + "id" : "" + }`; // is: book, article, magazine, newspaper, blog, other + return x; + } + } +} +#+END_SRC + +* 1. output defaults +** 0. tangle: :defaults: + +#+name: tangle_defaults +#+BEGIN_SRC d :tangle ../src/sdp/defaults.d +/++ + default settings ++/ +<> +<> +<> +#+END_SRC + +** imports + +#+name: defaults_imports +#+BEGIN_SRC d +private import + std.algorithm, + std.array, + std.container, + std.exception, + std.file, + std.getopt, + std.json, + std.path, + std.process, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; +#+END_SRC + +* 2. defaults shared by ao & output (generic) +** template: internal markup :markup: + +#+name: defaults_template_markup +#+BEGIN_SRC d +template InternalMarkup() { + struct InlineMarkup { + auto en_a_o = "【"; auto en_a_c = "】"; // endnote en_a_o: '~{'; en_a_c: '}~'; + auto en_b_o = "〖"; auto en_b_c = "〗"; // endnote en_b_o: '~['; en_b_c: ']~'; + auto lnk_o = "┥"; auto lnk_c = "┝"; // auto lnk_o = "⌠"; auto lnk_c = "⌡"; // '⌈' '⌋' '⌠' '⌡' #Mx[:lnk_o= '◁'; Mx[:lnk_c= '▷' #‹ › + auto url_o = "┤"; auto url_c = "├"; + auto mark_internal_site_lnk = "¤"; + auto nbsp = "░"; + auto br_line = "┘"; // "╱"; // lB ▌ 9612 ┘ ¶ + auto br_nl = "┙"; // "╲"; // lB ▌ 』 ┘ + auto br_paragraph = "┚"; // "█"; // FB █ 9608 # PP ∥ 8741 #▐ #'┘' #'¶' #FB █ 9608 lB ▌ 9612 RB ▐ 9616 + auto br_obj = "break_obj"; + auto br_page_line = "┼"; // "▭"; + auto br_page = "┿"; // "┼"; + auto br_page_new = "╂"; // "╋"; + auto tc_s = "┊"; // "┴"; //"『"; // "┏" ┓ + auto tc_o = "┏"; //"『"; // "┏" ┓ + auto tc_c = "┚"; // "』"; // "┚" table row mark #Mx[:tc_c]="』\n" + auto tc_p = "┆"; // table col/misc mark + string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { + _indent_spaces = replicate(_indent_spaces, indent); + return _indent_spaces; + } + string repeat_character_by_number_provided(C,N)(C _character ="-", N number=10) { + _character = replicate(_character, number); + return _character; + } + } +} +#+END_SRC + +** template language codes + +#+name: defaults_template_language_codes +#+BEGIN_SRC d +template SiSUlanguageCodes() { + /+ language codes +/ + struct Lang { + string[string][string] codes() { + auto _lang_codes = [ + "am": [ "c": "am", "n": "Amharic", "t": "Amharic", "xlp": "amharic" ], + "bg": [ "c": "bg", "n": "Bulgarian", "t": "Български (Bəlgarski)", "xlp": "bulgarian" ], + "bn": [ "c": "bn", "n": "Bengali", "t": "Bengali", "xlp": "bengali" ], + "br": [ "c": "br", "n": "Breton", "t": "Breton", "xlp": "breton" ], + "ca": [ "c": "ca", "n": "Catalan", "t": "catalan", "xlp": "catalan" ], + "cs": [ "c": "cs", "n": "Czech", "t": "česky", "xlp": "czech" ], + "cy": [ "c": "cy", "n": "Welsh", "t": "Welsh", "xlp": "welsh" ], + "da": [ "c": "da", "n": "Danish", "t": "dansk", "xlp": "danish" ], + "de": [ "c": "de", "n": "German", "t": "Deutsch", "xlp": "german" ], + "el": [ "c": "el", "n": "Greek", "t": "Ελληνικά (Ellinika)", "xlp": "greek" ], + "en": [ "c": "en", "n": "English", "t": "English", "xlp": "english" ], + "eo": [ "c": "eo", "n": "Esperanto", "t": "Esperanto", "xlp": "esperanto" ], + "es": [ "c": "es", "n": "Spanish", "t": "español", "xlp": "spanish" ], + "et": [ "c": "et", "n": "Estonian", "t": "Estonian", "xlp": "estonian" ], + "eu": [ "c": "eu", "n": "Basque", "t": "basque", "xlp": "basque" ], + "fi": [ "c": "fi", "n": "Finnish", "t": "suomi", "xlp": "finnish" ], + "fr": [ "c": "fr", "n": "French", "t": "français", "xlp": "french" ], + "ga": [ "c": "ga", "n": "Irish", "t": "Irish", "xlp": "irish" ], + "gl": [ "c": "gl", "n": "Galician", "t": "Galician", "xlp": "galician" ], + "he": [ "c": "he", "n": "Hebrew", "t": "Hebrew", "xlp": "hebrew" ], + "hi": [ "c": "hi", "n": "Hindi", "t": "Hindi", "xlp": "hindi" ], + "hr": [ "c": "hr", "n": "Croatian", "t": "Croatian", "xlp": "croatian" ], + "hy": [ "c": "hy", "n": "Armenian", "t": "Armenian", "xlp": "armenian" ], + "ia": [ "c": "ia", "n": "Interlingua", "t": "Interlingua", "xlp": "interlingua" ], + "is": [ "c": "is", "n": "Icelandic", "t": "Icelandic", "xlp": "icelandic" ], + "it": [ "c": "it", "n": "Italian", "t": "Italiano", "xlp": "italian" ], + "ja": [ "c": "ja", "n": "Japanese", "t": "日本語 (Nihongo)", "xlp": "japanese" ], + "ko": [ "c": "ko", "n": "Korean", "t": "Korean", "xlp": "korean" ], + "la": [ "c": "la", "n": "Latin", "t": "Latin", "xlp": "latin" ], + "lo": [ "c": "lo", "n": "Lao", "t": "Lao", "xlp": "lao" ], + "lt": [ "c": "lt", "n": "Lithuanian", "t": "Lithuanian", "xlp": "lithuanian" ], + "lv": [ "c": "lv", "n": "Latvian", "t": "Latvian", "xlp": "latvian" ], + "ml": [ "c": "ml", "n": "Malayalam", "t": "Malayalam", "xlp": "malayalam" ], + "mr": [ "c": "mr", "n": "Marathi", "t": "Marathi", "xlp": "marathi" ], + "nl": [ "c": "nl", "n": "Dutch", "t": "Nederlands", "xlp": "dutch" ], + "no": [ "c": "no", "n": "Norwegian", "t": "norsk", "xlp": "norsk" ], + "nn": [ "c": "nn", "n": "Norwegian Nynorsk", "t": "nynorsk", "xlp": "nynorsk" ], + "oc": [ "c": "oc", "n": "Occitan", "t": "Occitan", "xlp": "occitan" ], + "pl": [ "c": "pl", "n": "Polish", "t": "polski", "xlp": "polish" ], + "pt": [ "c": "pt", "n": "Portuguese", "t": "Português", "xlp": "portuges" ], + "pt_BR": [ "c": "pt_BR", "n": "Portuguese Brazil", "t": "Brazilian Português", "xlp": "brazilian" ], + "ro": [ "c": "ro", "n": "Romanian", "t": "română", "xlp": "romanian" ], + "ru": [ "c": "ru", "n": "Russian", "t": "Русский (Russkij)", "xlp": "russian" ], + "sa": [ "c": "sa", "n": "Sanskrit", "t": "Sanskrit", "xlp": "sanskrit" ], + "se": [ "c": "se", "n": "Sami", "t": "Samin", "xlp": "samin" ], + "sk": [ "c": "sk", "n": "Slovak", "t": "slovensky", "xlp": "slovak" ], + "sl": [ "c": "sl", "n": "Slovenian", "t": "Slovenian", "xlp": "slovenian" ], + "sq": [ "c": "sq", "n": "Albanian", "t": "Albanian", "xlp": "albanian" ], + "sr": [ "c": "sr", "n": "Serbian", "t": "Serbian", "xlp": "serbian" ], + "sv": [ "c": "sv", "n": "Swedish", "t": "svenska", "xlp": "swedish" ], + "ta": [ "c": "ta", "n": "Tamil", "t": "Tamil", "xlp": "tamil" ], + "te": [ "c": "te", "n": "Telugu", "t": "Telugu", "xlp": "telugu" ], + "th": [ "c": "th", "n": "Thai", "t": "Thai", "xlp": "thai" ], + "tk": [ "c": "tk", "n": "Turkmen", "t": "Turkmen", "xlp": "turkmen" ], + "tr": [ "c": "tr", "n": "Turkish", "t": "Türkçe", "xlp": "turkish" ], + "uk": [ "c": "uk", "n": "Ukranian", "t": "українська (ukrajins\"ka)", "xlp": "ukrainian" ], + "ur": [ "c": "ur", "n": "Urdu", "t": "Urdu", "xlp": "urdu" ], + "us": [ "c": "en", "n": "English (American)","t": "English", "xlp": "english" ], + "vi": [ "c": "vi", "n": "Vietnamese", "t": "Vietnamese", "xlp": "vietnamese" ], + "zh": [ "c": "zh", "n": "Chinese", "t": "中文", "xlp": "chinese" ], + "en": [ "c": "en", "n": "English", "t": "English", "xlp": "english" ], + "xx": [ "c": "xx", "n": "Default", "t": "English", "xlp": "english" ], + ]; + return _lang_codes; + } + string[] code_arr_ptr() { + auto _lang_codes = ["am", "bg", "bn", "br", "ca", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fi", "fr", "ga", "gl", "he", "hi", "hr", "hy", "ia", "is", "it", "ja", "ko", "la", "lo", "lt", "lv", "ml", "mr", "nl", "no", "nn", "oc", "pl", "pt", "pt_BR", "ro", "ru", "sa", "se", "sk", "sl", "sq", "sr", "sv", "ta", "te", "th", "tk", "tr", "uk", "ur", "us", "vi", "zh", "en", "xx",]; + return _lang_codes; + } + string[] code_arr() { + auto _lang_codes = ["am", "bg", "bn", "br", "ca", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fi", "fr", "ga", "gl", "he", "hi", "hr", "hy", "ia", "is", "it", "ja", "ko", "la", "lo", "lt", "lv", "ml", "mr", "nl", "no", "nn", "oc", "pl", "pt", "pt_BR", "ro", "ru", "sa", "se", "sk", "sl", "sq", "sr", "sv", "ta", "te", "th", "tk", "tr", "uk", "ur", "vi", "zh"]; + return _lang_codes; + } + auto codes_() { + return "(" ~ join(code_arr,"|") ~ ")"; + } + auto codes_regex() { + return regex(codes_); + } + } +} +#+END_SRC + +* +set colors for terminal+ (unused) :colors:terminal: + +#+name: ao_ansi_colors +#+BEGIN_SRC d +string[string] scr_txt_color = [ + "off" : "\033[0m", + "white" : "\033[37m", + "white_bold" : "\033[1m", + "marker" : "\033[42m", + "bold" : "\033[1m", + "underline" : "\033[4m", + "invert" : "\033[7m", + "darkgrey_hi" : "\033[100m", + "grey_hi" : "\033[47m", + "pink_hi" : "\033[105m", + "fuchsia_hi" : "\033[45m", + "red_hi" : "\033[41m", + "orange_hi" : "\033[101m", + "yellow_hi" : "\033[103m", + "brown_hi" : "\033[43m", + "lightgreen_hi" : "\033[102m", + "green_hi" : "\033[42m", + "cyan_hi" : "\033[106m", + "blue_hi" : "\033[104m", + "navy_hi" : "\033[44m", + "grey" : "\033[90m", + "pink" : "\033[95m", + "fuchsia" : "\033[35m", + "ruby" : "\033[31m", + "red" : "\033[91m", + "orange" : "\033[91m", + "yellow" : "\033[93m", + "brown" : "\033[33m", + "green" : "\033[92m", + "darkgreen" : "\033[32m", + "cyan" : "\033[36m", + "blue" : "\033[94m", + "navy" : "\033[34m", + "black" : "\033[30m" +]; +string[string] scr_txt_marker = [ + "white" : "\033[37m*\033[0m ", + "bold" : "\033[1m*\033[0m ", + "invert" : "\033[7m*\033[0m ", + "darkgrey_hi" : "\033[100m*\033[0m ", + "grey_hi" : "\033[47m*\033[0m ", + "pink_hi" : "\033[105m*\033[0m ", + "fuchsia_hi" : "\033[45m*\033[0m ", + "red_hi" : "\033[41m*\033[0m ", + "orange_hi" : "\033[101m*\033[0m ", + "yellow_hi" : "\033[103m*\033[0m ", + "brown_hi" : "\033[43m*\033[0m ", + "lightgreen_hi" : "\033[102m*\033[0m ", + "green_hi" : "\033[42m*\033[0m ", + "cyan_hi" : "\033[106m*\033[0m ", + "blue_hi" : "\033[104m*\033[0m ", + "navy_hi" : "\033[44m*\033[0m ", + "grey" : "\033[90m*\033[0m ", + "pink" : "\033[95m*\033[0m ", + "fuchsia" : "\033[35m*\033[0m ", + "ruby" : "\033[31m*\033[0m ", + "red" : "\033[91m*\033[0m ", + "orange" : "\033[91m*\033[0m ", + "yellow" : "\033[93m*\033[0m ", + "brown" : "\033[33m*\033[0m ", + "green" : "\033[92m*\033[0m ", + "darkgreen" : "\033[32m*\033[0m ", + "cyan" : "\033[36m*\033[0m ", + "blue" : "\033[94m*\033[0m ", + "navy" : "\033[34m*\033[0m ", + "black" : "\033[30m*\033[0m " +]; +#+END_SRC diff --git a/org/default_paths.org b/org/default_paths.org new file mode 100644 index 0000000..4c1cb3d --- /dev/null +++ b/org/default_paths.org @@ -0,0 +1,436 @@ +#+TITLE: sdp default paths +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:ao:read:file: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* 0. source paths :paths:dir:source: + +#+BEGIN_SRC d :tangle ../src/sdp/paths_source.d +/++ + read configuration files
+ - read config files
+ ao_config_files.d ++/ +import std.array, + std.path, + std.regex, + std.stdio; +import ao_rgx; +template SiSUpathsSRC() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSRC(D,Fn)( + D _pwd, + Fn _fn_src, + ) { + struct SisuSrcPaths { + auto pwd() { + return _pwd; + } + auto language() { + // use command line info as well? + string _k; + if (auto m = _fn_src.match(rgx.language_code_and_filename)) { + _k = m.captures[1]; + } else { + _k = "en"; + } + return _k; + } + auto doc_root() { + return "sisudoc"; + } + auto text_root() { + return doc_root.chainPath("text").array; + } + auto media_root() { + return doc_root.chainPath("docmedia").array; + } + auto conf_root() { + return doc_root.chainPath("conf").array; + } + auto image_root() { + return media_root.chainPath("image").array; + } + auto doc_src_fn_with_path_for_text_root_and_lng() { + return text_root.chainPath(language).array; + } + auto doc_src_with_relative_path() { + return pwd.chainPath(_fn_src).array; + } + auto doc_src_fn() { + return _fn_src.baseName.array; + } + } + return SisuSrcPaths(); + } +} +#+END_SRC + +* 1. output paths :paths:dir:output: +** 0. tangle, template output paths + +#+BEGIN_SRC d :tangle ../src/sdp/paths_output.d +/++ + default settings ++/ +import std.array, + std.path, + std.regex, + std.stdio; +import ao_rgx; +<> +<> +<> +<> +<> +<> +#+END_SRC + +** _sisupod_ (output bundled source) :sisupod: + +tree sisupod +sisupod +└── sisudoc + ├── conf + │   └── sisu_document_make + ├── docmedia + │   ├── audio + │   ├── image + │   └── video + ├── sisudoc.txt + └── text + └── en + +_replace:_ + +doc +├── en +│   └── the_wealth_of_networks.yochai_benkler.sst +└── _sisu + └── sisu_document_make + +*** pod archive + +#+name: template_paths_sisupod +#+BEGIN_SRC d +template SiSUpathsSisupod() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + string base_dir = "sisupod"; + string suffix = ".zip"; + auto SiSUpathsSisupod()() { + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string sisupod_filename(string fn_src) { + return base_dir.chainPath(base_filename(fn_src) ~ suffix).array; + } + string base(string fn_src) { + return base_dir.chainPath(base_filename(fn_src)).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +*** pod zipped archive + +#+name: template_paths_sisupod_zipped_archive +#+BEGIN_SRC d +template SiSUpathsSisupodZipped() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSisupodZipped(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + auto spod_pths = SiSUpathsSisupod!()(); // SiSUpodPaths(); + string base_filename(string fn_src) { + return spod_pths.base_filename(fn_src); + } + string sisupod_filename(string fn_src) { + return spod_pths.sisupod_filename(fn_src); + } + string base(string fn_src) { + return spod_pths.base(fn_src); + } + auto pod_root(string fn_src) { + return "sisudoc"; + } + auto text_root(string fn_src) { + return pod_root(fn_src).chainPath("text").array; + } + auto media_root(string fn_src) { + return pod_root(fn_src).chainPath("docmedia").array; + } + auto conf_root(string fn_src) { + return pod_root(fn_src).chainPath("conf").array; + } + auto doc(string fn_src) { + return text_root(fn_src); // or pod_root? + } + auto doc_lng(string fn_src) { + return text_root(fn_src).chainPath(lng).array; + } + auto image_root(string fn_src) { + return media_root(fn_src).chainPath("image").array; + } + auto css(string fn_src) { + return conf_root(fn_src).chainPath("css").array; + } + auto fn_doc(string fn_src) { + return (doc_lng(fn_src)).chainPath(fn_src.baseName).array; + } + auto fn_doc_insert(string fn_src, string fn_insert) { + return (doc_lng(fn_src)).chainPath(fn_insert.baseName).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +*** pod unzipped (sisusrc), archive on filesystem + +#+name: template_paths_sisupod_unzipped_filesystem +#+BEGIN_SRC d +template SiSUpathsSisupodFileSystem() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSisupodFileSystem(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + auto spod_pths = SiSUpathsSisupod!()(); // SiSUpodPaths(); + string base_filename(string fn_src) { + return spod_pths.base_filename(fn_src); + } + string sisupod_filename(string fn_src) { + return spod_pths.sisupod_filename(fn_src); + } + string base(string fn_src) { + return spod_pths.base(fn_src); + } + auto pod_root(string fn_src) { + return base(fn_src).chainPath("sisudoc").array; + } + auto text_root(string fn_src) { + return pod_root(fn_src).chainPath("text").array; + } + auto media_root(string fn_src) { + return pod_root(fn_src).chainPath("docmedia").array; + } + auto conf_root(string fn_src) { + return pod_root(fn_src).chainPath("conf").array; + } + auto doc(string fn_src) { + return pod_root(fn_src); + } + auto doc_lng(string fn_src) { + return text_root(fn_src).chainPath(lng).array; + } + auto image_root(string fn_src) { + return media_root(fn_src).chainPath("image").array; + } + auto css(string fn_src) { + return conf_root(fn_src).chainPath("css").array; + } + auto fn_doc(string fn_src) { + return (doc_lng(fn_src)).chainPath(fn_src.baseName).array; + } + auto fn_doc_insert(string fn_src, string fn_insert) { + return (doc_lng(fn_src)).chainPath(fn_insert.baseName).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +** shared out path, base directory :out: + +#+name: template_paths_out +#+BEGIN_SRC d +template SiSUoutPaths() { + auto SiSUoutPaths(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + string output_root() { + return "sisugen"; + } + string output_base() { + return output_root.chainPath(lng).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +** _html_ :html: + +#+name: template_paths_html +#+BEGIN_SRC d +template SiSUpathsHTML() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsHTML(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + auto out_pth = SiSUoutPaths!()(src_pth_info, lng); + string base_dir = "html"; + string suffix = ".html"; + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string base() { + return (out_pth.output_base).chainPath(base_dir).array; + } + string image() { + return (out_pth.output_root).chainPath("image").array; + } + string css() { + return (out_pth.output_root).chainPath("css").array; + } + string fn_css() { + return css.chainPath("html.css").array; + } + string seg(string fn_src) { + return base.chainPath(base_filename(fn_src)).array; + } + string fn_scroll(string fn_src) { + return base.chainPath(base_filename(fn_src) ~ suffix).array; + } + string fn_seg(string fn_src, string seg_filename) { + return seg(fn_src).chainPath(seg_filename ~ suffix).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +** _epub_ :epub: + +#+name: template_paths_epub +#+BEGIN_SRC d +template SiSUpathsEPUB() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsEPUB(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + auto out_pth = SiSUoutPaths!()(src_pth_info, lng); + string base_dir = "epub"; + struct _PathsStruct { + string base() { + return (out_pth.output_base).chainPath(base_dir).array; + } + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string epub_file(string fn_src) { + return base.chainPath(base_filename(fn_src) ~ ".epub").array; + } + string dirtop() { + return "".chainPath("").array; + } + string doc_meta_inf(string fn_src) { + return dirtop.chainPath("META-INF").array; + } + string doc_oebps(string fn_src) { + return dirtop.chainPath("OEBPS").array; + } + string doc_oebps_css(string fn_src) { + return doc_oebps(fn_src).chainPath("css").array; + } + string doc_oebps_image(string fn_src) { + return doc_oebps(fn_src).chainPath("image").array; + } + string fn_mimetypes(string fn_src) { + return dirtop.chainPath("mimetypes").array; + } + string fn_dmi_container_xml(string fn_src) { + return doc_meta_inf(fn_src).chainPath("container.xml").array; + } + string fn_oebps_toc_nav_xhtml(string fn_src) { + return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; + } + string fn_oebps_toc_ncx(string fn_src) { + return doc_oebps(fn_src).chainPath("toc.ncx").array; + } + string fn_oebps_content_opf(string fn_src) { + return doc_oebps(fn_src).chainPath("content.opf").array; + } + string fn_oebps_content_xhtml(string fn_src, string seg_filename) { + return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; + } + string fn_oebps_css(string fn_src) { + return doc_oebps_css(fn_src).chainPath("epub.css").array; + } + debug(epub_output) { + string dbg_docdir(string fn_src) { + return base.chainPath(base_filename(fn_src)).array; + } + string dbg_docdir_oebps(string fn_src) { + return dbg_docdir(fn_src).chainPath("OEBPS").array; + } + string dbg_doc_meta_inf(string fn_src) { + return dbg_docdir(fn_src).chainPath("META-INF").array; + } + string dbg_doc_oebps(string fn_src) { + return dbg_docdir(fn_src).chainPath("OEBPS").array; + } + string dbg_doc_oebps_css(string fn_src) { + return dbg_doc_oebps(fn_src).chainPath("css").array; + } + string dbg_doc_oebps_image(string fn_src) { + return dbg_doc_oebps(fn_src).chainPath("image").array; + } + string dbg_fn_mimetypes(string fn_src) { + return dbg_docdir(fn_src).chainPath("mimetypes").array; + } + string dbg_fn_dmi_container_xml(string fn_src) { + return dbg_doc_meta_inf(fn_src).chainPath("container.xml").array; + } + string dbg_fn_oebps_toc_nav_xhtml(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("toc_nav.xhtml").array; + } + string dbg_fn_oebps_toc_ncx(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("toc.ncx").array; + } + string dbg_fn_oebps_content_opf(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("content.opf").array; + } + string dbg_fn_oebps_content_xhtml(string fn_src, string seg_filename) { + return dbg_docdir_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; + } + string dbg_fn_oebps_css(string fn_src) { + return dbg_doc_oebps_css(fn_src).chainPath("epub.css").array; + } + } + } + return _PathsStruct(); + } +} +#+END_SRC diff --git a/org/default_regex.org b/org/default_regex.org new file mode 100644 index 0000000..92810ea --- /dev/null +++ b/org/default_regex.org @@ -0,0 +1,475 @@ +#+TITLE: sdp regex defaults +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:ao: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* 0. ao ctRegex :regex: +[[./sdp.org][sdp]] [[./][org/]] +http://dlang.org/phobos/std_regex.html +- Plain string, in which case it's compiled to bytecode before matching. +- Regex!char (wchar/dchar) that contains a pattern in the form of compiled bytecode. +- StaticRegex!char (wchar/dchar) that contains a pattern in the form of compiled native machine code. + +** 0. rgx code template: :ao_rgx: + +#+name: tangle_ao_rgx +#+BEGIN_SRC d :tangle ../src/sdp/ao_rgx.d +/++ + regex: regular expressions used in sisu document parser ++/ +template SiSUrgxInit() { + private import ao_defaults; + struct Rgx { + <> + <> + } +} +#+END_SRC + +** misc :misc: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ misc +/ +static true_dollar = ctRegex!(`\$`, "gm"); +static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); +static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); +static within_quotes = ctRegex!(`"(.+?)"`); +static make_heading_delimiter = ctRegex!(`[;][ ]*`); +static arr_delimiter = ctRegex!(`[ ]*[;][ ]*`); +static name_delimiter = ctRegex!(`^([^,]+)[ ]*,[ ]+(.+?)$`); +static book_index_go = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); +static book_index_go_scroll = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); +static book_index_go_seg = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?):(?P[a-z0-9_-]+)"); +static book_index_go_seg_ = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)(:(?P[a-z0-9_-]+))?"); +static book_index_go_seg_anchorless = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); +static trailing_comma = ctRegex!(",[ ]*$"); +static trailing_linebreak = ctRegex!(",[ ]{1,2}\\\\\\\\\n[ ]{4}$","m"); +static newline_eol_delimiter = ctRegex!("\n"); +static newline_eol_strip_preceding = ctRegex!("[ ]*\n"); +static newline_eol_delimiter_only = ctRegex!("^\n"); +static line_delimiter_ws_strip = ctRegex!("[ ]*\n[ ]*"); +static para_delimiter = ctRegex!("\n[ ]*\n+"); +static table_col_delimiter = ctRegex!("[ ]*\n+", "mg"); +static table_row_delimiter = ctRegex!("\n[ ]*\n+", "mg"); +static table_row_delimiter_special = ctRegex!("[ ]*\n", "mg"); // +static table_col_delimiter_special = ctRegex!("[ ]*[|][ ]*", "mg"); // +static levels_markup = ctRegex!(`^[A-D1-4]$`); +static levels_numbered = ctRegex!(`^[0-9]$`); +static levels_numbered_headings = ctRegex!(`^[0-7]$`); +static numeric = ctRegex!(`[ 0-9,.-]+`); +static numeric_col = ctRegex!(`^[ 0-9,.$£₤Є€€¥-]+$`); +#+END_SRC + +** comments :comment: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ comments +/ +static comment = ctRegex!(`^%+ `); +static comments = ctRegex!(`^%+ |^%+$`); +#+END_SRC + +** native headers +*** native header :native:header: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ header +/ +static main_headers = + ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m"); +static native_header = ctRegex!(`^@([a-z_]+):(?:\s|$)`); +static native_header_make = ctRegex!(`^@(make):(?:\s|$)`); +static native_header_meta = + ctRegex!(`^@(?:creator|title|rights|date|original|classify|identifier|notes|publisher|links):(?:\s|$)`); +static native_header_main = ctRegex!(`^@(?P
[a-z_]+):\s*(?P.*)`, "m"); +static native_header_sub = ctRegex!(`^[ ]*:(?P[a-z_]+):\s+(?P.+)`, "m"); +static native_header_meta_title = ctRegex!(`^@title:\s`, "m"); +static variable_doc_title = ctRegex!(`@title`); +static variable_doc_author = ctRegex!(`@author|@creator`); +static raw_author_munge = ctRegex!(`(\S.+?),\s+(.+)`,"i"); +#+END_SRC + +*** subheader :native:subheader: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ head +/ +static native_subhead_creator = ctRegex!(`^(?:author|translator|illustrator)$`, "m"); +static native_subhead_title = ctRegex!(`^(?:main|sub(?:title)?|full|language|edition|note)$`, "m"); +static native_subhead_rights = ctRegex!(`^(?:copyright|illustrations|license|cover)$`, "m"); +static native_subhead_date = ctRegex!(`^(?:published|created|issued|available|valid|modified|added_to_site)$`, "m"); +static native_subhead_original = ctRegex!(`^(?:title|language|source)$`, "m"); +static native_subhead_classify = ctRegex!(`^(?:topic_register|subject|keywords|loc|dewey)$`, "m"); +static native_subhead_identifier = ctRegex!(`^(?:oclc|pg|isbn)$`, "m"); +static native_subhead_notes = ctRegex!(`^(?:abstract|description)$`, "m"); +static native_subhead_publisher = ctRegex!(`^(?:name)$`, "m"); +static native_subhead_make = ctRegex!(`^(?:cover_image|home_button_image|home_button_text|footer|headings|num_top|num_depth|breaks|substitute|bold|italics|emphasis|texpdf_font|css)$`, "m"); +#+END_SRC + +** heading & paragraph operators :paragraph:operator: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ heading & paragraph operators +/ +static heading_a = ctRegex!(`^:?[A][~] `, "m"); +static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); +static heading_seg_and_above = ctRegex!(`^:?([A-D1])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); +static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); +static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~]([a-z0-9_.-]+) `,"i"); +static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9]+))`,"i"); + // unless dob.obj =~/^:?[A-D1-4]~\s+(?:|(?:chapter|article|section|clause)\s+)([0-9.]+)/i +static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`,"i"); +static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`); +static heading_marker_missing_tag = ctRegex!(`^:?([A-D1-4])[~] `); +static heading_title = ctRegex!(`^:?[A-D1-4][~][a-z0-9_.-]*[?]?\s+(.+?)$`); +static heading_all = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+(.+?)$`); // test, particularly [2] name/hashtag which may or may not be, does this affect title [3] +static heading_backmatter = ctRegex!(`^:?1[~][!](glossary|bibliography|biblio|blurb)\s+`,"i"); +static heading_biblio = ctRegex!(`^:?(1)[~][!](biblio(?:graphy)?|references?)`); +static heading_glossary = ctRegex!(`^:?(1)[~][!](glossary)`); +static heading_blurb = ctRegex!(`^:?(1)[~][!](blurb)`); +static heading_biblio_glossary = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|glossary)|[A-D1][~])`); +static heading_biblio_blurb = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|blurb)|[A-D1][~])`); +static heading_blurb_glossary = ctRegex!(`^:?(?:(1)[~][!](?:blurb|glossary)|[A-D1][~])`); +static para_bullet = ctRegex!(`^_[*] `); +static para_bullet_indent = ctRegex!(`^_([1-9])[*] `); +static para_indent = ctRegex!(`^_([1-9]) `); +static para_indent_hang = ctRegex!(`^_([0-9])_([0-9]) `); +static para_attribs = ctRegex!(`^_(?:(?:[0-9])(?:_([0-9]))?|(?:[1-9])?[*]) `); +#+END_SRC + +** blocked markup +*** blocked markup :block:tic: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ blocked markup +/ +static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); +static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); +#+END_SRC + +** blocked markup tics :block:tic: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ blocked markup tics +/ +static block_tic_open = ctRegex!("^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)"); // what of numbered code? +static block_tic_code_open = ctRegex!("^`{3} (?:code)(?:[.]([a-z][0-9a-z_]+))?(?:[ ]+([#]))?"); // extract additional info +static block_tic_poem_open = ctRegex!("^`{3} (poem)"); +static block_tic_group_open = ctRegex!("^`{3} (group)"); +static block_tic_block_open = ctRegex!("^`{3} (block)"); +static block_tic_quote_open = ctRegex!("^`{3} (quote)"); +static block_tic_table_open = ctRegex!("^`{3} table(.*)"); +static block_tic_close = ctRegex!("^(`{3})$","m"); +#+END_SRC + +*** blocked markup curly :block:curly: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ blocked markup curly +/ +static block_curly_open = ctRegex!(`^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)`); +static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); // extract additional info +static block_curly_code_close = ctRegex!(`^([}]code)`); +static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); +static block_curly_poem_close = ctRegex!(`^([}]poem)`); +static block_curly_group_open = ctRegex!(`^(group[{].*?$)`); +static block_curly_group_close = ctRegex!(`^([}]group)`); +static block_curly_block_open = ctRegex!(`^(block[{].*?$)`); +static block_curly_block_close = ctRegex!(`^([}]block)`); +static block_curly_quote_open = ctRegex!(`^(quote[{].*?$)`); +static block_curly_quote_close = ctRegex!(`^([}]quote)`); +static block_curly_table_open = ctRegex!(`^table[{](.*)`); +static block_curly_table_close = ctRegex!(`^([}]table)`); +static block_curly_table_special_markup = ctRegex!(`^[{]table((~h)?(?P(?:[ ]+[0-9]+;)+))[}]`, "mg"); // sepcial table block markup +#+END_SRC + +*** block sub-matches :block:curly: + +#+name: ao_rgx +#+BEGIN_SRC d +static table_head_instructions = ctRegex!(`(?Ph)?(?:[ ]+c(?P[0-9]);)?(?P(?:[ ]+[0-9]+[lr]?;)+)`); +static table_col_widths_and_alignment = ctRegex!(`(?P[0-9]+)(?P[lr]?)`); +static table_col_widths = ctRegex!(`(?P[0-9]+)`); +static table_col_align = ctRegex!(`(?P[lr]?)`); +static table_col_align_match = ctRegex!(`(?P[lr])`); +static table_col_separator = ctRegex!(`┊`); +static table_col_separator_nl = ctRegex!(`[┊]$`, "mg"); +#+END_SRC + +** inline markup footnotes endnotes :inline:footnote: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ inline markup footnotes endnotes +/ +static inline_notes_curly_gen = ctRegex!(`~\{.+?\}~`, "m"); +static inline_notes_curly = ctRegex!(`~\{\s*(.+?)\}~`, "mg"); +static inline_curly_delimiter_open_and_close_regular = ctRegex!(`~\{\s*|\s*\}~`, "m"); +static inline_notes_delimiter_curly_regular = ctRegex!(`~\{[ ]*(.+?)\}~`, "m"); +static inline_notes_curly_sp = ctRegex!(`~\{[*+]+\s+(.+?)\}~`, "m"); +static inline_notes_curly_sp_asterisk = ctRegex!(`~\{[*]+\s+(.+?)\}~`, "m"); +static inline_notes_curly_sp_plus = ctRegex!(`~\{[+]+\s+(.+?)\}~`, "m"); +static inline_note_curly_delimiters = ctRegex!(`(~\{[*+]?\s*)(.+?)(\}~)`, "mg"); +static inline_notes_square = ctRegex!(`~\[\s*(.+?)\]~`, "mg"); +static inline_text_and_note_square_sp = ctRegex!(`(.+?)~\[[*+]+\s+(.+?)\]~`, "mg"); +static inline_text_and_note_square = ctRegex!(`(.+?)~\[\s*(.+?)\]~`, "mg"); +static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "mg"); +static inline_curly_delimiter_open_regular = ctRegex!(`~\{\s*`, "m"); +static inline_curly_delimiter_open_symbol_star = ctRegex!(`~\{[*]\s`, "m"); // +static inline_curly_delimiter_open_symbol_plus = ctRegex!(`~\{[+]\s`, "m"); // +static inline_curly_delimiter_open_star_or_plus = ctRegex!(`~\{[+*]`, "m"); // +static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); +static inline_text_and_note_curly = ctRegex!(`(?P.+?)(?:(?:[~])[{][*+ ]*)(?P.+?)(?:[}][~])`, "mg"); +static note_ref = ctRegex!(`^\S+?noteref_([0-9]+)`, "mg"); // {^{73.}^}#noteref_73 +#+END_SRC + +*** links/ urls :inline:footnote: + +#+name: ao_rgx +#+BEGIN_SRC d +static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_#]`, "mg"); +static inline_url = ctRegex!(`((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]\S*)`, "mg"); +static inline_link_naked_url = ctRegex!(`(?P^|[ ])(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!'"]?(?:[ ]|$))`, "mg"); +static inline_link_markup_regular = ctRegex!(`(?P^|[ ])\{\s*(?P.+?)\s*\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); +static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); +static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+)`, "mg"); +#+END_SRC + +*** images :images: + +#+name: ao_rgx +#+BEGIN_SRC d +static image = ctRegex!(`([a-zA-Z0-9._-]+?\.(?:png|gif|jpg))`, "mg"); +#+END_SRC + +*** inline markup book index :inline:bookindex: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ inline markup book index +/ +static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); +static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); +static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); // strip +#+END_SRC + +** no obj_cite_number object :ocn:off:object: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ no obj_cite_number object +/ +static obj_cite_number_off = ctRegex!(`~#$`, "m"); +static obj_cite_number_off_dh = ctRegex!(`-#$`, "m"); +static obj_cite_number_off_all = ctRegex!(`[~-]#$`, "m"); +#+END_SRC + +** no obj_cite_number block :ocn:off:block: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ no obj_cite_number block +/ +static obj_cite_number_off_block = ctRegex!(`^--~#$`); +static obj_cite_number_off_block_dh = ctRegex!(`^---#$`); +static obj_cite_number_off_block_close = ctRegex!(`^--\+#$`); +static obj_cite_number_block_marks = ctRegex!(`^--[+~-]#$`); +#+END_SRC + +** ignore outside code blocks :block:code: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ ignore outside code blocks +/ +static skip_from_regular_parse = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); // not structural info +#+END_SRC + +** line & page breaks :break: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ line & page breaks +/ +static break_line_within_object = ctRegex!(`[\\]{2}( |$)`); +static break_page = ctRegex!(`^-[\\]{2}-$`); +static break_page_new = ctRegex!(`^=[\\]{2}=$`); +static break_page_line_across = ctRegex!(`^=[.]{2}=$`); +static break_string = ctRegex!(`』`); +static parent = ctRegex!(`([0-7]):([0-9]+)`); +#+END_SRC + +** json :json: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ json +/ +static tailing_comma = ctRegex!(`,$`, "m"); +#+END_SRC + +** biblio tags :biblio:tags: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ biblio tags +/ +static biblio_tags = ctRegex!(`^(is|au|author_raw|author|author_arr|editor_raw|ed|editor_arr|ti|title|subtitle|fulltitle|lng|language|trans|src|jo|journal|in|vol|volume|edn|edition|yr|year|pl|place|pb|pub|publisher|url|pg|pages|note|short_name|id):\s+(.+)`); +static biblio_abbreviations = ctRegex!(`^(au|ed|ti|lng|jo|vol|edn|yr|pl|pb|pub|pg|pgs|sn)$`); +#+END_SRC + +** bookindex split :bookindex:split: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ bookindex split +/ +static bi_main_terms_split = ctRegex!(`\s*;\s*`); +static bi_main_term_plus_rest_split = ctRegex!(`\s*:\s*`); +static bi_sub_terms_plus_obj_cite_number_offset_split = ctRegex!(`\s*\|\s*`); +static bi_term_and_obj_cite_numbers_match = ctRegex!(`^(.+?)\+(\d+)`); +#+END_SRC + +** language codes :language:codes: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ language codes +/ +auto language_codes = + ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); +auto language_code_and_filename = + ctRegex!("(?:^|[/])(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); +#+END_SRC + +* 1. output ctRegex :regex: +[[./sdp.org][sdp]] [[./][org/]] +http://dlang.org/phobos/std_regex.html +- Plain string, in which case it's compiled to bytecode before matching. +- Regex!char (wchar/dchar) that contains a pattern in the form of compiled bytecode. +- StaticRegex!char (wchar/dchar) that contains a pattern in the form of compiled native machine code. + +** 0. code template: :rgx: + +#+name: tangle_ao_rgx +#+BEGIN_SRC d :tangle ../src/sdp/output_rgx.d +/++ + regex: regular expressions used in sisu document parser ++/ +template SiSUoutputRgxInit() { + private import defaults; + struct Rgx { + <> + <> + } +} +#+END_SRC + +** special characters +*** xhtml special characters + +#+name: sp_ch_xhtml_rgx +#+BEGIN_SRC d +static xhtml_ampersand = ctRegex!(`[&]`); // & +static xhtml_less_than = ctRegex!(`[<]`); // < +static xhtml_greater_than = ctRegex!(`[>]`); // > +static xhtml_line_break = ctRegex!(` [\\]{2}`); //
+#+END_SRC + +* 2. ctRegex defaults shared by ao & output (generic) +** misc generic + +#+name: prgmkup_rgx +#+BEGIN_SRC d +static newline = ctRegex!("\n", "mg"); +static strip_br = ctRegex!("^
\n|
\n*$"); +static space = ctRegex!(`[ ]`, "mg"); +static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); +static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); // could be issues for endnotes +static two_spaces = ctRegex!(`[ ]{2}`, "mg"); +static nbsp_char = ctRegex!(`░`, "mg"); +static nbsp_chars_line_start = ctRegex!(`^░+`, "mg"); +static nbsp_and_space = ctRegex!(` [ ]`, "mg"); +static nbsp_char_and_space = ctRegex!(`░[ ]`, "mg"); +#+END_SRC + +** filename (and path) matching (including markup insert file) :insert:file:path:filename: + +#+name: prgmkup_rgx +#+BEGIN_SRC d +static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); +static src_fn = + ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); +static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); +static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); +static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); +static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); +static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); +#+END_SRC + +** inline markup +*** inline (internal program) markup footnotes endnotes :inline:footnote: + +#+name: prgmkup_rgx +#+BEGIN_SRC d +/+ inline markup footnotes endnotes +/ +static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); +static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); +static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); +static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); +static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); +static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); +static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); +static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); +static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); +static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); +static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); +static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); +static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); +#+END_SRC + +*** inline links + +#+name: prgmkup_rgx +#+BEGIN_SRC d +/+ inline markup footnotes endnotes +/ +static inline_link = ctRegex!(`┥(.+?)┝┤(.+?)├`, "mg"); +static inline_a_url = ctRegex!(`(┤)(\S+?)(├)`, "mg"); +static fn_suffix = ctRegex!(`\.fnSuffix`, "mg"); +static inline_link_fn_suffix = ctRegex!(`¤(.+?)(\.fnSuffix)`, "mg"); +static inline_seg_link = ctRegex!(`(¤)(?:.+?)\.fnSuffix`, "mg"); +static mark_internal_site_lnk = ctRegex!(`¤`, "mg"); +#+END_SRC + +*** inline markup font face mod :inline:font:face: + +#+name: prgmkup_rgx +#+BEGIN_SRC d +/+ inline markup font face mod +/ +static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); +static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); +static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); +static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); +static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); +static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); +static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); +static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); +static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); +static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); +static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); +static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); +#+END_SRC + +*** table related + +#+name: prgmkup_rgx +#+BEGIN_SRC d +/+ table delimiters +/ +static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); // +static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); // +#+END_SRC diff --git a/org/defaults.org b/org/defaults.org deleted file mode 100644 index 272933e..0000000 --- a/org/defaults.org +++ /dev/null @@ -1,1471 +0,0 @@ -#+TITLE: sdp defaults -#+AUTHOR: Ralph Amissah -#+EMAIL: ralph.amissah@gmail.com -#+STARTUP: indent -#+LANGUAGE: en -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+FILETAGS: :sdp:rel:ao: -#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) - -[[./sdp.org][sdp]] [[./][org/]] -* 0. ao regex & defaults -** 0. defaults :defaults: -[[./sdp.org][sdp]] [[./][org/]] - -*** 0. defaults: :defaults: - -#+name: tangle_defaults -#+BEGIN_SRC d :tangle ../src/sdp/ao_defaults.d -/++ - default settings -+/ -template SiSUregisters() { - <> - <> -} -<> -<> -<> -<> -<> -#+END_SRC - -*** imports - -#+name: ao_defaults_imports -#+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, - std.exception, - std.file, - std.getopt, - std.json, - std.path, - std.process, - std.range, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; -#+END_SRC - -*** settings metadata associative array indexes :settings: -***** conf associative array - -#+name: ao_defaults_template_registers -#+BEGIN_SRC d -string[string][string] conf_aa() { - auto conf_ = [ - "webserv": [ - "url_root" : "", - "path" : "~/sdp_www" , - "images" : "" , - "cgi" : "/usr/local/lib/sdp-cgi" - ], - "webserv_cgi": [ - "host" : "localhost", - "base_path" : "", - "port" : "8081", - "user" : "", - "file_links" : "www.sisudoc.org" - ], - "processing": [ - "path" : "~", - "dir" : "_sisu_processing", - "concord_max" : "400000" - ], - "flag": [ - "act0" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --manifest --verbose", - "act1" : "--digest --text --html --manifest", - "act2" : "--digest --text --html --epub --pdf --manifest", - "act3" : "--digest --qrcode --text --html --epub --concordance --pdf --manifest", - "act4" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --manifest", - "act5" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --sqlite --manifest", - "act6" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --manifest", - "act7" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --source --sisupod --manifest", - "act8" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --pg --update --manifest", - "act9" : "--digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --pg --update --source --sisupod --manifest" - ], - "default": [ - "papersize" : "a4,letter", - "text_wrap" : "78", - "emphasis" : "bold", - "language" : "en", - "digest" : "sha256" - ], - "permission": [ - "share_source" : "" - ], - "program_select": [ - "editor" : "vim", - "epub_viewer" : "ebook-viewer", - "html_viewer" : "xombrero", - "odf_viewer" : "lowriter", - "pdf_viewer" : "evince", - "xml_viewer" : "xml-viewer" - ], - "search": [ - "flag" : "", - "action" : "", - "db" : "", - "title" : "" - ] - ]; - return conf_; -} -#+END_SRC - -***** make associative array - -#+name: ao_defaults_template_registers -#+BEGIN_SRC d -string[string][string] make_aa() { - auto make_ = [ - "make": [ - "bold" : "", - "breaks" : "", - "cover_image" : "", - "css" : "", - "emphasis" : "", - "footer" : "", - "headings" : "", - "home_button_image" : "", - "home_button_text" : "", - "italics" : "", - "num_top" : "", - "num_depth" : "", - "substitute" : "", - "texpdf_font" : "" - ] - ]; - return make_; -} -#+END_SRC - -***** meta (metadata) associative array - -#+name: ao_defaults_template_registers -#+BEGIN_SRC d -string[string][string] meta_aa() { - auto meta_ = [ - "classify": [ - "dewey" : "", - "keywords" : "", - "loc" : "", - "subject" : "", - "topic_register" : "" - ], - "creator": [ - "author" : "", - "author_email" : "", - "illustrator" : "", - "translator" : "" - ], - "date": [ - "added_to_site" : "", - "available" : "", - "created" : "", - "issued" : "", - "modified" : "", - "published" : "", - "valid" : "" - ], - "identifier": [ - "isbn" : "", - "oclc" : "", - "pg" : "" - ], - "links": [ - "link" : "" - ], - "notes": [ - "abstract" : "", - "description" : "" - ], - "original": [ - "language" : "", - "source" : "", - "title" : "" - ], - "publisher": [ - "name" : "" - ], - "rights": [ - "copyright" : "", - "cover" : "", - "illustrations" : "", - "license" : "" - ], - "title": [ - "edition" : "", - "full" : "", - "language" : "", - "main" : "", - "note" : "", - "sub" : "", - "subtitle" : "" - ] - ]; - return meta_; -} -#+END_SRC - -*** metadata associative array indexes :header: - -#+name: ao_defaults_template_registers -#+BEGIN_SRC d -auto ptr_head_main = - [ - "classify", - "creator", - "date", - "identifier", - "links", - "make", /+ make +/ - "original", - "notes", - "rights", - "title" - ]; -auto ptr_head_sub_classify = - [ - "dewey", - "keywords", - "loc", - "subject", - "topic_register" - ]; -auto ptr_head_sub_creator = - [ - "author", - "author_email", - "cover", - "illustrator", - "translator" - ]; -auto ptr_head_sub_date = - [ - "added_to_site", - "available", - "created", - "issued", - "modified", - "published", - "valid" - ]; -auto ptr_head_sub_identifier = - [ - "isbn", - "oclc", - "pg" - ]; -/+ make +/ -auto ptr_head_sub_make = - [ - "cover_image", - "home_button_image", - "home_button_text", - "footer", "headings", - "num_top", "num_depth", - "breaks", - "substitute", - "bold", - "italics", - "emphasis", - "texpdf_font", - "css" - ]; -auto ptr_head_sub_notes = - [ - "abstract", - "description" - ]; -auto ptr_head_sub_original = - [ - "language", - "source", - "title" - ]; -auto ptr_head_sub_publisher = - [ "name" ]; -auto ptr_head_sub_rights = - [ - "copyright", - "cover", - "illustrations", - "license" - ]; -auto ptr_head_sub_title = - [ - "edition", - "full", - "language", - "main", - "note", - "sub" - ]; -auto config_jsonstr = `{ -}`; -#+END_SRC - -**** notes headers - -#+name: ao_defaults_template -#+BEGIN_SRC d -/+ - /+ - unify internal representation of header info for native & sdlang document headers - represent either using struct, hashes or possibly json - sdp internal representation should be identical for native & sdlang variants - +/ -header. - ├── make // make instructions - │   ├── bold - │   ├── breaks - │   ├── cover_image - │   ├── css - │   ├── emphasis - │   ├── footer - │   ├── headings - │   ├── home_button_image - │   ├── home_button_text - │   ├── italics - │   ├── num_top - │   ├── substitute - │   └── texpdf_font - └── meta // metadata -    ├── author // move author to creator:author -    ├── classify -    │   ├── dewey -    │   ├── keyword -    │   ├── loc -    │   ├── subject -    │   └── topic_register -    ├── creator -    │   ├── author - │ │ ├── [ [first_name: x0, last_name: y0], [first_name: x1, last_name: y1] ] - │ │ └── [ full_name0, full_name1 ] -    │   ├── author_email -    │   ├── illustrator -    │   └── translator -    ├── date -    │   ├── added_to_site -    │   ├── available -    │   ├── created -    │   ├── issued -    │   ├── modified -    │   ├── published -    │   └── valid -    ├── identifier -    │   ├── isbn -    │   ├── oclc -    │   └── pg -    ├── links -    ├── notes -    │   ├── abstract -    │   └── description -    ├── original -    │   ├── language -    │   ├── source -    │   └── title -    ├── publisher -    │   └── name -    ├── rights -    │   ├── copyright -    │   ├── cover -    │   ├── illustrations -    │   └── license -    └── title // move title: to title:main -    ├── edition -    ├── [ full (main + sub) ] -    ├── language -    ├── main -    ├── note -    ├── sub -    └── subtitle // move title:subtitle to title:sub - -61 leaves -+/ -#+END_SRC - -*** template: flags regex initialize :regex_flags: - -#+name: ao_defaults_template_init_flags -#+BEGIN_SRC d -template SiSUrgxInitFlags() { - /+ regex flags +/ - int[string] flags_type_init() { - int[string] flags_type_init = [ - "make_headings" : 0, - "header_make" : 0, - "header_meta" : 0, - "heading" : 0, - "biblio_section" : 0, - "glossary_section" : 0, - "blurb_section" : 0, - "para" : 0, - "blocks" : 0, // 0..2 generic - "code" : 0, // 0..2 - "poem" : 0, // 0..2 - "table" : 0, // 0..2 - "group" : 0, // 0..2 - "block" : 0, // 0..2 - "quote" : 0, // 0..2 - "verse_new" : 0, - "curly_code" : 0, - "curly_poem" : 0, - "curly_group" : 0, - "curly_block" : 0, - "curly_quote" : 0, - "curly_table" : 0, - "curly_table_special_markup" : 0, - "tic_code" : 0, - "tic_poem" : 0, - "tic_group" : 0, - "tic_block" : 0, - "tic_quote" : 0, - "tic_table" : 0, - "ocn_status" : 0, // 0 obj_cite_number; 1 no obj_cite_number; 2 no obj_cite_number & dummy headings - "ocn_status_multi_obj" : 0, // 0 obj_cite_number; 1 no obj_cite_number; 2 no obj_cite_number & dummy headings - "book_index" : 0, - ]; - return flags_type_init; - } -} -#+END_SRC - -#+name: ao_defaults_template_node -#+BEGIN_SRC d -template SiSUnode() { - string[string] node_metadata_heading_str() { - auto _node = [ - "is" : "", - "ocn" : "", - "marked_up_lev" : "", - "segment_anchor_tag" : "", - "attrib" : "", - ]; - return _node; - } - int[string] node_metadata_heading_int() { - auto _node = [ - "ocn" : 0, - "ptr_doc_object" : 0, - "ptr_html_segnames" : 0, - "ptr_heading" : 0, - "heading_lev_markup" : 9, - "heading_lev_collapsed" : 9, - "parent_ocn" : 0, - "parent_lev_markup" : 9, - ]; - return _node; - } - string[string] node_metadata_para_str() { - auto _node = [ - "is" : "", - "ocn" : "", - "attrib" : "", - ]; - return _node; - } - int[string] node_metadata_para_int() { - auto _node = [ - "ocn" : 0, - "indent_base" : 0, - "indent_hang" : 0, - "bullet" : 0, // bool (0|1) - ]; - return _node; - } -} -#+END_SRC - -*** template: bibliography :biblio: - -#+name: ao_defaults_template_biblio -#+BEGIN_SRC d -template SiSUbiblio() { - // required: deemed_author (author || editor); year; fulltitle; - struct BibJsnStr { - auto biblio_entry_tags_jsonstr() { - string x = `{ - "is" : "", - "sortby_deemed_author_year_title" : "", - "deemed_author" : "", - "author_raw" : "", - "author" : "", - "author_arr" : [ "" ], - "editor_raw" : "", - "editor" : "", - "editor_arr" : [ "" ], - "title" : "", - "subtitle" : "", - "fulltitle" : "", - "language" : "", - "trans" : "", - "src" : "", - "journal" : "", - "in" : "", - "volume" : "", - "edition" : "", - "year" : "", - "place" : "", - "publisher" : "", - "url" : "", - "pages" : "", - "note" : "", - "short_name" : "", - "id" : "" - }`; // is: book, article, magazine, newspaper, blog, other - return x; - } - } -} -#+END_SRC - -** 1. ctRegex :regex: -[[./sdp.org][sdp]] [[./][org/]] -http://dlang.org/phobos/std_regex.html -- Plain string, in which case it's compiled to bytecode before matching. -- Regex!char (wchar/dchar) that contains a pattern in the form of compiled bytecode. -- StaticRegex!char (wchar/dchar) that contains a pattern in the form of compiled native machine code. - -*** 0. rgx code template: :ao_rgx: - -#+name: tangle_ao_rgx -#+BEGIN_SRC d :tangle ../src/sdp/ao_rgx.d -/++ - regex: regular expressions used in sisu document parser -+/ -template SiSUrgxInit() { - private import ao_defaults; - struct Rgx { - <> - <> - } -} -#+END_SRC - -*** misc :misc: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ misc +/ -static true_dollar = ctRegex!(`\$`, "gm"); -static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); -static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); -static within_quotes = ctRegex!(`"(.+?)"`); -static make_heading_delimiter = ctRegex!(`[;][ ]*`); -static arr_delimiter = ctRegex!(`[ ]*[;][ ]*`); -static name_delimiter = ctRegex!(`^([^,]+)[ ]*,[ ]+(.+?)$`); -static book_index_go = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); -static book_index_go_scroll = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); -static book_index_go_seg = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?):(?P[a-z0-9_-]+)"); -static book_index_go_seg_ = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)(:(?P[a-z0-9_-]+))?"); -static book_index_go_seg_anchorless = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); -static trailing_comma = ctRegex!(",[ ]*$"); -static trailing_linebreak = ctRegex!(",[ ]{1,2}\\\\\\\\\n[ ]{4}$","m"); -static newline_eol_delimiter = ctRegex!("\n"); -static newline_eol_strip_preceding = ctRegex!("[ ]*\n"); -static newline_eol_delimiter_only = ctRegex!("^\n"); -static line_delimiter_ws_strip = ctRegex!("[ ]*\n[ ]*"); -static para_delimiter = ctRegex!("\n[ ]*\n+"); -static table_col_delimiter = ctRegex!("[ ]*\n+", "mg"); -static table_row_delimiter = ctRegex!("\n[ ]*\n+", "mg"); -static table_row_delimiter_special = ctRegex!("[ ]*\n", "mg"); // -static table_col_delimiter_special = ctRegex!("[ ]*[|][ ]*", "mg"); // -static levels_markup = ctRegex!(`^[A-D1-4]$`); -static levels_numbered = ctRegex!(`^[0-9]$`); -static levels_numbered_headings = ctRegex!(`^[0-7]$`); -static numeric = ctRegex!(`[ 0-9,.-]+`); -static numeric_col = ctRegex!(`^[ 0-9,.$£₤Є€€¥-]+$`); -#+END_SRC - -*** comments :comment: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ comments +/ -static comment = ctRegex!(`^%+ `); -static comments = ctRegex!(`^%+ |^%+$`); -#+END_SRC - -*** native headers -**** native header :native:header: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ header +/ -static main_headers = - ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m"); -static native_header = ctRegex!(`^@([a-z_]+):(?:\s|$)`); -static native_header_make = ctRegex!(`^@(make):(?:\s|$)`); -static native_header_meta = - ctRegex!(`^@(?:creator|title|rights|date|original|classify|identifier|notes|publisher|links):(?:\s|$)`); -static native_header_main = ctRegex!(`^@(?P
[a-z_]+):\s*(?P.*)`, "m"); -static native_header_sub = ctRegex!(`^[ ]*:(?P[a-z_]+):\s+(?P.+)`, "m"); -static native_header_meta_title = ctRegex!(`^@title:\s`, "m"); -static variable_doc_title = ctRegex!(`@title`); -static variable_doc_author = ctRegex!(`@author|@creator`); -static raw_author_munge = ctRegex!(`(\S.+?),\s+(.+)`,"i"); -#+END_SRC - -**** subheader :native:subheader: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ head +/ -static native_subhead_creator = ctRegex!(`^(?:author|translator|illustrator)$`, "m"); -static native_subhead_title = ctRegex!(`^(?:main|sub(?:title)?|full|language|edition|note)$`, "m"); -static native_subhead_rights = ctRegex!(`^(?:copyright|illustrations|license|cover)$`, "m"); -static native_subhead_date = ctRegex!(`^(?:published|created|issued|available|valid|modified|added_to_site)$`, "m"); -static native_subhead_original = ctRegex!(`^(?:title|language|source)$`, "m"); -static native_subhead_classify = ctRegex!(`^(?:topic_register|subject|keywords|loc|dewey)$`, "m"); -static native_subhead_identifier = ctRegex!(`^(?:oclc|pg|isbn)$`, "m"); -static native_subhead_notes = ctRegex!(`^(?:abstract|description)$`, "m"); -static native_subhead_publisher = ctRegex!(`^(?:name)$`, "m"); -static native_subhead_make = ctRegex!(`^(?:cover_image|home_button_image|home_button_text|footer|headings|num_top|num_depth|breaks|substitute|bold|italics|emphasis|texpdf_font|css)$`, "m"); -#+END_SRC - -*** heading & paragraph operators :paragraph:operator: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ heading & paragraph operators +/ -static heading_a = ctRegex!(`^:?[A][~] `, "m"); -static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); -static heading_seg_and_above = ctRegex!(`^:?([A-D1])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); -static heading_marker = ctRegex!(`^:?([A-D1-4])[~]`); -static heading_anchor_tag = ctRegex!(`^:?[A-D1-4][~]([a-z0-9_.-]+) `,"i"); -static heading_identify_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(?:(?:(?:chapter|article|section|clause)\s+[0-9.]+)|(?:[0-9]+))`,"i"); - // unless dob.obj =~/^:?[A-D1-4]~\s+(?:|(?:chapter|article|section|clause)\s+)([0-9.]+)/i -static heading_extract_named_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+(chapter|article|section|clause)\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`,"i"); -static heading_extract_unnamed_anchor_tag = ctRegex!(`^:?[A-D1-4][~]\s+((?:[0-9]+.)*[0-9]+)(?:[.:;, ]|$)`); -static heading_marker_missing_tag = ctRegex!(`^:?([A-D1-4])[~] `); -static heading_title = ctRegex!(`^:?[A-D1-4][~][a-z0-9_.-]*[?]?\s+(.+?)$`); -static heading_all = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+(.+?)$`); // test, particularly [2] name/hashtag which may or may not be, does this affect title [3] -static heading_backmatter = ctRegex!(`^:?1[~][!](glossary|bibliography|biblio|blurb)\s+`,"i"); -static heading_biblio = ctRegex!(`^:?(1)[~][!](biblio(?:graphy)?|references?)`); -static heading_glossary = ctRegex!(`^:?(1)[~][!](glossary)`); -static heading_blurb = ctRegex!(`^:?(1)[~][!](blurb)`); -static heading_biblio_glossary = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|glossary)|[A-D1][~])`); -static heading_biblio_blurb = ctRegex!(`^:?(?:(1)[~][!](?:(?:biblio(?:graphy)?|references?)|blurb)|[A-D1][~])`); -static heading_blurb_glossary = ctRegex!(`^:?(?:(1)[~][!](?:blurb|glossary)|[A-D1][~])`); -static para_bullet = ctRegex!(`^_[*] `); -static para_bullet_indent = ctRegex!(`^_([1-9])[*] `); -static para_indent = ctRegex!(`^_([1-9]) `); -static para_indent_hang = ctRegex!(`^_([0-9])_([0-9]) `); -static para_attribs = ctRegex!(`^_(?:(?:[0-9])(?:_([0-9]))?|(?:[1-9])?[*]) `); -#+END_SRC - -*** blocked markup -**** blocked markup :block:tic: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ blocked markup +/ -static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); -static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); -#+END_SRC - -*** blocked markup tics :block:tic: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ blocked markup tics +/ -static block_tic_open = ctRegex!("^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)"); -static block_tic_code_open = ctRegex!("^`{3} (?:code)(?:[.]([a-z][0-9a-z_]+))?(?:[ ]+([#]))?"); -static block_tic_poem_open = ctRegex!("^`{3} (poem)"); -static block_tic_group_open = ctRegex!("^`{3} (group)"); -static block_tic_block_open = ctRegex!("^`{3} (block)"); -static block_tic_quote_open = ctRegex!("^`{3} (quote)"); -static block_tic_table_open = ctRegex!("^`{3} table(.*)"); -static block_tic_close = ctRegex!("^(`{3})$","m"); -#+END_SRC - -**** blocked markup curly :block:curly: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ blocked markup curly +/ -static block_curly_open = ctRegex!(`^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)`); -static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); -static block_curly_code_close = ctRegex!(`^([}]code)`); -static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); -static block_curly_poem_close = ctRegex!(`^([}]poem)`); -static block_curly_group_open = ctRegex!(`^(group[{].*?$)`); -static block_curly_group_close = ctRegex!(`^([}]group)`); -static block_curly_block_open = ctRegex!(`^(block[{].*?$)`); -static block_curly_block_close = ctRegex!(`^([}]block)`); -static block_curly_quote_open = ctRegex!(`^(quote[{].*?$)`); -static block_curly_quote_close = ctRegex!(`^([}]quote)`); -static block_curly_table_open = ctRegex!(`^table[{](.*)`); -static block_curly_table_close = ctRegex!(`^([}]table)`); -static block_curly_table_special_markup = ctRegex!(`^[{]table((~h)?(?P(?:[ ]+[0-9]+;)+))[}]`, "mg"); // sepcial table block markup -#+END_SRC - -**** block sub-matches :block:curly: - -#+name: ao_rgx -#+BEGIN_SRC d -static table_head_instructions = ctRegex!(`(?Ph)?(?:[ ]+c(?P[0-9]);)?(?P(?:[ ]+[0-9]+[lr]?;)+)`); -static table_col_widths_and_alignment = ctRegex!(`(?P[0-9]+)(?P[lr]?)`); -static table_col_widths = ctRegex!(`(?P[0-9]+)`); -static table_col_align = ctRegex!(`(?P[lr]?)`); -static table_col_align_match = ctRegex!(`(?P[lr])`); -static table_col_separator = ctRegex!(`┊`); -static table_col_separator_nl = ctRegex!(`[┊]$`, "mg"); -#+END_SRC - -*** inline markup footnotes endnotes :inline:footnote: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ inline markup footnotes endnotes +/ -static inline_notes_curly_gen = ctRegex!(`~\{.+?\}~`, "m"); -static inline_notes_curly = ctRegex!(`~\{\s*(.+?)\}~`, "mg"); -static inline_curly_delimiter_open_and_close_regular = ctRegex!(`~\{\s*|\s*\}~`, "m"); -static inline_notes_delimiter_curly_regular = ctRegex!(`~\{[ ]*(.+?)\}~`, "m"); -static inline_notes_curly_sp = ctRegex!(`~\{[*+]+\s+(.+?)\}~`, "m"); -static inline_notes_curly_sp_asterisk = ctRegex!(`~\{[*]+\s+(.+?)\}~`, "m"); -static inline_notes_curly_sp_plus = ctRegex!(`~\{[+]+\s+(.+?)\}~`, "m"); -static inline_note_curly_delimiters = ctRegex!(`(~\{[*+]?\s*)(.+?)(\}~)`, "mg"); -static inline_notes_square = ctRegex!(`~\[\s*(.+?)\]~`, "mg"); -static inline_text_and_note_square_sp = ctRegex!(`(.+?)~\[[*+]+\s+(.+?)\]~`, "mg"); -static inline_text_and_note_square = ctRegex!(`(.+?)~\[\s*(.+?)\]~`, "mg"); -static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "mg"); -static inline_curly_delimiter_open_regular = ctRegex!(`~\{\s*`, "m"); -static inline_curly_delimiter_open_symbol_star = ctRegex!(`~\{[*]\s`, "m"); // -static inline_curly_delimiter_open_symbol_plus = ctRegex!(`~\{[+]\s`, "m"); // -static inline_curly_delimiter_open_star_or_plus = ctRegex!(`~\{[+*]`, "m"); // -static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); -static inline_text_and_note_curly = ctRegex!(`(?P.+?)(?:(?:[~])[{][*+ ]*)(?P.+?)(?:[}][~])`, "mg"); -static note_ref = ctRegex!(`^\S+?noteref_([0-9]+)`, "mg"); // {^{73.}^}#noteref_73 -#+END_SRC - -**** links/ urls :inline:footnote: - -#+name: ao_rgx -#+BEGIN_SRC d -static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_#]`, "mg"); -static inline_url = ctRegex!(`((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]\S*)`, "mg"); -static inline_link_naked_url = ctRegex!(`(?P^|[ ])(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!'"]?(?:[ ]|$))`, "mg"); -static inline_link_markup_regular = ctRegex!(`(?P^|[ ])\{\s*(?P.+?)\s*\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); -static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); -static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+)`, "mg"); -#+END_SRC - -**** images :images: - -#+name: ao_rgx -#+BEGIN_SRC d -static image = ctRegex!(`([a-zA-Z0-9._-]+?\.(?:png|gif|jpg))`, "mg"); -#+END_SRC - -**** inline markup book index :inline:bookindex: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ inline markup book index +/ -static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); -static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); -static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); // strip -#+END_SRC - -*** no obj_cite_number object :ocn:off:object: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ no obj_cite_number object +/ -static obj_cite_number_off = ctRegex!(`~#$`, "m"); -static obj_cite_number_off_dh = ctRegex!(`-#$`, "m"); -static obj_cite_number_off_all = ctRegex!(`[~-]#$`, "m"); -#+END_SRC - -*** no obj_cite_number block :ocn:off:block: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ no obj_cite_number block +/ -static obj_cite_number_off_block = ctRegex!(`^--~#$`); -static obj_cite_number_off_block_dh = ctRegex!(`^---#$`); -static obj_cite_number_off_block_close = ctRegex!(`^--\+#$`); -static obj_cite_number_block_marks = ctRegex!(`^--[+~-]#$`); -#+END_SRC - -*** ignore outside code blocks :block:code: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ ignore outside code blocks +/ -static skip_from_regular_parse = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); // not structural info -#+END_SRC - -*** line & page breaks :break: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ line & page breaks +/ -static break_line_within_object = ctRegex!(`[\\]{2}( |$)`); -static break_page = ctRegex!(`^-[\\]{2}-$`); -static break_page_new = ctRegex!(`^=[\\]{2}=$`); -static break_page_line_across = ctRegex!(`^=[.]{2}=$`); -static break_string = ctRegex!(`』`); -static parent = ctRegex!(`([0-7]):([0-9]+)`); -#+END_SRC - -*** json :json: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ json +/ -static tailing_comma = ctRegex!(`,$`, "m"); -#+END_SRC - -*** biblio tags :biblio:tags: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ biblio tags +/ -static biblio_tags = ctRegex!(`^(is|au|author_raw|author|author_arr|editor_raw|ed|editor_arr|ti|title|subtitle|fulltitle|lng|language|trans|src|jo|journal|in|vol|volume|edn|edition|yr|year|pl|place|pb|pub|publisher|url|pg|pages|note|short_name|id):\s+(.+)`); -static biblio_abbreviations = ctRegex!(`^(au|ed|ti|lng|jo|vol|edn|yr|pl|pb|pub|pg|pgs|sn)$`); -#+END_SRC - -*** bookindex split :bookindex:split: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ bookindex split +/ -static bi_main_terms_split = ctRegex!(`\s*;\s*`); -static bi_main_term_plus_rest_split = ctRegex!(`\s*:\s*`); -static bi_sub_terms_plus_obj_cite_number_offset_split = ctRegex!(`\s*\|\s*`); -static bi_term_and_obj_cite_numbers_match = ctRegex!(`^(.+?)\+(\d+)`); -#+END_SRC - -*** language codes :language:codes: - -#+name: ao_rgx -#+BEGIN_SRC d -/+ language codes +/ -auto language_codes = - ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); -auto language_code_and_filename = - ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); -#+END_SRC - -* 1. output regex & defaults -** 0. defaults :defaults: - -*** 0. defaults: :defaults: - -#+name: tangle_defaults -#+BEGIN_SRC d :tangle ../src/sdp/defaults.d -/++ - default settings -+/ -<> -<> -<> -<> -#+END_SRC - -*** imports - -#+name: defaults_imports -#+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, - std.exception, - std.file, - std.getopt, - std.json, - std.path, - std.process, - std.range, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; -#+END_SRC - - -*** TODO template: dir paths :dir:path: - -#+name: defaults_template_paths -#+BEGIN_SRC d -template SiSUpaths() { -#+END_SRC - -**** base - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct DirPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - } -#+END_SRC - -**** sisupod -***** pod - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct SiSUpodPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string sisupod_filename(string fn_src) { - return "sisupod".chainPath(base_filename(fn_src) ~ ".zip").array; - } - string base(string fn_src) { - return "sisupod".chainPath(base_filename(fn_src)).array; - } - } -#+END_SRC - -***** pod zipped - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct SiSUpodPathsZipped { - auto spod_pths = SiSUpodPaths(); - string base_filename(string fn_src) { - return spod_pths.base_filename(fn_src); - } - string sisupod_filename(string fn_src) { - return spod_pths.sisupod_filename(fn_src); - } - string base(string fn_src) { - return spod_pths.base(fn_src); - } - auto doc_root(string fn_src) { - return "doc"; - } - auto doc(string fn_src) { - return doc_root(fn_src); - } - auto doc_lng(string fn_src, string lng) { - return doc_root(fn_src).chainPath(lng).array; - } - auto conf(string fn_src) { - return doc_root(fn_src).chainPath("_sisu").array; - } - auto image(string fn_src) { - return conf(fn_src).chainPath("image").array; - } - auto css(string fn_src) { - return conf(fn_src).chainPath("css").array; - } - auto fn_doc(string fn_src, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_src)).array; - } - auto fn_doc_insert(string fn_src, string fn_insert, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_insert)).array; - } - } -#+END_SRC - -***** pod unzipped archive - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct SiSUpodPathsFilesystemArchive { - auto spod_pths = SiSUpodPaths(); - string base_filename(string fn_src) { - return spod_pths.base_filename(fn_src); - } - string sisupod_filename(string fn_src) { - return spod_pths.sisupod_filename(fn_src); - } - string base(string fn_src) { - return spod_pths.base(fn_src); - } - auto doc_root(string fn_src) { - return base(fn_src).chainPath("doc").array; - } - auto doc(string fn_src) { - return doc_root(fn_src); - } - auto doc_lng(string fn_src, string lng) { - return doc_root(fn_src).chainPath(lng).array; - } - auto conf(string fn_src) { - return doc_root(fn_src).chainPath("_sisu").array; - } - auto image(string fn_src) { - return conf(fn_src).chainPath("image").array; - } - auto css(string fn_src) { - return conf(fn_src).chainPath("css").array; - } - auto fn_doc(string fn_src, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_src)).array; - } - auto fn_doc_insert(string fn_src, string fn_insert, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_insert)).array; - } - } -#+END_SRC - -**** html5 - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct HtmlPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string base() { - return "en".chainPath("html").array; - } - string seg(string fn_src) { - return base.chainPath(base_filename(fn_src)).array; - } - string fn_scroll(string fn_src) { - return base.chainPath(base_filename(fn_src) ~ ".html").array; - } - string fn_seg(string fn_src, string seg_filename) { - return seg(fn_src).chainPath(seg_filename ~ ".html").array; - } - } -#+END_SRC - -**** epub3 - -#+name: defaults_template_paths -#+BEGIN_SRC d - struct Epub3paths { - string dirtop() { - return "".chainPath("").array; - } - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string base() { - return "en".chainPath("epub3").array; - } - string epub_file(string fn_src) { - return base.chainPath(base_filename(fn_src) ~ ".epub").array; - } - string docdir(string fn_src) { - return base.chainPath(base_filename(fn_src)).array; - } - string doc_meta_inf(string fn_src) { - return dirtop.chainPath("META-INF").array; - } - string doc_oebps(string fn_src) { - return dirtop.chainPath("OEBPS").array; - } - string doc_oebps_css(string fn_src) { - return doc_oebps(fn_src).chainPath("css").array; - } - string doc_oebps_image(string fn_src) { - return doc_oebps(fn_src).chainPath("image").array; - } - string fn_mimetypes(string fn_src) { - return dirtop.chainPath("mimetypes").array; - } - string fn_dmi_container_xml(string fn_src) { - return doc_meta_inf(fn_src).chainPath("container.xml").array; - } - string fn_oebps_toc_nav_xhtml(string fn_src) { - return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; - } - string fn_oebps_toc_ncx(string fn_src) { - return doc_oebps(fn_src).chainPath("toc.ncx").array; - } - string fn_oebps_content_opf(string fn_src) { - return doc_oebps(fn_src).chainPath("content.opf").array; - } - string fn_oebps_content_xhtml(string fn_src, string seg_filename) { - return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; - } - debug(epub_output) { - string dbg_doc_meta_inf(string fn_src) { - return docdir(fn_src).chainPath("META-INF").array; - } - string dbg_doc_oebps(string fn_src) { - return docdir(fn_src).chainPath("OEBPS").array; - } - string dbg_doc_oebps_css(string fn_src) { - return doc_oebps(fn_src).chainPath("css").array; - } - string dbg_doc_oebps_image(string fn_src) { - return doc_oebps(fn_src).chainPath("image").array; - } - string dbg_fn_mimetypes(string fn_src) { - return docdir(fn_src).chainPath("mimetypes").array; - } - string dbg_fn_dmi_container_xml(string fn_src) { - return doc_meta_inf(fn_src).chainPath("container.xml").array; - } - string dbg_fn_oebps_toc_nav_xhtml(string fn_src) { - return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; - } - string dbg_fn_oebps_toc_ncx(string fn_src) { - return doc_oebps(fn_src).chainPath("toc.ncx").array; - } - string dbg_fn_oebps_content_opf(string fn_src) { - return doc_oebps(fn_src).chainPath("content.opf").array; - } - string dbg_fn_oebps_content_xhtml(string fn_src, string seg_filename) { - return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; - } - } - } -} -#+END_SRC - -** 1. ctRegex :regex: -[[./sdp.org][sdp]] [[./][org/]] -http://dlang.org/phobos/std_regex.html -- Plain string, in which case it's compiled to bytecode before matching. -- Regex!char (wchar/dchar) that contains a pattern in the form of compiled bytecode. -- StaticRegex!char (wchar/dchar) that contains a pattern in the form of compiled native machine code. - -*** 0. code template: :rgx: - -#+name: tangle_ao_rgx -#+BEGIN_SRC d :tangle ../src/sdp/output_rgx.d -/++ - regex: regular expressions used in sisu document parser -+/ -template SiSUoutputRgxInit() { - private import defaults; - struct Rgx { - <> - <> - } -} -#+END_SRC - -*** special characters -**** xhtml special characters - -#+name: sp_ch_xhtml_rgx -#+BEGIN_SRC d -static xhtml_ampersand = ctRegex!(`[&]`); // & -static xhtml_less_than = ctRegex!(`[<]`); // < -static xhtml_greater_than = ctRegex!(`[>]`); // > -static xhtml_line_break = ctRegex!(` [\\]{2}`); //
-#+END_SRC - -* 2. defaults shared by ao & output (generic) -** 0. defaults :defaults: -*** template: internal markup :markup: - -#+name: defaults_template_markup -#+BEGIN_SRC d -template InternalMarkup() { - struct InlineMarkup { - auto en_a_o = "【"; auto en_a_c = "】"; // endnote en_a_o: '~{'; en_a_c: '}~'; - auto en_b_o = "〖"; auto en_b_c = "〗"; // endnote en_b_o: '~['; en_b_c: ']~'; - auto lnk_o = "┥"; auto lnk_c = "┝"; // auto lnk_o = "⌠"; auto lnk_c = "⌡"; // '⌈' '⌋' '⌠' '⌡' #Mx[:lnk_o= '◁'; Mx[:lnk_c= '▷' #‹ › - auto url_o = "┤"; auto url_c = "├"; - auto mark_internal_site_lnk = "¤"; - auto nbsp = "░"; - auto br_line = "┘"; // "╱"; // lB ▌ 9612 ┘ ¶ - auto br_nl = "┙"; // "╲"; // lB ▌ 』 ┘ - auto br_paragraph = "┚"; // "█"; // FB █ 9608 # PP ∥ 8741 #▐ #'┘' #'¶' #FB █ 9608 lB ▌ 9612 RB ▐ 9616 - auto br_obj = "break_obj"; - auto br_page_line = "┼"; // "▭"; - auto br_page = "┿"; // "┼"; - auto br_page_new = "╂"; // "╋"; - auto tc_s = "┊"; // "┴"; //"『"; // "┏" ┓ - auto tc_o = "┏"; //"『"; // "┏" ┓ - auto tc_c = "┚"; // "』"; // "┚" table row mark #Mx[:tc_c]="』\n" - auto tc_p = "┆"; // table col/misc mark - string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { - _indent_spaces = replicate(_indent_spaces, indent); - return _indent_spaces; - } - string repeat_character_by_number_provided(C,N)(C _character ="-", N number=10) { - _character = replicate(_character, number); - return _character; - } - } -} -#+END_SRC - -*** template language codes - -#+name: defaults_template_language_codes -#+BEGIN_SRC d -template SiSUlanguageCodes() { - /+ language codes +/ - struct Lang { - string[string][string] codes() { - auto _lang_codes = [ - "am": [ "c": "am", "n": "Amharic", "t": "Amharic", "xlp": "amharic" ], - "bg": [ "c": "bg", "n": "Bulgarian", "t": "Български (Bəlgarski)", "xlp": "bulgarian" ], - "bn": [ "c": "bn", "n": "Bengali", "t": "Bengali", "xlp": "bengali" ], - "br": [ "c": "br", "n": "Breton", "t": "Breton", "xlp": "breton" ], - "ca": [ "c": "ca", "n": "Catalan", "t": "catalan", "xlp": "catalan" ], - "cs": [ "c": "cs", "n": "Czech", "t": "česky", "xlp": "czech" ], - "cy": [ "c": "cy", "n": "Welsh", "t": "Welsh", "xlp": "welsh" ], - "da": [ "c": "da", "n": "Danish", "t": "dansk", "xlp": "danish" ], - "de": [ "c": "de", "n": "German", "t": "Deutsch", "xlp": "german" ], - "el": [ "c": "el", "n": "Greek", "t": "Ελληνικά (Ellinika)", "xlp": "greek" ], - "en": [ "c": "en", "n": "English", "t": "English", "xlp": "english" ], - "eo": [ "c": "eo", "n": "Esperanto", "t": "Esperanto", "xlp": "esperanto" ], - "es": [ "c": "es", "n": "Spanish", "t": "español", "xlp": "spanish" ], - "et": [ "c": "et", "n": "Estonian", "t": "Estonian", "xlp": "estonian" ], - "eu": [ "c": "eu", "n": "Basque", "t": "basque", "xlp": "basque" ], - "fi": [ "c": "fi", "n": "Finnish", "t": "suomi", "xlp": "finnish" ], - "fr": [ "c": "fr", "n": "French", "t": "français", "xlp": "french" ], - "ga": [ "c": "ga", "n": "Irish", "t": "Irish", "xlp": "irish" ], - "gl": [ "c": "gl", "n": "Galician", "t": "Galician", "xlp": "galician" ], - "he": [ "c": "he", "n": "Hebrew", "t": "Hebrew", "xlp": "hebrew" ], - "hi": [ "c": "hi", "n": "Hindi", "t": "Hindi", "xlp": "hindi" ], - "hr": [ "c": "hr", "n": "Croatian", "t": "Croatian", "xlp": "croatian" ], - "hy": [ "c": "hy", "n": "Armenian", "t": "Armenian", "xlp": "armenian" ], - "ia": [ "c": "ia", "n": "Interlingua", "t": "Interlingua", "xlp": "interlingua" ], - "is": [ "c": "is", "n": "Icelandic", "t": "Icelandic", "xlp": "icelandic" ], - "it": [ "c": "it", "n": "Italian", "t": "Italiano", "xlp": "italian" ], - "ja": [ "c": "ja", "n": "Japanese", "t": "日本語 (Nihongo)", "xlp": "japanese" ], - "ko": [ "c": "ko", "n": "Korean", "t": "Korean", "xlp": "korean" ], - "la": [ "c": "la", "n": "Latin", "t": "Latin", "xlp": "latin" ], - "lo": [ "c": "lo", "n": "Lao", "t": "Lao", "xlp": "lao" ], - "lt": [ "c": "lt", "n": "Lithuanian", "t": "Lithuanian", "xlp": "lithuanian" ], - "lv": [ "c": "lv", "n": "Latvian", "t": "Latvian", "xlp": "latvian" ], - "ml": [ "c": "ml", "n": "Malayalam", "t": "Malayalam", "xlp": "malayalam" ], - "mr": [ "c": "mr", "n": "Marathi", "t": "Marathi", "xlp": "marathi" ], - "nl": [ "c": "nl", "n": "Dutch", "t": "Nederlands", "xlp": "dutch" ], - "no": [ "c": "no", "n": "Norwegian", "t": "norsk", "xlp": "norsk" ], - "nn": [ "c": "nn", "n": "Norwegian Nynorsk", "t": "nynorsk", "xlp": "nynorsk" ], - "oc": [ "c": "oc", "n": "Occitan", "t": "Occitan", "xlp": "occitan" ], - "pl": [ "c": "pl", "n": "Polish", "t": "polski", "xlp": "polish" ], - "pt": [ "c": "pt", "n": "Portuguese", "t": "Português", "xlp": "portuges" ], - "pt_BR": [ "c": "pt_BR", "n": "Portuguese Brazil", "t": "Brazilian Português", "xlp": "brazilian" ], - "ro": [ "c": "ro", "n": "Romanian", "t": "română", "xlp": "romanian" ], - "ru": [ "c": "ru", "n": "Russian", "t": "Русский (Russkij)", "xlp": "russian" ], - "sa": [ "c": "sa", "n": "Sanskrit", "t": "Sanskrit", "xlp": "sanskrit" ], - "se": [ "c": "se", "n": "Sami", "t": "Samin", "xlp": "samin" ], - "sk": [ "c": "sk", "n": "Slovak", "t": "slovensky", "xlp": "slovak" ], - "sl": [ "c": "sl", "n": "Slovenian", "t": "Slovenian", "xlp": "slovenian" ], - "sq": [ "c": "sq", "n": "Albanian", "t": "Albanian", "xlp": "albanian" ], - "sr": [ "c": "sr", "n": "Serbian", "t": "Serbian", "xlp": "serbian" ], - "sv": [ "c": "sv", "n": "Swedish", "t": "svenska", "xlp": "swedish" ], - "ta": [ "c": "ta", "n": "Tamil", "t": "Tamil", "xlp": "tamil" ], - "te": [ "c": "te", "n": "Telugu", "t": "Telugu", "xlp": "telugu" ], - "th": [ "c": "th", "n": "Thai", "t": "Thai", "xlp": "thai" ], - "tk": [ "c": "tk", "n": "Turkmen", "t": "Turkmen", "xlp": "turkmen" ], - "tr": [ "c": "tr", "n": "Turkish", "t": "Türkçe", "xlp": "turkish" ], - "uk": [ "c": "uk", "n": "Ukranian", "t": "українська (ukrajins\"ka)", "xlp": "ukrainian" ], - "ur": [ "c": "ur", "n": "Urdu", "t": "Urdu", "xlp": "urdu" ], - "us": [ "c": "en", "n": "English (American)","t": "English", "xlp": "english" ], - "vi": [ "c": "vi", "n": "Vietnamese", "t": "Vietnamese", "xlp": "vietnamese" ], - "zh": [ "c": "zh", "n": "Chinese", "t": "中文", "xlp": "chinese" ], - "en": [ "c": "en", "n": "English", "t": "English", "xlp": "english" ], - "xx": [ "c": "xx", "n": "Default", "t": "English", "xlp": "english" ], - ]; - return _lang_codes; - } - string[] code_arr_ptr() { - auto _lang_codes = ["am", "bg", "bn", "br", "ca", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fi", "fr", "ga", "gl", "he", "hi", "hr", "hy", "ia", "is", "it", "ja", "ko", "la", "lo", "lt", "lv", "ml", "mr", "nl", "no", "nn", "oc", "pl", "pt", "pt_BR", "ro", "ru", "sa", "se", "sk", "sl", "sq", "sr", "sv", "ta", "te", "th", "tk", "tr", "uk", "ur", "us", "vi", "zh", "en", "xx",]; - return _lang_codes; - } - string[] code_arr() { - auto _lang_codes = ["am", "bg", "bn", "br", "ca", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fi", "fr", "ga", "gl", "he", "hi", "hr", "hy", "ia", "is", "it", "ja", "ko", "la", "lo", "lt", "lv", "ml", "mr", "nl", "no", "nn", "oc", "pl", "pt", "pt_BR", "ro", "ru", "sa", "se", "sk", "sl", "sq", "sr", "sv", "ta", "te", "th", "tk", "tr", "uk", "ur", "vi", "zh"]; - return _lang_codes; - } - auto codes_() { - return "(" ~ join(code_arr,"|") ~ ")"; - } - auto codes_regex() { - return regex(codes_); - } - } -} -#+END_SRC - -** 1. ctRegex :regex: - -*** misc generic - -#+name: prgmkup_rgx -#+BEGIN_SRC d -static newline = ctRegex!("\n", "mg"); -static strip_br = ctRegex!("^
\n|
\n*$"); -static space = ctRegex!(`[ ]`, "mg"); -static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); -static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); // could be issues for endnotes -static two_spaces = ctRegex!(`[ ]{2}`, "mg"); -static nbsp_char = ctRegex!(`░`, "mg"); -static nbsp_chars_line_start = ctRegex!(`^░+`, "mg"); -static nbsp_and_space = ctRegex!(` [ ]`, "mg"); -static nbsp_char_and_space = ctRegex!(`░[ ]`, "mg"); -#+END_SRC - -*** filename (and path) matching (including markup insert file) :insert:file:path:filename: - -#+name: prgmkup_rgx -#+BEGIN_SRC d -static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); -static src_fn = - ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); -static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); -static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); -static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); -static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); -static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); -#+END_SRC - -*** inline markup -**** inline (internal program) markup footnotes endnotes :inline:footnote: - -#+name: prgmkup_rgx -#+BEGIN_SRC d -/+ inline markup footnotes endnotes +/ -static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); -static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); -static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); -static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); -static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); -static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); -static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); -static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); -static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); -static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); -static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); -static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); -static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); -#+END_SRC - -**** inline links - -#+name: prgmkup_rgx -#+BEGIN_SRC d -/+ inline markup footnotes endnotes +/ -static inline_link = ctRegex!(`┥(.+?)┝┤(.+?)├`, "mg"); -static inline_a_url = ctRegex!(`(┤)(\S+?)(├)`, "mg"); -static fn_suffix = ctRegex!(`\.fnSuffix`, "mg"); -static inline_link_fn_suffix = ctRegex!(`¤(.+?)(\.fnSuffix)`, "mg"); -static inline_seg_link = ctRegex!(`(¤)(?:.+?)\.fnSuffix`, "mg"); -static mark_internal_site_lnk = ctRegex!(`¤`, "mg"); -#+END_SRC - -**** TODO inline markup font face mod :inline:font:face: - -#+name: prgmkup_rgx -#+BEGIN_SRC d -/+ inline markup font face mod +/ -static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); -static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); -static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); -static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); -static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); -static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); -static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); -static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); -static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); -static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); -static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); -static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); -#+END_SRC - -**** table related - -#+name: prgmkup_rgx -#+BEGIN_SRC d -/+ table delimiters +/ -static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); // -static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); // -#+END_SRC - -* +set colors for terminal+ (unused) :colors:terminal: - -#+name: ao_ansi_colors -#+BEGIN_SRC d -string[string] scr_txt_color = [ - "off" : "\033[0m", - "white" : "\033[37m", - "white_bold" : "\033[1m", - "marker" : "\033[42m", - "bold" : "\033[1m", - "underline" : "\033[4m", - "invert" : "\033[7m", - "darkgrey_hi" : "\033[100m", - "grey_hi" : "\033[47m", - "pink_hi" : "\033[105m", - "fuchsia_hi" : "\033[45m", - "red_hi" : "\033[41m", - "orange_hi" : "\033[101m", - "yellow_hi" : "\033[103m", - "brown_hi" : "\033[43m", - "lightgreen_hi" : "\033[102m", - "green_hi" : "\033[42m", - "cyan_hi" : "\033[106m", - "blue_hi" : "\033[104m", - "navy_hi" : "\033[44m", - "grey" : "\033[90m", - "pink" : "\033[95m", - "fuchsia" : "\033[35m", - "ruby" : "\033[31m", - "red" : "\033[91m", - "orange" : "\033[91m", - "yellow" : "\033[93m", - "brown" : "\033[33m", - "green" : "\033[92m", - "darkgreen" : "\033[32m", - "cyan" : "\033[36m", - "blue" : "\033[94m", - "navy" : "\033[34m", - "black" : "\033[30m" -]; -string[string] scr_txt_marker = [ - "white" : "\033[37m*\033[0m ", - "bold" : "\033[1m*\033[0m ", - "invert" : "\033[7m*\033[0m ", - "darkgrey_hi" : "\033[100m*\033[0m ", - "grey_hi" : "\033[47m*\033[0m ", - "pink_hi" : "\033[105m*\033[0m ", - "fuchsia_hi" : "\033[45m*\033[0m ", - "red_hi" : "\033[41m*\033[0m ", - "orange_hi" : "\033[101m*\033[0m ", - "yellow_hi" : "\033[103m*\033[0m ", - "brown_hi" : "\033[43m*\033[0m ", - "lightgreen_hi" : "\033[102m*\033[0m ", - "green_hi" : "\033[42m*\033[0m ", - "cyan_hi" : "\033[106m*\033[0m ", - "blue_hi" : "\033[104m*\033[0m ", - "navy_hi" : "\033[44m*\033[0m ", - "grey" : "\033[90m*\033[0m ", - "pink" : "\033[95m*\033[0m ", - "fuchsia" : "\033[35m*\033[0m ", - "ruby" : "\033[31m*\033[0m ", - "red" : "\033[91m*\033[0m ", - "orange" : "\033[91m*\033[0m ", - "yellow" : "\033[93m*\033[0m ", - "brown" : "\033[33m*\033[0m ", - "green" : "\033[92m*\033[0m ", - "darkgreen" : "\033[32m*\033[0m ", - "cyan" : "\033[36m*\033[0m ", - "blue" : "\033[94m*\033[0m ", - "navy" : "\033[34m*\033[0m ", - "black" : "\033[30m*\033[0m " -]; -#+END_SRC diff --git a/org/output.org b/org/output.org deleted file mode 100644 index e0a7985..0000000 --- a/org/output.org +++ /dev/null @@ -1,3442 +0,0 @@ -#+TITLE: sdp output html -#+AUTHOR: Ralph Amissah -#+EMAIL: ralph.amissah@gmail.com -#+STARTUP: indent -#+LANGUAGE: en -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+FILETAGS: :sdp:rel:output: -#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) - -[[./sdp.org][sdp]] [[./][org/]] -* 0. output hub [#A] - -#+BEGIN_SRC d :tangle ../src/sdp/output_hub.d -/++ - output hub
- check & generate output types requested -+/ -template outputHub() { - private import - std.regex, - std.algorithm, - std.array, - std.container, - std.exception, - std.getopt, - std.process, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf; - import - defaults, - output_epub3, - output_html, - output_xhtmls, - source_sisupod, - create_zip_file, - output_rgx, - output_xhtmls; - void outputHub(D,I)(D doc_abstraction, I doc_matters) { - mixin SiSUoutputRgxInit; - auto rgx = Rgx(); - if ((doc_matters.opt_action_bool["verbose"])) { - writeln(doc_matters.keys_seq.seg); - } - if (doc_matters.opt_action_bool["source"]) { - /+ mixin outputSource; +/ - writeln("source"); - } - if (doc_matters.opt_action_bool["sisupod"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("sisupod source processing... ");} - SiSUpod!()(doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("sisupod done");} - } - if (doc_matters.opt_action_bool["text"]) { - /+ mixin outputText; +/ - writeln("text processing"); - } - if (doc_matters.opt_action_bool["html"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html scroll processing... ");} - outputHTML!().scroll(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html scroll done");} - if ((doc_matters.opt_action_bool["verbose"])) {write("html seg processing... ");} - outputHTML!().seg(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html seg done");} - } else if (doc_matters.opt_action_bool["html_seg"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html seg processing... ");} - outputHTML!().seg(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html seg done");} - } else if (doc_matters.opt_action_bool["html_scroll"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html scroll processing... ");} - outputHTML!().scroll(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html scroll done");} - } - if (doc_matters.opt_action_bool["epub"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("epub3 processing... ");} - outputEPub3!()(doc_abstraction, doc_matters); - // epub.css_write; - if ((doc_matters.opt_action_bool["verbose"])) {writeln("epub3 done");} - } - if (doc_matters.opt_action_bool["pdf"]) { - /+ mixin outputPDF; +/ - writeln("pdf processing"); - } - if (doc_matters.opt_action_bool["odt"]) { - /+ mixin outputODT; +/ - writeln("odt processing"); - } - if (doc_matters.opt_action_bool["sqlite"]) { - /+ mixin outputSQLite; +/ - writeln("sqlite processing"); - } - if (doc_matters.opt_action_bool["postgresql"]) { - /+ mixin outputPostgreSQL; +/ - writeln("pgsql processing"); - } - } -} -#+END_SRC - -* 1. output functions :output: -** output imports - -#+name: output_imports -#+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, - std.digest.sha, - std.exception, - std.file, - std.getopt, - std.json, - std.outbuffer, - std.path, - std.process, - std.range, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.zip, - std.conv : to; -import - create_zip_file, - defaults, - output_rgx, - output_xhtmls; -#+END_SRC - -** _zip_ -*** template :template: - -#+BEGIN_SRC d :tangle ../src/sdp/create_zip_file.d -template createZipFile() { - import std.file; - import std.outbuffer; - import std.string; - import std.zip; - void createZipFile( - string zip_file_name, - void[] compressed_zip_data, - ) { - try { - write(zip_file_name, compressed_zip_data); - } catch (ZipException ex) { - // Handle Errors - } - } -} -#+END_SRC - -** _sisupod_ :sisupod: -*** template :template: - -#+BEGIN_SRC d :tangle ../src/sdp/source_sisupod.d -template SiSUpod() { - <> - void SiSUpod(T)(T doc_matters) { - <> - try { - <> - <> - <> - } - catch (ErrnoException ex) { - // Handle error - } - } -} -#+END_SRC - -*** mkdir - -#+name: source_sisupod_init -#+BEGIN_SRC d -debug(asserts) { - // static assert(is(typeof(doc_matters) == tuple)); -} -mixin SiSUoutputRgxInit; -mixin SiSUpaths; -auto pth_sisupod = SiSUpodPathsZipped(); -auto pth_sisupod_filesystem = SiSUpodPathsFilesystemArchive(); -mixin SiSUlanguageCodes; -auto lang = Lang(); -auto rgx = Rgx(); -assert (doc_matters.source_filename.match(rgx.src_fn)); -#+END_SRC - -#+name: source_sisupod_mkdirs -#+BEGIN_SRC d -/+ create directory structure +/ -if (!exists(pth_sisupod_filesystem.doc(doc_matters.source_filename))) { - pth_sisupod_filesystem.doc(doc_matters.source_filename).mkdirRecurse; -} -if (!exists(pth_sisupod_filesystem.conf(doc_matters.source_filename))) { - pth_sisupod_filesystem.conf(doc_matters.source_filename).mkdirRecurse; -} -if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { - pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; -} -if (!exists(pth_sisupod_filesystem.image(doc_matters.source_filename))) { - pth_sisupod_filesystem.image(doc_matters.source_filename).mkdirRecurse; -} -if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language))) { - pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse; -} -#+END_SRC - -*** copy - -#+name: source_sisupod_copy -#+BEGIN_SRC d -debug(sisupod) { - writeln(__LINE__, ": ", - doc_matters.source_filename, " -> ", - pth_sisupod_filesystem.fn_doc( - doc_matters.source_filename, - doc_matters.language - )); -} -auto zip = new ZipArchive(); -auto fn_sisupod = pth_sisupod.sisupod_filename(doc_matters.source_filename); -{ /+ bundle images +/ - foreach (image; doc_matters.image_list) { - debug(sisupodimages) { - writeln( - "_sisu/image/", image, " -> ", - pth_sisupod.image(doc_matters.source_filename), "/", image - ); - } - auto fn_src = "_sisu/image/"~ image; - auto fn_out = pth_sisupod.image(doc_matters.source_filename).to!string ~ "/" ~ image; - auto fn_out_filesystem = pth_sisupod_filesystem.image(doc_matters.source_filename).to!string ~ "/" ~ image; - if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn_out; - auto zip_data = new OutBuffer(); - zip_data.write(cast(char[]) ((fn_src).read)); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); - } - } - } -} -{ /+ bundle sisu_document_make +/ - auto fn_src = "_sisu/sisu_document_make"; // check (_sisu/sisu_document_make) - auto fn_out = pth_sisupod.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; - auto fn_out_filesystem = pth_sisupod_filesystem.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; - if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn_out; - auto zip_data = new OutBuffer(); - zip_data.write((fn_src).readText); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); - } - } -} -{ /+ bundle primary file +/ - auto fn_src = doc_matters.source_filename; - auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; - auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; - if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn_out; - auto zip_data = new OutBuffer(); - zip_data.write((fn_src).readText); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); - } - } -} -{ /+ bundle insert files +/ - if (doc_matters.file_insert_list.length > 0) { - foreach (insert_file; doc_matters.file_insert_list) { - debug(sisupod) { - writeln( - insert_file, " -> ", - pth_sisupod.fn_doc_insert( - doc_matters.source_filename, - insert_file, - doc_matters.language - )); - } - auto fn_src = insert_file; - auto fn_out = pth_sisupod.fn_doc_insert( - doc_matters.source_filename, - insert_file, - doc_matters.language - ).to!string; - auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc_insert( - doc_matters.source_filename, - insert_file, - doc_matters.language - ).to!string; - if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = insert_file; - auto zip_data = new OutBuffer(); - zip_data.write((fn_src).readText); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); - } - } - } - } -} -#+END_SRC - -*** sha256 of sisupod.zip, zip debug, read zip archive - -#+name: source_sisupod_copy -#+BEGIN_SRC d -if (exists(fn_sisupod)) { - try { - auto data = (cast(byte[]) (fn_sisupod).read); - writefln("%-(%02x%) %s", data.sha256Of, fn_sisupod); - debug(sisupod) { - try { - auto zipped = new ZipArchive((fn_sisupod).read); - foreach (filename, member; zipped.directory) { - auto data = zipped.expand(member); - writeln("> ", filename, " length ", data.length); // filename == member.name - // Use data - } - } - catch (ZipException ex) { - // Handle errors - } - if (doc_matters.source_filename == "en/the_wealth_of_networks.yochai_benkler.sst") { - assert( - ((data).sha256Of).toHexString - == "DDE0013C13C6A4F06D4BE72087E2CDEF47697CA38A6A2D65BA7207DB6B144271", - "\nsisupod: sha256 value for " - ~ doc_matters.source_filename - ~ " has changed, is now: " - ~ ((data).sha256Of).toHexString - ); - } - if (doc_matters.source_filename == "en/sisu_markup_stress_test.sst") { - assert( - ((data).sha256Of).toHexString - == "112C0AEDD2518A1803D91A7CF5785274A3116C0779A631782D0C0813B212C68A", - "\nsisupod: sha256 value for " - ~ doc_matters.source_filename - ~ " has changed, is now: " - ~ ((data).sha256Of).toHexString - ); - } - } - } - catch (ErrnoException ex) - { - // Handle errors - } -} -#+END_SRC - -** text [#C] :text: -** xml offspring (xhtml html epub) :xml: -*** format xhtml objects :format: -**** 0. xhtml common template :template: - -#+BEGIN_SRC d :tangle ../src/sdp/output_xhtmls.d -template outputXHTMLs() { - <> - mixin SiSUoutputRgxInit; - struct outputXHTMLs { - auto rgx = Rgx(); - <> -<> - } -} -#+END_SRC - -**** misc -***** special characters - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string special_characters(string _txt){ - _txt = (_txt) - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.xhtml_line_break, "
"); - return _txt; -} -#+END_SRC - -***** font_face - -#+name: xhtml_format_objects -#+BEGIN_SRC d -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; -} -#+END_SRC - -***** anchor tags - -#+name: xhtml_format_objects -#+BEGIN_SRC d -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; -} -#+END_SRC - -***** doc head & tails -****** scroll head - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto scroll_head(Me)( - Me dochead_meta, -) { - debug(asserts) { - static assert(is(typeof(dochead_meta) == string[string][string])); - } - string o; - o = format(q"¶ - - - - - %s%s - - - - - - - - - - - - - - - - - - - - -¶", -dochead_meta["title"]["full"], -(dochead_meta["creator"]["author"].empty) ? "" : ", " ~ dochead_meta["creator"]["author"], -); - return o; -} -#+END_SRC - -****** seg head - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto seg_head(Me)( - Me dochead_meta, -) { - debug(asserts) { - static assert(is(typeof(dochead_meta) == string[string][string])); - } - string o; - o = format(q"¶ - - - - - %s%s - - - - - - - - - - - - - - - - - - - - - -¶", -dochead_meta["title"]["full"], -(dochead_meta["creator"]["author"].empty) ? "" : ", " ~ dochead_meta["creator"]["author"], -); - return o; -} -#+END_SRC - -****** xhtml tail - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto tail() { - string o; - o = format(q"¶ - - - -¶"); - return o; -} -#+END_SRC - -**** inline markup -***** links - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_links(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - string seg_scroll = "seg", -) { - if (obj.inline_links) { - if ((seg_scroll == "scroll") - && _txt.match(rgx.mark_internal_site_lnk)) { - _txt = (_txt).replaceAll( - rgx.inline_seg_link, - "$1"); - } - _txt = (_txt).replaceAll( - rgx.inline_link_fn_suffix, - ("$1" ~ _suffix)); - _txt = (_txt).replaceAll( - rgx.inline_link, - ("$1")); - _txt = (_txt).replaceAll( - rgx.mark_internal_site_lnk, - "" - ); - } - debug(markup_links) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.inline_links, - "): ", obj.is_a, ": ", - obj.text - ); - } - } - debug(markup) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.inline_links, - "): ", obj.is_a, ": ", - obj.text - ); - } - } - return _txt; -} -#+END_SRC - -***** notes scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_notes_scroll(O)( - auto return ref const O obj, - string _txt, -) { - if (obj.inline_notes_reg) { - _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.is_a, ": ", obj.text); - } - } - debug(markup) { - if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); - } - } - // if (obj.inline_notes_star) { - // _txt = replaceAll( - // _txt, - // rgx.inline_notes_delimiter_al_regular_number_note, - // (" $1 ") - // ); - // } - return _txt; -} -#+END_SRC - -***** notes seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_notes_seg(O)( - auto return ref const O obj, - string _txt, -) { - string[] _endnotes; - if (obj.inline_notes_reg) { - /+ 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.is_a, ": ", obj.text); - } - } - auto t = tuple( - _txt, - _endnotes, - ); - return t; -} -#+END_SRC - -***** inline markup scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_markup_scroll(O)( - auto return ref const O obj, - 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; -} -#+END_SRC - -***** inline markup seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_markup_seg(O)( - auto return ref const O obj, - 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; -} -#+END_SRC - -**** toc - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto toc(O)( - auto return ref const O obj, -) { - string o; - o = format(q"¶
-

- %s -

-
¶", - obj.is_a, - obj.indent_hang, - obj.indent_base, - obj.text - ); - return o; -} -#+END_SRC - -**** heading -***** heading - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto heading(O)( - auto return ref const O obj, - string _txt, -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶


-
- %s - %s - -
¶", - obj.heading_lev_markup, - obj.is_a, - tags, - _txt, - obj.heading_lev_markup, - ); - } else { - o = format(q"¶


-
- - %s - %s - -
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.heading_lev_markup, - obj.is_a, - obj.obj_cite_number, - obj.obj_cite_number, - tags, - _txt, - obj.heading_lev_markup, - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto heading_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = heading(obj, _txt); - return o; -} -#+END_SRC - -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto heading_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = t[0]; - string[] _endnotes = t[1]; - string o = heading(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** para -***** para - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto para(O)( - auto return ref const O obj, - string _txt, -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - _txt = font_face(_txt); - string o; - _txt = (obj.bullet) ? ("●  " ~ _txt) : _txt; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

%s - %s -

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

%s - %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.indent_hang, - obj.indent_base, - obj.obj_cite_number, - tags, - _txt - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto para_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = para(obj, _txt); - return o; -} -#+END_SRC - -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto para_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); - string[] _endnotes = t[1]; - string o = para(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** quote - -***** quote - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto quote(O)( - auto return ref const O obj, - string _txt, -) { - _txt = font_face(_txt); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

- %s -

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

- %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto quote_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = quote(obj, _txt); - return o; -} -#+END_SRC -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto quote_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); - string[] _endnotes = t[1]; - string o = quote(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** group - -***** group - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto group(O)( - auto return ref const O obj, - string _txt, -) { - _txt = font_face(_txt); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

- %s -

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

- %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto group_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = group(obj, _txt); - return o; -} -#+END_SRC -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto group_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); - string[] _endnotes = t[1]; - string o = group(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** block - -***** block - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto block(O)( - auto return ref const O obj, - string _txt, -) { - _txt = font_face(_txt); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

- %s -

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

- %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto block_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = block(obj, _txt); - return o; -} -#+END_SRC -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto block_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); - string[] _endnotes = t[1]; - string o = block(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** poem verse -***** verse - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto verse(O)( // using code from code block, review - auto return ref const O obj, - string _txt, -) { - _txt = font_face(_txt); - _txt = (_txt) - .replaceAll(rgx.newline, "
\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"¶
-

-%s -

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

-%s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; -} -#+END_SRC - -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto verse_scroll(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _txt = inline_markup_scroll(obj, _suffix); // issue - string o = verse(obj, _txt); - return o; -} -#+END_SRC - -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto verse_seg(O)( - auto return ref const O obj, - string _suffix = ".html", -) { - auto t = inline_markup_seg(obj, _suffix); - string _txt = to!string(t[0]); - string[] _endnotes = t[1]; - string o = verse(obj, _txt); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -**** code - -#+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.newline, "
\n") - .replaceAll(rgx.nbsp_char, " "); - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

-%s -

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

-%s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; - } -#+END_SRC - -**** table - -***** TODO tablarize - -align="left|right|center" -$100 - -"style=\"text-align:right\"" -"style=\"text-align:left\"" - -"style=\"text-align:" ~ "right\"" - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto tablarize(O)( - auto return ref 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)) { // check row_idx+2 (rather than == ++row_idx) - _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; -} -#+END_SRC - -***** table - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto table(O)( - auto return ref const O obj, -) { - string _txt = obj.text; - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - _txt = font_face(_txt); - auto t = tablarize(obj, _txt); - _txt = t[0]; - string _note = t[1]; - string o; - o = format(q"¶
- -

%s - - %s -
- %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - tags, - _txt, - _note - ); - return o; -} -#+END_SRC - -**** endnote - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto endnote(O)( - auto return ref const O obj, -) { - string o; - o = format(q"¶

- %s -

¶", - obj.is_a, - obj.indent_hang, - obj.indent_base, - obj.text - ); - return o; -} -#+END_SRC - -*** _html_ [#A] :html: -**** template :template: - -#+BEGIN_SRC d :tangle ../src/sdp/output_html.d -template outputHTML() { - <> - mixin outputXHTMLs; - <> - <> - <> - <> -} -#+END_SRC - -**** scroll :scroll: -***** switch (sections & objects) format html output - -#+name: output_html_scroll -#+BEGIN_SRC d -void scroll(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, -) { - mixin SiSUoutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[] doc_html; - string[] doc; - string suffix = ".html"; - foreach (part; doc_matters.keys_seq.scroll) { - foreach (obj; doc_abstraction[part]) { - 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); - break; - case "toc": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, suffix); - break; - case "para": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - doc_html ~= xhtml_format.quote_scroll(obj); - break; - case "group": - doc_html ~= xhtml_format.group_scroll(obj); - break; - case "block": - doc_html ~= xhtml_format.block_scroll(obj); - break; - case "poem": - break; - case "verse": - doc_html ~= xhtml_format.verse_scroll(obj, suffix); - break; - case "code": - doc_html ~= xhtml_format.code(obj); - break; - case "table": - doc_html ~= xhtml_format.table(obj); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, suffix); - break; - case "endnote": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - case "glossary": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - case "bibliography": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - case "bookindex": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - case "blurb": - doc_html ~= xhtml_format.para_scroll(obj, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - break; - } - } - } - doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; - scroll_write_output(doc_matters.source_filename, doc); -} -#+END_SRC - -***** write output file - -#+name: output_html_scroll -#+BEGIN_SRC d -void scroll_write_output(Fn,C)( - Fn fn_src, - C doc, -) { - debug(asserts) { - static assert(is(typeof(fn_src) == string)); - static assert(is(typeof(doc) == string[])); - } - mixin SiSUpaths; - auto pth_html = HtmlPaths(); - try { - if (!exists(pth_html.base)) { - pth_html.base.mkdirRecurse; - } - auto f = File(pth_html.fn_scroll(fn_src), "w"); - foreach (o; doc) { - f.writeln(o); - } - } - catch (ErrnoException ex) { - // Handle error - } -} -#+END_SRC - -**** seg :seg: -***** switch (sections & objects) format html output - -#+name: output_html_seg -#+BEGIN_SRC d -void seg(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, -) { - mixin SiSUoutputRgxInit; - auto rgx = Rgx(); - auto xhtml_format = outputXHTMLs(); - string[][string] doc_html; - string[][string] doc_html_endnotes; - string[] doc; - string segment_filename; - string[] top_level_headings = ["","","",""]; - string suffix = ".html"; - foreach (part; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - if (obj.is_a == "heading") { // all headings: frontmatter, body & backmatter - switch (obj.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.heading_lev_markup) { - case 0: - top_level_headings[0] = ""; - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 1: - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 2: - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 3: - top_level_headings[3] = ""; - goto default; - default: - auto t = xhtml_format.heading_seg(obj, suffix); - top_level_headings[obj.heading_lev_markup] = t[0]; - break; - } - break; - case 4: - segment_filename = obj.segment_anchor_tag; - doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); - foreach (top_level_heading; top_level_headings) { - doc_html[segment_filename] ~= top_level_heading; - } - auto t = xhtml_format.heading_seg(obj, 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); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: // unused numbers, if remain check - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - } - break; - } - } else { - switch (obj.use) { - case "frontmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "toc": - auto t = xhtml_format.para_seg(obj, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "para": - auto t = xhtml_format.para_seg(obj, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(obj, 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); - 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); - 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); - 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); - break; - case "table": - doc_html[segment_filename] ~= xhtml_format.table(obj); - doc_html_endnotes[segment_filename] ~= ""; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "endnote": - auto t = xhtml_format.para_seg(obj, suffix); - doc_html[segment_filename] ~= t[0]; - break; - case "glossary": - auto t = xhtml_format.para_seg(obj, 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); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": - auto t = xhtml_format.para_seg(obj, 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); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - } - break; - } - } - } - } - seg_write_output(doc_matters, doc_html, doc_html_endnotes); -} -#+END_SRC - -***** write output files - -#+name: output_html_seg -#+BEGIN_SRC d -void seg_write_output(M,D,E)( - M doc_matters, - D doc_html, - E doc_html_endnotes, -) { - debug(asserts) { - static assert(is(typeof(doc_html) == string[][string])); - } - mixin SiSUoutputRgxInit; - auto rgx = Rgx(); - mixin SiSUpaths; - auto pth_html = HtmlPaths(); - auto xhtml_format = outputXHTMLs(); - auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); - try { - if (!exists(pth_html.seg(doc_matters.source_filename))) { - pth_html.seg(doc_matters.source_filename).mkdirRecurse; - } - foreach (seg_filename; doc_matters.segnames) { - auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); - foreach (docseg; doc_html[seg_filename]) { - f.writeln(docseg); - } - foreach (docseg; doc_html_endnotes[seg_filename]) { - f.writeln(docseg); - } - f.writeln(xhtml_format.tail); // needed for each lev4 - } - } - catch (ErrnoException ex) { - // handle error - } -} -#+END_SRC - -**** css :css: - -#+name: output_html_css -#+BEGIN_SRC d -auto html_css() { - string css; - css="/* SiSU css default stylesheet */ - body { - color: black; - background: #ffffff; - background-color: #ffffff; - } - a:link { - color: #003399; - text-decoration: none; - } - a:visited { - color: #003399; - text-decoration: none; - } - a:hover { - color: #000000; - background-color: #f9f9aa; - } - a.lnkocn:link { - color: #777777; - text-decoration: none; - } - a:hover img { - background-color: #ffffff; - } - a:active { - color: #003399; - text-decoration: underline; - } - div { - margin-left: 0; - margin-right: 0; - } - div.p { - margin-left: 5%; - margin-right: 1%; - } - .norm, .bold, .verse, .group, .block, .alt { - line-height: 133%; - margin-left: 0em; - margin-right: 2em; - margin-top: 12px; - margin-bottom: 0px; - padding-left: 0em; - text-indent: 0em; - } - p, h0, h1, h2, h3, h4, h5, h6, h7 { - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-size: 100%; - font-weight: normal; - line-height: 133%; - text-align: justify; - margin-left: 0em; - margin-right: 2em; - text-indent: 0mm; - margin-top: 0.8em; - margin-bottom: 0.8em; - } - /* indent */ - p.norm { } - p.i1 {padding-left: 1em;} - p.i2 {padding-left: 2em;} - p.i3 {padding-left: 3em;} - p.i4 {padding-left: 4em;} - p.i5 {padding-left: 5em;} - p.i6 {padding-left: 6em;} - p.i7 {padding-left: 7em;} - p.i8 {padding-left: 8em;} - p.i9 {padding-left: 9em;} - /* hanging indent */ - p[indent=\"h0i0\"] { - padding-left: 0em; - text-indent: 0em; - } - p[indent=\"h0i1\"] { - padding-left: 1em; - text-indent: -1em; - } - p[indent=\"h0i2\"] { - padding-left: 2em; - text-indent: -2em; - } - p[indent=\"h0i3\"] { - padding-left: 3em; - text-indent: -3em; - } - p[indent=\"h0i4\"] { - padding-left: 4em; - text-indent: -4em; - } - p[indent=\"h0i5\"] { - padding-left: 5em; - text-indent: -5em; - } - p[indent=\"h0i6\"] { - padding-left: 6em; - text-indent: -6em; - } - p[indent=\"h0i7\"] { - padding-left: 7em; - text-indent: -7em; - } - p[indent=\"h0i8\"] { - padding-left: 8em; - text-indent: -8em; - } - p[indent=\"h0i9\"] { - padding-left: 9em; - text-indent: -9em; - } - p[indent=\"h1i0\"] { - padding-left: 0em; - text-indent: 1em; - } - p[indent=\"h1i1\"] { - padding-left: 1em; - text-indent: 0em; - } - p[indent=\"h1i2\"] { - padding-left: 2em; - text-indent: -1em; - } - p[indent=\"h1i3\"] { - padding-left: 3em; - text-indent: -2em; - } - p[indent=\"h1i4\"] { - padding-left: 4em; - text-indent: -3em; - } - p[indent=\"h1i5\"] { - padding-left: 5em; - text-indent: -4em; - } - p[indent=\"h1i6\"] { - padding-left: 6em; - text-indent: -5em; - } - p[indent=\"h1i7\"] { - padding-left: 7em; - text-indent: -6em; - } - p[indent=\"h1i8\"] { - padding-left: 8em; - text-indent: -7em; - } - p[indent=\"h1i9\"] { - padding-left: 9em; - text-indent: -8em; - } - p[indent=\"h2i0\"] { - padding-left: 0em; - text-indent: 2em; - } - p[indent=\"h2i1\"] { - padding-left: 1em; - text-indent: 1em; - } - p[indent=\"h2i2\"] { - padding-left: 2em; - text-indent: 0em; - } - p[indent=\"h2i3\"] { - padding-left: 3em; - text-indent: -1em; - } - p[indent=\"h2i4\"] { - padding-left: 4em; - text-indent: -2em; - } - p[indent=\"h2i5\"] { - padding-left: 5em; - text-indent: -3em; - } - p[indent=\"h2i6\"] { - padding-left: 6em; - text-indent: -4em; - } - p[indent=\"h2i7\"] { - padding-left: 7em; - text-indent: -5em; - } - p[indent=\"h2i8\"] { - padding-left: 8em; - text-indent: -6em; - } - p[indent=\"h2i9\"] { - padding-left: 9em; - text-indent: -7em; - } - p[indent=\"h3i0\"] { - padding-left: 0em; - text-indent: 3em; - } - p[indent=\"h3i1\"] { - padding-left: 1em; - text-indent: 2em; - } - p[indent=\"h3i2\"] { - padding-left: 2em; - text-indent: 1em; - } - p[indent=\"h3i3\"] { - padding-left: 3em; - text-indent: 0em; - } - p[indent=\"h3i4\"] { - padding-left: 4em; - text-indent: -1em; - } - p[indent=\"h3i5\"] { - padding-left: 5em; - text-indent: -2em; - } - p[indent=\"h3i6\"] { - padding-left: 6em; - text-indent: -3em; - } - p[indent=\"h3i7\"] { - padding-left: 7em; - text-indent: -4em; - } - p[indent=\"h3i8\"] { - padding-left: 8em; - text-indent: -5em; - } - p[indent=\"h3i9\"] { - padding-left: 9em; - text-indent: -6em; - } - p[indent=\"h4i0\"] { - padding-left: 0em; - text-indent: 4em; - } - p[indent=\"h4i1\"] { - padding-left: 1em; - text-indent: 3em; - } - p[indent=\"h4i2\"] { - padding-left: 2em; - text-indent: 2em; - } - p[indent=\"h4i3\"] { - padding-left: 3em; - text-indent: 1em; - } - p[indent=\"h4i4\"] { - padding-left: 4em; - text-indent: 0em; - } - p[indent=\"h4i5\"] { - padding-left: 5em; - text-indent: -1em; - } - p[indent=\"h4i6\"] { - padding-left: 6em; - text-indent: -2em; - } - p[indent=\"h4i7\"] { - padding-left: 7em; - text-indent: -3em; - } - p[indent=\"h4i8\"] { - padding-left: 8em; - text-indent: -4em; - } - p[indent=\"h4i9\"] { - padding-left: 9em; - text-indent: -5em; - } - p[indent=\"h5i0\"] { - padding-left: 0em; - text-indent: 5em; - } - p[indent=\"h5i1\"] { - padding-left: 1em; - text-indent: 4em; - } - p[indent=\"h5i2\"] { - padding-left: 2em; - text-indent: 3em; - } - p[indent=\"h5i3\"] { - padding-left: 3em; - text-indent: 2em; - } - p[indent=\"h5i4\"] { - padding-left: 4em; - text-indent: 1em; - } - p[indent=\"h5i5\"] { - padding-left: 5em; - text-indent: 0em; - } - p[indent=\"h5i6\"] { - padding-left: 6em; - text-indent: -1em; - } - p[indent=\"h5i7\"] { - padding-left: 7em; - text-indent: -2em; - } - p[indent=\"h5i8\"] { - padding-left: 8em; - text-indent: -3em; - } - p[indent=\"h5i9\"] { - padding-left: 9em; - text-indent: -4em; - } - p[indent=\"h6i0\"] { - padding-left: 0em; - text-indent: 6em; - } - p[indent=\"h6i1\"] { - padding-left: 1em; - text-indent: 5em; - } - p[indent=\"h6i2\"] { - padding-left: 2em; - text-indent: 4em; - } - p[indent=\"h6i3\"] { - padding-left: 3em; - text-indent: 3em; - } - p[indent=\"h6i4\"] { - padding-left: 4em; - text-indent: 2em; - } - p[indent=\"h6i5\"] { - padding-left: 5em; - text-indent: 1em; - } - p[indent=\"h6i6\"] { - padding-left: 6em; - text-indent: 0em; - } - p[indent=\"h6i7\"] { - padding-left: 7em; - text-indent: -1em; - } - p[indent=\"h6i8\"] { - padding-left: 8em; - text-indent: -2em; - } - p[indent=\"h6i9\"] { - padding-left: 9em; - text-indent: -3em; - } - p[indent=\"h7i0\"] { - padding-left: 0em; - text-indent: 7em; - } - p[indent=\"h7i1\"] { - padding-left: 1em; - text-indent: 6em; - } - p[indent=\"h7i2\"] { - padding-left: 2em; - text-indent: 5em; - } - p[indent=\"h7i3\"] { - padding-left: 3em; - text-indent: 4em; - } - p[indent=\"h7i4\"] { - padding-left: 4em; - text-indent: 3em; - } - p[indent=\"h7i5\"] { - padding-left: 5em; - text-indent: 2em; - } - p[indent=\"h7i6\"] { - padding-left: 6em; - text-indent: 1em; - } - p[indent=\"h7i7\"] { - padding-left: 7em; - text-indent: 0em; - } - p[indent=\"h7i8\"] { - padding-left: 8em; - text-indent: -1em; - } - p[indent=\"h7i9\"] { - padding-left: 9em; - text-indent: -2em; - } - p[indent=\"h8i0\"] { - padding-left: 0em; - text-indent: 8em; - } - p[indent=\"h8i1\"] { - padding-left: 1em; - text-indent: 7em; - } - p[indent=\"h8i2\"] { - padding-left: 2em; - text-indent: 6em; - } - p[indent=\"h8i3\"] { - padding-left: 3em; - text-indent: 5em; - } - p[indent=\"h8i4\"] { - padding-left: 4em; - text-indent: 4em; - } - p[indent=\"h8i5\"] { - padding-left: 5em; - text-indent: 3em; - } - p[indent=\"h8i6\"] { - padding-left: 6em; - text-indent: 2em; - } - p[indent=\"h8i7\"] { - padding-left: 7em; - text-indent: 1em; - } - p[indent=\"h8i8\"] { - padding-left: 8em; - text-indent: 0em; - } - p[indent=\"h8i9\"] { - padding-left: 9em; - text-indent: -1em; - } - p[indent=\"h9i0\"] { - padding-left: 0em; - text-indent: 9em; - } - p[indent=\"h9i1\"] { - padding-left: 1em; - text-indent: 8em; - } - p[indent=\"h9i2\"] { - padding-left: 2em; - text-indent: 7em; - } - p[indent=\"h9i3\"] { - padding-left: 3em; - text-indent: 6em; - } - p[indent=\"h9i4\"] { - padding-left: 4em; - text-indent: 5em; - } - p[indent=\"h9i5\"] { - padding-left: 5em; - text-indent: 4em; - } - p[indent=\"h9i6\"] { - padding-left: 6em; - text-indent: 3em; - } - p[indent=\"h9i7\"] { - padding-left: 7em; - text-indent: 2em; - } - p[indent=\"h9i8\"] { - padding-left: 8em; - text-indent: 1em; - } - p[indent=\"h9i9\"] { - padding-left: 9em; - text-indent: 0em; - } - p.block { } - p.group { } - p.alt { } - p.verse { - margin-bottom: 6px; - } - p.code { - font-family: inconsolata, andale mono, courier new, courier, monospace; - font-size: 90%; - text-align: left; - background-color: #eeeeee; - } - p.caption { - text-align: left; - font-size: 80%; - display: inline; - } - p.endnote { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-right: 15mm; - } - p.endnote_indent { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-left: 2em; - margin-right: 15mm; - } - p.center { - text-align: center; - } - p.bold { - font-weight: bold; - } - p.bold_left { - font-weight: bold; - text-align: left; - } - p.centerbold { - text-align: center; - font-weight: bold; - } - p.em { - font-weight: bold; - font-style: normal; - background: #fff3b6; - } - p.small { - font-size: 80%; - margin-top: 0px; - margin-bottom: 0px; - margin-right: 6px; - text-align: left; - } - .tiny, .tiny_left, .tiny_right, .tiny_center { - font-size: 10px; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 6px; - text-align: left; - } - p.tiny { } - p.tiny_left { - margin-left: 0px; - margin-right: 0px; - text-align: left; - } - p.tiny_right { - margin-right: 1em; - text-align: right; - } - p.tiny_center { - margin-left: 0px; - margin-right: 0px; - text-align: center; - } - p.concordance_word { - line-height: 150%; - font-weight: bold; - display: inline; - margin-top: 4px; - margin-bottom: 1px; - } - p.concordance_count { - font-size: 80%; - color: #777777; - display: inline; - margin-left: 0em; - } - p.concordance_object { - font-size: 80%; - line-height: 120%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - p.book_index_lev1 { - line-height: 100%; - margin-top: 4px; - margin-bottom: 1px; - } - p.book_index_lev2 { - line-height: 100%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - tt { - font-family: inconsolata, andale mono, courier new, courier, monospace; - background-color: #eeeeee; - } - label.ocn { - width: 2%; - float: right; - top: 0; - font-size: 10px; - margin-top: 0px; - margin-bottom: 5px; - color: #777777; - margin-right: 5px; - text-align: right; - background-color: #ffffff; - } - table { } - tr { } - th,td { - vertical-align: top; - text-align: left; - } - th { - font-weight: bold; - } - p.left,th.left,td.left { - text-align: left; - } - p.small_left,th.small_left,td.small_left { - text-align: left; - font-size: 80%; - } - p.right,th.right,td.right { - text-align: right; - } - ul, li { - list-style-type: none; - list-style: none; - padding-left: 20px; - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-weight: normal; - line-height: 150%; - text-align: left; - text-indent: 0mm; - margin-left: 1em; - margin-right: 2em; - margin-top: 3px; - margin-bottom: 3px; - } - li { - background: url(../image_sys/bullet_09.png) no-repeat 0px 6px; - } - ul { - } - h0, h1, h2, h3, h4, h5, h6, h7 { - font-weight: bold; - line-height: 120%; - text-align: left; - margin-top: 20px; - margin-bottom: 10px; - } - h4.norm, h5.norm, h6.norm, h7.norm { - margin-top: 10px; - margin-bottom: 0px; - } - h0 { font-size: 125%; } - h1 { font-size: 120%; } - h2 { font-size: 115%; } - h3 { font-size: 110%; } - h4 { font-size: 105%; } - h5 { font-size: 100%; } - h6 { font-size: 100%; } - h7 { font-size: 100%; } - h1.i {margin-left: 2em;} - h2.i {margin-left: 3em;} - h3.i {margin-left: 4em;} - h4.i {margin-left: 5em;} - h5.i {margin-left: 6em;} - h6.i {margin-left: 7em;} - h7.i {margin-left: 8em;} - h8.i {margin-left: 9em;} - h9.i {margin-left: 10em;} - .toc { - font-weight: normal; - margin-top: 6px; - margin-bottom: 6px; - } - h0.toc { - margin-left: 1em; - font-size: 120%; - line-height: 150%; - } - h1.toc { - margin-left: 1em; - font-size: 115%; - line-height: 150%; - } - h2.toc { - margin-left: 2em; - font-size: 110%; - line-height: 140%; - } - h3.toc { - margin-left: 3em; - font-size: 105%; - line-height: 120%; - } - h4.toc { - margin-left: 4em; - font-size: 100%; - line-height: 120%; - } - h5.toc { - margin-left: 5em; - font-size: 95%; - line-height: 110%; - } - h6.toc { - margin-left: 6em; - font-size: 90%; - line-height: 110%; - } - h7.toc { - margin-left: 7em; - font-size: 85%; - line-height: 100%; - } - .subtoc { - margin-right: 34%; - font-weight: normal; - } - h5.subtoc { - margin-left: 2em; - font-size: 80%; - margin-top: 2px; - margin-bottom: 2px; - } - h6.subtoc { - margin-left: 3em; - font-size: 75%; - margin-top: 0px; - margin-bottom: 0px; - } - h7.subtoc { - margin-left: 4em; - font-size: 70%; - margin-top: 0px; - margin-bottom: 0px; - } - div.substance { - width: 100%; - background-color: #ffffff; - } - div.ocn { - width: 5%; - float: right; - top: 0; - background-color: #ffffff; - } - div.endnote { - width: 95%; - background-color: #fffffff; - } - div.toc { - position: absolute; - float: left; - margin: 0; - padding: 0; - padding-top: 0.5em; - border: 0; - width: 13em; - background-color: #eeeeee; - margin-right:1em; - } - div.summary { - margin: 0; - padding: 0; - border-left: 13em solid #eeeeee; - padding-left: 1em; - background-color: #eeeeee; - } - div.content, div.main_column { - margin: 0; - padding: 0; - border-left: 13em solid #ffffff; - padding-left: 1em; - padding-right: 1em; - } - div.content0, div.main_column0 { - margin: 0; - padding: 0; - border-left: 0% solid #ffffff; - padding-left: 5%; - } - div.scroll { - margin: 0; - padding: 0; - padding-left: 1em; - padding-right: 1em; - } - div.content:after { - content:' '; - clear:both; - display:block; - height:0; - overflow:hidden - } - div.footer { - clear:left; - padding: 0.5em; - font-size: 80%; - margin: 0; - } - div.toc ul { - list-style: none; - padding: 0; - margin: 0; - } - div.toc li ul a, li ul span.currentlink - { - font-weight: normal; - font-size: 90%; - padding-left: 2em; - background-color: #eeeeee; - } - div.toc a, span.currentlink{ - display:block; - text-decoration: none; - padding-left: 0.5em; - color: #0000aa; - } - hr { - width: 90%; - } - span.currentlink { - text-decoration: none; - background-color: #aaaaf9; - } - div.toc a:visited { - color: #0000aa; - } - div.toc a:hover { - color: #000000; - background-color: #f9f9aa; - }"; - return css; -} -auto css_write() { - auto pth_css= "_sisu/css"; - auto pth_css_fn= pth_css ~ "/html.css"; - try { - if (!exists(pth_css)) { - pth_css.mkdirRecurse; - } - auto f = File(pth_css_fn, "w"); - f.writeln(html_css); - // foreach (o; doc) { - // f.writeln(o); - // } - } - catch (ErrnoException ex) { - // Handle error - } -} -#+END_SRC - -*** _epub_ [#B] :epub: - -|-----------------------+--------------------------+---------------------------+----------------------------------| -| function | filename | module | variable | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| identify doc filetype | mimetype | epub3_mimetypes | mimetypes | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| identify doc root | META-INF/container.xml | epub3_container_xml | meta_inf_container_xml | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc manifest | OEBPS/content.opf | epub3_oebps_content | oebps_content_opf | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc navigation | OEBPS/toc_nav.xhtml | epub3_oebps_toc_nav_xhtml | oebps_toc_nav_xhtml | -| | OEBPS/toc.ncx | epub2_oebps_toc_ncx | oebps_toc_ncx | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc contents | OEBPS/[files ... ].xhtml | outputEPub3 | doc_epub3[seg_filename] | -| | | | doc_epub3_endnotes[seg_filename] | -|-----------------------+--------------------------+---------------------------+----------------------------------| - -**** template :template: - -#+BEGIN_SRC d :tangle ../src/sdp/output_epub3.d -template outputEPub3() { - <> - mixin InternalMarkup; - mixin outputXHTMLs; - <> - <> - <> - <> - <> -} -#+END_SRC - -**** special (epub) files :format: -***** DONE static -****** _identify doc filetype_ (mimetype) [static] - -- mimetype file indicating that zip file contains an EPUB - -#+name: output_epub3_fixed -#+BEGIN_SRC d -string epub3_mimetypes() { - string o; - o = format(q"¶application/epub+zip¶") ~ "\n"; - return o; -} -#+END_SRC - -****** _identify doc root_ (META-INF/container.xml) [static] rootfile: contains document root path - -- identifies the root package document (so systems can find it), [unchanged from epub2] - -#+name: output_epub3_fixed -#+BEGIN_SRC d -string epub3_container_xml() { - string o; - o = format(q"¶¶") ~ "\n"; - o ~= format(q"¶ - - -¶") ~ "\n\n"; - return o; -} -#+END_SRC - -***** constructs (in dir: OEBPS) -****** TODO _doc manifest_ (OEBPS/content.opf) manifest, register content: files, images etc. - -- manifest, listing all resources -- provides the default reading order -- identifies the navigation document - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { - string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO sort uuid in doc_matters! - string content = format(q"¶ - - - - %s - main - %s - subtitle - %s - %s - %s - Copyright: %s - %s - urn:uuid:%s - - - - - - - - - -¶", - uuid, - doc_matters.dochead_meta["title"]["full"], - doc_matters.dochead_meta["title"]["main"], - (doc_matters.dochead_meta["title"]["sub"].empty) - ? "" : doc_matters.dochead_meta["title"]["sub"], - (doc_matters.dochead_meta["creator"]["author"].empty) - ? "" : doc_matters.dochead_meta["creator"]["author"], - (doc_matters.dochead_meta["creator"]["author"].empty) - ? "" : doc_matters.dochead_meta["creator"]["author"], - doc_matters.language, - (doc_matters.dochead_meta["date"]["published"].empty) - ? "" : doc_matters.dochead_meta["date"]["published"], - (doc_matters.dochead_meta["rights"]["copyright"].empty) - ? "" : doc_matters.dochead_meta["rights"]["copyright"], - uuid, - uuid, - uuid, - ); - content ~= " " ~ "" ~ "\n "; - content ~= parts["manifest_documents"]; - // TODO sort jpg & png - content ~= " " ~ "" ~ "\n "; - foreach (image; doc_matters.image_list) { - content ~= format(q"¶ -¶", - image, // strip image type, remove .png .jpg suffix, use in media-type="image/" - image, - ); - } - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["spine"]; - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["guide"]; - content ~= " " ~ "" ~ "\n "; - content ~= "" ~ ""; - return content; -} -#+END_SRC - -****** _doc navigation epub3_ (OEBPS/toc_nav.xhtml) epub3 navigable toc using Dom structure - -- toc_nav.xhtml declared as nav file in content.opf (epub3 navigation document) - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { - enum DomTags { none, open, close, close_and_open, open_still, } - auto markup = InlineMarkup(); - string toc ="\n"; - return toc; -} -#+END_SRC - -****** TODO _doc navigation epub2_ (OEBPS/toc.ncx) navigable toc using Dom structure - -- toc.ncx (epub2 navigation document) - - (replaced in epub3 by a declared xhtml nav file, in our case toc_nav.xhtml) - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { - int counter = 0; - string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere - auto markup = InlineMarkup(); - enum DomTags { none, open, close, close_and_open, open_still, } - string toc = format(q"¶ - - - - %s%s - - - - - - - - - %s - - - %s - - ¶", - doc_matters.dochead_meta["title"]["full"], // title - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author - uuid, // uuid - "3", // content depth - doc_matters.dochead_meta["title"]["full"], // title - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : doc_matters.dochead_meta["creator"]["author"], // author - ); - foreach (sect; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[sect]) { - if (obj.is_a == "heading") { - foreach_reverse (k; 0 .. 7) { - switch (obj.dom_markedup[k]) { - case DomTags.close : -toc ~= ""; - break; - case DomTags.close_and_open : - ++counter; -toc ~= ""; -toc ~= format(q"¶ - - %s - -¶", -counter, -obj.text, -obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (links done in segment_anchor_tag) -); - break; - case DomTags.open : - ++counter; -toc ~= format(q"¶ - - %s - -¶", -counter, -obj.text, -obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (fix links in segment_anchor_tag) -); - break; - default : - break; - } - } - } - } - } - toc ~= format(q"¶ -¶"); - return toc; -} -#+END_SRC - -**** the document contents :seg: -***** switch (sections & objects) format epub3 xhtml output - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d -void outputEPub3(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, -) { - mixin SiSUoutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[][string] doc_epub3; - string[][string] doc_epub3_endnotes; - string[] doc; - string segment_filename; - string[] top_level_headings = ["","","",""]; - string[string] oepbs_content_parts; - string suffix = ".xhtml"; - foreach (part; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - if (obj.is_a == "heading") { - switch (obj.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.heading_lev_markup) { - case 0: - top_level_headings[0] = ""; - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 1: - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 2: - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 3: - top_level_headings[3] = ""; - goto default; - default: - auto t = xhtml_format.heading_seg(obj, suffix); - top_level_headings[obj.heading_lev_markup] = t[0]; - break; - } - break; - case 4: - segment_filename = obj.segment_anchor_tag; - doc_epub3[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); - foreach (top_level_heading; top_level_headings) { - doc_epub3[segment_filename] ~= top_level_heading; - } - auto t = xhtml_format.heading_seg(obj, 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); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: // unused numbers, if remain check - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - } - break; - } - } else { - switch (obj.use) { - case "frontmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "toc": - doc_epub3[segment_filename] ~= xhtml_format.toc(obj); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "para": - auto t = xhtml_format.para_seg(obj, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(obj, 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); - 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); - doc_epub3[segment_filename] ~= to!string(t[0]); - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "poem": - break; - case "verse": - auto t = xhtml_format.verse_seg(obj, 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); - break; - case "table": - auto t = xhtml_format.para_seg(obj, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "endnote": - auto t = xhtml_format.para_seg(obj, suffix); - doc_epub3[segment_filename] ~= t[0]; - break; - case "glossary": - auto t = xhtml_format.para_seg(obj, 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); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": - auto t = xhtml_format.para_seg(obj, 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); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - } - break; - } - } - if (obj.is_a == "heading") { - if (obj.heading_lev_markup == 4) { - oepbs_content_parts["manifest_documents"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - obj.segment_anchor_tag, - ); - oepbs_content_parts["spine"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - ); - oepbs_content_parts["guide"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - obj.segment_anchor_tag, - ); - } else if (obj.heading_lev_markup > 4) { - oepbs_content_parts["manifest_documents"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - oepbs_content_parts["spine"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - oepbs_content_parts["guide"] ~= format(q"¶ -¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - } - } - } - } - /+ epub specific documents +/ - auto mimetypes = epub3_mimetypes; - auto meta_inf_container_xml = epub3_container_xml; - auto oebps_toc_ncx = epub2_oebps_toc_ncx(doc_abstraction, doc_matters); - auto oebps_toc_nav_xhtml = epub3_oebps_toc_nav_xhtml(doc_abstraction, doc_matters); - auto oebps_content_opf = epub3_oebps_content(doc_abstraction, doc_matters, oepbs_content_parts); - epub3_write_output_files( - doc_matters, - doc_epub3, - doc_epub3_endnotes, - mimetypes, - meta_inf_container_xml, - oebps_toc_nav_xhtml, - oebps_toc_ncx, - oebps_content_opf, - ); -} -#+END_SRC - -**** write output files - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d -void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( - M doc_matters, - D doc_epub3, - E doc_epub3_endnotes, - Mt mimetypes, - Mic meta_inf_container_xml, - Otnx oebps_toc_nav_xhtml, - Otn oebps_toc_ncx, - Oc oebps_content_opf, -) { - debug(asserts) { - static assert(is(typeof(doc_epub3) == string[][string])); - static assert(is(typeof(mimetypes) == string)); - static assert(is(typeof(meta_inf_container_xml) == string)); - static assert(is(typeof(oebps_toc_nav_xhtml) == string)); - static assert(is(typeof(oebps_toc_ncx) == string)); - static assert(is(typeof(oebps_content_opf) == string)); - } - mixin SiSUpaths; - auto pth_epub3 = Epub3paths(); - auto xhtml_format = outputXHTMLs(); - /+ zip file +/ - auto fn_epub = pth_epub3.epub_file(doc_matters.source_filename); - auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); - /+ zip archive member files +/ - try { - if (!exists(pth_epub3.doc_meta_inf(doc_matters.source_filename))) { - pth_epub3.doc_meta_inf(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_epub3.doc_oebps_css(doc_matters.source_filename))) { - pth_epub3.doc_oebps_css(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_epub3.doc_oebps_image(doc_matters.source_filename))) { - pth_epub3.doc_oebps_image(doc_matters.source_filename).mkdirRecurse; - } - { /+ OEBPS/[segments].xhtml (the document contents) +/ - foreach (seg_filename; doc_matters.segnames) { - string fn = pth_epub3.fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add seg fn to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - debug(epub_output) { - string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); - auto f = File(fn_dbg, "w"); - } - /+ // f.writeln(seg_head); // not needed built and inserted earlier +/ - foreach (docseg; doc_epub3[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } - zip_data.write(docseg.dup); // cast as: char[] - } - foreach (docseg; doc_epub3_endnotes[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } - zip_data.write(docseg.dup); // cast as: char[] - } - debug(epub_output) { f.writeln(xhtml_format.tail); } // needed for each lev4 - zip_data.write(xhtml_format.tail.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - } - string fn; - debug(epub_output) { string fn_dbg; } - File f; - { /+ mimetypes (identify zip file type) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.source_filename); - File(fn_dbg, "w").writeln(mimetypes); - } - fn = pth_epub3.fn_mimetypes(doc_matters.source_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add mimetypes to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(mimetypes.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - { /+ META-INF/container.xml (identify doc root) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.source_filename); - File(fn_dbg, "w").writeln(meta_inf_container_xml); - } - fn = pth_epub3.fn_dmi_container_xml(doc_matters.source_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add META-INF/container.xml to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(meta_inf_container_xml.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); - } - fn = pth_epub3.fn_oebps_toc_nav_xhtml(doc_matters.source_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add OEBPS/toc_nav.xhtml to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_toc_nav_xhtml.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - { /+ TODO OEBPS/toc.ncx (navigation toc epub2) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_toc_ncx); - } - fn = pth_epub3.fn_oebps_toc_ncx(doc_matters.source_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add OEBPS/toc.ncx to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_toc_ncx.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - { /+ TODO OEBPS/content.opf (doc manifest) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_content_opf); - } - fn = pth_epub3.fn_oebps_content_opf(doc_matters.source_filename); - /+ add zip archive file members (with their content) +/ - auto zip_arc_member_file = new ArchiveMember(); - // add OEBPS/content.opf to zip archive - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_content_opf.dup); // cast as: char[] - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/_sisu/image (images) +/ - foreach (image; doc_matters.image_list) { - if (exists("_sisu/image/"~ image)) { - ("_sisu/image/"~ image) - .copy((pth_epub3.doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image); - } - } - foreach (image; doc_matters.image_list) { - debug(epub_images) { - writeln( - "_sisu/image/", image, " -> ", - pth_epub3.doc_oebps_image(doc_matters.source_filename), "/", image - ); - } - auto fn_src = "_sisu/image/"~ image; - auto fn_out = pth_epub3.doc_oebps_image(doc_matters.source_filename).to!string ~ "/" ~ image; - if (exists(fn_src)) { - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn_out; - auto zip_data = new OutBuffer(); - zip_data.write(cast(char[]) ((fn_src).read)); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - } - } - } - } - catch (ErrnoException ex) { - // Handle error - } -#+END_SRC - -*** zip debug, read zip archive - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - debug(epub_archive) { - if (exists(fn_epub)) { - try { - auto zipped = new ZipArchive((fn_epub).read); - foreach (filename, member; zipped.directory) { - auto data = zipped.expand(member); - writeln(filename, " length ", data.length); // member.name - // Use data - } - } - catch (ZipException ex) { - // Handle errors - } - } - } -} -#+END_SRC - -** pdf [#C] :pdf: -** odt :odt: -** sqlite [#B] :sqlite: -** pgsql :pgsql: diff --git a/org/output_hub.org b/org/output_hub.org new file mode 100644 index 0000000..736c622 --- /dev/null +++ b/org/output_hub.org @@ -0,0 +1,185 @@ +#+TITLE: sdp output hub +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:output: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* 0. output hub [#A] + +#+BEGIN_SRC d :tangle ../src/sdp/output_hub.d +/++ + output hub
+ check & generate output types requested ++/ +template outputHub() { + <> + void outputHub(D,I)(D doc_abstraction, I doc_matters) { + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + <> + } +} +#+END_SRC + +** initialize / imports + +#+name: output_imports +#+BEGIN_SRC d +private import + std.regex, + std.algorithm, + std.array, + std.container, + std.exception, + std.getopt, + std.process, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf; +import + defaults, + output_epub3, + output_html, + output_xhtmls, + source_sisupod, + create_zip_file, + output_rgx, + output_xhtmls, + paths_output; +#+END_SRC + +** output options +*** verbose + +#+name: output_options +#+BEGIN_SRC d +if ((doc_matters.opt_action_bool["verbose"])) { + writeln(doc_matters.keys_seq.seg); +} +#+END_SRC + +*** output source: _sisusrc_ &/or _sisupod_ +[[./output_sisupod.org][output_sisupod]] + +#+name: output_options +#+BEGIN_SRC d +if ((doc_matters.opt_action_bool["source"]) +|| (doc_matters.opt_action_bool["sisupod"])) { + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["source"])) + { write("sisu source processing... "); } + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["sisupod"])) + { write("sisupod source processing... "); } + SiSUpod!()(doc_matters); + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["source"])) + { writeln("sisu source done"); } + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["sisupod"])) + { writeln("sisupod done"); } +} +#+END_SRC + +*** text +[[./output_text.org][output_text]] + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["text"]) { + /+ mixin outputText; +/ + writeln("text processing"); +} +#+END_SRC + +*** html +[[./output_xmls.org][output_xmls]] + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["html"]) { + if ((doc_matters.opt_action_bool["verbose"])) { write("html scroll processing... "); } + outputHTML!().scroll(doc_abstraction, doc_matters); + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html scroll done"); } + if ((doc_matters.opt_action_bool["verbose"])) { write("html seg processing... "); } + outputHTML!().seg(doc_abstraction, doc_matters); + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html seg done"); } +} else if (doc_matters.opt_action_bool["html_seg"]) { + if ((doc_matters.opt_action_bool["verbose"])) { write("html seg processing... "); } + outputHTML!().seg(doc_abstraction, doc_matters); + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html seg done"); } +} else if (doc_matters.opt_action_bool["html_scroll"]) { + if ((doc_matters.opt_action_bool["verbose"])) { write("html scroll processing... "); } + outputHTML!().scroll(doc_abstraction, doc_matters); + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html scroll done"); } +} +#+END_SRC + +*** epub +[[./output_xmls.org][output_xmls]] + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["epub"]) { + if ((doc_matters.opt_action_bool["verbose"])) { write("epub3 processing... "); } + outputEPub3!()(doc_abstraction, doc_matters); + // epub.css_write; + if ((doc_matters.opt_action_bool["verbose"])) { writeln("epub3 done"); } +} +#+END_SRC + +*** pdf + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["pdf"]) { + /+ mixin outputPDF; +/ + writeln("pdf processing"); +} +#+END_SRC + +*** odt + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["odt"]) { + /+ mixin outputODT; +/ + writeln("odt processing"); +} +#+END_SRC + +*** sqlite + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["sqlite"]) { + /+ mixin outputSQLite; +/ + writeln("sqlite processing"); +} +#+END_SRC + +*** postgresql + +#+name: output_options +#+BEGIN_SRC d +if (doc_matters.opt_action_bool["postgresql"]) { + /+ mixin outputPostgreSQL; +/ + writeln("pgsql processing"); +} +#+END_SRC diff --git a/org/output_sisupod.org b/org/output_sisupod.org new file mode 100644 index 0000000..36f618f --- /dev/null +++ b/org/output_sisupod.org @@ -0,0 +1,280 @@ +#+TITLE: sdp output sisupod +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:output: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +[[./output_hub.org][output_hub]] +* sisupod template :template: + +#+BEGIN_SRC d :tangle ../src/sdp/source_sisupod.d +template SiSUpod() { + <> + void SiSUpod(T)(T doc_matters) { + <> + try { + <> + <> + <> + } + catch (ErrnoException ex) { + // Handle error + } + } +} +#+END_SRC + +* _sisupod_ :sisupod: +** output imports + +#+name: output_imports +#+BEGIN_SRC d +private import + std.algorithm, + std.array, + std.container, + std.digest.sha, + std.exception, + std.file, + std.getopt, + std.json, + std.outbuffer, + std.path, + std.process, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.zip, + std.conv : to; +import + create_zip_file, + defaults, + output_rgx, + output_xhtmls, + paths_output; +#+END_SRC + +** mkdir + +#+name: source_sisupod_init +#+BEGIN_SRC d +debug(asserts) { + // static assert(is(typeof(doc_matters) == tuple)); +} +mixin SiSUoutputRgxInit; +string pwd = doc_matters.environment["pwd"]; +auto src_path_info = doc_matters.src_path_info; +string lng = doc_matters.language; +auto pth_sisudoc_src = doc_matters.src_path_info; +auto pth_sisupod = SiSUpathsSisupodZipped!()(src_path_info, lng); +auto pth_sisupod_filesystem = SiSUpathsSisupodFileSystem!()(src_path_info, lng); +mixin SiSUlanguageCodes; +auto lang = Lang(); +auto rgx = Rgx(); +assert (doc_matters.source_filename.match(rgx.src_fn)); +#+END_SRC + +#+name: source_sisupod_mkdirs +#+BEGIN_SRC d +/+ create directory structure +/ +if (doc_matters.opt_action_bool["source"]) { + if (!exists(pth_sisupod_filesystem.text_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.text_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.conf_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.conf_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.media_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.media_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { + pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.image_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.image_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename))) { + pth_sisupod_filesystem.doc_lng(doc_matters.source_filename).mkdirRecurse; + } +} +#+END_SRC + +** copy + +#+name: source_sisupod_copy +#+BEGIN_SRC d +debug(sisupod) { + writeln(__LINE__, ": ", + doc_matters.source_filename, " -> ", + pth_sisupod_filesystem.fn_doc( + doc_matters.source_filename, + )); +} +auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); +auto fn_sisupod = pth_sisupod.sisupod_filename(doc_matters.source_filename); +{ /+ bundle images +/ + foreach (image; doc_matters.image_list) { + debug(sisupodimages) { + writeln( + pth_sisudoc_src.image_root.to!string, "/", image, " -> ", + pth_sisupod.image_root(doc_matters.source_filename), "/", image + ); + } + auto fn_src = pth_sisudoc_src.image_root.to!string ~ "/" ~ image; + auto fn_out = pth_sisupod.image_root(doc_matters.source_filename).to!string ~ "/" ~ image; + auto fn_out_filesystem = pth_sisupod_filesystem.image_root(doc_matters.source_filename).to!string ~ "/" ~ image; + if (exists(fn_src)) { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write(cast(char[]) ((fn_src).read)); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } + } +} +{ /+ bundle sisu_document_make +/ + auto fn_src = pth_sisudoc_src.conf_root.to!string ~ "/" ~ "sisu_document_make"; // check (_sisu/sisu_document_make) + auto fn_out = pth_sisupod.conf_root(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + auto fn_out_filesystem = pth_sisupod_filesystem.conf_root(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + if (exists(fn_src)) { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } +} +{ /+ bundle primary file +/ + auto fn_src = doc_matters.source_filename; + auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename).to!string; + auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename).to!string; + if (exists(fn_src)) { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } +} +{ /+ bundle insert files +/ + if (doc_matters.file_insert_list.length > 0) { + foreach (insert_file; doc_matters.file_insert_list) { + debug(sisupod) { + writeln( + insert_file, " -> ", + pth_sisupod.fn_doc_insert( + doc_matters.source_filename, + insert_file, + )); + } + auto fn_src = insert_file; + auto fn_out = pth_sisupod.fn_doc_insert( + doc_matters.source_filename, + insert_file, + ).to!string; + auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc_insert( + doc_matters.source_filename, + insert_file, + ).to!string; + if (exists(fn_src)) { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = insert_file; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } + } + } +} +#+END_SRC + +** sha256 of sisupod.zip, zip debug, read zip archive + +#+name: source_sisupod_copy +#+BEGIN_SRC d +if (exists(fn_sisupod)) { + try { + auto data = (cast(byte[]) (fn_sisupod).read); + writefln("%-(%02x%) %s", data.sha256Of, fn_sisupod); + debug(sisupod) { + try { + auto zipped = new ZipArchive((fn_sisupod).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln("> ", filename, " length ", data.length); // filename == member.name + // Use data + } + } + catch (ZipException ex) { + // Handle errors + } + if (doc_matters.source_filename == "sisudoc/text/en/the_wealth_of_networks.yochai_benkler.sst") { + assert( + ((data).sha256Of).toHexString + == "626F83A31ED82F42CF528E922C1643498A137ABA3F2E5AFF8A379EA79EA22A1E", + "\nsisupod: sha256 value for " + ~ doc_matters.source_filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + if (doc_matters.source_filename == "sisudoc/text/en/sisu_markup_stress_test.sst") { + assert( + ((data).sha256Of).toHexString + == "AAE0C87AB3F6D5F7385AEEA6EE661F56D40475CFE87AD930C78C9FE07FFB0D91", + "\nsisupod: sha256 value for " + ~ doc_matters.source_filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + } + } + catch (ErrnoException ex) + { + // Handle errors + } +} +#+END_SRC diff --git a/org/output_xmls.org b/org/output_xmls.org new file mode 100644 index 0000000..2812421 --- /dev/null +++ b/org/output_xmls.org @@ -0,0 +1,3116 @@ +#+TITLE: sdp output xmls +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:output: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +[[./output_hub.org][output_hub]] +* xml offspring (xhtml html epub) :xml: +** format xhtml objects :format: +*** 0. xhtml common template :template: + +#+BEGIN_SRC d :tangle ../src/sdp/output_xhtmls.d +template outputXHTMLs() { + <> + mixin SiSUoutputRgxInit; + struct outputXHTMLs { + auto rgx = Rgx(); + <> +<> + } +} +#+END_SRC + +*** output imports + +#+name: output_imports +#+BEGIN_SRC d +private import + std.algorithm, + std.array, + std.container, + std.digest.sha, + std.exception, + std.file, + std.getopt, + std.json, + std.outbuffer, + std.path, + std.process, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.zip, + std.conv : to; +import + create_zip_file, + defaults, + output_rgx, + output_xhtmls, + paths_output; +#+END_SRC + +*** misc +**** special characters + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string special_characters(string _txt){ + _txt = (_txt) + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.xhtml_line_break, "
"); + return _txt; +} +#+END_SRC + +**** font_face + +#+name: xhtml_format_objects +#+BEGIN_SRC d +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; +} +#+END_SRC + +**** anchor tags + +#+name: xhtml_format_objects +#+BEGIN_SRC d +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; +} +#+END_SRC + +**** doc head & tails +***** scroll head + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto scroll_head(Me)( + Me dochead_meta, +) { + debug(asserts) { + static assert(is(typeof(dochead_meta) == string[string][string])); + } + string o; + o = format(q"¶ + + + + + %s%s + + + + + + + + + + + + + + + + + + + + +¶", +dochead_meta["title"]["full"], +(dochead_meta["creator"]["author"].empty) ? "" : ", " ~ dochead_meta["creator"]["author"], +); + return o; +} +#+END_SRC + +***** seg head + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto seg_head(Me)( + Me dochead_meta, +) { + debug(asserts) { + static assert(is(typeof(dochead_meta) == string[string][string])); + } + string o; + o = format(q"¶ + + + + + %s%s + + + + + + + + + + + + + + + + + + + + + +¶", +dochead_meta["title"]["full"], +(dochead_meta["creator"]["author"].empty) ? "" : ", " ~ dochead_meta["creator"]["author"], +); + return o; +} +#+END_SRC + +***** xhtml tail + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto tail() { + string o; + o = format(q"¶ + + +¶"); + return o; +} +#+END_SRC + +*** inline markup +**** links + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_links(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + string seg_scroll = "seg", +) { + if (obj.inline_links) { + if ((seg_scroll == "scroll") + && _txt.match(rgx.mark_internal_site_lnk)) { + _txt = (_txt).replaceAll( + rgx.inline_seg_link, + "$1"); + } + _txt = (_txt).replaceAll( + rgx.inline_link_fn_suffix, + ("$1" ~ _suffix)); + _txt = (_txt).replaceAll( + rgx.inline_link, + ("$1")); + _txt = (_txt).replaceAll( + rgx.mark_internal_site_lnk, + "" + ); + } + debug(markup_links) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.inline_links, + "): ", obj.is_a, ": ", + obj.text + ); + } + } + debug(markup) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.inline_links, + "): ", obj.is_a, ": ", + obj.text + ); + } + } + return _txt; +} +#+END_SRC + +**** notes scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_notes_scroll(O)( + auto return ref const O obj, + string _txt, +) { + if (obj.inline_notes_reg) { + _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.is_a, ": ", obj.text); + } + } + debug(markup) { + if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); + } + } + // if (obj.inline_notes_star) { + // _txt = replaceAll( + // _txt, + // rgx.inline_notes_delimiter_al_regular_number_note, + // (" $1 ") + // ); + // } + return _txt; +} +#+END_SRC + +**** notes seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_notes_seg(O)( + auto return ref const O obj, + string _txt, +) { + string[] _endnotes; + if (obj.inline_notes_reg) { + /+ 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.is_a, ": ", obj.text); + } + } + auto t = tuple( + _txt, + _endnotes, + ); + return t; +} +#+END_SRC + +**** inline markup scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_markup_scroll(O)( + auto return ref const O obj, + 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; +} +#+END_SRC + +**** inline markup seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_markup_seg(O)( + auto return ref const O obj, + 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; +} +#+END_SRC + +*** toc + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto toc(O)( + auto return ref const O obj, +) { + string o; + o = format(q"¶
+

+ %s +

+
¶", + obj.is_a, + obj.indent_hang, + obj.indent_base, + obj.text + ); + return o; +} +#+END_SRC + +*** heading +**** heading + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto heading(O)( + auto return ref const O obj, + string _txt, +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _horizontal_rule = "
"; + if (obj.heading_lev_markup == 0) { + _horizontal_rule = ""; + } + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶%s +
+ %s + %s + +
¶", + _horizontal_rule, + obj.heading_lev_markup, + obj.is_a, + tags, + _txt, + obj.heading_lev_markup, + ); + } else { + o = format(q"¶%s +
+ + %s + %s + +
¶", + _horizontal_rule, + obj.obj_cite_number, + obj.obj_cite_number, + obj.heading_lev_markup, + obj.is_a, + obj.obj_cite_number, + obj.obj_cite_number, + tags, + _txt, + obj.heading_lev_markup, + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto heading_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = heading(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto heading_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = t[0]; + string[] _endnotes = t[1]; + string o = heading(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** para +**** para + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto para(O)( + auto return ref const O obj, + string _txt, +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + _txt = font_face(_txt); + string o; + _txt = (obj.bullet) ? ("●  " ~ _txt) : _txt; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

%s + %s +

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

%s + %s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.indent_hang, + obj.indent_base, + obj.obj_cite_number, + tags, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto para_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = para(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto para_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = to!string(t[0]); + string[] _endnotes = t[1]; + string o = para(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** quote +**** quote + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto quote(O)( + auto return ref const O obj, + string _txt, +) { + _txt = font_face(_txt); + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

+ %s +

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

+ %s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto quote_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = quote(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto quote_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = to!string(t[0]); + string[] _endnotes = t[1]; + string o = quote(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** group +**** group + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto group(O)( + auto return ref const O obj, + string _txt, +) { + _txt = font_face(_txt); + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

+ %s +

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

+ %s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto group_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = group(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto group_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = to!string(t[0]); + string[] _endnotes = t[1]; + string o = group(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** block +**** block + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto block(O)( + auto return ref const O obj, + string _txt, +) { + _txt = font_face(_txt); + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

%s

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

%s

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt.stripRight + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto block_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = block(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto block_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = to!string(t[0]); + string[] _endnotes = t[1]; + string o = block(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** poem verse +**** verse + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto verse(O)( // using code from code block, review + auto return ref const O obj, + string _txt, +) { + _txt = font_face(_txt); + _txt = (_txt) + .replaceAll(rgx.newline, "
\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"¶
+

%s

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

%s

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto verse_scroll(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _txt = inline_markup_scroll(obj, _suffix); // issue + string o = verse(obj, _txt); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto verse_seg(O)( + auto return ref const O obj, + string _suffix = ".html", +) { + auto t = inline_markup_seg(obj, _suffix); + string _txt = to!string(t[0]); + string[] _endnotes = t[1]; + string o = verse(obj, _txt); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** code + +#+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.newline, "
\n") + .replaceAll(rgx.nbsp_char, " "); + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

+%s +

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

+%s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; + } +#+END_SRC + +*** table +**** TODO tablarize + +align="left|right|center" +$100 + +"style=\"text-align:right\"" +"style=\"text-align:left\"" + +"style=\"text-align:" ~ "right\"" + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto tablarize(O)( + auto return ref 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)) { // check row_idx+2 (rather than == ++row_idx) + _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; +} +#+END_SRC + +**** table + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto table(O)( + auto return ref const O obj, +) { + string _txt = obj.text; + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + _txt = font_face(_txt); + auto t = tablarize(obj, _txt); + _txt = t[0]; + string _note = t[1]; + string o; + o = format(q"¶
+ +

%s + + %s +
+ %s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + tags, + _txt, + _note + ); + return o; +} +#+END_SRC + +*** endnote + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto endnote(O)( + auto return ref const O obj, +) { + string o; + o = format(q"¶

+ %s +

¶", + obj.is_a, + obj.indent_hang, + obj.indent_base, + obj.text + ); + return o; +} +#+END_SRC + +** _html_ [#A] :html: +*** template :template: + +#+BEGIN_SRC d :tangle ../src/sdp/output_html.d +template outputHTML() { + <> + mixin outputXHTMLs; + <> + <> + <> + <> +} +#+END_SRC + +*** scroll :scroll: +**** switch (sections & objects) format html output + +#+name: output_html_scroll +#+BEGIN_SRC d +void scroll(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, +) { + mixin SiSUoutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[] doc_html; + string[] doc; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.scroll) { + foreach (obj; doc_abstraction[part]) { + 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); + break; + case "toc": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, suffix); + break; + case "para": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + doc_html ~= xhtml_format.quote_scroll(obj); + break; + case "group": + doc_html ~= xhtml_format.group_scroll(obj); + break; + case "block": + doc_html ~= xhtml_format.block_scroll(obj); + break; + case "poem": + break; + case "verse": + doc_html ~= xhtml_format.verse_scroll(obj, suffix); + break; + case "code": + doc_html ~= xhtml_format.code(obj); + break; + case "table": + doc_html ~= xhtml_format.table(obj); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, suffix); + break; + case "endnote": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + case "glossary": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + case "bibliography": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + case "bookindex": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + case "blurb": + doc_html ~= xhtml_format.para_scroll(obj, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + } + } + } + doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; + scroll_write_output(doc_matters, doc); +} +#+END_SRC + +**** write output file + +#+name: output_html_scroll +#+BEGIN_SRC d +void scroll_write_output(M,C)( + M doc_matters, + C doc, +) { + debug(asserts) { + static assert(is(typeof(doc) == string[])); + } + string fn_src = doc_matters.source_filename; + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + try { + if (!exists(pth_html.base)) { + pth_html.base.mkdirRecurse; + } + auto f = File(pth_html.fn_scroll(fn_src), "w"); + foreach (o; doc) { + f.writeln(o); + } + } + catch (ErrnoException ex) { + // Handle error + } +} +#+END_SRC + +*** seg :seg: +**** switch (sections & objects) format html output + +#+name: output_html_seg +#+BEGIN_SRC d +void seg(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, +) { + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto xhtml_format = outputXHTMLs(); + string[][string] doc_html; + string[][string] doc_html_endnotes; + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + if (obj.is_a == "heading") { // all headings: frontmatter, body & backmatter + switch (obj.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.heading_lev_markup) { + case 0: + top_level_headings[0] = ""; + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 1: + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 2: + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 3: + top_level_headings[3] = ""; + goto default; + default: + auto t = xhtml_format.heading_seg(obj, suffix); + top_level_headings[obj.heading_lev_markup] = t[0]; + break; + } + break; + case 4: + segment_filename = obj.segment_anchor_tag; + doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); + foreach (top_level_heading; top_level_headings) { + // writeln(top_level_heading); + doc_html[segment_filename] ~= top_level_heading; + } + auto t = xhtml_format.heading_seg(obj, 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); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: // unused numbers, if remain check + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + } + break; + } + } else { + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "toc": + auto t = xhtml_format.para_seg(obj, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "para": + auto t = xhtml_format.para_seg(obj, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(obj, 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); + 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); + 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); + 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); + break; + case "table": + doc_html[segment_filename] ~= xhtml_format.table(obj); + doc_html_endnotes[segment_filename] ~= ""; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "endnote": + auto t = xhtml_format.para_seg(obj, suffix); + doc_html[segment_filename] ~= t[0]; + break; + case "glossary": + auto t = xhtml_format.para_seg(obj, 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); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": + auto t = xhtml_format.para_seg(obj, 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); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + } + break; + } + } + } + } + seg_write_output(doc_matters, doc_html, doc_html_endnotes); +} +#+END_SRC + +**** write output files + +#+name: output_html_seg +#+BEGIN_SRC d +void seg_write_output(M,D,E)( + M doc_matters, + D doc_html, + E doc_html_endnotes, +) { + debug(asserts) { + static assert(is(typeof(doc_html) == string[][string])); + } + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + auto xhtml_format = outputXHTMLs(); + auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); + try { + if (!exists(pth_html.seg(doc_matters.source_filename))) { + pth_html.seg(doc_matters.source_filename).mkdirRecurse; + } + foreach (seg_filename; doc_matters.segnames) { + auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); + foreach (docseg; doc_html[seg_filename]) { + f.writeln(docseg); + } + foreach (docseg; doc_html_endnotes[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); // needed for each lev4 + } + } + catch (ErrnoException ex) { + // handle error + } +} +#+END_SRC + +*** css :css: + +#+name: output_html_css +#+BEGIN_SRC d +auto html_css() { + string css; + css="/* SiSU css default stylesheet */ + body { + color: black; + background: #ffffff; + background-color: #ffffff; + } + a:link { + color: #003399; + text-decoration: none; + } + a:visited { + color: #003399; + text-decoration: none; + } + a:hover { + color: #000000; + background-color: #f9f9aa; + } + a.lnkocn:link { + color: #777777; + text-decoration: none; + } + a:hover img { + background-color: #ffffff; + } + a:active { + color: #003399; + text-decoration: underline; + } + div { + margin-left: 0; + margin-right: 0; + } + div.p { + margin-left: 5%; + margin-right: 1%; + } + .norm, .bold, .verse, .group, .block, .alt { + line-height: 133%; + margin-left: 0em; + margin-right: 2em; + margin-top: 12px; + margin-bottom: 0px; + padding-left: 0em; + text-indent: 0em; + } + p, h0, h1, h2, h3, h4, h5, h6, h7 { + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-size: 100%; + font-weight: normal; + line-height: 133%; + text-align: justify; + margin-left: 0em; + margin-right: 2em; + text-indent: 0mm; + margin-top: 0.8em; + margin-bottom: 0.8em; + } + /* indent */ + p.norm { } + p.i1 {padding-left: 1em;} + p.i2 {padding-left: 2em;} + p.i3 {padding-left: 3em;} + p.i4 {padding-left: 4em;} + p.i5 {padding-left: 5em;} + p.i6 {padding-left: 6em;} + p.i7 {padding-left: 7em;} + p.i8 {padding-left: 8em;} + p.i9 {padding-left: 9em;} + /* hanging indent */ + p[indent=\"h0i0\"] { + padding-left: 0em; + text-indent: 0em; + } + p[indent=\"h0i1\"] { + padding-left: 1em; + text-indent: -1em; + } + p[indent=\"h0i2\"] { + padding-left: 2em; + text-indent: -2em; + } + p[indent=\"h0i3\"] { + padding-left: 3em; + text-indent: -3em; + } + p[indent=\"h0i4\"] { + padding-left: 4em; + text-indent: -4em; + } + p[indent=\"h0i5\"] { + padding-left: 5em; + text-indent: -5em; + } + p[indent=\"h0i6\"] { + padding-left: 6em; + text-indent: -6em; + } + p[indent=\"h0i7\"] { + padding-left: 7em; + text-indent: -7em; + } + p[indent=\"h0i8\"] { + padding-left: 8em; + text-indent: -8em; + } + p[indent=\"h0i9\"] { + padding-left: 9em; + text-indent: -9em; + } + p[indent=\"h1i0\"] { + padding-left: 0em; + text-indent: 1em; + } + p[indent=\"h1i1\"] { + padding-left: 1em; + text-indent: 0em; + } + p[indent=\"h1i2\"] { + padding-left: 2em; + text-indent: -1em; + } + p[indent=\"h1i3\"] { + padding-left: 3em; + text-indent: -2em; + } + p[indent=\"h1i4\"] { + padding-left: 4em; + text-indent: -3em; + } + p[indent=\"h1i5\"] { + padding-left: 5em; + text-indent: -4em; + } + p[indent=\"h1i6\"] { + padding-left: 6em; + text-indent: -5em; + } + p[indent=\"h1i7\"] { + padding-left: 7em; + text-indent: -6em; + } + p[indent=\"h1i8\"] { + padding-left: 8em; + text-indent: -7em; + } + p[indent=\"h1i9\"] { + padding-left: 9em; + text-indent: -8em; + } + p[indent=\"h2i0\"] { + padding-left: 0em; + text-indent: 2em; + } + p[indent=\"h2i1\"] { + padding-left: 1em; + text-indent: 1em; + } + p[indent=\"h2i2\"] { + padding-left: 2em; + text-indent: 0em; + } + p[indent=\"h2i3\"] { + padding-left: 3em; + text-indent: -1em; + } + p[indent=\"h2i4\"] { + padding-left: 4em; + text-indent: -2em; + } + p[indent=\"h2i5\"] { + padding-left: 5em; + text-indent: -3em; + } + p[indent=\"h2i6\"] { + padding-left: 6em; + text-indent: -4em; + } + p[indent=\"h2i7\"] { + padding-left: 7em; + text-indent: -5em; + } + p[indent=\"h2i8\"] { + padding-left: 8em; + text-indent: -6em; + } + p[indent=\"h2i9\"] { + padding-left: 9em; + text-indent: -7em; + } + p[indent=\"h3i0\"] { + padding-left: 0em; + text-indent: 3em; + } + p[indent=\"h3i1\"] { + padding-left: 1em; + text-indent: 2em; + } + p[indent=\"h3i2\"] { + padding-left: 2em; + text-indent: 1em; + } + p[indent=\"h3i3\"] { + padding-left: 3em; + text-indent: 0em; + } + p[indent=\"h3i4\"] { + padding-left: 4em; + text-indent: -1em; + } + p[indent=\"h3i5\"] { + padding-left: 5em; + text-indent: -2em; + } + p[indent=\"h3i6\"] { + padding-left: 6em; + text-indent: -3em; + } + p[indent=\"h3i7\"] { + padding-left: 7em; + text-indent: -4em; + } + p[indent=\"h3i8\"] { + padding-left: 8em; + text-indent: -5em; + } + p[indent=\"h3i9\"] { + padding-left: 9em; + text-indent: -6em; + } + p[indent=\"h4i0\"] { + padding-left: 0em; + text-indent: 4em; + } + p[indent=\"h4i1\"] { + padding-left: 1em; + text-indent: 3em; + } + p[indent=\"h4i2\"] { + padding-left: 2em; + text-indent: 2em; + } + p[indent=\"h4i3\"] { + padding-left: 3em; + text-indent: 1em; + } + p[indent=\"h4i4\"] { + padding-left: 4em; + text-indent: 0em; + } + p[indent=\"h4i5\"] { + padding-left: 5em; + text-indent: -1em; + } + p[indent=\"h4i6\"] { + padding-left: 6em; + text-indent: -2em; + } + p[indent=\"h4i7\"] { + padding-left: 7em; + text-indent: -3em; + } + p[indent=\"h4i8\"] { + padding-left: 8em; + text-indent: -4em; + } + p[indent=\"h4i9\"] { + padding-left: 9em; + text-indent: -5em; + } + p[indent=\"h5i0\"] { + padding-left: 0em; + text-indent: 5em; + } + p[indent=\"h5i1\"] { + padding-left: 1em; + text-indent: 4em; + } + p[indent=\"h5i2\"] { + padding-left: 2em; + text-indent: 3em; + } + p[indent=\"h5i3\"] { + padding-left: 3em; + text-indent: 2em; + } + p[indent=\"h5i4\"] { + padding-left: 4em; + text-indent: 1em; + } + p[indent=\"h5i5\"] { + padding-left: 5em; + text-indent: 0em; + } + p[indent=\"h5i6\"] { + padding-left: 6em; + text-indent: -1em; + } + p[indent=\"h5i7\"] { + padding-left: 7em; + text-indent: -2em; + } + p[indent=\"h5i8\"] { + padding-left: 8em; + text-indent: -3em; + } + p[indent=\"h5i9\"] { + padding-left: 9em; + text-indent: -4em; + } + p[indent=\"h6i0\"] { + padding-left: 0em; + text-indent: 6em; + } + p[indent=\"h6i1\"] { + padding-left: 1em; + text-indent: 5em; + } + p[indent=\"h6i2\"] { + padding-left: 2em; + text-indent: 4em; + } + p[indent=\"h6i3\"] { + padding-left: 3em; + text-indent: 3em; + } + p[indent=\"h6i4\"] { + padding-left: 4em; + text-indent: 2em; + } + p[indent=\"h6i5\"] { + padding-left: 5em; + text-indent: 1em; + } + p[indent=\"h6i6\"] { + padding-left: 6em; + text-indent: 0em; + } + p[indent=\"h6i7\"] { + padding-left: 7em; + text-indent: -1em; + } + p[indent=\"h6i8\"] { + padding-left: 8em; + text-indent: -2em; + } + p[indent=\"h6i9\"] { + padding-left: 9em; + text-indent: -3em; + } + p[indent=\"h7i0\"] { + padding-left: 0em; + text-indent: 7em; + } + p[indent=\"h7i1\"] { + padding-left: 1em; + text-indent: 6em; + } + p[indent=\"h7i2\"] { + padding-left: 2em; + text-indent: 5em; + } + p[indent=\"h7i3\"] { + padding-left: 3em; + text-indent: 4em; + } + p[indent=\"h7i4\"] { + padding-left: 4em; + text-indent: 3em; + } + p[indent=\"h7i5\"] { + padding-left: 5em; + text-indent: 2em; + } + p[indent=\"h7i6\"] { + padding-left: 6em; + text-indent: 1em; + } + p[indent=\"h7i7\"] { + padding-left: 7em; + text-indent: 0em; + } + p[indent=\"h7i8\"] { + padding-left: 8em; + text-indent: -1em; + } + p[indent=\"h7i9\"] { + padding-left: 9em; + text-indent: -2em; + } + p[indent=\"h8i0\"] { + padding-left: 0em; + text-indent: 8em; + } + p[indent=\"h8i1\"] { + padding-left: 1em; + text-indent: 7em; + } + p[indent=\"h8i2\"] { + padding-left: 2em; + text-indent: 6em; + } + p[indent=\"h8i3\"] { + padding-left: 3em; + text-indent: 5em; + } + p[indent=\"h8i4\"] { + padding-left: 4em; + text-indent: 4em; + } + p[indent=\"h8i5\"] { + padding-left: 5em; + text-indent: 3em; + } + p[indent=\"h8i6\"] { + padding-left: 6em; + text-indent: 2em; + } + p[indent=\"h8i7\"] { + padding-left: 7em; + text-indent: 1em; + } + p[indent=\"h8i8\"] { + padding-left: 8em; + text-indent: 0em; + } + p[indent=\"h8i9\"] { + padding-left: 9em; + text-indent: -1em; + } + p[indent=\"h9i0\"] { + padding-left: 0em; + text-indent: 9em; + } + p[indent=\"h9i1\"] { + padding-left: 1em; + text-indent: 8em; + } + p[indent=\"h9i2\"] { + padding-left: 2em; + text-indent: 7em; + } + p[indent=\"h9i3\"] { + padding-left: 3em; + text-indent: 6em; + } + p[indent=\"h9i4\"] { + padding-left: 4em; + text-indent: 5em; + } + p[indent=\"h9i5\"] { + padding-left: 5em; + text-indent: 4em; + } + p[indent=\"h9i6\"] { + padding-left: 6em; + text-indent: 3em; + } + p[indent=\"h9i7\"] { + padding-left: 7em; + text-indent: 2em; + } + p[indent=\"h9i8\"] { + padding-left: 8em; + text-indent: 1em; + } + p[indent=\"h9i9\"] { + padding-left: 9em; + text-indent: 0em; + } + p.block { } + p.group { } + p.alt { } + p.verse { + margin-bottom: 6px; + } + p.code { + font-family: inconsolata, andale mono, courier new, courier, monospace; + font-size: 90%; + text-align: left; + background-color: #eeeeee; + } + p.caption { + text-align: left; + font-size: 80%; + display: inline; + } + p.endnote { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-right: 15mm; + } + p.endnote_indent { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-left: 2em; + margin-right: 15mm; + } + p.center { + text-align: center; + } + p.bold { + font-weight: bold; + } + p.bold_left { + font-weight: bold; + text-align: left; + } + p.centerbold { + text-align: center; + font-weight: bold; + } + p.em { + font-weight: bold; + font-style: normal; + background: #fff3b6; + } + p.small { + font-size: 80%; + margin-top: 0px; + margin-bottom: 0px; + margin-right: 6px; + text-align: left; + } + .tiny, .tiny_left, .tiny_right, .tiny_center { + font-size: 10px; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 6px; + text-align: left; + } + p.tiny { } + p.tiny_left { + margin-left: 0px; + margin-right: 0px; + text-align: left; + } + p.tiny_right { + margin-right: 1em; + text-align: right; + } + p.tiny_center { + margin-left: 0px; + margin-right: 0px; + text-align: center; + } + p.concordance_word { + line-height: 150%; + font-weight: bold; + display: inline; + margin-top: 4px; + margin-bottom: 1px; + } + p.concordance_count { + font-size: 80%; + color: #777777; + display: inline; + margin-left: 0em; + } + p.concordance_object { + font-size: 80%; + line-height: 120%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + p.book_index_lev1 { + line-height: 100%; + margin-top: 4px; + margin-bottom: 1px; + } + p.book_index_lev2 { + line-height: 100%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + tt { + font-family: inconsolata, andale mono, courier new, courier, monospace; + background-color: #eeeeee; + } + label.ocn { + width: 2%; + float: right; + top: 0; + font-size: 10px; + margin-top: 0px; + margin-bottom: 5px; + color: #777777; + margin-right: 5px; + text-align: right; + background-color: #ffffff; + } + table { } + tr { } + th,td { + vertical-align: top; + text-align: left; + } + th { + font-weight: bold; + } + p.left,th.left,td.left { + text-align: left; + } + p.small_left,th.small_left,td.small_left { + text-align: left; + font-size: 80%; + } + p.right,th.right,td.right { + text-align: right; + } + ul, li { + list-style-type: none; + list-style: none; + padding-left: 20px; + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-weight: normal; + line-height: 150%; + text-align: left; + text-indent: 0mm; + margin-left: 1em; + margin-right: 2em; + margin-top: 3px; + margin-bottom: 3px; + } + li { + background: url(../image_sys/bullet_09.png) no-repeat 0px 6px; + } + ul { + } + h0, h1, h2, h3, h4, h5, h6, h7 { + font-weight: bold; + line-height: 120%; + text-align: left; + margin-top: 20px; + margin-bottom: 10px; + } + h4.norm, h5.norm, h6.norm, h7.norm { + margin-top: 10px; + margin-bottom: 0px; + } + h0 { font-size: 125%; } + h1 { font-size: 120%; } + h2 { font-size: 115%; } + h3 { font-size: 110%; } + h4 { font-size: 105%; } + h5 { font-size: 100%; } + h6 { font-size: 100%; } + h7 { font-size: 100%; } + h1.i {margin-left: 2em;} + h2.i {margin-left: 3em;} + h3.i {margin-left: 4em;} + h4.i {margin-left: 5em;} + h5.i {margin-left: 6em;} + h6.i {margin-left: 7em;} + h7.i {margin-left: 8em;} + h8.i {margin-left: 9em;} + h9.i {margin-left: 10em;} + .toc { + font-weight: normal; + margin-top: 6px; + margin-bottom: 6px; + } + h0.toc { + margin-left: 1em; + font-size: 120%; + line-height: 150%; + } + h1.toc { + margin-left: 1em; + font-size: 115%; + line-height: 150%; + } + h2.toc { + margin-left: 2em; + font-size: 110%; + line-height: 140%; + } + h3.toc { + margin-left: 3em; + font-size: 105%; + line-height: 120%; + } + h4.toc { + margin-left: 4em; + font-size: 100%; + line-height: 120%; + } + h5.toc { + margin-left: 5em; + font-size: 95%; + line-height: 110%; + } + h6.toc { + margin-left: 6em; + font-size: 90%; + line-height: 110%; + } + h7.toc { + margin-left: 7em; + font-size: 85%; + line-height: 100%; + } + .subtoc { + margin-right: 34%; + font-weight: normal; + } + h5.subtoc { + margin-left: 2em; + font-size: 80%; + margin-top: 2px; + margin-bottom: 2px; + } + h6.subtoc { + margin-left: 3em; + font-size: 75%; + margin-top: 0px; + margin-bottom: 0px; + } + h7.subtoc { + margin-left: 4em; + font-size: 70%; + margin-top: 0px; + margin-bottom: 0px; + } + div.substance { + width: 100%; + background-color: #ffffff; + } + div.ocn { + width: 5%; + float: right; + top: 0; + background-color: #ffffff; + } + div.endnote { + width: 95%; + background-color: #fffffff; + } + div.toc { + position: absolute; + float: left; + margin: 0; + padding: 0; + padding-top: 0.5em; + border: 0; + width: 13em; + background-color: #eeeeee; + margin-right:1em; + } + div.summary { + margin: 0; + padding: 0; + border-left: 13em solid #eeeeee; + padding-left: 1em; + background-color: #eeeeee; + } + div.content, div.main_column { + margin: 0; + padding: 0; + border-left: 13em solid #ffffff; + padding-left: 1em; + padding-right: 1em; + } + div.content0, div.main_column0 { + margin: 0; + padding: 0; + border-left: 0% solid #ffffff; + padding-left: 5%; + } + div.scroll { + margin: 0; + padding: 0; + padding-left: 1em; + padding-right: 1em; + } + div.content:after { + content:' '; + clear:both; + display:block; + height:0; + overflow:hidden + } + div.footer { + clear:left; + padding: 0.5em; + font-size: 80%; + margin: 0; + } + div.toc ul { + list-style: none; + padding: 0; + margin: 0; + } + div.toc li ul a, li ul span.currentlink + { + font-weight: normal; + font-size: 90%; + padding-left: 2em; + background-color: #eeeeee; + } + div.toc a, span.currentlink{ + display:block; + text-decoration: none; + padding-left: 0.5em; + color: #0000aa; + } + hr { + width: 90%; + } + span.currentlink { + text-decoration: none; + background-color: #aaaaf9; + } + div.toc a:visited { + color: #0000aa; + } + div.toc a:hover { + color: #000000; + background-color: #f9f9aa; + }"; + return css; +} +auto css_write() { + auto pth_css= "_sisu/css"; + auto pth_css_fn= pth_css ~ "/html.css"; + try { + if (!exists(pth_css)) { + pth_css.mkdirRecurse; + } + auto f = File(pth_css_fn, "w"); + f.writeln(html_css); + // foreach (o; doc) { + // f.writeln(o); + // } + } + catch (ErrnoException ex) { + // Handle error + } +} +#+END_SRC + +** _epub_ [#B] :epub: + +|-----------------------+--------------------------+---------------------------+----------------------------------| +| function | filename | module | variable | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| identify doc filetype | mimetype | epub3_mimetypes | mimetypes | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| identify doc root | META-INF/container.xml | epub3_container_xml | meta_inf_container_xml | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc manifest | OEBPS/content.opf | epub3_oebps_content | oebps_content_opf | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc navigation | OEBPS/toc_nav.xhtml | epub3_oebps_toc_nav_xhtml | oebps_toc_nav_xhtml | +| | OEBPS/toc.ncx | epub2_oebps_toc_ncx | oebps_toc_ncx | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc contents | OEBPS/[files ... ].xhtml | outputEPub3 | doc_epub3[seg_filename] | +| | | | doc_epub3_endnotes[seg_filename] | +|-----------------------+--------------------------+---------------------------+----------------------------------| + +*** template :template: + +#+BEGIN_SRC d :tangle ../src/sdp/output_epub3.d +template outputEPub3() { + <> + mixin InternalMarkup; + mixin outputXHTMLs; + <> + <> + <> + <> + <> +} +#+END_SRC + +*** special (epub) files :format: +**** DONE static +***** _identify doc filetype_ (mimetype) [static] + +- mimetype file indicating that zip file contains an EPUB + +#+name: output_epub3_fixed +#+BEGIN_SRC d +string epub3_mimetypes() { + string o; + o = format(q"¶application/epub+zip¶") ~ "\n"; + return o; +} +#+END_SRC + +***** _identify doc root_ (META-INF/container.xml) [static] rootfile: contains document root path + +- identifies the root package document (so systems can find it), [unchanged from epub2] + +#+name: output_epub3_fixed +#+BEGIN_SRC d +string epub3_container_xml() { + string o; + o = format(q"¶¶") ~ "\n"; + o ~= format(q"¶ + + +¶") ~ "\n\n"; + return o; +} +#+END_SRC + +**** constructs (in dir: OEBPS) +***** TODO _doc manifest_ (OEBPS/content.opf) manifest, register content: files, images etc. + +- manifest, listing all resources +- provides the default reading order +- identifies the navigation document + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { + auto pth_epub3 = SiSUpathsEPUB!()(doc_matters.src_path_info, doc_matters.language); + string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO sort uuid in doc_matters! + string content = format(q"¶ + + + + %s + main + %s + subtitle + %s + %s + %s + Copyright: %s + %s + urn:uuid:%s + + + + + + + + + +¶", + uuid, + doc_matters.dochead_meta["title"]["full"], + doc_matters.dochead_meta["title"]["main"], + (doc_matters.dochead_meta["title"]["sub"].empty) + ? "" : doc_matters.dochead_meta["title"]["sub"], + (doc_matters.dochead_meta["creator"]["author"].empty) + ? "" : doc_matters.dochead_meta["creator"]["author"], + (doc_matters.dochead_meta["creator"]["author"].empty) + ? "" : doc_matters.dochead_meta["creator"]["author"], + doc_matters.language, + (doc_matters.dochead_meta["date"]["published"].empty) + ? "" : doc_matters.dochead_meta["date"]["published"], + (doc_matters.dochead_meta["rights"]["copyright"].empty) + ? "" : doc_matters.dochead_meta["rights"]["copyright"], + uuid, + uuid, + uuid, + (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), + ); + content ~= " " ~ "" ~ "\n "; + content ~= parts["manifest_documents"]; + // TODO sort jpg & png + content ~= " " ~ "" ~ "\n "; + foreach (image; doc_matters.image_list) { + content ~= format(q"¶ +¶", + image.baseName.stripExtension, + (pth_epub3.doc_oebps_image(doc_matters.source_filename)).chompPrefix("OEBPS/"), + image, + image.extension.chompPrefix("."), + ); + } + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["spine"]; + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["guide"]; + content ~= " " ~ "" ~ "\n "; + content ~= "" ~ ""; + return content; +} +#+END_SRC + +***** _doc navigation epub3_ (OEBPS/toc_nav.xhtml) epub3 navigable toc using Dom structure + +- toc_nav.xhtml declared as nav file in content.opf (epub3 navigation document) + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { + enum DomTags { none, open, close, close_and_open, open_still, } + auto markup = InlineMarkup(); + string toc ="\n"; + return toc; +} +#+END_SRC + +***** TODO _doc navigation epub2_ (OEBPS/toc.ncx) navigable toc using Dom structure + +- toc.ncx (epub2 navigation document) + - (replaced in epub3 by a declared xhtml nav file, in our case toc_nav.xhtml) + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { + int counter = 0; + string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere + auto markup = InlineMarkup(); + enum DomTags { none, open, close, close_and_open, open_still, } + string toc = format(q"¶ + + + + %s%s + + + + + + + + + %s + + + %s + + ¶", + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author + uuid, // uuid + "3", // content depth + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : doc_matters.dochead_meta["creator"]["author"], // author + ); + foreach (sect; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[sect]) { + if (obj.is_a == "heading") { + foreach_reverse (k; 0 .. 7) { + switch (obj.dom_markedup[k]) { + case DomTags.close : + // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags +toc ~= ""; + break; + case DomTags.close_and_open : + // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags + ++counter; +toc ~= ""; +toc ~= format(q"¶ + + %s + +¶", +counter, +obj.text, +obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (links done in segment_anchor_tag) +); + break; + case DomTags.open : + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags + ++counter; +toc ~= format(q"¶ + + %s + +¶", +counter, +obj.text, +obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml; lev > 4 [filename#ocn] (fix links in segment_anchor_tag) +); + break; + default : + break; + } + } + } + } + } + toc ~= format(q"¶ +¶"); + return toc; +} +#+END_SRC + +*** the document contents :seg: +**** switch (sections & objects) format epub3 xhtml output + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d +void outputEPub3(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, +) { + mixin SiSUoutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[][string] doc_epub3; + string[][string] doc_epub3_endnotes; + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string[string] oepbs_content_parts; + string suffix = ".xhtml"; + foreach (part; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + if (obj.is_a == "heading") { + switch (obj.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.heading_lev_markup) { + case 0: + top_level_headings[0] = ""; + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 1: + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 2: + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 3: + top_level_headings[3] = ""; + goto default; + default: + auto t = xhtml_format.heading_seg(obj, suffix); + top_level_headings[obj.heading_lev_markup] = t[0]; + break; + } + break; + case 4: + segment_filename = obj.segment_anchor_tag; + doc_epub3[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); + foreach (top_level_heading; top_level_headings) { + doc_epub3[segment_filename] ~= top_level_heading; + } + auto t = xhtml_format.heading_seg(obj, 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); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: // unused numbers, if remain check + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + } + break; + } + } else { + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "toc": + doc_epub3[segment_filename] ~= xhtml_format.toc(obj); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "para": + auto t = xhtml_format.para_seg(obj, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(obj, 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); + 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); + 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); + 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); + break; + case "table": + auto t = xhtml_format.para_seg(obj, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "endnote": + auto t = xhtml_format.para_seg(obj, suffix); + doc_epub3[segment_filename] ~= t[0]; + break; + case "glossary": + auto t = xhtml_format.para_seg(obj, 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); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": + auto t = xhtml_format.para_seg(obj, 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); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + } + break; + } + } + if (obj.is_a == "heading") { + if (obj.heading_lev_markup == 4) { + oepbs_content_parts["manifest_documents"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + obj.segment_anchor_tag, + ); + oepbs_content_parts["spine"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + ); + oepbs_content_parts["guide"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + obj.segment_anchor_tag, + ); + } else if (obj.heading_lev_markup > 4) { + oepbs_content_parts["manifest_documents"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + oepbs_content_parts["spine"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + oepbs_content_parts["guide"] ~= format(q"¶ +¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + } + } + } + } + /+ epub specific documents +/ + auto mimetypes = epub3_mimetypes; + auto meta_inf_container_xml = epub3_container_xml; + auto oebps_toc_ncx = epub2_oebps_toc_ncx(doc_abstraction, doc_matters); + auto oebps_toc_nav_xhtml = epub3_oebps_toc_nav_xhtml(doc_abstraction, doc_matters); + auto oebps_content_opf = epub3_oebps_content(doc_abstraction, doc_matters, oepbs_content_parts); + epub3_write_output_files( + doc_matters, + doc_epub3, + doc_epub3_endnotes, + mimetypes, + meta_inf_container_xml, + oebps_toc_nav_xhtml, + oebps_toc_ncx, + oebps_content_opf, + ); +} +#+END_SRC + +*** write output files + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d +void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( + M doc_matters, + D doc_epub3, + E doc_epub3_endnotes, + Mt mimetypes, + Mic meta_inf_container_xml, + Otnx oebps_toc_nav_xhtml, + Otn oebps_toc_ncx, + Oc oebps_content_opf, +) { + debug(asserts) { + static assert(is(typeof(doc_epub3) == string[][string])); + static assert(is(typeof(mimetypes) == string)); + static assert(is(typeof(meta_inf_container_xml) == string)); + static assert(is(typeof(oebps_toc_nav_xhtml) == string)); + static assert(is(typeof(oebps_toc_ncx) == string)); + static assert(is(typeof(oebps_content_opf) == string)); + } + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_epub3 = SiSUpathsEPUB!()(src_path_info, lng); + auto xhtml_format = outputXHTMLs(); + /+ zip file +/ + auto fn_epub = pth_epub3.epub_file(doc_matters.source_filename); + auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); + /+ zip archive member files +/ + try { + if (!exists(pth_epub3.base)) { + pth_epub3.base.mkdirRecurse; + } + debug(epub_output) { + if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename))) { + pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename).mkdirRecurse; + } + } + { /+ OEBPS/[segments].xhtml (the document contents) +/ + foreach (seg_filename; doc_matters.segnames) { + string fn = pth_epub3.fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add seg fn to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + debug(epub_output) { + string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); + auto f = File(fn_dbg, "w"); + } + /+ // f.writeln(seg_head); // not needed built and inserted earlier +/ + foreach (docseg; doc_epub3[seg_filename]) { + debug(epub_output) { f.writeln(docseg); } + zip_data.write(docseg.dup); // cast as: char[] + } + foreach (docseg; doc_epub3_endnotes[seg_filename]) { + debug(epub_output) { f.writeln(docseg); } + zip_data.write(docseg.dup); // cast as: char[] + } + debug(epub_output) { f.writeln(xhtml_format.tail); } // needed for each lev4 + zip_data.write(xhtml_format.tail.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + } + string fn; + debug(epub_output) { string fn_dbg; } + File f; + { /+ mimetypes (identify zip file type) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.source_filename); + File(fn_dbg, "w").writeln(mimetypes); + } + fn = pth_epub3.fn_mimetypes(doc_matters.source_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add mimetypes to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(mimetypes.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + { /+ META-INF/container.xml (identify doc root) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.source_filename); + File(fn_dbg, "w").writeln(meta_inf_container_xml); + } + fn = pth_epub3.fn_dmi_container_xml(doc_matters.source_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add META-INF/container.xml to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(meta_inf_container_xml.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); + } + fn = pth_epub3.fn_oebps_toc_nav_xhtml(doc_matters.source_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add OEBPS/toc_nav.xhtml to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_toc_nav_xhtml.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/toc.ncx (navigation toc epub2) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_toc_ncx); + } + fn = pth_epub3.fn_oebps_toc_ncx(doc_matters.source_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add OEBPS/toc.ncx to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_toc_ncx.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/content.opf (doc manifest) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_content_opf); + } + fn = pth_epub3.fn_oebps_content_opf(doc_matters.source_filename); + /+ add zip archive file members (with their content) +/ + auto zip_arc_member_file = new ArchiveMember(); + // add OEBPS/content.opf to zip archive + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_content_opf.dup); // cast as: char[] + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/_sisu/image (images) +/ + foreach (image; doc_matters.image_list) { + if (exists(doc_matters.src_path_info.image_root ~ "/" ~ image)) { + (doc_matters.src_path_info.image_root ~ "/" ~ image) + .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image); + } + } + foreach (image; doc_matters.image_list) { + debug(epub_images) { + writeln( + doc_matters.src_path_info.image_root, image, " -> ", + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename), "/", image + ); + } + auto fn_src = doc_matters.src_path_info.image_root ~ image; + auto fn_out = pth_epub3.doc_oebps_image(doc_matters.source_filename).to!string ~ "/" ~ image; + if (exists(fn_src)) { + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write(cast(char[]) ((fn_src).read)); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + } + } + } + } + catch (ErrnoException ex) { + // Handle error + } +#+END_SRC + +*** zip debug, read zip archive + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + debug(epub_archive) { + if (exists(fn_epub)) { + try { + auto zipped = new ZipArchive((fn_epub).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln(filename, " length ", data.length); // member.name + // Use data + } + } + catch (ZipException ex) { + // Handle errors + } + } + } +} +#+END_SRC diff --git a/org/output_zip.org b/org/output_zip.org new file mode 100644 index 0000000..a907997 --- /dev/null +++ b/org/output_zip.org @@ -0,0 +1,36 @@ +#+TITLE: sdp output zip +#+AUTHOR: Ralph Amissah +#+EMAIL: ralph.amissah@gmail.com +#+STARTUP: indent +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :sdp:rel:output: +#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./sdp.org][sdp]] [[./][org/]] +* _zip_ +** template :template: + +#+BEGIN_SRC d :tangle ../src/sdp/create_zip_file.d +template createZipFile() { + import std.file; + import std.outbuffer; + import std.string; + import std.zip; + void createZipFile( + string zip_file_name, + void[] compressed_zip_data, + ) { + try { + write(zip_file_name, compressed_zip_data); + } catch (ZipException ex) { + // Handle Errors + } + } +} +#+END_SRC diff --git a/org/sdp.org b/org/sdp.org index 19ec705..f6c26f2 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -23,7 +23,7 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 13, 9); +enum ver = Version(0, 14, 0); #+END_SRC * 1. sdp (sisu document parser) :sdp: @@ -98,7 +98,8 @@ import ao_read_config_files, ao_read_source_files, ao_rgx, - output_hub; + output_hub, + paths_source; #+END_SRC ****** notes @@ -406,7 +407,7 @@ if ((doc_matters.opt_action_bool["debug"]) #+END_SRC **** 2. _process outputs_ :outputs: -- [[./output.org][output]] +- [[./output_hub.org][output_hub]] #+NAME: sdp_each_file_do_selected_output #+BEGIN_SRC d @@ -515,19 +516,19 @@ static assert(!isTypeTuple!(_make_and_meta)); static assert(_make_and_meta.length==2); #+END_SRC -** 3. _document abstraction, tuple_ (pre-processing) :processing: -- [[./ao_abstract_doc_source.org][ao_abstract_doc_source]] +** 3. _document abstraction, tuple_ (pre-output-processing) :processing: +- [[./ao_doc_abstraction.org][ao_doc_abstraction]] - prepare the document abstraction used in downstream processing - return tuple of: - - document abstraction (the_document or doc_abstraction) + - document abstraction (_the_document_ or doc_abstraction) - document abstraction keys - (head, toc, body, endnotes, glossary, bibliography, bookindex, blurb, tail) - - (passed in doc_matters) - - segnames for html epub (passed in doc_matters) - - image list (passed in doc_matters) + - (transfer to _doc_matters_) + - segnames for html epub (transfer to _doc_matters_) + - image list (transfer to _doc_matters_) #+NAME: sdp_each_file_do_document_abstraction #+BEGIN_SRC d @@ -571,6 +572,11 @@ struct DocumentMatters { string[string][string] _k = _make_and_meta[makeMeta.meta]; return _k; } + auto src_path_info() { + string _pwd = env["pwd"]; + auto _k = SiSUpathsSRC!()(_pwd, fn_src); + return _k; + } auto source_filename() { string _k = fn_src; return _k; diff --git a/src/sdp.d b/src/sdp.d index 27b2d85..ca4f8c0 100755 --- a/src/sdp.d +++ b/src/sdp.d @@ -17,7 +17,8 @@ import ao_read_config_files, ao_read_source_files, ao_rgx, - output_hub; + output_hub, + paths_source; /+ sdlang http://sdlang.org +/ import sdlang; // sdlang.d /+ std +/ diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d index 714ab41..d6124a0 100644 --- a/src/sdp/abstraction.d +++ b/src/sdp/abstraction.d @@ -11,7 +11,8 @@ template SiSUabstraction() { ao_read_config_files, ao_read_source_files, ao_rgx, - output_hub; + output_hub, + paths_source; /+ sdlang http://sdlang.org +/ import sdlang; // sdlang.d /+ std +/ @@ -91,6 +92,11 @@ template SiSUabstraction() { string[string][string] _k = _make_and_meta[makeMeta.meta]; return _k; } + auto src_path_info() { + string _pwd = env["pwd"]; + auto _k = SiSUpathsSRC!()(_pwd, fn_src); + return _k; + } auto source_filename() { string _k = fn_src; return _k; diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d index 24fcd48..f7eca53 100644 --- a/src/sdp/ao_abstract_doc_source.d +++ b/src/sdp/ao_abstract_doc_source.d @@ -363,8 +363,9 @@ template SiSUdocAbstraction() { ); } line = (line).replaceAll(rgx.true_dollar, "$$$$"); - // dollar represented as $$ needed to stop submatching on $ - // (substitutions using ${identifiers} must take into account (i.e. happen earlier)) + /+ dollar represented as $$ needed to stop submatching on $ + (substitutions using ${identifiers} must take into account (i.e. happen earlier)) + +/ debug(source) { // source lines writeln(line); } @@ -414,7 +415,6 @@ template SiSUdocAbstraction() { writeln(__LINE__); writeln(line); } - // _glossary_block_(line, type); type["glossary_section"] = State.on; type["biblio_section"] = State.off; type["blurb_section"] = State.off; @@ -618,7 +618,6 @@ template SiSUdocAbstraction() { "code block status: none or closed" ); if (type["blocks"] == TriState.closing) { - // blocks closed, unless followed by book index debug(check) { // block writeln(__LINE__); writeln(line); @@ -668,14 +667,13 @@ template SiSUdocAbstraction() { && ((type["para"] == State.off) && (type["heading"] == State.off))) { /+ heading make set +/ - _heading_make_set_(line, line_occur, heading_match_rgx, type); + line = _heading_make_set_(line, line_occur, heading_match_rgx, type); } /+ TODO node info: all headings identified at this point, - extract node info here?? - how long can it wait? - should be incorporated in composite objects - should happen before endnote links set (they need to be moved down?) - // node_construct.node_emitter_heading segment anchor tag +/ if (line.matchFirst(rgx.heading)) { /+ heading match +/ @@ -791,7 +789,6 @@ template SiSUdocAbstraction() { writeln(segment_anchor_tag_that_object_belongs_to); } the_document_body_section ~= comp_obj_heading; - // track previous heading and make assertions debug(objectrelated1) { // check writeln(line); } @@ -850,7 +847,6 @@ template SiSUdocAbstraction() { line == null, "line variable should be empty, should not occur" ); - // check what happens when paragraph separated by 2 newlines } } // close else for line empty } // close else for not the above @@ -959,7 +955,6 @@ template SiSUdocAbstraction() { comp_obj_heading_.parent_ocn = 1; comp_obj_heading_.parent_lev_markup = 0; the_bibliography_section ~= comp_obj_heading_; - // --- comp_obj_heading_ = comp_obj_heading_.init; comp_obj_heading_.use = "backmatter"; comp_obj_heading_.is_of = "para"; @@ -1454,7 +1449,6 @@ template SiSUdocAbstraction() { foreach (ref obj; the_bookindex_section["scroll"]) { if (obj.is_a == "heading") { debug(dom) { - // writeln(obj.text); } if (obj.heading_lev_markup == 4) { obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; @@ -1540,7 +1534,6 @@ template SiSUdocAbstraction() { comp_obj_heading_.use = "empty"; comp_obj_heading_.is_of = "para"; comp_obj_heading_.is_a = "heading"; - // comp_obj_heading_.text = "(skip) this is the DOM tail"; comp_obj_heading_.ocn = 0; comp_obj_para.obj_cite_number = ""; comp_obj_heading_.segment_anchor_tag = ""; @@ -1892,6 +1885,7 @@ template SiSUdocAbstraction() { debug(quote) { // quote (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["quote"] = TriState.closing; type["curly_quote"] = TriState.off; @@ -1906,6 +1900,7 @@ template SiSUdocAbstraction() { debug(quote) { // quote (tic) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["quote"] = TriState.closing; type["tic_quote"] = TriState.off; @@ -1933,6 +1928,7 @@ template SiSUdocAbstraction() { debug(group) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["group"] = TriState.closing; type["curly_group"] = TriState.off; @@ -1947,6 +1943,7 @@ template SiSUdocAbstraction() { debug(group) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["group"] = TriState.closing; type["tic_group"] = TriState.off; @@ -1974,6 +1971,7 @@ template SiSUdocAbstraction() { debug(block) { // block (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["block"] = TriState.closing; type["curly_block"] = TriState.off; @@ -1988,6 +1986,7 @@ template SiSUdocAbstraction() { debug(block) { writeln(line); } + an_object[an_object_key] = an_object[an_object_key].stripRight; type["blocks"] = TriState.closing; type["block"] = TriState.closing; type["tic_block"] = TriState.off; @@ -2078,6 +2077,7 @@ template SiSUdocAbstraction() { ocn_emit(type["ocn_status"]); type["verse_new"] = State.off; } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; verse_line = TriState.off; type["verse_new"] = State.on; } @@ -2170,6 +2170,7 @@ template SiSUdocAbstraction() { ocn_emit(type["ocn_status"]); type["verse_new"] = State.off; } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; type["verse_new"] = State.on; verse_line = TriState.off; } @@ -2232,6 +2233,9 @@ template SiSUdocAbstraction() { debug(code) { // code (curly) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; type["blocks"] = TriState.closing; type["code"] = TriState.closing; type["curly_code"] = TriState.off; @@ -2246,6 +2250,9 @@ template SiSUdocAbstraction() { debug(code) { // code (tic) close writeln(line); } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; type["blocks"] = TriState.closing; type["code"] = TriState.closing; type["tic_code"] = TriState.off; @@ -2464,7 +2471,6 @@ template SiSUdocAbstraction() { header_tag_value=""; } } - // void _table_closed_make_special_notation_table_( char[] line, return ref string[string] an_object, @@ -2513,7 +2519,6 @@ template SiSUdocAbstraction() { string[string] obj_cite_number_poem, string[string][string] dochead_make_aa, ) { - // line.empty, post contents, empty variables --------------- assert( line.empty, "line should be empty" @@ -2966,6 +2971,7 @@ template SiSUdocAbstraction() { } } } + return line; } auto _heading_matched_(L,C,O,K,Lv,Lc,T,Me)( return ref L line, @@ -3748,7 +3754,6 @@ template SiSUdocAbstraction() { switch (obj_["is"]) { case "heading": static __gshared string anchor_tag = ""; - // TODO WORK ON, you still need to ensure that level 1 anchor_tags are unique obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, dochead_make_aa); obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"]); if (auto m = obj_txt["munge"].match(rgx.heading_anchor_tag)) { @@ -4955,9 +4960,10 @@ template SiSUdocAbstraction() { static assert(is(typeof(bib_arr_json) == JSONValue[])); } foreach (bibent; biblio_unordered) { - // update bib to include deemed_author, needed for: - // sort_bibliography_array_by_deemed_author_year_title - // either: sort on multiple fields, or; create such sort field + /+ update bib to include deemed_author, needed for: + sort_bibliography_array_by_deemed_author_year_title + either: sort on multiple fields, or; create such sort field + +/ JSONValue j = parseJSON(bibent); if (!empty(j["fulltitle"].str)) { if (!empty(j["author_raw"].str)) { diff --git a/src/sdp/ao_defaults.d b/src/sdp/ao_defaults.d index 21352e2..0f1ba2a 100644 --- a/src/sdp/ao_defaults.d +++ b/src/sdp/ao_defaults.d @@ -309,7 +309,7 @@ template SiSUnode() { } int[string] node_metadata_heading_int() { auto _node = [ - "ocn" : 0, + "ocn" : 0, // decide whether to use or keep? "ptr_doc_object" : 0, "ptr_html_segnames" : 0, "ptr_heading" : 0, @@ -325,6 +325,7 @@ template SiSUnode() { "is" : "", "ocn" : "", "attrib" : "", + // "segment_anchor_tag" : "", ]; return _node; } @@ -334,6 +335,10 @@ template SiSUnode() { "indent_base" : 0, "indent_hang" : 0, "bullet" : 0, // bool (0|1) + // "ptr_doc_object" : 0, + // "ptr_html_segnames" : 0, + // "parent_ocn" : 0, + // "parent_lev_markup" : 9, ]; return _node; } diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index 0844a5f..8c73423 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -89,8 +89,8 @@ template SiSUrgxInit() { static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); /+ blocked markup tics +/ - static block_tic_open = ctRegex!("^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)"); - static block_tic_code_open = ctRegex!("^`{3} (?:code)(?:[.]([a-z][0-9a-z_]+))?(?:[ ]+([#]))?"); + static block_tic_open = ctRegex!("^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)"); // what of numbered code? + static block_tic_code_open = ctRegex!("^`{3} (?:code)(?:[.]([a-z][0-9a-z_]+))?(?:[ ]+([#]))?"); // extract additional info static block_tic_poem_open = ctRegex!("^`{3} (poem)"); static block_tic_group_open = ctRegex!("^`{3} (group)"); static block_tic_block_open = ctRegex!("^`{3} (block)"); @@ -99,7 +99,7 @@ template SiSUrgxInit() { static block_tic_close = ctRegex!("^(`{3})$","m"); /+ blocked markup curly +/ static block_curly_open = ctRegex!(`^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)`); - static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); + static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); // extract additional info static block_curly_code_close = ctRegex!(`^([}]code)`); static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); static block_curly_poem_close = ctRegex!(`^([}]poem)`); @@ -182,7 +182,7 @@ template SiSUrgxInit() { auto language_codes = ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); auto language_code_and_filename = - ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); + ctRegex!("(?:^|[/])(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); static newline = ctRegex!("\n", "mg"); static strip_br = ctRegex!("^
\n|
\n*$"); static space = ctRegex!(`[ ]`, "mg"); diff --git a/src/sdp/defaults.d b/src/sdp/defaults.d index 537b4ba..bbfd8d8 100644 --- a/src/sdp/defaults.d +++ b/src/sdp/defaults.d @@ -2,192 +2,6 @@ default settings +/ -template SiSUpaths() { - struct DirPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - } - struct SiSUpodPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string sisupod_filename(string fn_src) { - return "sisupod".chainPath(base_filename(fn_src) ~ ".zip").array; - } - string base(string fn_src) { - return "sisupod".chainPath(base_filename(fn_src)).array; - } - } - struct SiSUpodPathsZipped { - auto spod_pths = SiSUpodPaths(); - string base_filename(string fn_src) { - return spod_pths.base_filename(fn_src); - } - string sisupod_filename(string fn_src) { - return spod_pths.sisupod_filename(fn_src); - } - string base(string fn_src) { - return spod_pths.base(fn_src); - } - auto doc_root(string fn_src) { - return "doc"; - } - auto doc(string fn_src) { - return doc_root(fn_src); - } - auto doc_lng(string fn_src, string lng) { - return doc_root(fn_src).chainPath(lng).array; - } - auto conf(string fn_src) { - return doc_root(fn_src).chainPath("_sisu").array; - } - auto image(string fn_src) { - return conf(fn_src).chainPath("image").array; - } - auto css(string fn_src) { - return conf(fn_src).chainPath("css").array; - } - auto fn_doc(string fn_src, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_src)).array; - } - auto fn_doc_insert(string fn_src, string fn_insert, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_insert)).array; - } - } - struct SiSUpodPathsFilesystemArchive { - auto spod_pths = SiSUpodPaths(); - string base_filename(string fn_src) { - return spod_pths.base_filename(fn_src); - } - string sisupod_filename(string fn_src) { - return spod_pths.sisupod_filename(fn_src); - } - string base(string fn_src) { - return spod_pths.base(fn_src); - } - auto doc_root(string fn_src) { - return base(fn_src).chainPath("doc").array; - } - auto doc(string fn_src) { - return doc_root(fn_src); - } - auto doc_lng(string fn_src, string lng) { - return doc_root(fn_src).chainPath(lng).array; - } - auto conf(string fn_src) { - return doc_root(fn_src).chainPath("_sisu").array; - } - auto image(string fn_src) { - return conf(fn_src).chainPath("image").array; - } - auto css(string fn_src) { - return conf(fn_src).chainPath("css").array; - } - auto fn_doc(string fn_src, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_src)).array; - } - auto fn_doc_insert(string fn_src, string fn_insert, string lng) { - return (doc_lng(fn_src, lng)).chainPath(baseName(fn_insert)).array; - } - } - struct HtmlPaths { - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string base() { - return "en".chainPath("html").array; - } - string seg(string fn_src) { - return base.chainPath(base_filename(fn_src)).array; - } - string fn_scroll(string fn_src) { - return base.chainPath(base_filename(fn_src) ~ ".html").array; - } - string fn_seg(string fn_src, string seg_filename) { - return seg(fn_src).chainPath(seg_filename ~ ".html").array; - } - } - struct Epub3paths { - string dirtop() { - return "".chainPath("").array; - } - string base_filename(string fn_src) { - return baseName(stripExtension(fn_src)); - } - string base() { - return "en".chainPath("epub3").array; - } - string epub_file(string fn_src) { - return base.chainPath(base_filename(fn_src) ~ ".epub").array; - } - string docdir(string fn_src) { - return base.chainPath(base_filename(fn_src)).array; - } - string doc_meta_inf(string fn_src) { - return dirtop.chainPath("META-INF").array; - } - string doc_oebps(string fn_src) { - return dirtop.chainPath("OEBPS").array; - } - string doc_oebps_css(string fn_src) { - return doc_oebps(fn_src).chainPath("css").array; - } - string doc_oebps_image(string fn_src) { - return doc_oebps(fn_src).chainPath("image").array; - } - string fn_mimetypes(string fn_src) { - return dirtop.chainPath("mimetypes").array; - } - string fn_dmi_container_xml(string fn_src) { - return doc_meta_inf(fn_src).chainPath("container.xml").array; - } - string fn_oebps_toc_nav_xhtml(string fn_src) { - return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; - } - string fn_oebps_toc_ncx(string fn_src) { - return doc_oebps(fn_src).chainPath("toc.ncx").array; - } - string fn_oebps_content_opf(string fn_src) { - return doc_oebps(fn_src).chainPath("content.opf").array; - } - string fn_oebps_content_xhtml(string fn_src, string seg_filename) { - return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; - } - debug(epub_output) { - string dbg_doc_meta_inf(string fn_src) { - return docdir(fn_src).chainPath("META-INF").array; - } - string dbg_doc_oebps(string fn_src) { - return docdir(fn_src).chainPath("OEBPS").array; - } - string dbg_doc_oebps_css(string fn_src) { - return doc_oebps(fn_src).chainPath("css").array; - } - string dbg_doc_oebps_image(string fn_src) { - return doc_oebps(fn_src).chainPath("image").array; - } - string dbg_fn_mimetypes(string fn_src) { - return docdir(fn_src).chainPath("mimetypes").array; - } - string dbg_fn_dmi_container_xml(string fn_src) { - return doc_meta_inf(fn_src).chainPath("container.xml").array; - } - string dbg_fn_oebps_toc_nav_xhtml(string fn_src) { - return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; - } - string dbg_fn_oebps_toc_ncx(string fn_src) { - return doc_oebps(fn_src).chainPath("toc.ncx").array; - } - string dbg_fn_oebps_content_opf(string fn_src) { - return doc_oebps(fn_src).chainPath("content.opf").array; - } - string dbg_fn_oebps_content_xhtml(string fn_src, string seg_filename) { - return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; - } - } - } -} template InternalMarkup() { struct InlineMarkup { auto en_a_o = "【"; auto en_a_c = "】"; // endnote en_a_o: '~{'; en_a_c: '}~'; diff --git a/src/sdp/output_epub3.d b/src/sdp/output_epub3.d index 314fe64..f16b25b 100644 --- a/src/sdp/output_epub3.d +++ b/src/sdp/output_epub3.d @@ -25,7 +25,8 @@ template outputEPub3() { create_zip_file, defaults, output_rgx, - output_xhtmls; + output_xhtmls, + paths_output; mixin InternalMarkup; mixin outputXHTMLs; string epub3_mimetypes() { @@ -45,6 +46,7 @@ template outputEPub3() { return o; } string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { + auto pth_epub3 = SiSUpathsEPUB!()(doc_matters.src_path_info, doc_matters.language); string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO sort uuid in doc_matters! string content = format(q"¶ @@ -70,7 +72,7 @@ template outputEPub3() { - + ¶", @@ -91,16 +93,19 @@ template outputEPub3() { uuid, uuid, uuid, + (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), ); content ~= " " ~ "" ~ "\n "; content ~= parts["manifest_documents"]; // TODO sort jpg & png content ~= " " ~ "" ~ "\n "; foreach (image; doc_matters.image_list) { - content ~= format(q"¶ + content ~= format(q"¶ ¶", - image, // strip image type, remove .png .jpg suffix, use in media-type="image/" + image.baseName.stripExtension, + (pth_epub3.doc_oebps_image(doc_matters.source_filename)).chompPrefix("OEBPS/"), image, + image.extension.chompPrefix("."), ); } content ~= " " ~ "" ~ "\n "; @@ -208,9 +213,12 @@ template outputEPub3() { foreach_reverse (k; 0 .. 7) { switch (obj.dom_markedup[k]) { case DomTags.close : + // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags toc ~= ""; break; case DomTags.close_and_open : + // writeln(markup.indent_by_spaces_provided(k), ""); // --debug dom tags + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; toc ~= ""; toc ~= format(q"¶ @@ -224,6 +232,7 @@ template outputEPub3() { ); break; case DomTags.open : + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; toc ~= format(q"¶ @@ -375,7 +384,7 @@ template outputEPub3() { doc_epub3[segment_filename] ~= to!string(t[0]); doc_epub3_endnotes[segment_filename] ~= t[1]; break; - case "poem": + case "poem": // double check why both poem & verse break; case "verse": auto t = xhtml_format.verse_seg(obj, suffix); @@ -530,22 +539,29 @@ template outputEPub3() { static assert(is(typeof(oebps_toc_ncx) == string)); static assert(is(typeof(oebps_content_opf) == string)); } - mixin SiSUpaths; - auto pth_epub3 = Epub3paths(); + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_epub3 = SiSUpathsEPUB!()(src_path_info, lng); auto xhtml_format = outputXHTMLs(); /+ zip file +/ auto fn_epub = pth_epub3.epub_file(doc_matters.source_filename); auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); /+ zip archive member files +/ try { - if (!exists(pth_epub3.doc_meta_inf(doc_matters.source_filename))) { - pth_epub3.doc_meta_inf(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_epub3.base)) { + pth_epub3.base.mkdirRecurse; } - if (!exists(pth_epub3.doc_oebps_css(doc_matters.source_filename))) { - pth_epub3.doc_oebps_css(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_epub3.doc_oebps_image(doc_matters.source_filename))) { - pth_epub3.doc_oebps_image(doc_matters.source_filename).mkdirRecurse; + debug(epub_output) { + if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename))) { + pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename).mkdirRecurse; + } } { /+ OEBPS/[segments].xhtml (the document contents) +/ foreach (seg_filename; doc_matters.segnames) { @@ -630,7 +646,7 @@ template outputEPub3() { /+ create the zip file +/ createZipFile!()(fn_epub, zip.build()); } - { /+ TODO OEBPS/toc.ncx (navigation toc epub2) +/ + { /+ OEBPS/toc.ncx (navigation toc epub2) +/ debug(epub_output) { fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.source_filename); File(fn_dbg, "w").writeln(oebps_toc_ncx); @@ -647,7 +663,7 @@ template outputEPub3() { /+ create the zip file +/ createZipFile!()(fn_epub, zip.build()); } - { /+ TODO OEBPS/content.opf (doc manifest) +/ + { /+ OEBPS/content.opf (doc manifest) +/ debug(epub_output) { fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.source_filename); File(fn_dbg, "w").writeln(oebps_content_opf); @@ -666,19 +682,19 @@ template outputEPub3() { } { /+ OEBPS/_sisu/image (images) +/ foreach (image; doc_matters.image_list) { - if (exists("_sisu/image/"~ image)) { - ("_sisu/image/"~ image) - .copy((pth_epub3.doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image); + if (exists(doc_matters.src_path_info.image_root ~ "/" ~ image)) { + (doc_matters.src_path_info.image_root ~ "/" ~ image) + .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image); } } foreach (image; doc_matters.image_list) { debug(epub_images) { writeln( - "_sisu/image/", image, " -> ", - pth_epub3.doc_oebps_image(doc_matters.source_filename), "/", image + doc_matters.src_path_info.image_root, image, " -> ", + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename), "/", image ); } - auto fn_src = "_sisu/image/"~ image; + auto fn_src = doc_matters.src_path_info.image_root ~ image; auto fn_out = pth_epub3.doc_oebps_image(doc_matters.source_filename).to!string ~ "/" ~ image; if (exists(fn_src)) { { diff --git a/src/sdp/output_html.d b/src/sdp/output_html.d index 431b81c..d5b1a22 100644 --- a/src/sdp/output_html.d +++ b/src/sdp/output_html.d @@ -25,7 +25,8 @@ template outputHTML() { create_zip_file, defaults, output_rgx, - output_xhtmls; + output_xhtmls, + paths_output; mixin outputXHTMLs; void scroll(D,I)( @@ -167,18 +168,20 @@ template outputHTML() { } } doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; - scroll_write_output(doc_matters.source_filename, doc); + scroll_write_output(doc_matters, doc); } - void scroll_write_output(Fn,C)( - Fn fn_src, + void scroll_write_output(M,C)( + M doc_matters, C doc, ) { debug(asserts) { - static assert(is(typeof(fn_src) == string)); static assert(is(typeof(doc) == string[])); } - mixin SiSUpaths; - auto pth_html = HtmlPaths(); + string fn_src = doc_matters.source_filename; + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); try { if (!exists(pth_html.base)) { pth_html.base.mkdirRecurse; @@ -240,6 +243,7 @@ template outputHTML() { segment_filename = obj.segment_anchor_tag; doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); foreach (top_level_heading; top_level_headings) { + // writeln(top_level_heading); doc_html[segment_filename] ~= top_level_heading; } auto t = xhtml_format.heading_seg(obj, suffix); @@ -413,8 +417,10 @@ template outputHTML() { } mixin SiSUoutputRgxInit; auto rgx = Rgx(); - mixin SiSUpaths; - auto pth_html = HtmlPaths(); + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); auto xhtml_format = outputXHTMLs(); auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); try { diff --git a/src/sdp/output_hub.d b/src/sdp/output_hub.d index 9e4f971..c38b8e5 100644 --- a/src/sdp/output_hub.d +++ b/src/sdp/output_hub.d @@ -29,47 +29,55 @@ template outputHub() { source_sisupod, create_zip_file, output_rgx, - output_xhtmls; + output_xhtmls, + paths_output; void outputHub(D,I)(D doc_abstraction, I doc_matters) { mixin SiSUoutputRgxInit; auto rgx = Rgx(); if ((doc_matters.opt_action_bool["verbose"])) { writeln(doc_matters.keys_seq.seg); } - if (doc_matters.opt_action_bool["source"]) { - /+ mixin outputSource; +/ - writeln("source"); - } - if (doc_matters.opt_action_bool["sisupod"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("sisupod source processing... ");} + if ((doc_matters.opt_action_bool["source"]) + || (doc_matters.opt_action_bool["sisupod"])) { + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["source"])) + { write("sisu source processing... "); } + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["sisupod"])) + { write("sisupod source processing... "); } SiSUpod!()(doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("sisupod done");} + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["source"])) + { writeln("sisu source done"); } + if ((doc_matters.opt_action_bool["verbose"]) + && (doc_matters.opt_action_bool["sisupod"])) + { writeln("sisupod done"); } } if (doc_matters.opt_action_bool["text"]) { /+ mixin outputText; +/ writeln("text processing"); } if (doc_matters.opt_action_bool["html"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html scroll processing... ");} + if ((doc_matters.opt_action_bool["verbose"])) { write("html scroll processing... "); } outputHTML!().scroll(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html scroll done");} - if ((doc_matters.opt_action_bool["verbose"])) {write("html seg processing... ");} + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html scroll done"); } + if ((doc_matters.opt_action_bool["verbose"])) { write("html seg processing... "); } outputHTML!().seg(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html seg done");} + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html seg done"); } } else if (doc_matters.opt_action_bool["html_seg"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html seg processing... ");} + if ((doc_matters.opt_action_bool["verbose"])) { write("html seg processing... "); } outputHTML!().seg(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html seg done");} + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html seg done"); } } else if (doc_matters.opt_action_bool["html_scroll"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("html scroll processing... ");} + if ((doc_matters.opt_action_bool["verbose"])) { write("html scroll processing... "); } outputHTML!().scroll(doc_abstraction, doc_matters); - if ((doc_matters.opt_action_bool["verbose"])) {writeln("html scroll done");} + if ((doc_matters.opt_action_bool["verbose"])) { writeln("html scroll done"); } } if (doc_matters.opt_action_bool["epub"]) { - if ((doc_matters.opt_action_bool["verbose"])) {write("epub3 processing... ");} + if ((doc_matters.opt_action_bool["verbose"])) { write("epub3 processing... "); } outputEPub3!()(doc_abstraction, doc_matters); // epub.css_write; - if ((doc_matters.opt_action_bool["verbose"])) {writeln("epub3 done");} + if ((doc_matters.opt_action_bool["verbose"])) { writeln("epub3 done"); } } if (doc_matters.opt_action_bool["pdf"]) { /+ mixin outputPDF; +/ diff --git a/src/sdp/output_xhtmls.d b/src/sdp/output_xhtmls.d index 804b82f..b85123e 100644 --- a/src/sdp/output_xhtmls.d +++ b/src/sdp/output_xhtmls.d @@ -25,7 +25,8 @@ template outputXHTMLs() { create_zip_file, defaults, output_rgx, - output_xhtmls; + output_xhtmls, + paths_output; mixin SiSUoutputRgxInit; struct outputXHTMLs { auto rgx = Rgx(); @@ -146,7 +147,6 @@ template outputXHTMLs() { string o; o = format(q"¶ - ¶"); return o; @@ -204,7 +204,7 @@ template outputXHTMLs() { if (obj.inline_notes_reg) { _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - (" $1 ") + (" $1 ") ); } debug(markup_endnotes) { @@ -251,7 +251,7 @@ template outputXHTMLs() { } _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - (" $1 ") + (" $1 ") ); } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { debug(markup) { @@ -305,14 +305,19 @@ template outputXHTMLs() { string _txt, ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _horizontal_rule = "
"; + if (obj.heading_lev_markup == 0) { + _horizontal_rule = ""; + } string o; if (obj.obj_cite_number.empty) { - o = format(q"¶


+ o = format(q"¶%s
%s %s
¶", + _horizontal_rule, obj.heading_lev_markup, obj.is_a, tags, @@ -320,13 +325,14 @@ template outputXHTMLs() { obj.heading_lev_markup, ); } else { - o = format(q"¶


+ o = format(q"¶%s
%s %s
¶", + _horizontal_rule, obj.obj_cite_number, obj.obj_cite_number, obj.heading_lev_markup, @@ -541,25 +547,21 @@ template outputXHTMLs() { string o; if (obj.obj_cite_number.empty) { o = format(q"¶
-

- %s -

+

%s

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

- %s -

+

%s

¶", obj.obj_cite_number, obj.obj_cite_number, obj.is_a, obj.obj_cite_number, - _txt + _txt.stripRight ); } return o; @@ -600,9 +602,7 @@ template outputXHTMLs() { string o; if (obj.obj_cite_number.empty) { o = format(q"¶
-

- %s -

+

%s

¶", obj.is_a, _txt @@ -610,9 +610,7 @@ template outputXHTMLs() { } else { o = format(q"¶
-

- %s -

+

%s

¶", obj.obj_cite_number, obj.obj_cite_number, diff --git a/src/sdp/paths_output.d b/src/sdp/paths_output.d new file mode 100644 index 0000000..9c91384 --- /dev/null +++ b/src/sdp/paths_output.d @@ -0,0 +1,287 @@ +/++ + default settings ++/ +import std.array, + std.path, + std.regex, + std.stdio; +import ao_rgx; +template SiSUpathsSisupod() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + string base_dir = "sisupod"; + string suffix = ".zip"; + auto SiSUpathsSisupod()() { + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string sisupod_filename(string fn_src) { + return base_dir.chainPath(base_filename(fn_src) ~ suffix).array; + } + string base(string fn_src) { + return base_dir.chainPath(base_filename(fn_src)).array; + } + } + return _PathsStruct(); + } +} +template SiSUpathsSisupodZipped() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSisupodZipped(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + auto spod_pths = SiSUpathsSisupod!()(); // SiSUpodPaths(); + string base_filename(string fn_src) { + return spod_pths.base_filename(fn_src); + } + string sisupod_filename(string fn_src) { + return spod_pths.sisupod_filename(fn_src); + } + string base(string fn_src) { + return spod_pths.base(fn_src); + } + auto pod_root(string fn_src) { + return "sisudoc"; + } + auto text_root(string fn_src) { + return pod_root(fn_src).chainPath("text").array; + } + auto media_root(string fn_src) { + return pod_root(fn_src).chainPath("docmedia").array; + } + auto conf_root(string fn_src) { + return pod_root(fn_src).chainPath("conf").array; + } + auto doc(string fn_src) { + return text_root(fn_src); // or pod_root? + } + auto doc_lng(string fn_src) { + return text_root(fn_src).chainPath(lng).array; + } + auto image_root(string fn_src) { + return media_root(fn_src).chainPath("image").array; + } + auto css(string fn_src) { + return conf_root(fn_src).chainPath("css").array; + } + auto fn_doc(string fn_src) { + return (doc_lng(fn_src)).chainPath(fn_src.baseName).array; + } + auto fn_doc_insert(string fn_src, string fn_insert) { + return (doc_lng(fn_src)).chainPath(fn_insert.baseName).array; + } + } + return _PathsStruct(); + } +} +template SiSUpathsSisupodFileSystem() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSisupodFileSystem(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + auto spod_pths = SiSUpathsSisupod!()(); // SiSUpodPaths(); + string base_filename(string fn_src) { + return spod_pths.base_filename(fn_src); + } + string sisupod_filename(string fn_src) { + return spod_pths.sisupod_filename(fn_src); + } + string base(string fn_src) { + return spod_pths.base(fn_src); + } + auto pod_root(string fn_src) { + return base(fn_src).chainPath("sisudoc").array; + } + auto text_root(string fn_src) { + return pod_root(fn_src).chainPath("text").array; + } + auto media_root(string fn_src) { + return pod_root(fn_src).chainPath("docmedia").array; + } + auto conf_root(string fn_src) { + return pod_root(fn_src).chainPath("conf").array; + } + auto doc(string fn_src) { + return pod_root(fn_src); + } + auto doc_lng(string fn_src) { + return text_root(fn_src).chainPath(lng).array; + } + auto image_root(string fn_src) { + return media_root(fn_src).chainPath("image").array; + } + auto css(string fn_src) { + return conf_root(fn_src).chainPath("css").array; + } + auto fn_doc(string fn_src) { + return (doc_lng(fn_src)).chainPath(fn_src.baseName).array; + } + auto fn_doc_insert(string fn_src, string fn_insert) { + return (doc_lng(fn_src)).chainPath(fn_insert.baseName).array; + } + } + return _PathsStruct(); + } +} +template SiSUoutPaths() { + auto SiSUoutPaths(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + struct _PathsStruct { + string output_root() { + return "sisugen"; + } + string output_base() { + return output_root.chainPath(lng).array; + } + } + return _PathsStruct(); + } +} +template SiSUpathsHTML() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsHTML(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + auto out_pth = SiSUoutPaths!()(src_pth_info, lng); + string base_dir = "html"; + string suffix = ".html"; + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string base() { + return (out_pth.output_base).chainPath(base_dir).array; + } + string image() { + return (out_pth.output_root).chainPath("image").array; + } + string css() { + return (out_pth.output_root).chainPath("css").array; + } + string fn_css() { + return css.chainPath("html.css").array; + } + string seg(string fn_src) { + return base.chainPath(base_filename(fn_src)).array; + } + string fn_scroll(string fn_src) { + return base.chainPath(base_filename(fn_src) ~ suffix).array; + } + string fn_seg(string fn_src, string seg_filename) { + return seg(fn_src).chainPath(seg_filename ~ suffix).array; + } + } + return _PathsStruct(); + } +} +template SiSUpathsEPUB() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsEPUB(Ps,Lng)( + Ps src_pth_info, + Lng lng, + ) { + auto out_pth = SiSUoutPaths!()(src_pth_info, lng); + string base_dir = "epub"; + struct _PathsStruct { + string base() { + return (out_pth.output_base).chainPath(base_dir).array; + } + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string epub_file(string fn_src) { + return base.chainPath(base_filename(fn_src) ~ ".epub").array; + } + string dirtop() { + return "".chainPath("").array; + } + string doc_meta_inf(string fn_src) { + return dirtop.chainPath("META-INF").array; + } + string doc_oebps(string fn_src) { + return dirtop.chainPath("OEBPS").array; + } + string doc_oebps_css(string fn_src) { + return doc_oebps(fn_src).chainPath("css").array; + } + string doc_oebps_image(string fn_src) { + return doc_oebps(fn_src).chainPath("image").array; + } + string fn_mimetypes(string fn_src) { + return dirtop.chainPath("mimetypes").array; + } + string fn_dmi_container_xml(string fn_src) { + return doc_meta_inf(fn_src).chainPath("container.xml").array; + } + string fn_oebps_toc_nav_xhtml(string fn_src) { + return doc_oebps(fn_src).chainPath("toc_nav.xhtml").array; + } + string fn_oebps_toc_ncx(string fn_src) { + return doc_oebps(fn_src).chainPath("toc.ncx").array; + } + string fn_oebps_content_opf(string fn_src) { + return doc_oebps(fn_src).chainPath("content.opf").array; + } + string fn_oebps_content_xhtml(string fn_src, string seg_filename) { + return doc_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; + } + string fn_oebps_css(string fn_src) { + return doc_oebps_css(fn_src).chainPath("epub.css").array; + } + debug(epub_output) { + string dbg_docdir(string fn_src) { + return base.chainPath(base_filename(fn_src)).array; + } + string dbg_docdir_oebps(string fn_src) { + return dbg_docdir(fn_src).chainPath("OEBPS").array; + } + string dbg_doc_meta_inf(string fn_src) { + return dbg_docdir(fn_src).chainPath("META-INF").array; + } + string dbg_doc_oebps(string fn_src) { + return dbg_docdir(fn_src).chainPath("OEBPS").array; + } + string dbg_doc_oebps_css(string fn_src) { + return dbg_doc_oebps(fn_src).chainPath("css").array; + } + string dbg_doc_oebps_image(string fn_src) { + return dbg_doc_oebps(fn_src).chainPath("image").array; + } + string dbg_fn_mimetypes(string fn_src) { + return dbg_docdir(fn_src).chainPath("mimetypes").array; + } + string dbg_fn_dmi_container_xml(string fn_src) { + return dbg_doc_meta_inf(fn_src).chainPath("container.xml").array; + } + string dbg_fn_oebps_toc_nav_xhtml(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("toc_nav.xhtml").array; + } + string dbg_fn_oebps_toc_ncx(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("toc.ncx").array; + } + string dbg_fn_oebps_content_opf(string fn_src) { + return dbg_docdir_oebps(fn_src).chainPath("content.opf").array; + } + string dbg_fn_oebps_content_xhtml(string fn_src, string seg_filename) { + return dbg_docdir_oebps(fn_src).chainPath(seg_filename ~ ".xhtml").array; + } + string dbg_fn_oebps_css(string fn_src) { + return dbg_doc_oebps_css(fn_src).chainPath("epub.css").array; + } + } + } + return _PathsStruct(); + } +} diff --git a/src/sdp/paths_source.d b/src/sdp/paths_source.d new file mode 100644 index 0000000..f60949d --- /dev/null +++ b/src/sdp/paths_source.d @@ -0,0 +1,59 @@ +/++ + read configuration files
+ - read config files
+ ao_config_files.d ++/ +import std.array, + std.path, + std.regex, + std.stdio; +import ao_rgx; +template SiSUpathsSRC() { + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto SiSUpathsSRC(D,Fn)( + D _pwd, + Fn _fn_src, + ) { + struct SisuSrcPaths { + auto pwd() { + return _pwd; + } + auto language() { + // use command line info as well? + string _k; + if (auto m = _fn_src.match(rgx.language_code_and_filename)) { + _k = m.captures[1]; + } else { + _k = "en"; + } + return _k; + } + auto doc_root() { + return "sisudoc"; + } + auto text_root() { + return doc_root.chainPath("text").array; + } + auto media_root() { + return doc_root.chainPath("docmedia").array; + } + auto conf_root() { + return doc_root.chainPath("conf").array; + } + auto image_root() { + return media_root.chainPath("image").array; + } + auto doc_src_fn_with_path_for_text_root_and_lng() { + return text_root.chainPath(language).array; + } + auto doc_src_with_relative_path() { + return pwd.chainPath(_fn_src).array; + } + auto doc_src_fn() { + return _fn_src.baseName.array; + } + } + return SisuSrcPaths(); + } +} diff --git a/src/sdp/source_sisupod.d b/src/sdp/source_sisupod.d index cf15348..9b48ddb 100644 --- a/src/sdp/source_sisupod.d +++ b/src/sdp/source_sisupod.d @@ -25,60 +25,70 @@ template SiSUpod() { create_zip_file, defaults, output_rgx, - output_xhtmls; + output_xhtmls, + paths_output; void SiSUpod(T)(T doc_matters) { debug(asserts) { // static assert(is(typeof(doc_matters) == tuple)); } mixin SiSUoutputRgxInit; - mixin SiSUpaths; - auto pth_sisupod = SiSUpodPathsZipped(); - auto pth_sisupod_filesystem = SiSUpodPathsFilesystemArchive(); + string pwd = doc_matters.environment["pwd"]; + auto src_path_info = doc_matters.src_path_info; + string lng = doc_matters.language; + auto pth_sisudoc_src = doc_matters.src_path_info; + auto pth_sisupod = SiSUpathsSisupodZipped!()(src_path_info, lng); + auto pth_sisupod_filesystem = SiSUpathsSisupodFileSystem!()(src_path_info, lng); mixin SiSUlanguageCodes; auto lang = Lang(); auto rgx = Rgx(); assert (doc_matters.source_filename.match(rgx.src_fn)); try { /+ create directory structure +/ - if (!exists(pth_sisupod_filesystem.doc(doc_matters.source_filename))) { - pth_sisupod_filesystem.doc(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_sisupod_filesystem.conf(doc_matters.source_filename))) { - pth_sisupod_filesystem.conf(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { - pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_sisupod_filesystem.image(doc_matters.source_filename))) { - pth_sisupod_filesystem.image(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language))) { - pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse; + if (doc_matters.opt_action_bool["source"]) { + if (!exists(pth_sisupod_filesystem.text_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.text_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.conf_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.conf_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.media_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.media_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { + pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.image_root(doc_matters.source_filename))) { + pth_sisupod_filesystem.image_root(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename))) { + pth_sisupod_filesystem.doc_lng(doc_matters.source_filename).mkdirRecurse; + } } debug(sisupod) { writeln(__LINE__, ": ", doc_matters.source_filename, " -> ", pth_sisupod_filesystem.fn_doc( doc_matters.source_filename, - doc_matters.language )); } - auto zip = new ZipArchive(); + auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); auto fn_sisupod = pth_sisupod.sisupod_filename(doc_matters.source_filename); { /+ bundle images +/ foreach (image; doc_matters.image_list) { debug(sisupodimages) { writeln( - "_sisu/image/", image, " -> ", - pth_sisupod.image(doc_matters.source_filename), "/", image + pth_sisudoc_src.image_root.to!string, "/", image, " -> ", + pth_sisupod.image_root(doc_matters.source_filename), "/", image ); } - auto fn_src = "_sisu/image/"~ image; - auto fn_out = pth_sisupod.image(doc_matters.source_filename).to!string ~ "/" ~ image; - auto fn_out_filesystem = pth_sisupod_filesystem.image(doc_matters.source_filename).to!string ~ "/" ~ image; + auto fn_src = pth_sisudoc_src.image_root.to!string ~ "/" ~ image; + auto fn_out = pth_sisupod.image_root(doc_matters.source_filename).to!string ~ "/" ~ image; + auto fn_out_filesystem = pth_sisupod_filesystem.image_root(doc_matters.source_filename).to!string ~ "/" ~ image; if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); @@ -91,12 +101,14 @@ template SiSUpod() { } } { /+ bundle sisu_document_make +/ - auto fn_src = "_sisu/sisu_document_make"; // check (_sisu/sisu_document_make) - auto fn_out = pth_sisupod.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; - auto fn_out_filesystem = pth_sisupod_filesystem.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + auto fn_src = pth_sisudoc_src.conf_root.to!string ~ "/" ~ "sisu_document_make"; // check (_sisu/sisu_document_make) + auto fn_out = pth_sisupod.conf_root(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + auto fn_out_filesystem = pth_sisupod_filesystem.conf_root(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); @@ -109,11 +121,13 @@ template SiSUpod() { } { /+ bundle primary file +/ auto fn_src = doc_matters.source_filename; - auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; - auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; + auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename).to!string; + auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename).to!string; if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); @@ -133,23 +147,22 @@ template SiSUpod() { pth_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, - doc_matters.language )); } auto fn_src = insert_file; auto fn_out = pth_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, - doc_matters.language ).to!string; auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc_insert( doc_matters.source_filename, insert_file, - doc_matters.language ).to!string; if (exists(fn_src)) { - fn_src.copy(fn_out_filesystem); - { + if (doc_matters.opt_action_bool["source"]) { + fn_src.copy(fn_out_filesystem); + } + if (doc_matters.opt_action_bool["sisupod"]) { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = insert_file; auto zip_data = new OutBuffer(); @@ -178,20 +191,20 @@ template SiSUpod() { catch (ZipException ex) { // Handle errors } - if (doc_matters.source_filename == "en/the_wealth_of_networks.yochai_benkler.sst") { + if (doc_matters.source_filename == "sisudoc/text/en/the_wealth_of_networks.yochai_benkler.sst") { assert( ((data).sha256Of).toHexString - == "DDE0013C13C6A4F06D4BE72087E2CDEF47697CA38A6A2D65BA7207DB6B144271", + == "626F83A31ED82F42CF528E922C1643498A137ABA3F2E5AFF8A379EA79EA22A1E", "\nsisupod: sha256 value for " ~ doc_matters.source_filename ~ " has changed, is now: " ~ ((data).sha256Of).toHexString ); } - if (doc_matters.source_filename == "en/sisu_markup_stress_test.sst") { + if (doc_matters.source_filename == "sisudoc/text/en/sisu_markup_stress_test.sst") { assert( ((data).sha256Of).toHexString - == "112C0AEDD2518A1803D91A7CF5785274A3116C0779A631782D0C0813B212C68A", + == "AAE0C87AB3F6D5F7385AEEA6EE661F56D40475CFE87AD930C78C9FE07FFB0D91", "\nsisupod: sha256 value for " ~ doc_matters.source_filename ~ " has changed, is now: " diff --git a/views/version.txt b/views/version.txt index fe2ce85..2750f99 100644 --- a/views/version.txt +++ b/views/version.txt @@ -4,4 +4,4 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 13, 9); +enum ver = Version(0, 14, 0); -- cgit v1.2.3