diff options
-rw-r--r-- | org/ao_doc_abstraction.org | 40 | ||||
-rw-r--r-- | org/default_misc.org | 777 | ||||
-rw-r--r-- | org/default_paths.org | 436 | ||||
-rw-r--r-- | org/default_regex.org | 475 | ||||
-rw-r--r-- | org/defaults.org | 1471 | ||||
-rw-r--r-- | org/output_hub.org | 185 | ||||
-rw-r--r-- | org/output_sisupod.org | 280 | ||||
-rw-r--r-- | org/output_xmls.org (renamed from org/output.org) | 616 | ||||
-rw-r--r-- | org/output_zip.org | 36 | ||||
-rw-r--r-- | org/sdp.org | 24 | ||||
-rwxr-xr-x | src/sdp.d | 3 | ||||
-rw-r--r-- | src/sdp/abstraction.d | 8 | ||||
-rw-r--r-- | src/sdp/ao_abstract_doc_source.d | 40 | ||||
-rw-r--r-- | src/sdp/ao_defaults.d | 7 | ||||
-rw-r--r-- | src/sdp/ao_rgx.d | 8 | ||||
-rw-r--r-- | src/sdp/defaults.d | 186 | ||||
-rw-r--r-- | src/sdp/output_epub3.d | 60 | ||||
-rw-r--r-- | src/sdp/output_html.d | 24 | ||||
-rw-r--r-- | src/sdp/output_hub.d | 44 | ||||
-rw-r--r-- | src/sdp/output_xhtmls.d | 38 | ||||
-rw-r--r-- | src/sdp/paths_output.d | 287 | ||||
-rw-r--r-- | src/sdp/paths_source.d | 59 | ||||
-rw-r--r-- | src/sdp/source_sisupod.d | 103 | ||||
-rw-r--r-- | views/version.txt | 2 |
24 files changed, 2916 insertions, 2293 deletions
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() { <<abs_functions_block_code>> <<abs_functions_block_table>> <<abs_functions_block_biblio>> - // <<abs_functions_block_glossary>> <<abs_functions_block_line_status_empty>> <<abs_functions_book_index>> <<abs_functions_heading>> @@ -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() { + <<ao_defaults_imports>> + <<ao_defaults_template_registers>> +} +<<ao_defaults_template_init_flags>> +<<ao_defaults_template_node>> +<<ao_defaults_template_biblio>> +<<defaults_template_markup>> +<<defaults_template_language_codes>> +#+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 ++/ +<<defaults_template_init_flags>> +<<defaults_template_markup>> +<<defaults_template_language_codes>> +#+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<BR> + - read config files<BR> + 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; +<<template_paths_sisupod>> +<<template_paths_sisupod_zipped_archive>> +<<template_paths_sisupod_unzipped_filesystem>> +<<template_paths_out>> +<<template_paths_html>> +<<template_paths_epub>> +#+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 { + <<ao_rgx>> + <<prgmkup_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<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)"); +static book_index_go_scroll = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)"); +static book_index_go_seg = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?):(?P<seg>[a-z0-9_-]+)"); +static book_index_go_seg_ = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)(:(?P<seg>[a-z0-9_-]+))?"); +static book_index_go_seg_anchorless = ctRegex!("(?P<link>(?P<ocn>[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<header>[a-z_]+):\s*(?P<content>.*)`, "m"); +static native_header_sub = ctRegex!(`^[ ]*:(?P<subheader>[a-z_]+):\s+(?P<content>.+)`, "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<columns>(?:[ ]+[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<columns>(?:[ ]+[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!(`(?P<c_heading>h)?(?:[ ]+c(?P<c_num>[0-9]);)?(?P<c_widths>(?:[ ]+[0-9]+[lr]?;)+)`); +static table_col_widths_and_alignment = ctRegex!(`(?P<width>[0-9]+)(?P<align>[lr]?)`); +static table_col_widths = ctRegex!(`(?P<widths>[0-9]+)`); +static table_col_align = ctRegex!(`(?P<align>[lr]?)`); +static table_col_align_match = ctRegex!(`(?P<align>[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<text>.+?)(?:(?:[~])[{][*+ ]*)(?P<note>.+?)(?:[}][~])`, "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<before>^|[ ])(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!'"]?(?:[ ]|$))`, "mg"); +static inline_link_markup_regular = ctRegex!(`(?P<before>^|[ ])\{\s*(?P<content>.+?)\s*\}(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!]?(?:[ ]|$))`, "mg"); +static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P<content>.+?)\}(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!]?(?:[ ]|$))`, "mg"); +static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P<content>.+?)\}(?P<link>(?:(?: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 { + <<prgmkup_rgx>> + <<sp_ch_xhtml_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}`); // <br /> +#+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!("^<br>\n|<br>\n*$"); +static space = ctRegex!(`[ ]`, "mg"); +static spaces_line_start = ctRegex!(`^(?P<opening_spaces>[ ]+)`, "mg"); +static spaces_multiple = ctRegex!(`(?P<multiple_spaces>[ ]{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<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])$`); +static src_fn = + ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P<fn_src>(?P<fn_base>[a-zA-Z0-9._-]+)[.](?P<fn_src_suffix>ss[tm]))$`); +static src_fn_master = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssm)$`); +static src_fn_text = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]sst)$`); +static src_fn_insert = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssi)$`); +static src_fn_find_inserts = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[im])$`); +static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[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<text>.+?)【(?:[*+ ]*)(?P<note>.+?)】`, "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<markup>(?P<mod>[*!_^,+#-])\{(?P<text>.+?)\}[*!_^,+#-])`, "mg"); +static inline_emphasis = ctRegex!(`\*\{(?P<text>.+?)\}\*`, "mg"); +static inline_bold = ctRegex!(`!\{(?P<text>.+?)\}!`, "mg"); +static inline_underscore = ctRegex!(`_\{(?P<text>.+?)\}_`, "mg"); +static inline_italics = ctRegex!(`/\{(?P<text>.+?)\}/`, "mg"); +static inline_superscript = ctRegex!(`\^\{(?P<text>.+?)\}\^`, "mg"); +static inline_subscript = ctRegex!(`,\{(?P<text>.+?)\},`, "mg"); +static inline_strike = ctRegex!(`-\{(?P<text>.+?)\}-`, "mg"); +static inline_insert = ctRegex!(`\+\{(?P<text>.+?)\}\+`, "mg"); +static inline_mono = ctRegex!(`#\{(?P<text>.+?)\}#`, "mg"); +static inline_cite = ctRegex!(`"\{(?P<text>.+?)\}"`, "mg"); +static inline_faces_line = ctRegex!(`^[*!/_]_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_emphasis_line = ctRegex!(`^\*_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_bold_line = ctRegex!(`^!_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_italics_line = ctRegex!(`^/_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); +static inline_underscore_line = ctRegex!(`^__ (?P<text>.+?)((?: [\\]{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() { - <<ao_defaults_imports>> - <<ao_defaults_template_registers>> -} -<<ao_defaults_template_init_flags>> -<<ao_defaults_template_node>> -<<ao_defaults_template_biblio>> -<<defaults_template_markup>> -<<defaults_template_language_codes>> -#+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 { - <<ao_rgx>> - <<prgmkup_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<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)"); -static book_index_go_scroll = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)"); -static book_index_go_seg = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?):(?P<seg>[a-z0-9_-]+)"); -static book_index_go_seg_ = ctRegex!("(?P<link>(?P<ocn>[0-9]+)(?:-[0-9]+)?)(:(?P<seg>[a-z0-9_-]+))?"); -static book_index_go_seg_anchorless = ctRegex!("(?P<link>(?P<ocn>[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<header>[a-z_]+):\s*(?P<content>.*)`, "m"); -static native_header_sub = ctRegex!(`^[ ]*:(?P<subheader>[a-z_]+):\s+(?P<content>.+)`, "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<columns>(?:[ ]+[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<columns>(?:[ ]+[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!(`(?P<c_heading>h)?(?:[ ]+c(?P<c_num>[0-9]);)?(?P<c_widths>(?:[ ]+[0-9]+[lr]?;)+)`); -static table_col_widths_and_alignment = ctRegex!(`(?P<width>[0-9]+)(?P<align>[lr]?)`); -static table_col_widths = ctRegex!(`(?P<widths>[0-9]+)`); -static table_col_align = ctRegex!(`(?P<align>[lr]?)`); -static table_col_align_match = ctRegex!(`(?P<align>[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<text>.+?)(?:(?:[~])[{][*+ ]*)(?P<note>.+?)(?:[}][~])`, "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<before>^|[ ])(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!'"]?(?:[ ]|$))`, "mg"); -static inline_link_markup_regular = ctRegex!(`(?P<before>^|[ ])\{\s*(?P<content>.+?)\s*\}(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!]?(?:[ ]|$))`, "mg"); -static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P<content>.+?)\}(?P<link>(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P<after>[.,;:?!]?(?:[ ]|$))`, "mg"); -static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P<content>.+?)\}(?P<link>(?:(?: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 -+/ -<<defaults_template_init_flags>> -<<defaults_template_paths>> -<<defaults_template_markup>> -<<defaults_template_language_codes>> -#+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 { - <<prgmkup_rgx>> - <<sp_ch_xhtml_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}`); // <br /> -#+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!("^<br>\n|<br>\n*$"); -static space = ctRegex!(`[ ]`, "mg"); -static spaces_line_start = ctRegex!(`^(?P<opening_spaces>[ ]+)`, "mg"); -static spaces_multiple = ctRegex!(`(?P<multiple_spaces>[ ]{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<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])$`); -static src_fn = - ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P<fn_src>(?P<fn_base>[a-zA-Z0-9._-]+)[.](?P<fn_src_suffix>ss[tm]))$`); -static src_fn_master = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssm)$`); -static src_fn_text = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]sst)$`); -static src_fn_insert = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssi)$`); -static src_fn_find_inserts = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[im])$`); -static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[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<text>.+?)【(?:[*+ ]*)(?P<note>.+?)】`, "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<markup>(?P<mod>[*!_^,+#-])\{(?P<text>.+?)\}[*!_^,+#-])`, "mg"); -static inline_emphasis = ctRegex!(`\*\{(?P<text>.+?)\}\*`, "mg"); -static inline_bold = ctRegex!(`!\{(?P<text>.+?)\}!`, "mg"); -static inline_underscore = ctRegex!(`_\{(?P<text>.+?)\}_`, "mg"); -static inline_italics = ctRegex!(`/\{(?P<text>.+?)\}/`, "mg"); -static inline_superscript = ctRegex!(`\^\{(?P<text>.+?)\}\^`, "mg"); -static inline_subscript = ctRegex!(`,\{(?P<text>.+?)\},`, "mg"); -static inline_strike = ctRegex!(`-\{(?P<text>.+?)\}-`, "mg"); -static inline_insert = ctRegex!(`\+\{(?P<text>.+?)\}\+`, "mg"); -static inline_mono = ctRegex!(`#\{(?P<text>.+?)\}#`, "mg"); -static inline_cite = ctRegex!(`"\{(?P<text>.+?)\}"`, "mg"); -static inline_faces_line = ctRegex!(`^[*!/_]_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_emphasis_line = ctRegex!(`^\*_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_bold_line = ctRegex!(`^!_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_italics_line = ctRegex!(`^/_ (?P<text>.+?)((?: [\\]{2}|[~]#){0,2}$)`); -static inline_underscore_line = ctRegex!(`^__ (?P<text>.+?)((?: [\\]{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_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<BR> + check & generate output types requested ++/ +template outputHub() { + <<output_imports>> + void outputHub(D,I)(D doc_abstraction, I doc_matters) { + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + <<output_options>> + } +} +#+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() { + <<output_imports>> + void SiSUpod(T)(T doc_matters) { + <<source_sisupod_init>> + try { + <<source_sisupod_mkdirs>> + <<source_sisupod_copy>> + <<source_sisupod_zip>> + } + 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.org b/org/output_xmls.org index e0a7985..2812421 100644 --- a/org/output.org +++ b/org/output_xmls.org @@ -1,4 +1,4 @@ -#+TITLE: sdp output html +#+TITLE: sdp output xmls #+AUTHOR: Ralph Amissah #+EMAIL: ralph.amissah@gmail.com #+STARTUP: indent @@ -13,104 +13,24 @@ #+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<br> - 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; +[[./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() { + <<output_imports>> + mixin SiSUoutputRgxInit; + struct outputXHTMLs { 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"); - } + <<xhtml_format_objects>> +<<xhtml_format_objects_code>> } } #+END_SRC -* 1. output functions :output: -** output imports +*** output imports #+name: output_imports #+BEGIN_SRC d @@ -140,269 +60,12 @@ 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() { - <<output_imports>> - void SiSUpod(T)(T doc_matters) { - <<source_sisupod_init>> - try { - <<source_sisupod_mkdirs>> - <<source_sisupod_copy>> - <<source_sisupod_zip>> - } - 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()); - } - } - } - } -} + output_xhtmls, + paths_output; #+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() { - <<output_imports>> - mixin SiSUoutputRgxInit; - struct outputXHTMLs { - auto rgx = Rgx(); - <<xhtml_format_objects>> -<<xhtml_format_objects_code>> - } -} -#+END_SRC - -**** misc -***** special characters +*** misc +**** special characters #+name: xhtml_format_objects #+BEGIN_SRC d @@ -416,7 +79,7 @@ string special_characters(string _txt){ } #+END_SRC -***** font_face +**** font_face #+name: xhtml_format_objects #+BEGIN_SRC d @@ -436,7 +99,7 @@ string font_face(string _txt){ } #+END_SRC -***** anchor tags +**** anchor tags #+name: xhtml_format_objects #+BEGIN_SRC d @@ -453,8 +116,8 @@ string _xhtml_anchor_tags(const(string[]) anchor_tags) { } #+END_SRC -***** doc head & tails -****** scroll head +**** doc head & tails +***** scroll head #+name: xhtml_format_objects #+BEGIN_SRC d @@ -500,7 +163,7 @@ dochead_meta["title"]["full"], } #+END_SRC -****** seg head +***** seg head #+name: xhtml_format_objects #+BEGIN_SRC d @@ -546,7 +209,7 @@ dochead_meta["title"]["full"], } #+END_SRC -****** xhtml tail +***** xhtml tail #+name: xhtml_format_objects #+BEGIN_SRC d @@ -554,15 +217,14 @@ auto tail() { string o; o = format(q"¶ <a name="bottom" id="bottom"></a> <a name="end" id="end"></a> -</div> </body> </html>¶"); return o; } #+END_SRC -**** inline markup -***** links +*** inline markup +**** links #+name: xhtml_format_objects #+BEGIN_SRC d @@ -614,7 +276,7 @@ auto inline_links(O)( } #+END_SRC -***** notes scroll +**** notes scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -625,7 +287,7 @@ auto inline_notes_scroll(O)( if (obj.inline_notes_reg) { _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") ); } debug(markup_endnotes) { @@ -649,7 +311,7 @@ auto inline_notes_scroll(O)( } #+END_SRC -***** notes seg +**** notes seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -678,7 +340,7 @@ auto inline_notes_seg(O)( } _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") ); } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { debug(markup) { @@ -693,7 +355,7 @@ auto inline_notes_seg(O)( } #+END_SRC -***** inline markup scroll +**** inline markup scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -709,7 +371,7 @@ auto inline_markup_scroll(O)( } #+END_SRC -***** inline markup seg +**** inline markup seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -725,7 +387,7 @@ auto inline_markup_seg(O)( } #+END_SRC -**** toc +*** toc #+name: xhtml_format_objects #+BEGIN_SRC d @@ -747,8 +409,8 @@ auto toc(O)( } #+END_SRC +*** heading **** heading -***** heading #+name: xhtml_format_objects #+BEGIN_SRC d @@ -757,14 +419,19 @@ auto heading(O)( string _txt, ) { auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _horizontal_rule = "<hr />"; + if (obj.heading_lev_markup == 0) { + _horizontal_rule = ""; + } string o; if (obj.obj_cite_number.empty) { - o = format(q"¶<br /><hr /><br /> + o = format(q"¶%s <div class="substance"> <h%s class="%s">%s %s </h%s> </div>¶", + _horizontal_rule, obj.heading_lev_markup, obj.is_a, tags, @@ -772,13 +439,14 @@ auto heading(O)( obj.heading_lev_markup, ); } else { - o = format(q"¶<br /><hr /><br /> + o = format(q"¶%s <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> <h%s class="%s" id="%s"><a name="%s"></a>%s %s </h%s> </div>¶", + _horizontal_rule, obj.obj_cite_number, obj.obj_cite_number, obj.heading_lev_markup, @@ -794,7 +462,7 @@ auto heading(O)( } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -809,7 +477,7 @@ auto heading_scroll(O)( } #+END_SRC -***** seg +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -829,8 +497,8 @@ auto heading_seg(O)( } #+END_SRC +*** para **** para -***** para #+name: xhtml_format_objects #+BEGIN_SRC d @@ -875,7 +543,7 @@ auto para(O)( } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -890,7 +558,7 @@ auto para_scroll(O)( } #+END_SRC -***** seg +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -910,10 +578,9 @@ auto para_seg(O)( } #+END_SRC +*** quote **** quote -***** quote - #+name: xhtml_format_objects #+BEGIN_SRC d auto quote(O)( @@ -949,7 +616,7 @@ auto quote(O)( } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -963,7 +630,8 @@ auto quote_scroll(O)( return o; } #+END_SRC -***** seg + +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -983,10 +651,9 @@ auto quote_seg(O)( } #+END_SRC +*** group **** group -***** group - #+name: xhtml_format_objects #+BEGIN_SRC d auto group(O)( @@ -1022,7 +689,7 @@ auto group(O)( } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1036,7 +703,8 @@ auto group_scroll(O)( return o; } #+END_SRC -***** seg + +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1056,10 +724,9 @@ auto group_seg(O)( } #+END_SRC +*** block **** block -***** block - #+name: xhtml_format_objects #+BEGIN_SRC d auto block(O)( @@ -1070,32 +737,28 @@ auto block(O)( string o; if (obj.obj_cite_number.empty) { o = format(q"¶ <div class="substance"> - <p class="%s"> - %s - </p> + <p class="%s">%s</p> </div>¶", obj.is_a, - _txt + _txt.stripRight ); } else { o = format(q"¶ <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <p class="%s" id="%s"> - %s - </p> + <p class="%s" id="%s">%s</p> </div>¶", obj.obj_cite_number, obj.obj_cite_number, obj.is_a, obj.obj_cite_number, - _txt + _txt.stripRight ); } return o; } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1109,7 +772,8 @@ auto block_scroll(O)( return o; } #+END_SRC -***** seg + +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1129,8 +793,8 @@ auto block_seg(O)( } #+END_SRC -**** poem verse -***** verse +*** poem verse +**** verse #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1147,9 +811,7 @@ auto verse(O)( // using code from code block, review string o; if (obj.obj_cite_number.empty) { o = format(q"¶ <div class="substance"> - <p class="%s"> -%s - </p> + <p class="%s">%s</p> </div>¶", obj.is_a, _txt @@ -1157,9 +819,7 @@ auto verse(O)( // using code from code block, review } else { o = format(q"¶ <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <p class="%s" id="%s"> -%s - </p> + <p class="%s" id="%s">%s</p> </div>¶", obj.obj_cite_number, obj.obj_cite_number, @@ -1172,7 +832,7 @@ auto verse(O)( // using code from code block, review } #+END_SRC -***** scroll +**** scroll #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1187,7 +847,7 @@ auto verse_scroll(O)( } #+END_SRC -***** seg +**** seg #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1207,7 +867,7 @@ auto verse_seg(O)( } #+END_SRC -**** code +*** code #+name: xhtml_format_objects_code #+BEGIN_SRC d @@ -1246,9 +906,8 @@ auto verse_seg(O)( } #+END_SRC -**** table - -***** TODO tablarize +*** table +**** TODO tablarize align="left|right|center" <td align="right">$100</td> @@ -1295,7 +954,7 @@ auto tablarize(O)( } #+END_SRC -***** table +**** table #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1330,7 +989,7 @@ auto table(O)( } #+END_SRC -**** endnote +*** endnote #+name: xhtml_format_objects #+BEGIN_SRC d @@ -1350,8 +1009,8 @@ auto endnote(O)( } #+END_SRC -*** _html_ [#A] :html: -**** template :template: +** _html_ [#A] :html: +*** template :template: #+BEGIN_SRC d :tangle ../src/sdp/output_html.d template outputHTML() { @@ -1364,8 +1023,8 @@ template outputHTML() { } #+END_SRC -**** scroll :scroll: -***** switch (sections & objects) format html output +*** scroll :scroll: +**** switch (sections & objects) format html output #+name: output_html_scroll #+BEGIN_SRC d @@ -1508,24 +1167,26 @@ void scroll(D,I)( } } 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); } #+END_SRC -***** write output file +**** write output file #+name: output_html_scroll #+BEGIN_SRC d -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; @@ -1541,8 +1202,8 @@ void scroll_write_output(Fn,C)( } #+END_SRC -**** seg :seg: -***** switch (sections & objects) format html output +*** seg :seg: +**** switch (sections & objects) format html output #+name: output_html_seg #+BEGIN_SRC d @@ -1594,6 +1255,7 @@ void seg(D,I)( 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); @@ -1759,7 +1421,7 @@ void seg(D,I)( } #+END_SRC -***** write output files +**** write output files #+name: output_html_seg #+BEGIN_SRC d @@ -1773,8 +1435,10 @@ void seg_write_output(M,D,E)( } 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 { @@ -1798,7 +1462,7 @@ void seg_write_output(M,D,E)( } #+END_SRC -**** css :css: +*** css :css: #+name: output_html_css #+BEGIN_SRC d @@ -2654,7 +2318,7 @@ auto css_write() { } #+END_SRC -*** _epub_ [#B] :epub: +** _epub_ [#B] :epub: |-----------------------+--------------------------+---------------------------+----------------------------------| | function | filename | module | variable | @@ -2672,7 +2336,7 @@ auto css_write() { | | | | doc_epub3_endnotes[seg_filename] | |-----------------------+--------------------------+---------------------------+----------------------------------| -**** template :template: +*** template :template: #+BEGIN_SRC d :tangle ../src/sdp/output_epub3.d template outputEPub3() { @@ -2687,9 +2351,9 @@ template outputEPub3() { } #+END_SRC -**** special (epub) files :format: -***** DONE static -****** _identify doc filetype_ (mimetype) [static] +*** special (epub) files :format: +**** DONE static +***** _identify doc filetype_ (mimetype) [static] - mimetype file indicating that zip file contains an EPUB @@ -2702,7 +2366,7 @@ string epub3_mimetypes() { } #+END_SRC -****** _identify doc root_ (META-INF/container.xml) [static] rootfile: contains document root path +***** _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] @@ -2721,8 +2385,8 @@ xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> } #+END_SRC -***** constructs (in dir: OEBPS) -****** TODO _doc manifest_ (OEBPS/content.opf) manifest, register content: files, images etc. +**** 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 @@ -2731,6 +2395,7 @@ xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> #+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"¶ <?xml version='1.0' encoding='utf-8'?> <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="EPB-UUID"> @@ -2756,7 +2421,7 @@ string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { <!-- NCX epub2 navigation --> <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" /> <!-- CSS Style Sheets --> - <item id="main-css" href="css/xhtml.css" media-type="text/css" /> + <link rel="stylesheet" href="%s" type="text/css" id="main-css" /> <!-- nav epub3 navigation --> <item id="nav" href="toc_nav.xhtml" media-type="application/xhtml+xml" properties="nav" /> ¶", @@ -2777,16 +2442,19 @@ string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { uuid, uuid, uuid, + (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), ); content ~= " " ~ "<!-- Content Documents -->" ~ "\n "; content ~= parts["manifest_documents"]; // TODO sort jpg & png content ~= " " ~ "<!-- Images -->" ~ "\n "; foreach (image; doc_matters.image_list) { - content ~= format(q"¶ <item id="%s" href="image/%s" media-type="image/png" /> + content ~= format(q"¶ <item id="%s" href="%s/%s" media-type="image/%s" /> ¶", - 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 ~= " " ~ "</manifest>" ~ "\n "; @@ -2801,7 +2469,7 @@ string epub3_oebps_content(D,I,P)(D doc_abstraction, I doc_matters, P parts) { } #+END_SRC -****** _doc navigation epub3_ (OEBPS/toc_nav.xhtml) epub3 navigable toc using Dom structure +***** _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) @@ -2866,7 +2534,7 @@ string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { } #+END_SRC -****** TODO _doc navigation epub2_ (OEBPS/toc.ncx) navigable toc using Dom structure +***** 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) @@ -2911,9 +2579,12 @@ string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { foreach_reverse (k; 0 .. 7) { switch (obj.dom_markedup[k]) { case DomTags.close : + // writeln(markup.indent_by_spaces_provided(k), "</", k, ">"); // --debug dom tags toc ~= "</navPoint>"; break; case DomTags.close_and_open : + // writeln(markup.indent_by_spaces_provided(k), "</", k, ">"); // --debug dom tags + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; toc ~= "</navPoint>"; toc ~= format(q"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> @@ -2927,6 +2598,7 @@ obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml ); break; case DomTags.open : + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; toc ~= format(q"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> <navLabel> @@ -2951,8 +2623,8 @@ obj.segment_anchor_tag, // lev < 4 [no link]; lev == 4 [filename] markup.xhtml } #+END_SRC -**** the document contents :seg: -***** switch (sections & objects) format epub3 xhtml output +*** the document contents :seg: +**** switch (sections & objects) format epub3 xhtml output #+name: output_epub3_xhtml_seg #+BEGIN_SRC d @@ -3084,7 +2756,7 @@ void outputEPub3(D,I)( 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); @@ -3223,7 +2895,7 @@ void outputEPub3(D,I)( } #+END_SRC -**** write output files +*** write output files #+name: output_epub3_xhtml_seg #+BEGIN_SRC d @@ -3245,22 +2917,29 @@ void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( 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.doc_oebps_css(doc_matters.source_filename))) { - pth_epub3.doc_oebps_css(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_epub3.base)) { + pth_epub3.base.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) { @@ -3345,7 +3024,7 @@ void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( /+ 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); @@ -3362,7 +3041,7 @@ void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( /+ 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); @@ -3381,19 +3060,19 @@ void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( } { /+ 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)) { { @@ -3435,8 +3114,3 @@ void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( } } #+END_SRC - -** pdf [#C] :pdf: -** odt :odt: -** sqlite [#B] :sqlite: -** pgsql :pgsql: 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; @@ -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<columns>(?:[ ]+[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!("^<br>\n|<br>\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"¶ <?xml version='1.0' encoding='utf-8'?> <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="EPB-UUID"> @@ -70,7 +72,7 @@ template outputEPub3() { <!-- NCX epub2 navigation --> <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" /> <!-- CSS Style Sheets --> - <item id="main-css" href="css/xhtml.css" media-type="text/css" /> + <link rel="stylesheet" href="%s" type="text/css" id="main-css" /> <!-- nav epub3 navigation --> <item id="nav" href="toc_nav.xhtml" media-type="application/xhtml+xml" properties="nav" /> ¶", @@ -91,16 +93,19 @@ template outputEPub3() { uuid, uuid, uuid, + (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), ); content ~= " " ~ "<!-- Content Documents -->" ~ "\n "; content ~= parts["manifest_documents"]; // TODO sort jpg & png content ~= " " ~ "<!-- Images -->" ~ "\n "; foreach (image; doc_matters.image_list) { - content ~= format(q"¶ <item id="%s" href="image/%s" media-type="image/png" /> + content ~= format(q"¶ <item id="%s" href="%s/%s" media-type="image/%s" /> ¶", - 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 ~= " " ~ "</manifest>" ~ "\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), "</", k, ">"); // --debug dom tags toc ~= "</navPoint>"; break; case DomTags.close_and_open : + // writeln(markup.indent_by_spaces_provided(k), "</", k, ">"); // --debug dom tags + // writeln(markup.indent_by_spaces_provided(k), "<", k, ">", obj.text); // --debug dom tags ++counter; toc ~= "</navPoint>"; toc ~= format(q"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> @@ -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"¶<navPoint class="chapter" id="navpoint" playOrder="%s"> <navLabel> @@ -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"¶ <a name="bottom" id="bottom"></a> <a name="end" id="end"></a> - </div> </body> </html>¶"); return o; @@ -204,7 +204,7 @@ template outputXHTMLs() { if (obj.inline_notes_reg) { _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") ); } debug(markup_endnotes) { @@ -251,7 +251,7 @@ template outputXHTMLs() { } _txt = (_txt).replaceAll( rgx.inline_notes_delimiter_al_regular_number_note, - ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") + ("<a href=\"#note_$1\"><note id=\"noteref_$1\"> <sup>$1</sup> </note></a>") ); } 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 = "<hr />"; + if (obj.heading_lev_markup == 0) { + _horizontal_rule = ""; + } string o; if (obj.obj_cite_number.empty) { - o = format(q"¶<br /><hr /><br /> + o = format(q"¶%s <div class="substance"> <h%s class="%s">%s %s </h%s> </div>¶", + _horizontal_rule, obj.heading_lev_markup, obj.is_a, tags, @@ -320,13 +325,14 @@ template outputXHTMLs() { obj.heading_lev_markup, ); } else { - o = format(q"¶<br /><hr /><br /> + o = format(q"¶%s <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> <h%s class="%s" id="%s"><a name="%s"></a>%s %s </h%s> </div>¶", + _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"¶ <div class="substance"> - <p class="%s"> - %s - </p> + <p class="%s">%s</p> </div>¶", obj.is_a, - _txt + _txt.stripRight ); } else { o = format(q"¶ <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <p class="%s" id="%s"> - %s - </p> + <p class="%s" id="%s">%s</p> </div>¶", 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"¶ <div class="substance"> - <p class="%s"> - %s - </p> + <p class="%s">%s</p> </div>¶", obj.is_a, _txt @@ -610,9 +610,7 @@ template outputXHTMLs() { } else { o = format(q"¶ <div class="substance"> <label class="ocn"><a href="#%s" class="lnkocn">%s</a></label> - <p class="%s" id="%s"> - %s - </p> + <p class="%s" id="%s">%s</p> </div>¶", 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<BR> + - read config files<BR> + 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); |