From 60d6073bcfc4fa91253428094813de0dac41a2b4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 9 May 2017 13:01:06 -0400 Subject: 0.16.0 files/modules re-arranged --- makefile | 3 + maker.org | 26 +- org/ao_conf_make_meta.org | 40 +- org/ao_debugs.org | 11 +- org/ao_doc_abstraction.org | 33 +- org/ao_read_source_files.org | 137 +- org/compile_time_info.org | 4 +- org/default_misc.org | 12 +- org/default_paths.org | 12 +- org/default_regex.org | 12 +- org/imports.org | 79 +- org/output_hub.org | 31 +- org/output_sisupod.org | 30 +- org/output_xmls.org | 40 +- org/output_xmls_css.org | 4 +- org/output_zip.org | 4 +- org/sdp.org | 58 +- src/sdp/abstraction.d | 116 - src/sdp/abstraction_summary.d | 81 - src/sdp/ao/abstract_doc_source.d | 5541 +++++++++++++++++++++++++++++++++++ src/sdp/ao/abstraction.d | 132 + src/sdp/ao/abstraction_summary.d | 81 + src/sdp/ao/conf_make_meta.d | 47 + src/sdp/ao/conf_make_meta_native.d | 330 +++ src/sdp/ao/conf_make_meta_sdlang.d | 150 + src/sdp/ao/defaults.d | 493 ++++ src/sdp/ao/doc_debugs.d | 659 +++++ src/sdp/ao/object_setter.d | 64 + src/sdp/ao/package.d | 17 + src/sdp/ao/read_config_files.d | 87 + src/sdp/ao/read_source_files.d | 294 ++ src/sdp/ao/rgx.d | 246 ++ src/sdp/ao_abstract_doc_source.d | 5554 ------------------------------------ src/sdp/ao_conf_make_meta.d | 47 - src/sdp/ao_conf_make_meta_native.d | 330 --- src/sdp/ao_conf_make_meta_sdlang.d | 150 - src/sdp/ao_defaults.d | 493 ---- src/sdp/ao_doc_debugs.d | 660 ----- src/sdp/ao_object_setter.d | 64 - src/sdp/ao_read_config_files.d | 124 - src/sdp/ao_read_source_files.d | 306 -- src/sdp/ao_rgx.d | 246 -- src/sdp/compile_time_info.d | 38 - src/sdp/conf/compile_time_info.d | 38 + src/sdp/create_zip_file.d | 17 - src/sdp/defaults.d | 120 - src/sdp/imports_for_ao.d | 41 - src/sdp/imports_for_output.d | 28 - src/sdp/output/create_zip_file.d | 17 + src/sdp/output/defaults.d | 120 + src/sdp/output/epub3.d | 756 +++++ src/sdp/output/html.d | 447 +++ src/sdp/output/hub.d | 79 + src/sdp/output/package.d | 20 + src/sdp/output/paths_output.d | 288 ++ src/sdp/output/paths_source.d | 60 + src/sdp/output/rgx.d | 73 + src/sdp/output/source_sisupod.d | 208 ++ src/sdp/output/xmls.d | 800 ++++++ src/sdp/output/xmls_css.d | 869 ++++++ src/sdp/output_epub3.d | 774 ----- src/sdp/output_html.d | 465 --- src/sdp/output_hub.d | 92 - src/sdp/output_rgx.d | 73 - src/sdp/output_xmls.d | 818 ------ src/sdp/output_xmls_css.d | 869 ------ src/sdp/paths_output.d | 288 -- src/sdp/paths_source.d | 60 - src/sdp/sisu_d_parser.d | 221 ++ src/sdp/source_sisupod.d | 226 -- src/sisu_d_parser.d | 205 -- views/version.txt | 2 +- 72 files changed, 12372 insertions(+), 12588 deletions(-) delete mode 100644 src/sdp/abstraction.d delete mode 100644 src/sdp/abstraction_summary.d create mode 100644 src/sdp/ao/abstract_doc_source.d create mode 100644 src/sdp/ao/abstraction.d create mode 100644 src/sdp/ao/abstraction_summary.d create mode 100644 src/sdp/ao/conf_make_meta.d create mode 100644 src/sdp/ao/conf_make_meta_native.d create mode 100644 src/sdp/ao/conf_make_meta_sdlang.d create mode 100644 src/sdp/ao/defaults.d create mode 100644 src/sdp/ao/doc_debugs.d create mode 100644 src/sdp/ao/object_setter.d create mode 100644 src/sdp/ao/package.d create mode 100644 src/sdp/ao/read_config_files.d create mode 100644 src/sdp/ao/read_source_files.d create mode 100644 src/sdp/ao/rgx.d delete mode 100644 src/sdp/ao_abstract_doc_source.d delete mode 100644 src/sdp/ao_conf_make_meta.d delete mode 100644 src/sdp/ao_conf_make_meta_native.d delete mode 100644 src/sdp/ao_conf_make_meta_sdlang.d delete mode 100644 src/sdp/ao_defaults.d delete mode 100644 src/sdp/ao_doc_debugs.d delete mode 100644 src/sdp/ao_object_setter.d delete mode 100644 src/sdp/ao_read_config_files.d delete mode 100644 src/sdp/ao_read_source_files.d delete mode 100644 src/sdp/ao_rgx.d delete mode 100644 src/sdp/compile_time_info.d create mode 100644 src/sdp/conf/compile_time_info.d delete mode 100644 src/sdp/create_zip_file.d delete mode 100644 src/sdp/defaults.d delete mode 100644 src/sdp/imports_for_ao.d delete mode 100644 src/sdp/imports_for_output.d create mode 100644 src/sdp/output/create_zip_file.d create mode 100644 src/sdp/output/defaults.d create mode 100644 src/sdp/output/epub3.d create mode 100644 src/sdp/output/html.d create mode 100644 src/sdp/output/hub.d create mode 100644 src/sdp/output/package.d create mode 100644 src/sdp/output/paths_output.d create mode 100644 src/sdp/output/paths_source.d create mode 100644 src/sdp/output/rgx.d create mode 100644 src/sdp/output/source_sisupod.d create mode 100644 src/sdp/output/xmls.d create mode 100644 src/sdp/output/xmls_css.d delete mode 100644 src/sdp/output_epub3.d delete mode 100644 src/sdp/output_html.d delete mode 100644 src/sdp/output_hub.d delete mode 100644 src/sdp/output_rgx.d delete mode 100644 src/sdp/output_xmls.d delete mode 100644 src/sdp/output_xmls_css.d delete mode 100644 src/sdp/paths_output.d delete mode 100644 src/sdp/paths_source.d create mode 100755 src/sdp/sisu_d_parser.d delete mode 100644 src/sdp/source_sisupod.d delete mode 100755 src/sisu_d_parser.d diff --git a/makefile b/makefile index 2f63b04..f4225eb 100644 --- a/makefile +++ b/makefile @@ -154,6 +154,9 @@ release_rdmd: distclean tangle $(PRG_SRCDIR)/$(PRG_SRC) $(DC_FLAG_BINOF)$(PRG_BINDIR)/$(PRG_BIN) \ $(PRG_SRCDIR)/$(PRG_SRC) skel: + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/ao; \ + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/conf; \ + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/output; \ mkdir -p $(PRG_SRCDIR)/$(PRG_NAME); \ mkdir -p $(PRG_BINDIR); diff --git a/maker.org b/maker.org index ff7509d..62fa07d 100644 --- a/maker.org +++ b/maker.org @@ -379,6 +379,9 @@ release_rdmd: distclean tangle $(PRG_SRCDIR)/$(PRG_SRC) #+BEGIN_SRC makefile :tangle makefile skel: + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/ao; \ + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/conf; \ + mkdir -p $(PRG_SRCDIR)/$(PRG_NAME)/output; \ mkdir -p $(PRG_SRCDIR)/$(PRG_NAME); \ mkdir -p $(PRG_BINDIR); @@ -845,17 +848,17 @@ time dub --compiler=ldc2 -v --force *** dmd [#A] :dmd: #+BEGIN_SRC sh -dmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc -of./bin/sdp ./src/sisu_d_parser.d -dmd -de -w -J./views -I./src/sdp -of./bin/sdp ./src/sisu_d_parser.d -dmd -de -w -J./views -I./src/sdp -O -release -of./bin/sdp ./src/sisu_d_parser.d +dmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc -of./bin/sdp ./src/sdp/sisu_d_parser.d +dmd -de -w -J./views -I./src/sdp -of./bin/sdp ./src/sdp/sisu_d_parser.d +dmd -de -w -J./views -I./src/sdp -O -release -of./bin/sdp ./src/sdp/sisu_d_parser.d #+END_SRC *** ldc2 [#A] :ldc2: #+BEGIN_SRC sh -ldc2 -de -w -J./views -I./src/sdp -unittest -d-debug=checkdoc -d-debug=summary -d-debug=dumpdoc -of=./bin/sdp ./src/sisu_d_parser.d -ldc2 -de -w -J./views -I./src/sdp -of=./bin/sdp ./src/sisu_d_parser.d -ldc2 -de -w -J./views -I./src/sdp -O4 -release -of=./bin/sdp ./src/sisu_d_parser.d +ldc2 -de -w -J./views -I./src/sdp -unittest -d-debug=checkdoc -d-debug=summary -d-debug=dumpdoc -of=./bin/sdp ./src/sdp/sisu_d_parser.d +ldc2 -de -w -J./views -I./src/sdp -of=./bin/sdp ./src/sdp/sisu_d_parser.d +ldc2 -de -w -J./views -I./src/sdp -O4 -release -of=./bin/sdp ./src/sdp/sisu_d_parser.d #+END_SRC *** gdc (not done) [#F] :gdc: @@ -877,15 +880,15 @@ re: dmd "one can easily get 2x (and even more) speedup by simply switching to gd flags similar to dmd #+BEGIN_SRC sh -rdmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc -of./bin/sdp ./src/sisu_d_parser.d -rdmd -de -w -J./views -I./src/sdp -of./bin/sdp ./src/sisu_d_parser.d -rdmd -de -w -J./views -I./src/sdp -O -release -of./bin/sdp ./src/sisu_d_parser.d +rdmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc -of./bin/sdp ./src/sdp/sisu_d_parser.d +rdmd -de -w -J./views -I./src/sdp -of./bin/sdp ./src/sdp/sisu_d_parser.d +rdmd -de -w -J./views -I./src/sdp -O -release -of./bin/sdp ./src/sdp/sisu_d_parser.d #dmd -rdmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc --compiler=ldc2 -of./bin/sdp ./src/sisu_d_parser.d +rdmd -de -w -J./views -I./src/sdp -unittest -debug=checkdoc -debug=summary -debug=dumpdoc --compiler=ldc2 -of./bin/sdp ./src/sdp/sisu_d_parser.d #ldc -rdmd -de -w -J./views -I./src/sdp -unittest -d-debug=checkdoc -d-debug=summary -d-debug=dumpdoc --compiler=ldc2 -of./bin/sdp ./src/sisu_d_parser.d +rdmd -de -w -J./views -I./src/sdp -unittest -d-debug=checkdoc -d-debug=summary -d-debug=dumpdoc --compiler=ldc2 -of./bin/sdp ./src/sdp/sisu_d_parser.d #+END_SRC *** dub [#A] :dub: @@ -979,6 +982,7 @@ debugVersions "checkdoc" debugVersions "code" debugVersions "comment" debugVersions "configfile" +debugVersions "dom" debugVersions "dumpdoc" debugVersions "endnotes" debugVersions "endnotes_build" diff --git a/org/ao_conf_make_meta.org b/org/ao_conf_make_meta.org index 471d233..f66b597 100644 --- a/org/ao_conf_make_meta.org +++ b/org/ao_conf_make_meta.org @@ -16,7 +16,7 @@ * 0. Header Hub :module:sdp:ao_conf_make_meta: ** module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta.d /++ extract native/orig header return associative array
@@ -27,9 +27,9 @@ converting the metadata and make instructions to a common json format used by program internally. Moved to associative array. +/ -module sdp.ao_conf_make_meta; +module sdp.ao.conf_make_meta; template SiSUheaderExtractHub() { - private import + import std.exception, std.regex, std.stdio, @@ -37,11 +37,11 @@ template SiSUheaderExtractHub() { std.typecons, std.utf, std.conv : to; - private import sdlang; - private import - sdp.ao_rgx, - sdp.ao_conf_make_meta_native, - sdp.ao_conf_make_meta_sdlang; + import sdlang; + import + sdp.ao.conf_make_meta_native, + sdp.ao.conf_make_meta_sdlang, + sdp.ao.rgx; mixin SiSUrgxInit; mixin SiSUheaderExtractNative; mixin SiSUheaderExtractSDLang; @@ -70,14 +70,14 @@ template SiSUheaderExtractHub() { ** module template ** extract sdlang header -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_sdlang.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta_sdlang.d /++ sdlang headers
extract sdlang header return sdlang +/ -module sdp.ao_conf_make_meta_sdlang; +module sdp.ao.conf_make_meta_sdlang; template SiSUheaderExtractSDLang() { - private import + import std.exception, std.regex, std.stdio, @@ -86,9 +86,9 @@ template SiSUheaderExtractSDLang() { std.typecons, std.utf, std.conv : to; - private import - sdp.ao_rgx, - sdp.ao_defaults; + import + sdp.ao.defaults, + sdp.ao.rgx; struct HeaderExtractSDL { mixin SiSUregisters; mixin SiSUrgxInit; @@ -270,14 +270,14 @@ private auto headerSDLangToAA(Hs,Ma)(Hs header_sdlang_src, Ma conf_doc_make_aa) * B. header native :module:sdp:ao_conf_make_meta_native: ** Header Native :header:native:markup_header_extract_native: -#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_native.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/conf_make_meta_native.d /++ native headers using
@title:
:subtitle:
type tags
extract native/orig header return associative array +/ -module sdp.ao_conf_make_meta_native; +module sdp.ao.conf_make_meta_native; template SiSUheaderExtractNative() { - private import + import std.exception, std.regex, std.stdio, @@ -286,9 +286,9 @@ template SiSUheaderExtractNative() { std.typecons, std.utf, std.conv : to; - private import - sdp.ao_rgx, - sdp.ao_defaults; + import + sdp.ao.defaults, + sdp.ao.rgx; struct HeaderDocMetadataAndMakeNativeToAA { mixin SiSUregisters; mixin SiSUrgxInitFlags; diff --git a/org/ao_debugs.org b/org/ao_debugs.org index 838d7cf..52172fb 100644 --- a/org/ao_debugs.org +++ b/org/ao_debugs.org @@ -16,11 +16,11 @@ * 1. abstraction debugs :module:sdp:ao_doc_debugs: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_doc_debugs.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/doc_debugs.d /++ output debugs +/ -module sdp.ao_doc_debugs; +module sdp.ao.doc_debugs; template SiSUdebugs() { <> auto SiSUdebugs(S,T)( @@ -46,9 +46,9 @@ template SiSUdebugs() { #+name: debug_imports #+BEGIN_SRC d import - sdp.ao_defaults, - sdp.ao_rgx; -private import + sdp.ao.defaults, + sdp.ao.rgx; +import std.algorithm, std.array, std.container, @@ -62,7 +62,6 @@ private import std.string, std.traits, std.typecons, - std.uni, std.utf, std.conv : to; #+END_SRC diff --git a/org/ao_doc_abstraction.org b/org/ao_doc_abstraction.org index 75ed2a6..cd178aa 100644 --- a/org/ao_doc_abstraction.org +++ b/org/ao_doc_abstraction.org @@ -107,13 +107,13 @@ Process markup document, create document abstraction. ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_abstract_doc_source.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/abstract_doc_source.d /++ document abstraction: abstraction of sisu markup for downstream processing ao_abstract_doc_source.d +/ -module sdp.ao_abstract_doc_source; +module sdp.ao.abstract_doc_source; template SiSUdocAbstraction() { /+ ↓ abstraction imports +/ <> @@ -233,30 +233,17 @@ template SiSUdocAbstraction() { #+name: abs_top_imports #+BEGIN_SRC d +import sdp.ao; import - sdp.ao_defaults, - sdp.ao_object_setter, - sdp.ao_rgx, - sdp.output_hub; -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; + std.path; +import + sdp.ao.defaults, + sdp.ao.object_setter, + sdp.ao.rgx; #+END_SRC *** mixins :mixins: @@ -6872,13 +6859,13 @@ set abstracted objects for downstream processing ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_object_setter.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/object_setter.d /++ object setter: setting of sisu objects for downstream processing ao_object_setter.d +/ -module sdp.ao_object_setter; +module sdp.ao.object_setter; template ObjectSetter() { /+ structs +/ <> diff --git a/org/ao_read_source_files.org b/org/ao_read_source_files.org index 9b9e863..b53fdc5 100644 --- a/org/ao_read_source_files.org +++ b/org/ao_read_source_files.org @@ -13,65 +13,77 @@ #+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) [[./sdp.org][sdp]] [[./][org/]] +* imports + +#+name: imports_std +#+BEGIN_SRC d +import + sdp.ao, + std.file, + std.path; +#+END_SRC + * 1. get config file (read in) :module:sdp:ao_read_config_files: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_read_config_files.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/read_config_files.d /++ read configuration files
- read config files
ao_config_files.d +/ -module sdp.ao_read_config_files; -template ConfigIn() { - <> - import std.file; - <> -} +module sdp.ao.read_config_files; +<> +<> +<> #+END_SRC -** read config file, (conf.sdl & sisu_document_make) :file:config: +** 1. read config file, (conf.sdl & sisu_document_make) :file:config: #+name: ao_config_file_in #+BEGIN_SRC d -final string ConfigIn(C,E)(C conf_sdl, E env) { - string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; - string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; - string dot_home = chainPath(to!string(env["home"]), ".sisu").array; - string[] possible_config_path_locations = [ - dot_pwd, - underscore_pwd, - dot_home, - "/etc/sisu" - ]; - string config_file_str; - foreach(pth; possible_config_path_locations) { - auto conf_file = format( - "%s/%s", - pth, - conf_sdl, - ); - try { - if (exists(conf_file)) { - debug(configfile) { - writeln(conf_file); +template ConfigIn() { + <> + final string ConfigIn(C,E)(C conf_sdl, E env) { + string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; + string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; + string dot_home = chainPath(to!string(env["home"]), ".sisu").array; + string[] possible_config_path_locations = [ + dot_pwd, + underscore_pwd, + dot_home, + "/etc/sisu" + ]; + string config_file_str; + foreach(pth; possible_config_path_locations) { + auto conf_file = format( + "%s/%s", + pth, + conf_sdl, + ); + try { + if (exists(conf_file)) { + debug(configfile) { + writeln(conf_file); + } + config_file_str = conf_file.readText; + break; } - config_file_str = conf_file.readText; - break; + } + catch (ErrnoException ex) { + } + catch (FileException ex) { } } - catch (ErrnoException ex) { - } - catch (FileException ex) { - } + return config_file_str; } - return config_file_str; } #+END_SRC -** 0. config files get sdlang root tag - -#+BEGIN_SRC d :tangle ../src/sdp/ao_read_config_files.d +** 2. config files get sdlang root tag +*** 0. template +#+name: ao_config_file_sdl +#+BEGIN_SRC d /+ +/ @@ -82,7 +94,7 @@ template ConfigSDLang() { } #+END_SRC -** config file get sdl root tag :file:conf:sdlang: +*** config file get sdl root tag :file:conf:sdlang: #+name: ao_config_file_sdlang #+BEGIN_SRC d @@ -106,10 +118,11 @@ auto ConfigSDLang(string configuration, string conf_sdl_filename) { } #+END_SRC -** config file (conf.sdl & sisu_document_make) :file:config:hub: -*** config hub template +** 3. config file (conf.sdl & sisu_document_make) :file:config:hub: +*** 0. template -#+BEGIN_SRC d :tangle ../src/sdp/ao_read_config_files.d +#+name: ao_config_file_hub +#+BEGIN_SRC d /+ +/ template ConfigHub() { @@ -119,32 +132,10 @@ template ConfigHub() { } #+END_SRC -*** imports - -#+name: imports_std -#+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, - std.exception, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; -#+END_SRC - *** config hub import sdlang #+name: ao_config_file_import_mixin #+BEGIN_SRC d -private import sdlang; +import sdlang; #+END_SRC *** config hub function @@ -159,19 +150,18 @@ final auto ConfigHub(C,E)(C conf_sdl, E env) { #+END_SRC * 2. get markup source, read file :module:sdp:ao_read_source_files: - ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/ao_read_source_files.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/read_source_files.d /++ module ao_read_source_files;
- open markup files
- if master file scan for addional files to import/insert +/ -module sdp.ao_read_source_files; +module sdp.ao.read_source_files; template SiSUrawMarkupContent() { - private import - sdp.ao_rgx; + import + sdp.ao.rgx; <> mixin SiSUrgxInit; auto rgx = Rgx(); @@ -213,7 +203,7 @@ template SiSUrawMarkupContent() { } } struct MarkupRawUnit { - private import std.file; + import std.file; <> <> <> @@ -222,7 +212,7 @@ template SiSUrawMarkupContent() { <> } struct Inserts { - private import sdp.ao_defaults; + import sdp.ao.defaults; auto scan_subdoc_source( char[][] markup_sourcefile_insert_content, string fn_src @@ -559,4 +549,3 @@ auto t = tuple( return t; #+END_SRC -* 3. config files (conf.sdl & sisu_document_make) :ao_config_files: diff --git a/org/compile_time_info.org b/org/compile_time_info.org index 5da7e04..e29ede1 100644 --- a/org/compile_time_info.org +++ b/org/compile_time_info.org @@ -22,11 +22,11 @@ version(Windows) {} else { ... } ** 0. module template -#+begin_src d :tangle ../src/sdp/compile_time_info.d +#+begin_src d :tangle ../src/sdp/conf/compile_time_info.d /++ compile_time_info +/ -module sdp.compile_time_info; +module sdp.conf.compile_time_info; template CompileTimeInfo() { <> } diff --git a/org/default_misc.org b/org/default_misc.org index 84b9076..f4adc70 100644 --- a/org/default_misc.org +++ b/org/default_misc.org @@ -17,11 +17,11 @@ ** 0. module template #+name: tangle_defaults -#+BEGIN_SRC d :tangle ../src/sdp/ao_defaults.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/defaults.d /++ default settings +/ -module sdp.ao_defaults; +module sdp.ao.defaults; template SiSUregisters() { <> <> @@ -37,7 +37,7 @@ template SiSUregisters() { #+name: ao_defaults_imports #+BEGIN_SRC d -private import +import std.algorithm, std.array, std.container, @@ -536,11 +536,11 @@ template SiSUbiblio() { ** 0. module template #+name: tangle_defaults -#+BEGIN_SRC d :tangle ../src/sdp/defaults.d +#+BEGIN_SRC d :tangle ../src/sdp/output/defaults.d /++ default settings +/ -module sdp.defaults; +module sdp.output.defaults; <> <> <> @@ -550,7 +550,7 @@ module sdp.defaults; #+name: defaults_imports #+BEGIN_SRC d -private import +import std.algorithm, std.array, std.container, diff --git a/org/default_paths.org b/org/default_paths.org index 597f162..043bc25 100644 --- a/org/default_paths.org +++ b/org/default_paths.org @@ -16,18 +16,18 @@ * 0. source paths :module:sdp:paths_source: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/paths_source.d +#+BEGIN_SRC d :tangle ../src/sdp/output/paths_source.d /++ read configuration files
- read config files
ao_config_files.d +/ -module sdp.paths_source; +module sdp.output.paths_source; import std.array, std.path, std.regex, std.stdio; -import sdp.ao_rgx; +import sdp.ao.rgx; template SiSUpathsSRC() { mixin SiSUrgxInit; auto rgx = Rgx(); @@ -82,16 +82,16 @@ template SiSUpathsSRC() { * 1. output paths :module:sdp:paths_output: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/paths_output.d +#+BEGIN_SRC d :tangle ../src/sdp/output/paths_output.d /++ default settings +/ -module sdp.paths_output; +module sdp.output.paths_output; import std.array, std.path, std.regex, std.stdio; -import sdp.ao_rgx; +import sdp.ao.rgx; <> <> <> diff --git a/org/default_regex.org b/org/default_regex.org index 4c126a2..3d291fe 100644 --- a/org/default_regex.org +++ b/org/default_regex.org @@ -23,13 +23,13 @@ http://dlang.org/phobos/std_regex.html ** 0. module template #+name: tangle_ao_rgx -#+BEGIN_SRC d :tangle ../src/sdp/ao_rgx.d +#+BEGIN_SRC d :tangle ../src/sdp/ao/rgx.d /++ regex: regular expressions used in sisu document parser +/ -module sdp.ao_rgx; +module sdp.ao.rgx; template SiSUrgxInit() { - private import sdp.ao_defaults; + import sdp.ao.defaults; struct Rgx { <> <> @@ -353,13 +353,13 @@ http://dlang.org/phobos/std_regex.html ** 0. module template #+name: tangle_ao_rgx -#+BEGIN_SRC d :tangle ../src/sdp/output_rgx.d +#+BEGIN_SRC d :tangle ../src/sdp/output/rgx.d /++ regex: regular expressions used in sisu document parser +/ -module sdp.output_rgx; +module sdp.output.rgx; template SiSUoutputRgxInit() { - private import sdp.defaults; + import sdp.output.defaults; struct Rgx { <> <> diff --git a/org/imports.org b/org/imports.org index 17819b8..05f5dc9 100644 --- a/org/imports.org +++ b/org/imports.org @@ -13,82 +13,65 @@ #+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n) * 1. imports for ao +** package dir -#+NAME: version_txt -#+BEGIN_SRC d :tangle ../src/sdp/imports_for_ao.d -module sdp.imports_for_ao; -public import - sdp.abstraction_summary, - sdp.ao_abstract_doc_source, - sdp.ao_conf_make_meta, - sdp.ao_conf_make_meta_native, - sdp.ao_conf_make_meta_sdlang, - sdp.ao_defaults, - sdp.ao_doc_debugs, - sdp.ao_read_config_files, - sdp.ao_read_source_files, - sdp.ao_rgx, - sdp.output_hub, - sdp.paths_source; -/+ sdlang http://sdlang.org +/ -public import sdlang; -/+ aarchive https://github.com/rcythr/archive +/ +#+BEGIN_SRC d :tangle ../src/sdp/ao/package.d +module sdp.ao; +<> +#+END_SRC + +** import list + +#+NAME: imports_for_ao_general +#+BEGIN_SRC d public import - archive.core, - archive.zip; + sdp.ao.defaults, + sdp.ao.rgx; /+ std +/ public import - // std.algorithm, std.array, - // std.container, - std.digest.sha, std.exception, - std.getopt, - std.process, - std.stdio, - // std.file, - // std.path, std.range, - // std.range, std.regex, + std.stdio, std.string, std.traits, std.typecons, - std.uni, + // std.uni, std.utf, std.conv : to; #+END_SRC * 2. imports for output -#+NAME: version_txt -#+BEGIN_SRC d :tangle ../src/sdp/imports_for_output.d -module sdp.imports_for_output; +** package dir + +#+BEGIN_SRC d :tangle ../src/sdp/output/package.d +module sdp.output; +<> +#+END_SRC + +** import list + +#+NAME: imports_for_output_general +#+BEGIN_SRC d public import - std.regex, std.algorithm, std.array, std.container, std.exception, - std.getopt, - std.process, - std.stdio, - std.file, std.path, + std.process, std.range, std.regex, + std.stdio, std.string, std.traits, std.typecons, - std.uni, + // std.uni, std.utf; public import - sdp.defaults, - sdp.output_epub3, - sdp.output_html, - sdp.output_rgx, - sdp.output_xmls, - sdp.source_sisupod, - sdp.create_zip_file, - sdp.paths_output; + sdp.output.defaults, + sdp.output.paths_output, + sdp.output.rgx; #+END_SRC diff --git a/org/output_hub.org b/org/output_hub.org index 4e66c59..d17d3c5 100644 --- a/org/output_hub.org +++ b/org/output_hub.org @@ -16,12 +16,12 @@ * 0. output hub [#A] :module:sdp:output_hub: ** module template -#+BEGIN_SRC d :tangle ../src/sdp/output_hub.d +#+BEGIN_SRC d :tangle ../src/sdp/output/hub.d /++ output hub
check & generate output types requested +/ -module sdp.output_hub; +module sdp.output.hub; template outputHub() { <> void outputHub(D,I)(D doc_abstraction, I doc_matters) { @@ -36,26 +36,13 @@ template outputHub() { #+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 - sdp.imports_for_output; +import sdp.output, + sdp.output.epub3, + sdp.output.html, + sdp.output.xmls, + sdp.output.source_sisupod, + sdp.output.create_zip_file, + sdp.output.paths_output; #+END_SRC ** output options diff --git a/org/output_sisupod.org b/org/output_sisupod.org index f768176..c706746 100644 --- a/org/output_sisupod.org +++ b/org/output_sisupod.org @@ -17,8 +17,8 @@ * sisupod :module:sdp:source_sisupod: ** module template -#+BEGIN_SRC d :tangle ../src/sdp/source_sisupod.d -module sdp.source_sisupod; +#+BEGIN_SRC d :tangle ../src/sdp/output/source_sisupod.d +module sdp.output.source_sisupod; template SiSUpod() { <> void SiSUpod(T)(T doc_matters) { @@ -39,34 +39,16 @@ template SiSUpod() { #+name: output_imports #+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, +import sdp.output; +import 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.paths_output; + sdp.output.create_zip_file, + sdp.output.xmls; #+END_SRC ** mkdir diff --git a/org/output_xmls.org b/org/output_xmls.org index 4ee8074..4b20157 100644 --- a/org/output_xmls.org +++ b/org/output_xmls.org @@ -18,8 +18,8 @@ ** format xhtml objects :format: *** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/output_xmls.d -module sdp.output_xmls; +#+BEGIN_SRC d :tangle ../src/sdp/output/xmls.d +module sdp.output.xmls; template outputXHTMLs() { <> mixin SiSUoutputRgxInit; @@ -35,35 +35,17 @@ template outputXHTMLs() { #+name: output_imports #+BEGIN_SRC d -private import - std.algorithm, - std.array, - std.container, +import sdp.output; +import 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.output_xmls_css, - sdp.paths_output; + sdp.output.create_zip_file, + sdp.output.xmls, + sdp.output.xmls_css; #+END_SRC *** misc @@ -1079,8 +1061,8 @@ auto endnote(O)( * _html_ [#A] :module:sdp:output_html: ** module template -#+BEGIN_SRC d :tangle ../src/sdp/output_html.d -module sdp.output_html; +#+BEGIN_SRC d :tangle ../src/sdp/output/html.d +module sdp.output.html; template outputHTML() { <> mixin outputXHTMLs; @@ -1574,8 +1556,8 @@ void css(M)( ** module template -#+BEGIN_SRC d :tangle ../src/sdp/output_epub3.d -module sdp.output_epub3; +#+BEGIN_SRC d :tangle ../src/sdp/output/epub3.d +module sdp.output.epub3; template outputEPub3() { <> mixin InternalMarkup; diff --git a/org/output_xmls_css.org b/org/output_xmls_css.org index 8fd2c6b..27063b2 100644 --- a/org/output_xmls_css.org +++ b/org/output_xmls_css.org @@ -16,11 +16,11 @@ * 0. ao css defaults :module:sdp:output_xmls_css: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/output_xmls_css.d +#+BEGIN_SRC d :tangle ../src/sdp/output/xmls_css.d /++ default css settings +/ -module sdp.output_xmls_css; +module sdp.output.xmls_css; template SiSUcss() { auto SiSUcss() { string css_shared=" diff --git a/org/output_zip.org b/org/output_zip.org index 98aede6..7798579 100644 --- a/org/output_zip.org +++ b/org/output_zip.org @@ -16,8 +16,8 @@ * _zip_ :module:sdp:create_zip_file: ** module template -#+BEGIN_SRC d :tangle ../src/sdp/create_zip_file.d -module sdp.create_zip_file; +#+BEGIN_SRC d :tangle ../src/sdp/output/create_zip_file.d +module sdp.output.create_zip_file; template createZipFile() { import std.file; import std.outbuffer; diff --git a/org/sdp.org b/org/sdp.org index e34c57b..2f93812 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -23,7 +23,7 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 15, 0); +enum ver = Version(0, 16, 0); #+END_SRC * 1. sdp (sisu document parser) :sdp: @@ -37,15 +37,15 @@ enum ver = Version(0, 15, 0); - process file - output -** 0. sdp src/sdp.d :template: +** 0. sdp src/sdp :template: -#+BEGIN_SRC d :tangle ../src/sisu_d_parser.d :shebang #!/usr/bin/env rdmd +#+BEGIN_SRC d :tangle ../src/sdp/sisu_d_parser.d :shebang #!/usr/bin/env rdmd /+ sdp +/ import - sdp.compile_time_info, - sdp.abstraction; + sdp.conf.compile_time_info, + sdp.ao.abstraction; <> <> <> @@ -87,7 +87,23 @@ unittest { #+NAME: imports_sdp #+BEGIN_SRC d /+ sdp: sisu document parser, see http://sisudoc.org +/ -import sdp.imports_for_ao; +import sdp.ao; +import + std.getopt, + std.process; +import + sdp.ao.abstraction_summary, + sdp.ao.abstract_doc_source, + sdp.ao.conf_make_meta, + // sdp.ao.conf_make_meta_native, + sdp.ao.conf_make_meta_sdlang, + sdp.ao.defaults, + sdp.ao.doc_debugs, + sdp.ao.read_config_files, + sdp.ao.read_source_files, + sdp.ao.rgx, + sdp.output.hub, + sdp.output.paths_source; #+END_SRC ****** notes @@ -402,8 +418,8 @@ break; // terminate, stop * 2. _document abstraction functions_ :module:sdp:abstraction: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/abstraction.d -module sdp.abstraction; +#+BEGIN_SRC d :tangle ../src/sdp/ao/abstraction.d +module sdp.ao.abstraction; template SiSUabstraction() { <> <> @@ -578,8 +594,8 @@ auto doc_matters = DocumentMatters(); * 3. document abstraction _summary_ :module:sdp:abstraction_summary: ** 0. module template -#+BEGIN_SRC d :tangle ../src/sdp/abstraction_summary.d -module sdp.abstraction_summary; +#+BEGIN_SRC d :tangle ../src/sdp/ao/abstraction_summary.d +module sdp.ao.abstraction_summary; template SiSUabstractionSummary() { auto SiSUabstractionSummary(S,T)( auto return ref const S doc_abstraction, @@ -601,8 +617,8 @@ template SiSUabstractionSummary() { #+name: abstraction_summary_imports #+BEGIN_SRC d import - sdp.ao_defaults, - sdp.ao_rgx; + sdp.ao.defaults, + sdp.ao.rgx; import std.array, std.exception, @@ -652,35 +668,35 @@ char_repeat_number = (char_repeat_number > min_repeat_number) ? char_repeat_number : min_repeat_number; writefln( - "%s\n\"%s\", %s\n%s\n%s\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n(%s: %s)\n%s", + "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n(%s: %s)\n%s", markup.repeat_character_by_number_provided("-", char_repeat_number), doc_matters.dochead_meta["title"]["full"], doc_matters.dochead_meta["creator"]["author"], doc_matters.source_filename, markup.repeat_character_by_number_provided("-", char_repeat_number), - "length toc arr: ", + "length toc arr:", to!int(doc_abstraction["toc_seg"].length), - "length doc_abstraction arr: ", + "length doc_abstraction arr:", to!int(doc_abstraction["body"].length), - "last obj_cite_number: ", + "last obj_cite_number:", to!int(check["last_obj_cite_number"]), - "length endnotes: ", + "length endnotes:", (doc_abstraction["endnotes"].length > 1) ? (to!int(doc_abstraction["endnotes"].length)) : 0, - "length glossary: ", + "length glossary:", (doc_abstraction["glossary"].length > 1) ? (to!int(doc_abstraction["glossary"].length)) : 0, - "length biblio: ", + "length biblio:", (doc_abstraction["bibliography"].length > 1) ? (to!int(doc_abstraction["bibliography"].length)) : 0, - "length bookindex: ", + "length bookindex:", (doc_abstraction["bookindex_seg"].length > 1) ? (to!int(doc_abstraction["bookindex_seg"].length)) : 0, - "length blurb: ", + "length blurb:", (doc_abstraction["blurb"].length > 1) ? (to!int(doc_abstraction["blurb"].length)) : 0, diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d deleted file mode 100644 index 351fd1f..0000000 --- a/src/sdp/abstraction.d +++ /dev/null @@ -1,116 +0,0 @@ -module sdp.abstraction; -template SiSUabstraction() { - /+ sdp: sisu document parser, see http://sisudoc.org +/ - import sdp.imports_for_ao; - - - mixin SiSUrgxInit; - mixin SiSUregisters; - mixin SiSUheaderExtractSDLang; - mixin SiSUnode; - mixin SiSUbiblio; - mixin SiSUrgxInitFlags; - mixin outputHub; - enum headBody { header, body_content, insert_filelist } - enum makeMeta { make, meta } - enum docAbst { doc_abstraction, section_keys, segnames, segnames_0_4, images } - auto rgx = Rgx(); - auto SiSUabstraction(Fn,O,E)(Fn fn_src, O opts, E env){ - auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); - auto sdl_root_doc_make = ConfigHub!()("sisu_document_make", env); - auto confsdl = HeaderExtractSDL(); - auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); - auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); - /+ ↓ read file (filename with path) +/ - /+ ↓ file tuple of header and content +/ - auto _header_body_inserts = - SiSUrawMarkupContent!()(fn_src); - static assert(!isTypeTuple!(_header_body_inserts)); - static assert(_header_body_inserts.length==3); - debug(header_and_body) { - writeln(header); - writeln(_header_body_inserts.length); - writeln(_header_body_inserts.length[headBody.body_content][0]); - } - /+ ↓ split header into make and meta +/ - auto _make_and_meta = - SiSUheaderExtractHub!()(_header_body_inserts[headBody.header], conf_doc_make_aa); - static assert(!isTypeTuple!(_make_and_meta)); - static assert(_make_and_meta.length==2); - /+ ↓ document abstraction: process document, return abstraction as tuple +/ - auto da = SiSUdocAbstraction!()( - (_header_body_inserts[headBody.body_content]), - (_make_and_meta[makeMeta.make]), - (_make_and_meta[makeMeta.meta]), - opts - ); - static assert(!isTypeTuple!(da)); - static assert(da.length==5); - auto doc_abstraction = da[docAbst.doc_abstraction]; /+ head ~ toc ~ body ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~ blurb; +/ - auto _document_section_keys_sequenced = da[docAbst.section_keys]; - string[] _doc_html_segnames = da[docAbst.segnames]; - string[] _doc_epub_segnames_0_4 = da[docAbst.segnames_0_4]; - auto _images = da[docAbst.images]; - struct DocumentMatters { - auto keys_seq() { - /+ contains .seg & .scroll sequences +/ - auto _k = _document_section_keys_sequenced; - return _k; - } - string[] segnames() { - string[] _k = _doc_html_segnames; - return _k; - } - string[] segnames_lv_0_to_4() { - string[] _k = _doc_epub_segnames_0_4; - return _k; - } - auto dochead_make() { - string[string][string] _k = _make_and_meta[makeMeta.make]; - return _k; - } - auto dochead_meta() { - 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; - } - auto language() { - string _k; - if (auto m = fn_src.match(rgx.language_code_and_filename)) { - _k = m.captures[1]; - } else { - _k = "en"; - } - return _k; - } - auto file_insert_list() { - string[] _k = _header_body_inserts[headBody.insert_filelist]; - return _k; - } - auto image_list() { - auto _k = _images; - return _k; - } - auto opt_action_bool() { - bool[string] _k = opts; - return _k; - } - auto environment() { - auto _k = env; - return _k; - } - } - auto doc_matters = DocumentMatters(); - auto t = tuple(doc_abstraction, doc_matters); - static assert(t.length==2); - return t; - } -} diff --git a/src/sdp/abstraction_summary.d b/src/sdp/abstraction_summary.d deleted file mode 100644 index 9532fc7..0000000 --- a/src/sdp/abstraction_summary.d +++ /dev/null @@ -1,81 +0,0 @@ -module sdp.abstraction_summary; -template SiSUabstractionSummary() { - auto SiSUabstractionSummary(S,T)( - auto return ref const S doc_abstraction, - auto return ref T doc_matters, - ) { - import - sdp.ao_defaults, - sdp.ao_rgx; - import - std.array, - std.exception, - std.stdio, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - mixin InternalMarkup; - auto markup = InlineMarkup(); - if (doc_matters.opt_action_bool["verbose"]) { - string[string] check = [ - "last_obj_cite_number" : "NA [debug \"checkdoc\" not run]", - ]; - foreach (k; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[k]) { - if (obj.use != "empty") { - if (!empty(obj.obj_cite_number)) { - check["last_obj_cite_number"] = obj.obj_cite_number; - } - } - } - } - auto min_repeat_number = 66; - auto char_repeat_number = (doc_matters.dochead_meta["title"]["full"].length - + doc_matters.dochead_meta["creator"]["author"].length + 4); - char_repeat_number = (char_repeat_number > min_repeat_number) - ? char_repeat_number - : min_repeat_number; - writefln( - "%s\n\"%s\", %s\n%s\n%s\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n%s%10d\n(%s: %s)\n%s", - markup.repeat_character_by_number_provided("-", char_repeat_number), - doc_matters.dochead_meta["title"]["full"], - doc_matters.dochead_meta["creator"]["author"], - doc_matters.source_filename, - markup.repeat_character_by_number_provided("-", char_repeat_number), - "length toc arr: ", - to!int(doc_abstraction["toc_seg"].length), - "length doc_abstraction arr: ", - to!int(doc_abstraction["body"].length), - "last obj_cite_number: ", - to!int(check["last_obj_cite_number"]), - "length endnotes: ", - (doc_abstraction["endnotes"].length > 1) - ? (to!int(doc_abstraction["endnotes"].length)) - : 0, - "length glossary: ", - (doc_abstraction["glossary"].length > 1) - ? (to!int(doc_abstraction["glossary"].length)) - : 0, - "length biblio: ", - (doc_abstraction["bibliography"].length > 1) - ? (to!int(doc_abstraction["bibliography"].length)) - : 0, - "length bookindex: ", - (doc_abstraction["bookindex_seg"].length > 1) - ? (to!int(doc_abstraction["bookindex_seg"].length)) - : 0, - "length blurb: ", - (doc_abstraction["blurb"].length > 1) - ? (to!int(doc_abstraction["blurb"].length)) - : 0, - __FILE__, - __LINE__, - markup.repeat_character_by_number_provided("-", min_repeat_number), - ); - } - } -} diff --git a/src/sdp/ao/abstract_doc_source.d b/src/sdp/ao/abstract_doc_source.d new file mode 100644 index 0000000..9fee954 --- /dev/null +++ b/src/sdp/ao/abstract_doc_source.d @@ -0,0 +1,5541 @@ +/++ + document abstraction: + abstraction of sisu markup for downstream processing + ao_abstract_doc_source.d ++/ +module sdp.ao.abstract_doc_source; +template SiSUdocAbstraction() { + /+ ↓ abstraction imports +/ + import sdp.ao; + import + std.algorithm, + std.container, + std.file, + std.json, + std.path; + import + sdp.ao.defaults, + sdp.ao.object_setter, + sdp.ao.rgx; + /+ ↓ abstraction mixins +/ + mixin ObjectSetter; + mixin InternalMarkup; + mixin SiSUrgxInit; + /+ ↓ abstraction struct init +/ + /+ initialize +/ + ObjGenericComposite[][string] the_table_of_contents_section; + ObjGenericComposite[] the_document_head_section, the_document_body_section, the_bibliography_section, the_glossary_section, the_blurb_section; + ObjGenericComposite[] the_dom_tail_section; + string[string] an_object, processing; + string an_object_key; + string[] anchor_tags; + string anchor_tag_; + string segment_anchor_tag_that_object_belongs_to; + string segment_anchor_tag_that_object_belongs_to_uri; + /+ enum +/ + enum State { off, on } + enum TriState { off, on, closing } + enum DocStructMarkupHeading { + h_sect_A, + h_sect_B, + h_sect_C, + h_sect_D, + h_text_1, + h_text_2, + h_text_3, + h_text_4, + h_text_5, // extra level, drop + content_non_header + } // header section A-D; header text 1-4 + /+ biblio variables +/ + string biblio_tag_name, biblio_tag_entry, st; + string[] biblio_arr_json; + string biblio_entry_str_json; + JSONValue[] bib_arr_json; + int bib_entry; + /+ counters +/ + int cntr, previous_count, previous_length; + bool reset_note_numbers=true; + int[string] line_occur; + int html_segnames_ptr=0; + int html_segnames_ptr_cntr=0; + int verse_line, heading_ptr; + /+ paragraph attributes +/ + int[string] indent; + bool bullet = true; + string content_non_header = "8"; + auto obj_im = ObjInlineMarkup(); + auto obj_att = ObjAttributes(); + /+ ocn +/ + int obj_cite_number, obj_cite_number_; + auto object_citation_number = OCNemitter(); + int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_markedup_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_collapsed_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + enum DomTags { none, open, close, close_and_open, open_still, } + void heading_ancestors(O)( + auto return ref O obj, + return ref string[] lv_ancestors, + ) { + switch (obj.heading_lev_markup) { + case 0: + lv_ancestors[0] = obj.text.to!string; + foreach(k; 1..8) { + lv_ancestors[k] = ""; + } + goto default; + case 1: + lv_ancestors[1] = obj.text.to!string; + foreach(k; 2..8) { + lv_ancestors[k] = ""; + } + goto default; + case 2: + lv_ancestors[2] = obj.text.to!string; + foreach(k; 3..8) { + lv_ancestors[k] = ""; + } + goto default; + case 3: + lv_ancestors[3] = obj.text.to!string; + foreach(k; 4..8) { + lv_ancestors[k] = ""; + } + goto default; + case 4: + lv_ancestors[4] = obj.text.to!string; + foreach(k; 5..8) { + lv_ancestors[k] = ""; + } + goto default; + case 5: + lv_ancestors[5] = obj.text.to!string; + foreach(k; 6..8) { + lv_ancestors[k] = ""; + } + goto default; + case 6: + lv_ancestors[6] = obj.text.to!string; + lv_ancestors[7] = ""; + goto default; + case 7: + lv_ancestors[7] = obj.text.to!string; + goto default; + default: + obj.heading_ancestors_text = lv_ancestors.dup; + } + } + auto dom_set_markup_tags(int[] dom, int lev) { + foreach (i; 0 .. 8) { + if (i < lev) { + if (dom[i] == DomTags.open + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.open_still; + } else if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } + } else if (i == lev) { + if (lev == 0 + && dom[i] == DomTags.open_still + ) { + dom[i] = DomTags.close; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close_and_open; + } else { + dom[i] = DomTags.open; + } + } else if (i > lev) { + if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close; + } + } + } + debug(dom_magic_numbers) { + writeln("marked up: ", lev, ": ", dom); + } + return dom; + } + auto dom_set_collapsed_tags(int[] dom, int lev) { + foreach (i; 0 .. 8) { + if (i < lev) { + if (dom[i] == DomTags.open + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.open_still; + } else if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } + } else if (i == lev) { + if (lev == 0 + && dom[i] == DomTags.open_still + ) { + dom[i] = DomTags.close; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close_and_open; + } else { + dom[i] = DomTags.open; + } + } else if (i > lev) { + if (dom[i] == DomTags.close) { + dom[i] = DomTags.none; + } else if (dom[i] == DomTags.open + || dom[i] == DomTags.open_still + || dom[i] == DomTags.close_and_open + ) { + dom[i] = DomTags.close; + } + } + } + debug(dom_magic_numbers) { + writeln("collapsed: ", lev, ": ", dom); + } + return dom; + } + int ocn_emit(int ocn_status_flag) { + return object_citation_number.ocn_emitter(ocn_status_flag); + } + /+ book index variables +/ + string book_idx_tmp; + string[][string][string] bookindex_unordered_hashes; + /+ node +/ + ObjGenericComposite comp_obj_heading, comp_obj_location, comp_obj_block, comp_obj_code, comp_obj_poem_ocn, comp_obj_comment; + auto node_construct = NodeStructureMetadata(); + enum sObj { content, anchor_tags, notes_reg, notes_star, links } + /+ ↓ abstract marked up document +/ + auto SiSUdocAbstraction(Src,Make,Meta,Opt)( + Src markup_sourcefile_content, + Make dochead_make_aa, + Meta dochead_meta_aa, + Opt opt_action_bool, + ) { + auto rgx = Rgx(); + debug(asserts) { + static assert(is(typeof(markup_sourcefile_content) == char[][])); + static assert(is(typeof(dochead_make_aa) == string[string][string])); + static assert(is(typeof(dochead_meta_aa) == string[string][string])); + static assert(is(typeof(opt_action_bool) == bool[string])); + } + /+ ↓ abstraction init +/ + scope(success) { + } + scope(failure) { + } + scope(exit) { + destroy(the_document_head_section); + destroy(the_table_of_contents_section); + destroy(the_document_body_section); + destroy(the_bibliography_section); + destroy(an_object); + destroy(processing); + destroy(biblio_arr_json); + previous_length=0; + reset_note_numbers=true; + } + mixin SiSUrgxInitFlags; + mixin SiSUnode; + auto node_para_int_ = node_metadata_para_int; + auto node_para_str_ = node_metadata_para_str; + ObjGenericComposite comp_obj_heading_, comp_obj_para, comp_obj_toc; + line_occur = [ + "heading" : 0, + "para" : 0, + "glossary" : 0, + "blurb" : 0, + ]; + auto type = flags_type_init; + string[string] obj_cite_number_poem = [ + "start" : "", + "end" : "" + ]; + string[] lv_ancestors = [ "", "", "", "", "", "", "", "", ]; + int[string] lv = [ + "lv" : State.off, + "h0" : State.off, + "h1" : State.off, + "h2" : State.off, + "h3" : State.off, + "h4" : State.off, + "h5" : State.off, + "h6" : State.off, + "h7" : State.off, + "lev_int_collapsed" : 0, + ]; + int[string] collapsed_lev = [ + "h0" : State.off, + "h1" : State.off, + "h2" : State.off, + "h3" : State.off, + "h4" : State.off, + "h5" : State.off, + "h6" : State.off, + "h7" : State.off + ]; + string[string] heading_match_str = [ + "h_A": "^(none)", + "h_B": "^(none)", + "h_C": "^(none)", + "h_D": "^(none)", + "h_1": "^(none)", + "h_2": "^(none)", + "h_3": "^(none)", + "h_4": "^(none)" + ]; + auto heading_match_rgx = [ + "h_A": regex(r"^(none)"), + "h_B": regex(r"^(none)"), + "h_C": regex(r"^(none)"), + "h_D": regex(r"^(none)"), + "h_1": regex(r"^(none)"), + "h_2": regex(r"^(none)"), + "h_3": regex(r"^(none)"), + "h_4": regex(r"^(none)") + ]; + string _anchor_tag; + string toc_txt_; + an_object["glossary_nugget"] = ""; + an_object["blurb_nugget"] = ""; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "frontmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Table of Contents"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "toc"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.ptr_html_segnames = html_segnames_ptr; + comp_obj_heading_.anchor_tags = ["toc"]; + auto toc_head = comp_obj_heading_; + html_segnames_ptr_cntr++; + the_table_of_contents_section = [ + "seg": [toc_head], + "scroll": [toc_head], + ]; + auto mkup = InlineMarkup(); + auto munge = ObjInlineMarkupMunge(); + auto note_section = NotesSection(); + auto bookindex_extract_hash = BookIndexNuggetHash(); + string[][string] lev4_subtoc; + string[] html_segnames=["toc"]; + int cnt1 = 1; int cnt2 = 1; int cnt3 = 1; + /+ abstraction init ↑ +/ + /+ ↓ loop markup document/text line by line +/ + srcDocLoop: + foreach (line; markup_sourcefile_content) { + /+ ↓ markup document/text line by line +/ + /+ scope +/ + scope(exit) { + } + scope(failure) { + stderr.writefln( + "%s\n%s\n%s:%s failed here:\n line: %s", + __MODULE__, __FUNCTION__, + __FILE__, __LINE__, + line, + ); + } + 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)) + +/ + debug(source) { // source lines + writeln(line); + } + debug(srclines) { + if (!line.empty) { // source lines, not empty + writefln( + "* %s", + line + ); + } + } + if (!line.empty) { + _check_ocn_status_(line, type); + } + if (type["code"] == TriState.on) { + /+ block object: code +/ + _code_block_(line, an_object, type); + continue; + } else if (!matchFirst(line, rgx.skip_from_regular_parse)) { + /+ object other than "code block" object + (includes regular text paragraph, headings & blocks other than code) +/ + /+ heading, glossary, blurb, poem, group, block, quote, table +/ + if (line.matchFirst(rgx.heading_biblio) + || (type["biblio_section"] == State.on + && (!(line.matchFirst(rgx.heading_blurb_glossary))) + && (!(line.matchFirst(rgx.heading))) + && (!(line.matchFirst(rgx.comment))))) { + /+ within section (block object): biblio +/ + type["glossary_section"] = State.off; + type["biblio_section"] = State.on; + type["blurb_section"] = State.off; + if (opt_action_bool["backmatter"] && opt_action_bool["section_biblio"]) { + _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); + debug(bibliobuild) { + writeln("- ", biblio_entry_str_json); + writeln("-> ", biblio_arr_json.length); + } + } + continue; + } else if (line.matchFirst(rgx.heading_glossary) + || (type["glossary_section"] == State.on + && (!(line.matchFirst(rgx.heading_biblio_blurb))) + && (!(line.matchFirst(rgx.heading))) + && (!(line.matchFirst(rgx.comment))))) { + /+ within section (block object): glossary +/ + debug(glossary) { + writeln(__LINE__); + writeln(line); + } + type["glossary_section"] = State.on; + type["biblio_section"] = State.off; + type["blurb_section"] = State.off; + if (opt_action_bool["backmatter"] && opt_action_bool["section_glossary"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="glossary_nugget"; // + if (line.matchFirst(rgx.heading_glossary)) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Glossary"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "_part_glossary"; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_glossary_section ~= comp_obj_heading_; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Glossary"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "glossary"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 2; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.anchor_tags = ["glossary"]; + the_glossary_section ~= comp_obj_heading_; + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + comp_obj_para = comp_obj_para.init; + comp_obj_para.use = "backmatter"; + comp_obj_para.is_of = "para"; + comp_obj_para.is_a = "glossary"; + comp_obj_para.text = line.to!string.strip; + comp_obj_para.ocn = 0; + comp_obj_para.obj_cite_number = ""; + comp_obj_para.indent_hang = indent["hang_position"]; + comp_obj_para.indent_base = indent["base_position"]; + comp_obj_para.bullet = bullet; + the_glossary_section ~= comp_obj_para; + } + type["ocn_status"] = TriState.off; + } + continue; + } else if (line.matchFirst(rgx.heading_blurb) + || (type["blurb_section"] == State.on + && (!(line.matchFirst(rgx.heading_biblio_glossary))) + && (!(line.matchFirst(rgx.heading))) + && (!(line.matchFirst(rgx.comment))))) { + /+ within section (block object): blurb +/ + debug(blurb) { + writeln(__LINE__); + writeln(line); + } + type["glossary_section"] = State.off; + type["biblio_section"] = State.off; + type["blurb_section"] = State.on; + if (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"]) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + type["para"] = State.on; + line_occur["para"] = State.off; + an_object_key="blurb_nugget"; + if (line.matchFirst(rgx.heading_blurb)) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Blurb"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "_part_blurb"; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_blurb_section ~= comp_obj_heading_; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Blurb"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "blurb"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 2; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.anchor_tags = ["blurb"]; + the_blurb_section ~= comp_obj_heading_; + } else if (line.matchFirst(rgx.heading) + && (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"])) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = line.to!string; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "blurb"; + comp_obj_heading_.marked_up_level = an_object["lev"].to!string; + comp_obj_heading_.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv + comp_obj_heading_.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_blurb_section ~= comp_obj_heading_; + } else { + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + comp_obj_para = comp_obj_para.init; + comp_obj_para.use = "backmatter"; + comp_obj_para.is_of = "para"; + comp_obj_para.is_a = "blurb"; + comp_obj_para.text = line.to!string.strip; + comp_obj_para.ocn = 0; + comp_obj_para.obj_cite_number = ""; + comp_obj_para.indent_hang = indent["hang_position"]; + comp_obj_para.indent_base = indent["base_position"]; + comp_obj_para.bullet = bullet; + the_blurb_section ~= comp_obj_para; + } + type["ocn_status"] = TriState.off; + } + continue; + } else if (type["quote"] == TriState.on) { + /+ within block object: quote +/ + _quote_block_(line, an_object, type); + continue; + /+ within block object: group +/ + } else if (type["group"] == TriState.on) { + /+ within block object: group +/ + line = (line) + .replaceAll(rgx.para_delimiter, mkup.br_paragraph ~ "$1"); + _group_block_(line, an_object, type); + continue; + } else if (type["block"] == TriState.on) { + /+ within block object: block +/ + if (auto m = line.match(rgx.spaces_line_start)) { + line = (line) + .replaceAll(rgx.spaces_line_start, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); + } + if (auto m = line.match(rgx.spaces_multiple)) { + line = (line) + .replaceAll(rgx.spaces_multiple, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); + } + _block_block_(line, an_object, type); + continue; + } else if (type["poem"] == TriState.on) { + /+ within block object: poem +/ + _poem_block_(line, an_object, type, cntr, obj_cite_number_poem, dochead_make_aa); + continue; + } else if (type["table"] == TriState.on) { + /+ within block object: table +/ + _table_block_(line, an_object, type, dochead_make_aa); + continue; + } else { + /+ not within a block group +/ + assert( + (type["blocks"] == TriState.off) + || (type["blocks"] == TriState.closing), + "block status: none or closed" + ); + assertions_flag_types_block_status_none_or_closed(type); + if (line.matchFirst(rgx.block_open)) { + if (line.matchFirst(rgx.block_poem_open)) { + /+ poem to verse exceptions! +/ + object_reset(an_object); + processing.remove("verse"); + obj_cite_number_poem["start"] = obj_cite_number.to!string; + } + _start_block_(line, type, obj_cite_number_poem); + continue; + } else if (!line.empty) { + /+ line not empty +/ + /+ non blocks (headings, paragraphs) & closed blocks +/ + assert( + !line.empty, + "line tested, line not empty surely:\n \"" ~ line ~ "\"" + ); + assert( + (type["blocks"] == TriState.off) + || (type["blocks"] == TriState.closing), + "code block status: none or closed" + ); + if (type["blocks"] == TriState.closing) { + debug(check) { // block + writeln(__LINE__); + writeln(line); + } + assert( + line.matchFirst(rgx.book_index) + || line.matchFirst(rgx.book_index_open) + || type["book_index"] == State.on, + "\nblocks closed, unless followed by book index, non-matching line:\n \"" + ~ line ~ "\"" + ); + } + if (line.matchFirst(rgx.book_index) + || line.matchFirst(rgx.book_index_open) + || type["book_index"] == State.on ) { + /+ book_index +/ + _book_index_(line, book_idx_tmp, an_object, type, opt_action_bool); + } else { + /+ not book_index +/ + an_object_key="body_nugget"; + if (auto m = matchFirst(line, rgx.comment)) { + /+ matched comment +/ + debug(comment) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + comp_obj_comment = comp_obj_comment.init; + comp_obj_comment.use = "comment"; + comp_obj_comment.is_of = "comment"; + comp_obj_comment.is_a = "comment"; + comp_obj_comment.text = an_object[an_object_key].strip; + the_document_body_section ~= comp_obj_comment; + _common_reset_(line_occur, an_object, type); + processing.remove("verse"); + ++cntr; + } else if (((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((type["para"] == State.off) + && (type["heading"] == State.off))) { + /+ heading or para but neither flag nor line exists +/ + if ((dochead_make_aa["make"]["headings"].length > 2) + && (type["make_headings"] == State.off)) { + /+ heading found +/ + _heading_found_(line, dochead_make_aa["make"]["headings"], heading_match_str, heading_match_rgx, type); + } + if ((type["make_headings"] == State.on) + && ((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((type["para"] == State.off) + && (type["heading"] == State.off))) { + /+ heading make set +/ + 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?) + +/ + if (line.matchFirst(rgx.heading)) { + /+ heading match +/ + _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); + } else if (line_occur["para"] == State.off) { + /+ para match +/ + an_object_key="body_nugget"; + _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); + } + } else if (line_occur["heading"] > State.off) { + /+ heading +/ + debug(heading) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + ++line_occur["heading"]; + } else if (line_occur["para"] > State.off) { + /+ paragraph +/ + debug(para) { + writeln(an_object_key, "-> ", line); + } + an_object[an_object_key] ~= " " ~ line; + ++line_occur["para"]; + } + } + } else if (type["blocks"] == TriState.closing) { + /+ line empty, with blocks flag +/ + _block_flag_line_empty_( + bookindex_extract_hash, + line, + an_object, + the_document_body_section, + bookindex_unordered_hashes, + obj_cite_number, + comp_obj_heading, + cntr, + type, + obj_cite_number_poem, + dochead_make_aa + ); + } else { + /+ line.empty, post contents, empty variables: +/ + assert( + line.empty, + "\nline should be empty:\n \"" + ~ line ~ "\"" + ); + assert( + (type["blocks"] == State.off), + "code block status: none" + ); + if ((type["heading"] == State.on) + && (line_occur["heading"] > State.off)) { + /+ heading object (current line empty) +/ + obj_cite_number = (an_object["lev_markup_number"].to!int == 0) + ? (ocn_emit(3)) + : (obj_cite_number = ocn_emit(type["ocn_status"])); + an_object["is"] = "heading"; + an_object_key="body_nugget"; + auto substantive_object_and_anchor_tags_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_object_and_anchor_tags_tuple[sObj.content]; + anchor_tags = substantive_object_and_anchor_tags_tuple[sObj.anchor_tags]; + if (an_object["lev_markup_number"].to!int == 4) { + segment_anchor_tag_that_object_belongs_to = anchor_tags[0]; + segment_anchor_tag_that_object_belongs_to_uri = anchor_tags[0] ~ ".fnSuffix"; + anchor_tag_ = anchor_tags[0]; + } else if (an_object["lev_markup_number"].to!int > 4) { + segment_anchor_tag_that_object_belongs_to = anchor_tag_; + segment_anchor_tag_that_object_belongs_to_uri = anchor_tag_ ~ ".fnSuffix#" ~ obj_cite_number.to!string; + } else if (an_object["lev_markup_number"].to!int < 4) { + string segn; + switch (an_object["lev_markup_number"].to!int) { + case 0: + segn = "_the_title"; + goto default; + case 1: + segn = "_part_" ~ cnt1.to!string; + ++cnt1; + goto default; + case 2: + segn = "_part_" ~ cnt1.to!string ~ "_" ~ cnt2.to!string; + ++cnt2; + goto default; + case 3: + segn = "_part_" ~ cnt1.to!string ~ "_" ~ cnt2.to!string ~ "_" ~ cnt3.to!string; + ++cnt3; + goto default; + default: + segment_anchor_tag_that_object_belongs_to = segn; + segment_anchor_tag_that_object_belongs_to_uri = segn ~ ".fnSuffix"; + break; + } + } + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash(an_object["bookindex_nugget"], obj_cite_number, segment_anchor_tag_that_object_belongs_to); + /+ (incrementally build toc) table of contents here! +/ + _anchor_tag=to!string(obj_cite_number); + the_table_of_contents_section = obj_im.table_of_contents_gather_headings( + an_object, + dochead_make_aa, + segment_anchor_tag_that_object_belongs_to, + _anchor_tag, + lev4_subtoc, + the_table_of_contents_section, + ); + if (an_object["lev_markup_number"] == "4") { + html_segnames ~= segment_anchor_tag_that_object_belongs_to; + html_segnames_ptr = html_segnames_ptr_cntr; + html_segnames_ptr_cntr++; + } + auto comp_obj_heading = + node_construct.node_emitter_heading( + an_object["substantive"], // string + an_object["lev"], // string + an_object["lev_markup_number"], // string + an_object["lev_collapsed_number"], // string + segment_anchor_tag_that_object_belongs_to, // string + obj_cite_number, // int + cntr, // int + heading_ptr, // int + lv_ancestors, // string[] + an_object["is"], // string + html_segnames_ptr, // int + substantive_object_and_anchor_tags_tuple[sObj.notes_reg], + substantive_object_and_anchor_tags_tuple[sObj.notes_star], + substantive_object_and_anchor_tags_tuple[sObj.links], + ); + ++heading_ptr; + debug(segments) { + writeln(an_object["lev_markup_number"]); + writeln(segment_anchor_tag_that_object_belongs_to); + } + the_document_body_section ~= comp_obj_heading; + debug(objectrelated1) { // check + writeln(line); + } + _common_reset_(line_occur, an_object, type); + an_object.remove("lev"); + an_object.remove("lev_markup_number"); + processing.remove("verse"); + ++cntr; + } else if ((type["para"] == State.on) + && (line_occur["para"] > State.off)) { + /+ paragraph object (current line empty) +/ + obj_cite_number = ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash(an_object["bookindex_nugget"], obj_cite_number, segment_anchor_tag_that_object_belongs_to); + an_object["is"] = "para"; + auto comp_obj_heading = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"], + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_para = comp_obj_para.init; + comp_obj_para.use = "body"; + comp_obj_para.is_of = "para"; + comp_obj_para.is_a = "para"; + comp_obj_para.text = an_object["substantive"].to!string.strip; + comp_obj_para.ocn = obj_cite_number; + comp_obj_para.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_para.indent_hang = indent["hang_position"]; + comp_obj_para.indent_base = indent["base_position"]; + comp_obj_para.bullet = bullet; + comp_obj_para.anchor_tags = anchor_tags; + comp_obj_para.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_para.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_para.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_para; + _common_reset_(line_occur, an_object, type); + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + processing.remove("verse"); + ++cntr; + } else { + assert( + line == null, + "line variable should be empty, should not occur" + ); + } + } // close else for line empty + } // close else for not the above + } // close after non code, other blocks or regular text + /+ unless (the_document_body_section.length == 0) ? +/ + if (the_document_body_section.length > 0) { + if (((the_document_body_section[$-1].is_a == "para") + || (the_document_body_section[$-1].is_a == "heading") + || (the_document_body_section[$-1].is_a == "quote") + || (the_document_body_section[$-1].is_a == "group") + || (the_document_body_section[$-1].is_a == "block") + || (the_document_body_section[$-1].is_a == "verse")) + && (the_document_body_section.length > previous_length)) { + if ((the_document_body_section[$-1].is_a == "heading") + && (the_document_body_section[$-1].heading_lev_markup < 5)) { + type["biblio_section"] = State.off; + type["glossary_section"] = State.off; + type["blurb_section"] = State.off; + } + if (the_document_body_section[$-1].is_a == "verse") { + /+ scan for endnotes for whole poem (each verse in poem) +/ + foreach (i; previous_length .. the_document_body_section.length) { + if (the_document_body_section[i].is_a == "verse") { + if ((the_document_body_section[i].text).match( + rgx.inline_notes_delimiter_al_regular_number_note + )) { + note_section.gather_notes_for_endnote_section( + the_document_body_section, + segment_anchor_tag_that_object_belongs_to, + to!int(i), + ); + } + } + } + } else { + /+ scan object for endnotes +/ + previous_length = the_document_body_section.length.to!int; + if ((the_document_body_section[$-1].text).match( + rgx.inline_notes_delimiter_al_regular_number_note + )) { + previous_count=(the_document_body_section.length -1).to!int; + note_section.gather_notes_for_endnote_section( + the_document_body_section, + segment_anchor_tag_that_object_belongs_to, + to!int(the_document_body_section.length-1), + ); + } + } + previous_length = the_document_body_section.length.to!int; + } + } + } /+ ← closed: loop markup document/text line by line +/ + /+ ↓ post loop markup document/text +/ + auto en_tuple = + note_section.endnote_objects(obj_cite_number, opt_action_bool); + static assert(!isTypeTuple!(en_tuple)); + auto the_endnotes_section = en_tuple[0]; + obj_cite_number = en_tuple[1]; + debug(endnotes) { + writefln( + "%s %s", + __LINE__, + the_endnotes_section.length + ); + foreach (o; the_endnotes_section) { + writeln(o); + } + } + if (an_object["glossary_nugget"].length == 0) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "empty"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Glossary section"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_glossary_section ~= comp_obj_heading_; + } else { + writeln("gloss"); + } + debug(glossary) { + foreach (gloss; the_glossary_section) { + writeln(gloss.text); + } + } + auto biblio_unsorted_incomplete = biblio_arr_json.dup; + auto biblio = Bibliography(); + auto biblio_ordered = + biblio._bibliography_(biblio_unsorted_incomplete, bib_arr_json); + if (biblio_ordered.length > 0) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Bibliography"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "_part_bibliography"; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + 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"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Bibliography"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "bibliography"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 2; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.anchor_tags = ["bibliography"]; + the_bibliography_section ~= comp_obj_heading_; + } else { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "empty"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Bibliography"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_bibliography_section ~= comp_obj_heading_; + } + string out_; + foreach (entry; biblio_ordered) { + out_ = format( + "%s \"%s\"%s%s%s%s%s%s%s%s%s.", + ((entry["author"].str.empty) ? entry["editor"].str : entry["author"].str), + entry["fulltitle"].str, + ((entry["journal"].str.empty) ? "" : ", /{" ~ entry["journal"].str ~ "}/"), + ((entry["volume"].str.empty) ? "" : ", " ~ entry["volume"].str), + ((entry["in"].str.empty) ? "" : ", " ~ entry["in"].str), + ((!(entry["author"].str.empty) && (!(entry["editor"].str.empty))) ? entry["editor"].str : ""), + ", " ~ entry["year"].str, + ((entry["pages"].str.empty) ? "" : ", " ~ entry["pages"].str), + ((entry["publisher"].str.empty) ? "" : ", " ~ entry["publisher"].str), + ((entry["place"].str.empty) ? "" : ", " ~ entry["place"].str), + ((entry["url"].str.empty) ? "" : ", [" ~ entry["url"].str ~ "]"), + ); + comp_obj_para = comp_obj_para.init; + comp_obj_para.use = "backmatter"; + comp_obj_para.is_of = "para"; + comp_obj_para.is_a = "bibliography"; + comp_obj_para.text = out_.to!string.strip; + comp_obj_para.ocn = 0; + comp_obj_para.obj_cite_number = ""; + comp_obj_para.indent_hang = 0; + comp_obj_para.indent_base = 1; + comp_obj_para.bullet = bullet; + comp_obj_para.anchor_tags = anchor_tags; + the_bibliography_section ~= comp_obj_para; + } + debug(bibliosection) { + foreach (o; the_bibliography_section) { + writeln(o.text); + } + } + auto bi = BookIndexReportSection(); + auto bi_tuple = + bi.bookindex_build_abstraction_section( + bookindex_unordered_hashes, + obj_cite_number, + opt_action_bool, + ); + destroy(bookindex_unordered_hashes); + static assert(!isTypeTuple!(bi_tuple)); + auto the_bookindex_section = bi_tuple[0]; + obj_cite_number = bi_tuple[1]; + debug(bookindex) { + foreach (bi_entry; the_bookindex_section["seg"]) { + writeln(bi_entry); + } + } + if (an_object["blurb_nugget"].length == 0) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "empty"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Blurb section"; + comp_obj_heading_.ocn = 0; + comp_obj_para.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = ""; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_blurb_section ~= comp_obj_heading_; + } + debug(blurb) { + foreach (blurb; the_blurb_section) { + writeln(blurb.text); + } + } + indent=[ + "hang_position" : 1, + "base_position" : 1, + ]; + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.use = "frontmatter"; + comp_obj_toc.is_of = "para"; + comp_obj_toc.is_a = "toc"; + comp_obj_toc.ocn = 0; + comp_obj_toc.obj_cite_number = ""; + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.bullet = false; + if (the_endnotes_section.length > 1) { + toc_txt_ = format( + "{ %s }%s%s%s", + "Endnotes", + mkup.mark_internal_site_lnk, + "endnotes", // segment_anchor_tag_that_object_belongs_to + ".fnSuffix", + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + } + if (the_glossary_section.length > 1) { + toc_txt_ = format( + "{ %s }%s%s%s", + "Glossary", + mkup.mark_internal_site_lnk, + "glossary", // segment_anchor_tag_that_object_belongs_to + ".fnSuffix", + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + toc_txt_ = format( + "{ %s }#%s", + "Glossary", + "glossary", // _anchor_tag + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } + if (the_bibliography_section.length > 1){ + toc_txt_ = format( + "{ %s }%s%s%s", + "Bibliography", + mkup.mark_internal_site_lnk, + "bibliography", // segment_anchor_tag_that_object_belongs_to + ".fnSuffix", + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + + toc_txt_ = format( + "{ %s }#%s", + "Bibliography", + "bibliography", // _anchor_tag + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } + if (the_bookindex_section["seg"].length > 1) { + toc_txt_ = format( + "{ %s }%s%s%s", + "Book Index", + mkup.mark_internal_site_lnk, + "bookindex", // segment_anchor_tag_that_object_belongs_to + ".fnSuffix", + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + } + if (the_bookindex_section["scroll"].length > 1) { + toc_txt_ = format( + "{ %s }#%s", + "Book Index", + "bookindex", // _anchor_tag + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } + if (the_blurb_section.length > 1) { + toc_txt_ = format( + "{ %s }%s%s%s", + "Blurb", + mkup.mark_internal_site_lnk, + "blurb", // segment_anchor_tag_that_object_belongs_to + ".fnSuffix", + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + toc_txt_ = format( + "{ %s }#%s", + "Blurb", + "blurb", // _anchor_tag + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.inline_links = true; + comp_obj_toc.text = toc_txt_.to!string.strip; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } + debug(toc) { + writefln( + "%s %s", + __LINE__, + the_table_of_contents_section["seg"].length + ); + foreach (toc_linked_heading; the_table_of_contents_section["seg"]) { + writeln(mkup.indent_by_spaces_provided(toc_linked_heading.indent_hang), toc_linked_heading.text); + } + } + debug(tocscroll) { + writefln( + "%s %s", + __LINE__, + the_table_of_contents_section["seg"].length + ); + foreach (toc_linked_heading; the_table_of_contents_section["scroll"]) { + writeln(mkup.indent_by_spaces_provided(toc_linked_heading.indent_hang), toc_linked_heading.text); + } + } + the_document_head_section ~= the_document_body_section[0]; + the_document_body_section=the_document_body_section[1..$]; + if (the_endnotes_section.length > 1) { + html_segnames ~= "endnotes"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref section; the_endnotes_section) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; + } + if (the_glossary_section.length > 1) { + html_segnames ~= "glossary"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref section; the_glossary_section) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; + } + if (the_bibliography_section.length > 1) { + html_segnames ~= "bibliography"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref section; the_bibliography_section) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; + } + if (the_bookindex_section["scroll"].length > 1) { + html_segnames ~= "bookindex"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref section; the_bookindex_section["scroll"]) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + foreach (ref section; the_bookindex_section["seg"]) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; + } + if (the_blurb_section.length > 1) { + html_segnames ~= "blurb"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref section; the_blurb_section) { + if (section.heading_lev_markup == 4) { + section.ptr_html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; + } + string[] _images; + auto extract_images(S)(S content_block) { + string[] images_; + if (auto m = content_block.matchAll(rgx.image)) { + images_ ~= m.captures[1]; + } + return images_; + } + string[] segnames_0_4; + foreach (ref obj; the_document_head_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + if (the_table_of_contents_section["scroll"].length > 1) { + dom_markedup_buffer = dom_markedup.dup; + dom_collapsed_buffer = dom_collapsed.dup; + foreach (ref obj; the_table_of_contents_section["scroll"]) { + if (obj.is_a == "heading") { + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + dom_markedup = dom_markedup_buffer.dup; + dom_collapsed = dom_collapsed_buffer.dup; + foreach (ref obj; the_table_of_contents_section["seg"]) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + } + /+ multiple 1~ levels, loop through document body +/ + if (the_document_body_section.length > 1) { + foreach (ref obj; the_document_body_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.lev4_subtoc = lev4_subtoc[obj.segment_anchor_tag]; + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } else if (obj.is_a == "para") { + _images ~= extract_images(obj.text); + } + } + } + auto images=uniq(_images.sort()); + /+ optional only one 1~ level +/ + if (the_endnotes_section.length > 1) { + dom_markedup_buffer = dom_markedup.dup; + dom_collapsed_buffer = dom_collapsed.dup; + dom_markedup = dom_markedup_buffer.dup; + dom_collapsed = dom_collapsed_buffer.dup; + foreach (ref obj; the_endnotes_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + } + /+ optional only one 1~ level +/ + if (the_glossary_section.length > 1) { + foreach (ref obj; the_glossary_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + } + /+ optional only one 1~ level +/ + if (the_bibliography_section.length > 1) { + foreach (ref obj; the_bibliography_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + } + /+ optional only one 1~ level +/ + if (the_bookindex_section["scroll"].length > 1) { + dom_markedup_buffer = dom_markedup.dup; + dom_collapsed_buffer = dom_collapsed.dup; + foreach (ref obj; the_bookindex_section["scroll"]) { + if (obj.is_a == "heading") { + debug(dom) { + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + dom_markedup = dom_markedup_buffer.dup; + dom_collapsed = dom_collapsed_buffer.dup; + foreach (ref obj; the_bookindex_section["seg"]) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + } + /+ optional only one 1~ level +/ + if (the_blurb_section.length > 1) { + foreach (ref obj; the_blurb_section) { + if (obj.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.heading_lev_markup <= 4) { + segnames_0_4 ~= obj.segment_anchor_tag; + if (obj.heading_lev_markup == 4) { + obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; + if (html_segnames.length > obj.ptr_html_segnames + 1) { + obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; + } + assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); + } + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + obj.dom_markedup = + dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; + obj.dom_collapsed = + dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; + } + heading_ancestors(obj, lv_ancestors); + } + } + /+ TODO + - note create/insert heading object sole purpose eof close all open tags + sort out: + - obj.dom_markedup = dom_markedup; + - obj.dom_collapsed = dom_collapsed; + +/ + dom_markedup = dom_set_markup_tags(dom_markedup, 0); + dom_collapsed = dom_set_collapsed_tags(dom_collapsed, 0); + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "empty"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.ocn = 0; + comp_obj_para.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = ""; + comp_obj_heading_.marked_up_level = ""; + comp_obj_heading_.heading_lev_markup = 9; + comp_obj_heading_.heading_lev_collapsed = 9; + comp_obj_heading_.parent_ocn = 0; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.dom_markedup = dom_markedup.dup; + comp_obj_heading_.dom_collapsed = dom_collapsed.dup; + the_dom_tail_section ~= comp_obj_heading_; + } + auto document_the = [ + "head": the_document_head_section, + "toc_seg": the_table_of_contents_section["seg"], + "toc_scroll": the_table_of_contents_section["scroll"], + /+ substantive/body: +/ + "body": the_document_body_section, + /+ backmatter: +/ + "endnotes": the_endnotes_section, + "glossary": the_glossary_section, + "bibliography": the_bibliography_section, + "bookindex_scroll": the_bookindex_section["scroll"], + "bookindex_seg": the_bookindex_section["seg"], + "blurb": the_blurb_section, + /+ dom tail only +/ + "tail": the_dom_tail_section, + ]; + string[][string] document_section_keys_sequenced = [ + "seg": ["head", "toc_seg", "body",], + "scroll": ["head", "toc_scroll", "body",] + ]; + if (document_the["endnotes"].length > 1) { + document_section_keys_sequenced["seg"] ~= "endnotes"; + document_section_keys_sequenced["scroll"] ~= "endnotes"; + } + if (document_the["glossary"].length > 1) { + document_section_keys_sequenced["seg"] ~= "glossary"; + document_section_keys_sequenced["scroll"] ~= "glossary"; + } + if (document_the["bibliography"].length > 1) { + document_section_keys_sequenced["seg"] ~= "bibliography"; + document_section_keys_sequenced["scroll"] ~= "bibliography"; + } + if (document_the["bookindex_seg"].length > 1) { + document_section_keys_sequenced["seg"] ~= "bookindex_seg"; + } + if (document_the["bookindex_scroll"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "bookindex_scroll"; + } + if (document_the["blurb"].length > 1) { + document_section_keys_sequenced["seg"] ~= "blurb"; + document_section_keys_sequenced["scroll"] ~= "blurb"; + } + if ((opt_action_bool["html"]) + || (opt_action_bool["html_scroll"]) + || (opt_action_bool["html_seg"]) + || (opt_action_bool["epub"])) { + document_section_keys_sequenced["seg"] ~= "tail"; + document_section_keys_sequenced["scroll"] ~= "tail"; + } + auto segnames = html_segnames.dup; + destroy(the_document_head_section); + destroy(the_table_of_contents_section); + destroy(the_document_body_section); + destroy(the_endnotes_section); + destroy(the_glossary_section); + destroy(the_bibliography_section); + destroy(the_bookindex_section); + destroy(the_blurb_section); + destroy(html_segnames); + destroy(bookindex_unordered_hashes); + destroy(an_object); + biblio_arr_json = []; + obj_cite_number=0; + obj_cite_number_=0; + html_segnames_ptr=0; + html_segnames_ptr_cntr=0; + content_non_header = "8"; + dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + dom_markedup_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + dom_collapsed_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; + auto t = tuple( + document_the, + docSectKeysSeq!()(document_section_keys_sequenced), + segnames, + segnames_0_4, + images, + ); + return t; + /+ post loop markup document/text ↑ +/ + } /+ ← closed: abstract doc source +/ + /+ ↓ abstraction functions +/ + auto object_reset(O)(ref O an_object) { + debug(asserts) { + static assert(is(typeof(an_object) == string[string])); + } + an_object.remove("body_nugget"); + an_object.remove("substantive"); + an_object.remove("is"); + an_object.remove("attrib"); + an_object.remove("bookindex_nugget"); + } + auto _common_reset_(L,O,T)( + return ref L line_occur, + return ref O an_object, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line_occur) == int[string])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + line_occur["heading"] = State.off; + line_occur["para"] = State.off; + type["heading"] = State.off; + type["para"] = State.off; + object_reset(an_object); + } + void _check_ocn_status_(L,T)( + L line, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if ((!line.empty) && (type["ocn_status_multi_obj"] == TriState.off)) { + /+ not multi-line object, check whether obj_cite_number is on or turned off +/ + if (line.matchFirst(rgx.obj_cite_number_block_marks)) { + /+ switch off obj_cite_number +/ + if (line.matchFirst(rgx.obj_cite_number_off_block)) { + type["ocn_status_multi_obj"] = TriState.on; + debug(ocnoff) { + writeln(line); + } + } + if (line.matchFirst(rgx.obj_cite_number_off_block_dh)) { + type["ocn_status_multi_obj"] = TriState.closing; + debug(ocnoff) { + writeln(line); + } + } + } else { + if (type["ocn_status_multi_obj"] == TriState.off) { + if (line.matchFirst(rgx.obj_cite_number_off)) { + type["ocn_status"] = TriState.on; + } else if (line.matchFirst(rgx.obj_cite_number_off_dh)) { + type["ocn_status"] = TriState.closing; + } else { + type["ocn_status"] = TriState.off; + } + } else { + type["ocn_status"] = + type["ocn_status_multi_obj"]; + } + } + } else if ((!line.empty) && (type["ocn_status_multi_obj"] > TriState.off)) { + if (line.matchFirst(rgx.obj_cite_number_off_block_close)) { + type["ocn_status_multi_obj"] = TriState.off; + type["ocn_status"] = TriState.off; + debug(ocnoff) { + writeln(line); + } + } + } + } + void _start_block_(L,T,N)( + L line, + return ref T type, + N obj_cite_number_poem + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(type) == int[string])); + static assert(is(typeof(obj_cite_number_poem) == string[string])); + } + auto rgx = Rgx(); + string code_block_syntax = ""; + bool code_block_numbered = false; + if (auto m = line.matchFirst(rgx.block_curly_code_open)) { + /+ curly code open +/ + code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; + code_block_numbered = (m.captures[2] == "#") ? true : false; + debug(code) { // code (curly) open + writefln( + "* [code curly] %s", + line + ); + } + type["blocks"] = TriState.on; + type["code"] = TriState.on; + type["curly_code"] = TriState.on; + } else if (line.matchFirst(rgx.block_curly_poem_open)) { + /+ curly poem open +/ + debug(poem) { // poem (curly) open + writefln( + "* [poem curly] %s", + line + ); + } + obj_cite_number_poem["start"] = + obj_cite_number.to!string; + type["blocks"] = TriState.on; + type["verse_new"] = State.on; + type["poem"] = TriState.on; + type["curly_poem"] = TriState.on; + } else if (line.matchFirst(rgx.block_curly_group_open)) { + /+ curly group open +/ + debug(group) { // group (curly) open + writefln( + "* [group curly] %s", + line + ); + } + type["blocks"] = TriState.on; + type["group"] = TriState.on; + type["curly_group"] = TriState.on; + } else if (line.matchFirst(rgx.block_curly_block_open)) { + /+ curly block open +/ + debug(block) { // block (curly) open + writefln( + "* [block curly] %s", + line + ); + } + type["blocks"] = TriState.on; + type["block"] = TriState.on; + type["curly_block"] = TriState.on; + } else if (line.matchFirst(rgx.block_curly_quote_open)) { + /+ curly quote open +/ + debug(quote) { // quote (curly) open + writefln( + "* [quote curly] %s", + line + ); + } + type["blocks"] = TriState.on; + type["quote"] = TriState.on; + type["curly_quote"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_curly_table_open)) { + /+ curly table open +/ + debug(table) { // table (curly) open + writefln( + "* [table curly] %s", + line + ); + } + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "curly"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["curly_table"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { + /+ table: special table block markup syntax! +/ + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "special"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["curly_table_special_markup"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_tic_code_open)) { + /+ tic code open +/ + code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; + code_block_numbered = (m.captures[2] == "#") ? true : false; + debug(code) { // code (tic) open + writefln( + "* [code tic] %s", + line + ); + } + type["blocks"] = TriState.on; + type["code"] = TriState.on; + type["tic_code"] = TriState.on; + } else if (line.matchFirst(rgx.block_tic_poem_open)) { + /+ tic poem open +/ + debug(poem) { // poem (tic) open + writefln( + "* [poem tic] %s", + line + ); + } + obj_cite_number_poem["start"] = obj_cite_number.to!string; + type["blocks"] = TriState.on; + type["verse_new"] = State.on; + type["poem"] = TriState.on; + type["tic_poem"] = TriState.on; + } else if (line.matchFirst(rgx.block_tic_group_open)) { + /+ tic group open +/ + debug(group) { // group (tic) open + writefln( + "* [group tic] %s", + line + ); + } + type["blocks"] = TriState.on; + type["group"] = TriState.on; + type["tic_group"] = TriState.on; + } else if (line.matchFirst(rgx.block_tic_block_open)) { + /+ tic block open +/ + debug(block) { // block (tic) open + writefln( + "* [block tic] %s", + line + ); + } + type["blocks"] = TriState.on; + type["block"] = TriState.on; + type["tic_block"] = TriState.on; + } else if (line.matchFirst(rgx.block_tic_quote_open)) { + /+ tic quote open +/ + debug(quote) { // quote (tic) open + writefln( + "* [quote tic] %s", + line + ); + } + type["blocks"] = TriState.on; + type["quote"] = TriState.on; + type["tic_quote"] = TriState.on; + } else if (auto m = line.matchFirst(rgx.block_tic_table_open)) { + /+ tic table open +/ + debug(table) { // table (tic) open + writefln( + "* [table tic] %s", + line + ); + } + an_object["table_head"] = m.captures[1].to!string; + an_object["block_type"] = "tic"; + type["blocks"] = TriState.on; + type["table"] = TriState.on; + type["tic_table"] = TriState.on; + } + } + void _quote_block_(L,O,T)( + return ref L line, + return ref O an_object, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if (type["curly_quote"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_quote_close)) { + 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; + } else { + debug(quote) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + } + } else if (type["tic_quote"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + 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; + } else { + debug(quote) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + } + } + } + void _group_block_(L,O,T)( + return ref L line, + return ref O an_object, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if (type["curly_group"] == State.on) { + if (line.matchFirst(rgx.block_curly_group_close)) { + 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; + } else { + debug(group) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) + } + } else if (type["tic_group"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + 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; + } else { + debug(group) { // group + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) + } + } + } + void _block_block_(L,O,T)( + return ref L line, + return ref O an_object, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if (type["curly_block"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_block_close)) { + 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; + } else { + debug(block) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) + } + } else if (type["tic_block"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + 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; + } else { + debug(block) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) + } + } + } + void _poem_block_(L,O,T,C,N,Ma)( + L line, + return ref O an_object, + return ref T type, + return ref C cntr, + N obj_cite_number_poem, + Ma dochead_make_aa, + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + static assert(is(typeof(cntr) == int)); + static assert(is(typeof(obj_cite_number_poem) == string[string])); + static assert(is(typeof(dochead_make_aa) == string[string][string])); + } + auto rgx = Rgx(); + if (type["curly_poem"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_poem_close)) { + if (an_object_key in an_object + || processing.length > 0) { + an_object[an_object_key] = ""; + debug(poem) { // poem (curly) close + writefln( + "* [poem curly] %s", + line + ); + } + if (processing.length > 0) { + an_object[an_object_key] = processing["verse"]; + } + debug(poem) { // poem (curly) close + writeln(__LINE__); + writefln( + "* %s %s", + obj_cite_number, + line + ); + } + if (an_object.length > 0) { + debug(poem) { // poem (curly) close + writeln( + obj_cite_number, + an_object[an_object_key] + ); + } + an_object["is"] = "verse"; + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "verse"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + } + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + obj_cite_number_poem["end"] = + obj_cite_number.to!string; + type["blocks"] = TriState.closing; + type["poem"] = TriState.closing; + type["curly_poem"] = TriState.off; + } else { + processing["verse"] ~= line ~= "\n"; + if (type["verse_new"] == State.on) { + obj_cite_number = + 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; + } + if (type["verse_new"] == State.on) { + verse_line=1; + an_object[an_object_key] = processing["verse"]; + debug(poem) { // poem verse + writefln( + "* %s curly\n%s", + obj_cite_number, + an_object[an_object_key] + ); + } + processing.remove("verse"); + an_object["is"] = "verse"; + auto comp_obj_location = node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "verse"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + } + } else if (type["tic_poem"] == TriState.on) { + if (auto m = line.matchFirst(rgx.block_tic_close)) { // tic_poem_close + an_object[an_object_key]="verse"; + debug(poem) { // poem (curly) close + writefln( + "* [poem tic] %s", + line + ); + } + if (processing.length > 0) { + an_object[an_object_key] = processing["verse"]; + } + if (an_object.length > 0) { + debug(poem) { // poem (tic) close + writeln(__LINE__); + writeln(obj_cite_number, line); + } + processing.remove("verse"); + an_object["is"] = "verse"; + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "verse"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + obj_cite_number_poem["end"] = obj_cite_number.to!string; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + type["blocks"] = TriState.closing; + type["poem"] = TriState.closing; + type["tic_poem"] = TriState.off; + } else { + processing["verse"] ~= line ~= "\n"; + if (type["verse_new"] == State.on) { + obj_cite_number = + 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; + } + if (type["verse_new"] == State.on) { + verse_line=1; + an_object[an_object_key] = processing["verse"]; + debug(poem) { // poem (tic) close + writefln( + "* %s tic\n%s", + obj_cite_number, + an_object[an_object_key] + ); + } + processing.remove("verse"); + an_object["is"] = "verse"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "verse"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + } + } + } + void _code_block_(L,O,T)( + return ref L line, + return ref O an_object, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if (type["curly_code"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_code_close)) { + 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; + } else { + debug(code) { // code (curly) line + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // code (curly) line + } + } else if (type["tic_code"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + 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; + } else { + debug(code) { // code (tic) line + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // code (tic) line + } + } + } + void _table_block_(L,O,T,Ma)( + return ref L line, + return ref O an_object, + return ref T type, + return ref Ma dochead_make_aa + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if (type["curly_table"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_table_close)) { + debug(table) { // table (curly) close + writeln(line); + } + type["blocks"] = TriState.closing; + type["table"] = TriState.closing; + type["curly_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } else if (type["curly_table_special_markup"] == TriState.on) { + if (line.empty) { + type["blocks"] = TriState.off; + type["table"] = TriState.off; + type["curly_table_special_markup"] = TriState.off; + _table_closed_make_special_notation_table_( + line, + an_object, + the_document_body_section, + obj_cite_number, + comp_obj_heading, + cntr, + type, + dochead_make_aa + ); + } else { + debug(table) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + } + } else if (type["tic_table"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + debug(table) { // table (tic) close + writeln(line); + } + type["blocks"] = TriState.closing; + type["table"] = TriState.closing; + type["tic_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } + } + final string biblio_tag_map(A)(A abr) { + debug(asserts) { + static assert(is(typeof(abr) == string)); + } + auto btm = [ + "au" : "author_raw", + "ed" : "editor_raw", + "ti" : "fulltitle", + "lng" : "language", + "jo" : "journal", + "vol" : "volume", + "edn" : "edition", + "yr" : "year", + "pl" : "place", + "pb" : "publisher", + "pub" : "publisher", + "pg" : "pages", + "pgs" : "pages", + "sn" : "short_name" + ]; + return btm[abr]; + } + void _biblio_block_( + char[] line, + return ref int[string] type, + return ref int bib_entry, + return ref string biblio_entry_str_json, + return ref string[] biblio_arr_json + ) { + mixin SiSUbiblio; + auto jsn = BibJsnStr(); + auto rgx = Rgx(); + if (line.matchFirst(rgx.heading_biblio)) { + type["biblio_section"] = TriState.on; + type["blurb_section"] = State.off; + type["glossary_section"] = State.off; + } + if (line.empty) { + debug { + debug(biblioblock) { + writeln("---"); + } + debug(biblioblockinclude) { + writeln(biblio_entry_str_json.length); + } + } + if ((bib_entry == State.off) + && (biblio_entry_str_json.empty)) { + bib_entry = State.on; + biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; + } else if (!(biblio_entry_str_json.empty)) { + bib_entry = State.off; + if (!(biblio_entry_str_json == jsn.biblio_entry_tags_jsonstr)) { + auto biblio_entry = parseJSON(biblio_entry_str_json); + if (biblio_entry["fulltitle"].str.empty) { + writeln("check problem entry (Title missing): ", biblio_entry_str_json); + } else if ((biblio_entry["author_raw"].str.empty) && (biblio_entry["editor_raw"].str.empty)) { + writeln("check problem entry (No author and no editor): ", biblio_entry_str_json); + } else { + biblio_arr_json ~= biblio_entry_str_json; + } + biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; + } + } else { // CHECK ERROR + writeln("?? 2. ERROR ", biblio_entry_str_json, "??"); + biblio_entry_str_json = ""; + } + } else if (line.matchFirst(rgx.biblio_tags)) { + debug(biblioblock) { + writeln(line); + } + auto bt = line.match(rgx.biblio_tags); + bib_entry = State.off; + st = bt.captures[1].to!string; + auto header_tag_value=(bt.captures[2]).to!string; + JSONValue j = parseJSON(biblio_entry_str_json); + biblio_tag_name = (st.match(rgx.biblio_abbreviations)) + ? (biblio_tag_map(st)) + : st; + j.object[biblio_tag_name] = header_tag_value; + debug(bibliounsortedcheckduplicates) { + writeln(biblio_tag_name, ": ", header_tag_value); + writeln("--"); + } + switch (biblio_tag_name) { + case "author_raw": // author_arr author (fn sn) + j["author_arr"] = + header_tag_value.split(rgx.arr_delimiter); + string tmp; + biblioAuthorLoop: + foreach (au; j["author_arr"].array) { + if (auto x = au.str.match(rgx.name_delimiter)) { + tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; + } else { + tmp ~= au.str; + } + } + tmp = (tmp).replace(rgx.trailing_comma, ""); + j["author"].str = tmp; + goto default; + case "editor_raw": // editor_arr editor (fn sn) + j["editor_arr"] = + header_tag_value.split(rgx.arr_delimiter); + string tmp; + biblioEditorLoop: + foreach (ed; j["editor_arr"].array) { + if (auto x = ed.str.match(rgx.name_delimiter)) { + tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; + } else { + tmp ~= ed.str; + } + } + tmp = (tmp).replace(rgx.trailing_comma, ""); + j["editor"].str = tmp; + goto default; + case "fulltitle": // title & subtitle + goto default; + default: + break; + } + auto s = j.toString(); + debug(biblio1) { + writefln( + "* %s: %s\n%s", + biblio_tag_name, + biblio_tag_entry, + j[biblio_tag_name] + ); + } + if (line.match(rgx.comment)) { + writeln("ERROR", line, "COMMENT"); + writeln("ERROR", s, "%%"); + } + if (!(match(line, rgx.comment))) { + debug(biblioblockinclude) { + writeln(line); + } + biblio_entry_str_json = s; + } else { + biblio_entry_str_json = ""; + } + header_tag_value=""; + } + } + void _table_closed_make_special_notation_table_( + char[] line, + return ref string[string] an_object, + return ref ObjGenericComposite[] the_document_body_section, + return ref int obj_cite_number, + return ref ObjGenericComposite _comp_obj_heading, + return ref int cntr, + return ref int[string] type, + string[string][string] dochead_make_aa, + ) { + comp_obj_block = comp_obj_block.init; + obj_cite_number = + ocn_emit(type["ocn_status"]); + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + "table" + ); + an_object["is"] = "table"; + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, "body_nugget", dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); + comp_obj_block = table_substantive_munge_special(comp_obj_block, an_object["substantive"]); + the_document_body_section ~= comp_obj_block; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + void _block_flag_line_empty_(B)( + B bookindex_extract_hash, + char[] line, + return ref string[string] an_object, + return ref ObjGenericComposite[] the_document_body_section, + return ref string[][string][string] bookindex_unordered_hashes, + return ref int obj_cite_number, + return ref ObjGenericComposite _comp_obj_heading, + return ref int cntr, + return ref int[string] type, + string[string] obj_cite_number_poem, + string[string][string] dochead_make_aa, + ) { + assert( + line.empty, + "\nline should be empty:\n \"" + ~ line ~ "\"" + ); + assert( + (type["blocks"] == TriState.closing), + "code block status: closed" + ); + assertions_flag_types_block_status_none_or_closed(type); + if (type["quote"] == TriState.closing) { + obj_cite_number = + ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "quote"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "quote"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + type["blocks"] = TriState.off; + type["quote"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } else if (type["group"] == TriState.closing) { + obj_cite_number = + ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "group"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "group"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + type["blocks"] = TriState.off; + type["group"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } else if (type["block"] == TriState.closing) { + obj_cite_number = ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "block"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.use = "body"; + comp_obj_block.is_of = "block"; + comp_obj_block.is_a = "block"; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + type["blocks"] = TriState.off; + type["block"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } else if (type["poem"] == TriState.closing) { + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "verse"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + comp_obj_poem_ocn = comp_obj_poem_ocn.init; + comp_obj_poem_ocn.use = "body"; + comp_obj_poem_ocn.is_of = "block"; + comp_obj_poem_ocn.is_a = "poem"; + comp_obj_poem_ocn.ocn = obj_cite_number; + comp_obj_poem_ocn.obj_cite_number = (obj_cite_number_poem["start"], obj_cite_number_poem["end"]); + comp_obj_poem_ocn.text = ""; + the_document_body_section ~= comp_obj_poem_ocn; + type["blocks"] = TriState.off; + type["poem"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + } else if (type["code"] == TriState.closing) { + obj_cite_number = + ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "code"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; + comp_obj_code = comp_obj_code.init; + comp_obj_code.use = "body"; + comp_obj_code.is_of = "block"; + comp_obj_code.is_a = "code"; + comp_obj_code.ocn = obj_cite_number; + comp_obj_code.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_code.text = an_object["substantive"]; + comp_obj_code.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_code.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_code.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_code; + type["blocks"] = TriState.off; + type["code"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } else if (type["table"] == TriState.closing) { + comp_obj_block = comp_obj_block.init; + obj_cite_number = + ocn_emit(type["ocn_status"]); + an_object["bookindex_nugget"] = + ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; + bookindex_unordered_hashes = + bookindex_extract_hash.bookindex_nugget_hash( + an_object["bookindex_nugget"], + obj_cite_number, + segment_anchor_tag_that_object_belongs_to + ); + an_object["is"] = "table"; + auto comp_obj_location = + node_construct.node_location_emitter( + content_non_header, + segment_anchor_tag_that_object_belongs_to, + obj_cite_number, + cntr, + heading_ptr-1, + an_object["is"] + ); + auto substantive_obj_misc_tuple = + obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.ocn = obj_cite_number; + comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); + comp_obj_block = table_substantive_munge(comp_obj_block, an_object["substantive"]); + the_document_body_section ~= comp_obj_block; + type["blocks"] = TriState.off; + type["table"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + } + auto _book_index_(L,I,O,T,B)( + L line, + return ref I book_idx_tmp, + return ref O an_object, + return ref T type, + B opt_action_bool, + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(book_idx_tmp) == string)); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + static assert(is(typeof(opt_action_bool) == bool[string])); + } + auto rgx = Rgx(); + if (auto m = line.match(rgx.book_index)) { + /+ match book_index +/ + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + m.captures[1].to!string, + ); + } + an_object["bookindex_nugget"] = m.captures[1].to!string; + } else if (auto m = line.match(rgx.book_index_open)) { + /+ match open book_index +/ + type["book_index"] = State.on; + if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { + book_idx_tmp = m.captures[1].to!string; + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } + } + } else if (type["book_index"] == State.on ) { + /+ book_index flag set +/ + if (auto m = line.match(rgx.book_index_close)) { + type["book_index"] = State.off; + if (opt_action_bool["backmatter"] + && opt_action_bool["section_bookindex"]) { + an_object["bookindex_nugget"] = book_idx_tmp ~ m.captures[1].to!string; + debug(bookindexmatch) { // book index + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } + } + book_idx_tmp = ""; + } else { + if (opt_action_bool["backmatter"] + && opt_action_bool["section_bookindex"]) { + book_idx_tmp ~= line; + } + } + } + } + auto _heading_found_(L,X,H,R,T)( + L line, + X dochead_make_identify_unmarked_headings, + return ref H heading_match_str, + return ref R heading_match_rgx, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(dochead_make_identify_unmarked_headings) == string)); + static assert(is(typeof(heading_match_str) == string[string])); + static assert(is(typeof(heading_match_rgx) == Regex!(char)[string])); + static assert(is(typeof(type) == int[string])); + } + auto rgx = Rgx(); + if ((dochead_make_identify_unmarked_headings.length > 2) + && (type["make_headings"] == State.off)) { + /+ headings found +/ + debug(headingsfound) { + writeln(dochead_make_identify_unmarked_headings); + } + char[][] make_headings_spl = + (cast(char[]) dochead_make_identify_unmarked_headings) + .split(rgx.make_heading_delimiter); + debug(headingsfound) { + writeln(make_headings_spl.length); + writeln(make_headings_spl); + } + switch (make_headings_spl.length) { + case 7 : + if (!empty(make_headings_spl[6])) { + heading_match_str["h_4"] = + "^(" ~ make_headings_spl[6].to!string ~ ")"; + heading_match_rgx["h_4"] = + regex(heading_match_str["h_4"]); + } + goto case; + case 6 : + if (!empty(make_headings_spl[5])) { + heading_match_str["h_3"] = + "^(" ~ make_headings_spl[5].to!string ~ ")"; + heading_match_rgx["h_3"] = + regex(heading_match_str["h_3"]); + } + goto case; + case 5 : + if (!empty(make_headings_spl[4])) { + heading_match_str["h_2"] = + "^(" ~ make_headings_spl[4].to!string ~ ")"; + heading_match_rgx["h_2"] = + regex(heading_match_str["h_2"]); + } + goto case; + case 4 : + if (!empty(make_headings_spl[3])) { + heading_match_str["h_1"] = + "^(" ~ make_headings_spl[3].to!string ~ ")"; + heading_match_rgx["h_1"] = + regex(heading_match_str["h_1"]); + } + goto case; + case 3 : + if (!empty(make_headings_spl[2])) { + heading_match_str["h_D"] = + "^(" ~ make_headings_spl[2].to!string ~ ")"; + heading_match_rgx["h_D"] = + regex(heading_match_str["h_D"]); + } + goto case; + case 2 : + if (!empty(make_headings_spl[1])) { + heading_match_str["h_C"] = + "^(" ~ make_headings_spl[1].to!string ~ ")"; + heading_match_rgx["h_C"] = + regex(heading_match_str["h_C"]); + } + goto case; + case 1 : + if (!empty(make_headings_spl[0])) { + heading_match_str["h_B"] = + "^(" ~ make_headings_spl[0].to!string ~ ")"; + heading_match_rgx["h_B"] = + regex(heading_match_str["h_B"]); + } + break; + default: + break; + } + type["make_headings"] = State.on; + } + } + auto _heading_make_set_(L,C,R,T)( + L line, + C line_occur, + return ref R heading_match_rgx, + return ref T type + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(line_occur) == int[string])); + static assert(is(typeof(heading_match_rgx) == Regex!(char)[string])); + static assert(is(typeof(type) == int[string])); + } + if ((type["make_headings"] == State.on) + && ((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((type["para"] == State.off) + && (type["heading"] == State.off))) { + /+ heading make set +/ + if (line.matchFirst(heading_match_rgx["h_B"])) { + line = "B~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_C"])) { + line = "C~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_D"])) { + line = "D~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_1"])) { + line = "1~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_2"])) { + line = "2~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_3"])) { + line = "3~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + if (line.matchFirst(heading_match_rgx["h_4"])) { + line = "4~ " ~ line; + debug(headingsfound) { + writeln(line); + } + } + } + return line; + } + auto _heading_matched_(L,C,O,K,Lv,Lc,T,Me)( + return ref L line, + return ref C line_occur, + return ref O an_object, + return ref K an_object_key, + return ref Lv lv, + return ref Lc collapsed_lev, + return ref T type, + return ref Me dochead_meta_aa, + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(line_occur) == int[string])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(an_object_key) == string)); + static assert(is(typeof(lv) == int[string])); + static assert(is(typeof(collapsed_lev) == int[string])); + static assert(is(typeof(type) == int[string])); + static assert(is(typeof(dochead_meta_aa) == string[string][string])); + } + auto rgx = Rgx(); + if (auto m = line.match(rgx.heading)) { + /+ heading match +/ + type["heading"] = State.on; + if (line.match(rgx.heading_seg_and_above)) { + type["biblio_section"] = State.off; + type["glossary_section"] = State.off; + type["blurb_section"] = State.off; + } + type["para"] = State.off; + ++line_occur["heading"]; + an_object[an_object_key] ~= line ~= "\n"; + an_object["lev"] ~= m.captures[1]; + assertions_doc_structure(an_object, lv); // includes most of the logic for collapsed levels + switch (an_object["lev"]) { + case "A": + an_object[an_object_key]=(an_object[an_object_key]) + .replaceFirst(rgx.variable_doc_title, + (dochead_meta_aa["title"]["full"] ~ ",")) + .replaceFirst(rgx.variable_doc_author, + dochead_meta_aa["creator"]["author"]); + collapsed_lev["h0"] = 0; + an_object["lev_collapsed_number"] = + collapsed_lev["h0"].to!string; + lv["lv"] = DocStructMarkupHeading.h_sect_A; + ++lv["h0"]; + lv["h1"] = State.off; + lv["h2"] = State.off; + lv["h3"] = State.off; + lv["h4"] = State.off; + lv["h5"] = State.off; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "B": + collapsed_lev["h1"] = collapsed_lev["h0"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h1"].to!string; + lv["lv"] = DocStructMarkupHeading.h_sect_B; + ++lv["h1"]; + lv["h2"] = State.off; + lv["h3"] = State.off; + lv["h4"] = State.off; + lv["h5"] = State.off; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "C": + collapsed_lev["h2"] = collapsed_lev["h1"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h2"].to!string; + lv["lv"] = DocStructMarkupHeading.h_sect_C; + ++lv["h2"]; + lv["h3"] = State.off; + lv["h4"] = State.off; + lv["h5"] = State.off; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "D": + collapsed_lev["h3"] = collapsed_lev["h2"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h3"].to!string; + lv["lv"] = DocStructMarkupHeading.h_sect_D; + ++lv["h3"]; + lv["h4"] = State.off; + lv["h5"] = State.off; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "1": + if (lv["h3"] > State.off) { + collapsed_lev["h4"] = collapsed_lev["h3"] + 1; + } else if (lv["h2"] > State.off) { + collapsed_lev["h4"] = collapsed_lev["h2"] + 1; + } else if (lv["h1"] > State.off) { + collapsed_lev["h4"] = collapsed_lev["h1"] + 1; + } else if (lv["h0"] > State.off) { + collapsed_lev["h4"] = collapsed_lev["h0"] + 1; + } + an_object["lev_collapsed_number"] = + collapsed_lev["h4"].to!string; + lv["lv"] = DocStructMarkupHeading.h_text_1; + ++lv["h4"]; + lv["h5"] = State.off; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "2": + if (lv["h5"] > State.off) { + an_object["lev_collapsed_number"] = + collapsed_lev["h5"].to!string; + } else if (lv["h4"] > State.off) { + collapsed_lev["h5"] = collapsed_lev["h4"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h5"].to!string; + } + lv["lv"] = DocStructMarkupHeading.h_text_2; + ++lv["h5"]; + lv["h6"] = State.off; + lv["h7"] = State.off; + goto default; + case "3": + if (lv["h6"] > State.off) { + an_object["lev_collapsed_number"] = + collapsed_lev["h6"].to!string; + } else if (lv["h5"] > State.off) { + collapsed_lev["h6"] = collapsed_lev["h5"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h6"].to!string; + } + lv["lv"] = DocStructMarkupHeading.h_text_3; + ++lv["h6"]; + lv["h7"] = State.off; + goto default; + case "4": + if (lv["h7"] > State.off) { + an_object["lev_collapsed_number"] = + collapsed_lev["h7"].to!string; + } else if (lv["h6"] > State.off) { + collapsed_lev["h7"] = collapsed_lev["h6"] + 1; + an_object["lev_collapsed_number"] = + collapsed_lev["h7"].to!string; + } + lv["lv"] = DocStructMarkupHeading.h_text_4; + ++lv["h7"]; + goto default; + default: + an_object["lev_markup_number"] = lv["lv"].to!string; + } + debug(heading) { // heading + writeln(line.strip); + } + } + } + void _para_match_(L,O,K,I,B,T,C)( + return ref L line, + return ref O an_object, + return ref K an_object_key, + return ref I indent, + return ref B bullet, + return ref T type, + return ref C line_occur, + ) { + debug(asserts) { + static assert(is(typeof(line) == char[])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(an_object_key) == string)); + static assert(is(typeof(indent) == int[string])); + static assert(is(typeof(bullet) == bool)); + static assert(is(typeof(type) == int[string])); + static assert(is(typeof(line_occur) == int[string])); + } + auto rgx = Rgx(); + if (line_occur["para"] == State.off) { + line = font_faces_line(line); + /+ para matches +/ + type["para"] = State.on; + an_object[an_object_key] ~= line; // body_nugget + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + if (auto m = line.matchFirst(rgx.para_indent)) { + debug(paraindent) { // para indent + writeln(line); + } + indent["hang_position"] = (m.captures[1]).to!int; + indent["base_position"] = 0; + } else if (line.matchFirst(rgx.para_bullet)) { + debug(parabullet) { // para bullet + writeln(line); + } + bullet = true; + } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { + debug(paraindenthang) { // para indent hang + writeln(line); + } + indent=[ + "hang_position" : (m.captures[1]).to!int, + "base_position" : (m.captures[2]).to!int, + ]; + } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { + debug(parabulletindent) { // para bullet indent + writeln(line); + } + indent=[ + "hang_position" : (m.captures[1]).to!int, + "base_position" : 0, + ]; + bullet = true; + } + ++line_occur["para"]; + } + } + auto font_faces_line(T)( + return ref T textline, + ) { + auto rgx = Rgx(); + if (textline.match(rgx.inline_faces_line)) { + textline = (textline) + .replaceFirst(rgx.inline_emphasis_line, ("*{$1}*$2")) + .replaceFirst(rgx.inline_bold_line, ("!{$1}!$2")) + .replaceFirst(rgx.inline_underscore_line, ("_{$1}_$2")) + .replaceFirst(rgx.inline_italics_line, ("/{$1}/$2")); + } + return textline; + } + auto table_instructions(O,H)( + return ref O table_object, + return ref H table_head, + ) { + auto rgx = Rgx(); + table_object.use = "body"; + table_object.is_of = "block"; + table_object.is_a = "table"; + table_object.inline_notes_reg = false; + table_object.inline_notes_star = false; + table_object.inline_links = false; + if (auto m = table_head.matchFirst(rgx.table_head_instructions)) { + table_object.table_heading = ((m["c_heading"].length > 0) && (m["c_heading"] == "h")) ? true : false; + table_object.table_number_of_columns = ((m["c_num"].length > 0) && (m["c_num"].to!int > 0)) ? m["c_num"].to!int : 0; // double check, may be obsolete + foreach (cw; m["c_widths"].matchAll(rgx.table_col_widths)) { + auto x = cw.hit.matchFirst(rgx.table_col_widths_and_alignment); + table_object.table_column_widths ~= x["width"].to!int; + table_object.table_column_aligns ~= (x["align"].empty) ? "" : x["align"]; + } + } + return table_object; + } + auto table_array_munge(O,T)( + return ref O table_object, + return ref T table_array, + ) { + auto rgx = Rgx(); + auto mng = InlineMarkup(); + string _table_substantive; + ulong col_num; + ulong col_num_; + ulong col_num_chk = 0; + foreach(idx_r, row; table_array) { + debug(table_dev) { + writeln("row ", idx_r); + } + col_num_ = 0; + if (col_num == 0 + || col_num < row.length) { + col_num = row.length; + } + if (col_num_chk == 0) { + col_num_chk = col_num; + } else if (col_num == 1) { + debug(table_dev) { + writeln("table note: "); + } + } else if (col_num_chk != col_num) { + debug(table_dev) { + writeln("warning irregular number of columns: ", col_num_chk, " != ", col_num); + } + } else { + } + foreach(idx_c, col; row) { + debug(table_dev) { + write(idx_c, ", "); + } + col_num_ = idx_c; + _table_substantive ~= col ~ mng.tc_s; + if (idx_r == 0 && comp_obj_block.table_heading) { + } else if (idx_r == 1 && col.match(rgx.numeric_col)) { + if ((comp_obj_block.table_column_aligns.length > idx_c) + && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { + comp_obj_block.table_column_aligns[idx_c] + = comp_obj_block.table_column_aligns[idx_c]; + } else if (comp_obj_block.table_column_aligns.length > idx_c) { + comp_obj_block.table_column_aligns[idx_c] = "r"; + } else { + comp_obj_block.table_column_aligns ~= "r"; + } + } else if (idx_r == 1) { + if ((comp_obj_block.table_column_aligns.length > idx_c) + && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { + comp_obj_block.table_column_aligns[idx_c] + = comp_obj_block.table_column_aligns[idx_c]; + } else if (comp_obj_block.table_column_aligns.length > idx_c) { + comp_obj_block.table_column_aligns[idx_c] = "l"; + } else { + comp_obj_block.table_column_aligns ~= "l"; + } + } + } + debug(table_dev) { + writeln(""); + } + if (col_num_chk > 0 && (col_num != col_num_chk)) { + } else if (col_num == col_num_chk){ + } else { + col_num_chk = col_num; + } + _table_substantive = _table_substantive.replaceFirst(rgx.table_col_separator_nl, "\n"); + } + if (comp_obj_block.table_number_of_columns != col_num) { + if (comp_obj_block.table_number_of_columns == 0) { + comp_obj_block.table_number_of_columns = (col_num).to!int; + } else { + debug(table_dev) { + writeln(comp_obj_block.table_number_of_columns, " != ", col_num); + } + } + } + if (table_object.table_number_of_columns == 0 + && table_object.table_column_widths.length > 0) { + writeln(__LINE__, " ERROR"); + } + if (table_object.table_number_of_columns > 0 + && table_object.table_column_widths.length == 0) { + double col_w = (100.00 / table_object.table_number_of_columns); + foreach (i; 0..table_object.table_number_of_columns) { + table_object.table_column_widths ~= col_w; + } + } else if (table_object.table_number_of_columns + != table_object.table_column_widths.length) { + debug(table_dev) { + writeln(m.hit); // further logic required + } + if (table_object.table_number_of_columns > table_object.table_column_widths.length) { + double col_w = (100.00 - (table_object.table_column_widths).sum) + / (table_object.table_number_of_columns - table_object.table_column_widths.length); + foreach (i; 0..table_object.table_column_widths.length) { + table_object.table_column_widths ~= col_w; + } + foreach (i; 0..(table_object.table_number_of_columns - table_object.table_column_widths.length)) { + table_object.table_column_widths ~= col_w; + } + } else if (table_object.table_number_of_columns < table_object.table_column_widths.length) { + writeln(__LINE__, " warning, ERROR"); + } + } + if (table_object.table_column_widths.sum > 101 + || table_object.table_column_widths.sum < 95 ) { + writeln("sum: ", table_object.table_column_widths.sum, + ", array: ", table_object.table_column_widths, + ", cols: ", table_object.table_number_of_columns); + writeln(_table_substantive); + } + debug(table_res) { + writeln("aligns: ", comp_obj_block.table_column_aligns, "\n", + "no. of columns: ", comp_obj_block.table_number_of_columns, "\n", + "col widths: ", comp_obj_block.table_column_widths, + " sum: ", comp_obj_block.table_column_widths.sum, "\n", + _table_substantive); + } + comp_obj_block.text = _table_substantive; + return table_object; + } + auto table_array_munge_open_close(O,T)( + return ref O table_object, + return ref T table_array, + ) { + auto rgx = Rgx(); + auto mng = InlineMarkup(); + string _table_substantive; + foreach(row; table_array) { + foreach(col; row) { + _table_substantive ~= mng.tc_o ~ col ~ mng.tc_c; + } + _table_substantive ~= "\n"; + } + debug(table_dev) { + writeln(_table_substantive); + } + comp_obj_block.text = _table_substantive; + return table_object; + } + auto table_substantive_munge(O,T)( + return ref O table_object, + return ref T table_substantive, + ) { + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter); + string[] _table_cols; + string[][] _table; + foreach(col; _table_rows) { + _table_cols = col.split(rgx.table_col_delimiter); + _table ~= _table_cols; + } + table_object = table_array_munge(table_object, _table); + return table_object; + } + auto table_substantive_munge_special(O,T)( + return ref O table_object, + return ref T table_substantive, + ) { + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter_special); + string[] _table_cols; + string[][] _table; + foreach(col; _table_rows) { + _table_cols = col.split(rgx.table_col_delimiter_special); + _table ~= _table_cols; + } + table_object = table_array_munge(table_object, _table); + return table_object; + } + /+ abstraction functions ↑ +/ + /+ ↓ abstraction function emitters +/ + struct OCNemitter { + int obj_cite_number, obj_cite_number_; + int ocn_emitter(int ocn_status_flag) + in { assert(ocn_status_flag <= 3); } + body { + if (ocn_status_flag == 3) { + obj_cite_number = obj_cite_number_ = 1; + } else { + obj_cite_number=(ocn_status_flag == 0) + ? ++obj_cite_number_ + : 0; + } + assert(obj_cite_number >= 0); + return obj_cite_number; + } + invariant() { + } + } + /+ +/ + struct ObjInlineMarkupMunge { + string[string] obj_txt; + int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; + string asterisks_; + string obj_txt_out, tail, note; + auto rgx = Rgx(); + auto mkup = InlineMarkup(); + int stage_reset_note_numbers = true; + private auto initialize_note_numbers() { + n_foot = 0; + n_foot_reg = 0; + n_foot_sp_asterisk = 0; + n_foot_sp_plus = 0; + } + string url_links(Ot)(Ot obj_txt_in) { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + /+ url matched +/ + if (obj_txt_in.match(rgx.inline_url_generic)) { + /+ link: naked url: http://url +/ + if (obj_txt_in.match(rgx.inline_link_naked_url)) { + obj_txt_in = (obj_txt_in).replaceAll( + rgx.inline_link_naked_url, + ("$1" + ~ mkup.lnk_o ~ "$2" ~ mkup.lnk_c + ~ mkup.url_o ~ "$2" ~ mkup.url_c + ~ "$3") // ("$1{ $2 }$2$3") + ); + } + /+ link with helper for endnote including the url: + {~^ link which includes url as footnote }http://url + maps to: + { link which includes url as footnote }http://url~{ { http://url }http://url }~ + +/ + if (obj_txt_in.match(rgx.inline_link_endnote_url_helper)) { + obj_txt_in = (obj_txt_in).replaceAll( + rgx.inline_link_endnote_url_helper_punctuated, + (mkup.lnk_o ~ "$1" ~ mkup.lnk_c + ~ mkup.url_o ~ "$2" ~ mkup.url_c + ~ "~{ " ~ mkup.lnk_o ~ " $2 " ~ mkup.lnk_c + ~ mkup.url_o ~ "$2" ~ mkup.url_c + ~ " }~$3") // ("{ $1 }$2~{ { $2 }$2 }~$3") + ); + obj_txt_in = (obj_txt_in).replaceAll( + rgx.inline_link_endnote_url_helper, + (mkup.lnk_o ~ "$1" ~ mkup.lnk_c + ~ mkup.url_o ~ "$2" ~ mkup.url_c + ~ "~{ " ~ mkup.lnk_o ~ " $2 " ~ mkup.lnk_c + ~ mkup.url_o ~ "$2" ~ mkup.url_c + ~ " }~") // ("{ $1 }$2~{ { $2 }$2 }~") + ); + } + /+ link with regular markup: + { linked text or image }http://url + +/ + if (obj_txt_in.match(rgx.inline_link_markup_regular)) { + obj_txt_in = (obj_txt_in).replaceAll( + rgx.inline_link_markup_regular, + ("$1" + ~ mkup.lnk_o ~ "$2" ~ mkup.lnk_c + ~ mkup.url_o ~ "$3" ~ mkup.url_c + ~ "$4") // ("$1{ $2 }$3$4") + ); + } + } + return obj_txt_in; + } + auto footnotes_endnotes_markup_and_number_or_stars(Ot)(Ot obj_txt_in, bool reset_note_numbers) { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + /+ endnotes (regular) +/ + bool flg_notes_reg = false; + bool flg_notes_star = false; + obj_txt_in = (obj_txt_in).replaceAll( + rgx.inline_notes_curly, + (mkup.en_a_o ~ " $1" ~ mkup.en_a_c) + ); + if (!(stage_reset_note_numbers) && reset_note_numbers) { + stage_reset_note_numbers = true; + } + if (obj_txt_in.match(rgx.inline_notes_al_gen)) { + if (auto m = obj_txt_in.matchAll(rgx.inline_text_and_note_al_)) { + if (stage_reset_note_numbers) { + n_foot = 0; + n_foot_reg = 0; + n_foot_sp_asterisk = 0; + n_foot_sp_plus = 0; + } + stage_reset_note_numbers = false; + foreach(n; m) { + if (n.hit.to!string.match(rgx.inline_al_delimiter_open_symbol_star)) { + flg_notes_star = true; + ++n_foot_sp_asterisk; + asterisks_ = "*"; + n_foot=n_foot_sp_asterisk; + obj_txt_out ~= n.hit.to!string.replaceFirst( + rgx.inline_al_delimiter_open_symbol_star, + (mkup.en_a_o ~ replicate(asterisks_, n_foot_sp_asterisk) ~ " ") + ) ~ "\n"; + } else if (n.hit.to!string.match(rgx.inline_al_delimiter_open_regular)) { + flg_notes_reg = true; + ++n_foot_reg; + n_foot=n_foot_reg; + obj_txt_out ~= n.hit.to!string.replaceFirst( + rgx.inline_al_delimiter_open_regular, + (mkup.en_a_o ~ to!string(n_foot) ~ " ") + ) ~ "\n"; + } else { + obj_txt_out ~= n.hit.to!string ~ "\n"; + } + } + } + } else { + obj_txt_out = obj_txt_in; + } + auto t = tuple( + obj_txt_out, + flg_notes_reg, + flg_notes_star, + ); + return t; + } + private auto object_notes_and_links_(Ot)(Ot obj_txt_in, bool reset_note_numbers=false) + in { + debug(asserts) { + assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt_out = ""; + bool urls = false; + tail = ""; + /+ special endnotes +/ + obj_txt_in = obj_txt_in.replaceAll( + rgx.inline_notes_curly_sp_asterisk, + (mkup.en_a_o ~ "*" ~ " $1" ~ mkup.en_a_c) + ); + obj_txt_in = + obj_txt_in.replaceAll( + rgx.inline_notes_curly_sp_plus, + (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) + ); + /+ url matched +/ + if (obj_txt_in.match(rgx.inline_url)) { + urls = true; + obj_txt_in = url_links(obj_txt_in); + } + auto ftn = footnotes_endnotes_markup_and_number_or_stars(obj_txt_in, reset_note_numbers); + obj_txt_out = ftn[0]; + debug(footnotes) { + writeln(obj_txt_out, tail); + } + obj_txt_out = obj_txt_out ~ tail; + debug(footnotesdone) { + foreach(m; matchAll(obj_txt_out, + (mkup.en_a_o ~ `\s*(.+?)` ~ mkup.en_a_c))) { + writeln(m.captures[1]); + writeln(m.hit); + } + } + auto t = tuple( + obj_txt_out, + ftn[1], + ftn[2], + urls, + ); + return t; + } + auto init() + in { } + body { + auto t = object_notes_and_links_(""); + return t; + } + invariant() { + } + auto munge_heading(Ot)(Ot obj_txt_in, bool reset_note_numbers=false) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=(obj_txt_in) + .replaceFirst(rgx.heading, "") + .replaceFirst(rgx.obj_cite_number_off_all, "") + .strip; + auto t = object_notes_and_links_(obj_txt["munge"], reset_note_numbers); + debug(munge) { + writeln(__LINE__); + writeln(obj_txt_in); + writeln(__LINE__); + writeln(obj_txt["munge"].to!string); + } + return t; + } + invariant() { + } + auto munge_para(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=(obj_txt_in) + .replaceFirst(rgx.para_attribs, "") + .replaceFirst(rgx.obj_cite_number_off_all, ""); + auto t = object_notes_and_links_(obj_txt["munge"]); + debug(munge) { + writeln(__LINE__); + writeln(obj_txt_in); + writeln(__LINE__); + writeln(obj_txt["munge"].to!string); + } + return t; + } + string munge_quote(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + auto munge_group(string obj_txt_in) + in { } + body { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } + auto munge_block(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } + auto munge_verse(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } + string munge_code(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt_in = (obj_txt_in).replaceAll(rgx.space, mkup.nbsp); + obj_txt["munge"] = obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string munge_table(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + string munge_comment(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } + } + struct ObjInlineMarkup { + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + string[string] obj_txt; + auto obj_inline_markup_and_anchor_tags_and_misc(O,K,Ma)( + O obj_, + K obj_key_, + Ma dochead_make_aa + ) + in { + debug(asserts) { + static assert(is(typeof(obj_) == string[string])); + static assert(is(typeof(obj_key_) == string)); + static assert(is(typeof(dochead_make_aa) == string[string][string])); + } + } + body { + obj_txt["munge"] = obj_[obj_key_].dup; + obj_txt["munge"] = (obj_["is"].match(ctRegex!(`verse|code`))) + ? obj_txt["munge"] + : strip(obj_txt["munge"]); + static __gshared string[] anchor_tags_ = []; + auto x = munge.init; + bool[string] obj_notes_and_links; + obj_notes_and_links["notes_reg"] = false; + obj_notes_and_links["notes_star"] = false; + obj_notes_and_links["links"] = false; + switch (obj_["is"]) { + case "heading": + static __gshared string anchor_tag = ""; + 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)) { + anchor_tag = m.captures[1]; + anchor_tags_ ~= anchor_tag; + } else if (obj_["lev"] == "1") { + writeln("heading anchor tag missing: ", obj_txt["munge"]); + } + x =munge.munge_heading(obj_txt["munge"], reset_note_numbers); + reset_note_numbers=false; + goto default; + case "para": + x = munge.munge_para(obj_txt["munge"]); + goto default; + case "group": + x = munge.munge_group(obj_txt["munge"]); + goto default; + case "block": + x = munge.munge_block(obj_txt["munge"]); + goto default; + case "verse": + x = munge.munge_verse(obj_txt["munge"]); + goto default; + case "code": + obj_txt["munge"] = munge.munge_code(obj_txt["munge"]); + break; + case "table": + obj_txt["munge"] = munge.munge_table(obj_txt["munge"]); + break; + case "quote": + obj_txt["munge"] = munge.munge_quote(obj_txt["munge"]); + break; + case "comment": + obj_txt["munge"] = munge.munge_comment(obj_txt["munge"]); + break; + case "doc_end_reset": + munge.initialize_note_numbers(); + break; + default: + /+ para, heading, group, block, verse +/ + obj_txt["munge"] = x[0]; + obj_notes_and_links["notes_reg"] = x[1]; + obj_notes_and_links["notes_star"] = x[2]; + obj_notes_and_links["links"] = x[3]; + break; + } + auto t = tuple( + obj_txt["munge"], + anchor_tags_, + obj_notes_and_links["notes_reg"], + obj_notes_and_links["notes_star"], + obj_notes_and_links["links"], + ); + anchor_tags_=[]; + return t; + } + invariant() { + } + auto _clean_heading_toc_(Toc)( + Toc heading_toc_, + ) { + debug(asserts) { + static assert(is(typeof(heading_toc_) == char[])); + } + auto m = (cast(char[]) heading_toc_).matchFirst(rgx.heading); + heading_toc_ = (m.post).replaceAll( + rgx.inline_notes_curly_gen, + ""); + return heading_toc_; + }; + auto table_of_contents_gather_headings(O,Ma,Ts,Ta,X,Toc)( + O obj_, + Ma dochead_make_aa, + Ts segment_anchor_tag_that_object_belongs_to, + Ta _anchor_tag, + return ref X lev4_subtoc, + Toc the_table_of_contents_section, + ) + in { + debug(asserts) { + static assert(is(typeof(obj_) == string[string])); + static assert(is(typeof(dochead_make_aa) == string[string][string])); + static assert(is(typeof(segment_anchor_tag_that_object_belongs_to) == string)); + static assert(is(typeof(_anchor_tag) == string)); + static assert(is(typeof(lev4_subtoc) == string[][string])); + static assert(is(typeof(the_table_of_contents_section) == ObjGenericComposite[][string])); + } + } + body { + ObjGenericComposite comp_obj_toc; + mixin InternalMarkup; + auto mkup = InlineMarkup(); + char[] heading_toc_ = (obj_["substantive"].dup.strip.to!(char[])).replaceAll(rgx.inline_notes_al, ""); + heading_toc_ = _clean_heading_toc_(heading_toc_); + auto attrib=""; + string toc_txt_, subtoc_txt_; + int[string] indent; + if (obj_["lev_markup_number"].to!int > 0) { + indent=[ + "hang_position" : obj_["lev_markup_number"].to!int, + "base_position" : obj_["lev_markup_number"].to!int, + ]; + toc_txt_ = format( + "{ %s }#%s", + heading_toc_, + _anchor_tag, + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.use = "frontmatter"; + comp_obj_toc.is_of = "para"; + comp_obj_toc.is_a = "toc"; + comp_obj_toc.ocn = 0; + comp_obj_toc.obj_cite_number = ""; + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.bullet = false; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } else { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.use = "frontmatter"; + comp_obj_toc.is_of = "para"; + comp_obj_toc.is_a = "toc"; + comp_obj_toc.ocn = 0; + comp_obj_toc.obj_cite_number = ""; + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.bullet = false; + comp_obj_toc.text = "Table of Contents"; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["scroll"] ~= comp_obj_toc; + } + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.use = "frontmatter"; + comp_obj_toc.is_of = "para"; + comp_obj_toc.is_a = "toc"; + comp_obj_toc.ocn = 0; + comp_obj_toc.obj_cite_number = ""; + comp_obj_toc.bullet = false; + comp_obj_toc.inline_links = true; + switch (obj_["lev_markup_number"].to!int) { + case 0: + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + toc_txt_ = "{ Table of Contents }" ~ mkup.mark_internal_site_lnk ~ "toc.fnSuffix"; + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + break; + case 1: .. case 3: + indent=[ + "hang_position" : obj_["lev_markup_number"].to!int, + "base_position" : obj_["lev_markup_number"].to!int, + ]; + toc_txt_ = format( + "%s", + heading_toc_, + ); + toc_txt_= munge.url_links(toc_txt_); + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + break; + case 4: + toc_txt_ = format( + "{ %s }%s%s%s", + heading_toc_, + mkup.mark_internal_site_lnk, + segment_anchor_tag_that_object_belongs_to, + ".fnSuffix", + ); + lev4_subtoc[segment_anchor_tag_that_object_belongs_to] = []; + toc_txt_= munge.url_links(toc_txt_); + indent=[ + "hang_position" : obj_["lev_markup_number"].to!int, + "base_position" : obj_["lev_markup_number"].to!int, + ]; + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + break; + case 5: .. case 7: + toc_txt_ = format( + "{ %s }%s%s%s#%s", + heading_toc_, + mkup.mark_internal_site_lnk, + segment_anchor_tag_that_object_belongs_to, + ".fnSuffix", + _anchor_tag, + ); + subtoc_txt_ = format( + "{ %s }#%s", + heading_toc_, + _anchor_tag, + ); + lev4_subtoc[segment_anchor_tag_that_object_belongs_to] + ~= obj_["lev_markup_number"] ~ "~ " ~ subtoc_txt_.to!string.strip; + toc_txt_= munge.url_links(toc_txt_); + indent=[ + "hang_position" : obj_["lev_markup_number"].to!int, + "base_position" : obj_["lev_markup_number"].to!int, + ]; + comp_obj_toc.indent_hang = indent["hang_position"]; + comp_obj_toc.indent_base = indent["base_position"]; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.inline_links = true; + the_table_of_contents_section["seg"] ~= comp_obj_toc; + break; + default: + break; + } + return the_table_of_contents_section; + } + invariant() { + } + private: + static string _configured_auto_heading_numbering_and_segment_anchor_tags(M,O,Ma)( + M munge_, + O obj_, + Ma dochead_make_aa + ) { + debug(asserts) { + static assert(is(typeof(munge_) == string)); + static assert(is(typeof(obj_) == string[string])); + static assert(is(typeof(dochead_make_aa) == string[string][string])); + } + if (dochead_make_aa["make"]["num_top"].length > 0) { + static __gshared int heading_num_top_level=9; + static __gshared int heading_num_depth=2; + static __gshared int heading_num_0 = 0; + static __gshared int heading_num_1 = 0; + static __gshared int heading_num_2 = 0; + static __gshared int heading_num_3 = 0; + static __gshared string heading_number_auto_composite = ""; + if (heading_num_top_level==9) { + if (dochead_make_aa["make"]["num_depth"].length > 0) { + heading_num_depth = dochead_make_aa["make"]["num_depth"].to!uint; + } + switch (dochead_make_aa["make"]["num_top"]) { + case "A": + break; + case "B": + heading_num_top_level=1; + break; + case "C": + heading_num_top_level=2; + break; + case "D": + heading_num_top_level=3; + break; + case "1": + heading_num_top_level=4; + break; + case "2": + heading_num_top_level=5; + break; + case "3": + heading_num_top_level=6; + break; + case "4": + heading_num_top_level=7; + break; + default: + break; + } + } + /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ + if ( + heading_num_top_level + > obj_["lev_markup_number"].to!uint + ) { + heading_num_0 = 0; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == obj_["lev_markup_number"].to!uint + ) { + heading_num_0 ++; + heading_num_1 = 0; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (obj_["lev_markup_number"].to!uint - 1) + ) { + heading_num_1 ++; + heading_num_2 = 0; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (obj_["lev_markup_number"].to!uint - 2) + ) { + heading_num_2 ++; + heading_num_3 = 0; + } else if ( + heading_num_top_level + == (obj_["lev_markup_number"].to!uint - 3) + ) { + heading_num_3 ++; + } + if (heading_num_3 > 0) { + heading_number_auto_composite = + (heading_num_depth == 3) + ? ( heading_num_0.to!string ~ "." + ~ heading_num_1.to!string ~ "." + ~ heading_num_2.to!string ~ "." + ~ heading_num_3.to!string + ) + : ""; + } else if (heading_num_2 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 2) + && (heading_num_depth <= 3)) + ? ( heading_num_0.to!string ~ "." + ~ heading_num_1.to!string ~ "." + ~ heading_num_2.to!string + ) + : ""; + } else if (heading_num_1 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 1) + && (heading_num_depth <= 3)) + ? ( heading_num_0.to!string ~ "." + ~ heading_num_1.to!string + ) + : ""; + } else if (heading_num_0 > 0) { + heading_number_auto_composite = + ((heading_num_depth >= 0) + && (heading_num_depth <= 3)) + ? (heading_num_0.to!string) + : ""; + } else { + heading_number_auto_composite = ""; + } + debug(heading_number_auto) { + writeln(heading_number_auto_composite); + } + if (!(munge_.match(rgx.heading_anchor_tag)) + && !empty(heading_number_auto_composite)) { + munge_=(munge_) + .replaceFirst(rgx.heading, + "$1~$2 " ~ heading_number_auto_composite ~ ". ") + .replaceFirst(rgx.heading_marker_missing_tag, + "$1~" ~ heading_number_auto_composite ~ " "); + } + } + return munge_; + } + static string _make_segment_anchor_tags_if_none_provided(M,Lv)(M munge_, Lv lev_) { + debug(asserts) { + static assert(is(typeof(munge_) == string)); + static assert(is(typeof(lev_) == string)); + } + if (!(munge_.match(rgx.heading_anchor_tag))) { + if (munge_.match(rgx.heading_identify_anchor_tag)) { + if (auto m = munge_.match(rgx.heading_extract_named_anchor_tag)) { + munge_=(munge_).replaceFirst( + rgx.heading_marker_missing_tag, + "$1~" ~ m.captures[1].toLower ~ "_" ~ m.captures[2] ~ " "); + } else if (auto m = munge_.match(rgx.heading_extract_unnamed_anchor_tag)) { + munge_=(munge_).replaceFirst( + rgx.heading_marker_missing_tag, + "$1~" ~ "s" ~ m.captures[1] ~ " "); + } + } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" + static __gshared int heading_num_lev1 = 0; + heading_num_lev1 ++; + munge_=(munge_).replaceFirst( + rgx.heading_marker_missing_tag, + "$1~" ~ "x" ~ heading_num_lev1.to!string ~ " "); + } + } + return munge_; + } + unittest { + string txt_lev="1"; + string txt_in, txt_out; + + txt_in = "1~copyright Copyright"; + txt_out ="1~copyright Copyright"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in = "1~ 6. Writing Copyright Licenses"; + txt_out ="1~s6 6. Writing Copyright Licenses"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 1. Reinforcing trends"; + txt_out= "1~s1 1. Reinforcing trends"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ 11 SCIENCE AS A COMMONS"; + txt_out= "1~s11 11 SCIENCE AS A COMMONS"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1"; + txt_out="1~chapter_1 Chapter 1"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1."; + txt_out="1~chapter_1 Chapter 1."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 1: Done"; + txt_out="1~chapter_1 Chapter 1: Done"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + txt_out= "1~chapter_11 Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER I."; + txt_out="1~x1 CHAPTER I."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + + txt_in= "1~ CHAPTER II."; + txt_out="1~x2 CHAPTER II."; + assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); + } + } + /+ +/ + struct ObjAttributes { + string[string] _obj_attrib; + string obj_attributes(Oi,OR,OH)( + Oi obj_is_, + OR obj_raw, + OH _comp_obj_heading, + ) + in { + debug(asserts) { + static assert(is(typeof(obj_is_) == string)); + static assert(is(typeof(obj_raw) == string)); + static assert(is(typeof(_comp_obj_heading) == ObjGenericComposite)); + } + } + body { + scope(exit) { + destroy(obj_is_); + destroy(obj_raw); + destroy(_comp_obj_heading); + } + _obj_attrib["json"] ="{"; + switch (obj_is_) { + case "heading": + _obj_attrib["json"] ~= _heading(obj_raw); + break; + case "para": + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _para(obj_raw); + break; + case "code": + _obj_attrib["json"] ~= _code(obj_raw); + break; + case "group": + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _group(obj_raw); + break; + case "block": + _obj_attrib["json"] ~= _para_and_blocks(obj_raw) + ~ _block(obj_raw); + break; + case "verse": + _obj_attrib["json"] ~= _verse(obj_raw); + break; + case "quote": + _obj_attrib["json"] ~= _quote(obj_raw); + break; + case "table": + _obj_attrib["json"] ~= _table(obj_raw); + break; + case "comment": + _obj_attrib["json"] ~= _comment(obj_raw); + break; + default: + _obj_attrib["json"] ~= _para(obj_raw); + break; + } + _obj_attrib["json"] ~=" }"; + _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, _comp_obj_heading); + debug(structattrib) { + if (oa_j["is"].str() == "heading") { + writeln(_obj_attrib["json"]); + writeln( + "is: ", oa_j["is"].str(), + "; obj_cite_number: ", oa_j["obj_cite_number"].integer() + ); + } + } + return _obj_attrib["json"]; + } + invariant() { + } + private: + string _obj_attributes; + string _para_and_blocks(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + if (obj_txt_in.matchFirst(rgx.para_bullet)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_hang\": 0," + ~ " \"indent_base\": 0,"; + } else if (auto m = obj_txt_in.matchFirst(rgx.para_bullet_indent)) { + _obj_attributes =" \"bullet\": \"true\"," + ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," + ~ " \"indent_base\": " ~ m.captures[1].to!string ~ ","; + } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent_hang)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," + ~ " \"indent_base\": " ~ m.captures[2].to!string ~ ","; + } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," + ~ " \"indent_base\": " ~ m.captures[1].to!string ~ ","; + } else { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": 0," + ~ " \"indent_base\": 0,"; + } + return _obj_attributes; + } + string _heading(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"heading\""; + return _obj_attributes; + } + invariant() { + } + string _para(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"para\""; + return _obj_attributes; + } + invariant() { + } + string _quote(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"quote\""; + return _obj_attributes; + } + invariant() { + } + string _group(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"group\""; + return _obj_attributes; + } + invariant() { + } + string _block(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"block\""; + return _obj_attributes; + } + invariant() { + } + string _verse(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"verse\""; + return _obj_attributes; + } + invariant() { + } + string _code(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"code\""; + return _obj_attributes; + } + invariant() { + } + string _table(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"table\""; + return _obj_attributes; + } + invariant() { + } + string _comment(Ot)(Ot obj_txt_in) + in { + debug(asserts) { + static assert(is(typeof(obj_txt_in) == string)); + } + } + body { + _obj_attributes = " \"use\": \"comment\"," + ~ " \"of\": \"comment\"," + ~ " \"is\": \"comment\""; + return _obj_attributes; + } + invariant() { + } + string _set_additional_values_parse_as_json(OA,Oi,OH)( + OA _obj_attrib, + Oi obj_is_, + OH _comp_obj_heading, + ) { + debug(asserts) { + static assert(is(typeof(_obj_attrib) == string)); + static assert(is(typeof(obj_is_) == string)); + static assert(is(typeof(_comp_obj_heading) == ObjGenericComposite)); + } + JSONValue oa_j = parseJSON(_obj_attrib); + assert( + (oa_j.type == JSON_TYPE.OBJECT) + ); + if (obj_is_ == "heading") { + oa_j.object["obj_cite_number"] = _comp_obj_heading.ocn; + oa_j.object["lev_markup_number"] = _comp_obj_heading.heading_lev_markup; + oa_j.object["lev_collapsed_number"] = _comp_obj_heading.heading_lev_collapsed; + oa_j.object["heading_ptr"] = + _comp_obj_heading.ptr_heading; + oa_j.object["doc_object_ptr"] = + _comp_obj_heading.ptr_doc_object; + } + oa_j.object["parent_obj_cite_number"] = _comp_obj_heading.parent_ocn; + oa_j.object["parent_lev_markup_number"] = _comp_obj_heading.parent_lev_markup; + _obj_attrib = oa_j.toString(); + return _obj_attrib; + } + } + /+ +/ + struct BookIndexNuggetHash { + string main_term, sub_term, sub_term_bits; + int obj_cite_number_offset, obj_cite_number_endpoint; + string[] obj_cite_numbers; + string[][string][string] bi; + string[][string][string] hash_nugget; + string[] bi_main_terms_split_arr; + string[][string][string] bookindex_nugget_hash(BI,N,S)( + BI bookindex_section, + N obj_cite_number, + S segment_anchor_tag, + ) + in { + debug(asserts) { + static assert(is(typeof(bookindex_section) == string)); + static assert(is(typeof(obj_cite_number) == int)); + } + debug(bookindexraw) { + if (!bookindex_section.empty) { + writeln( + "* [bookindex] ", + "[", obj_cite_number.to!string, ": ", segment_anchor_tag, "] ", bookindex_section + ); + } + } + } + body { + auto rgx = Rgx(); + if (!bookindex_section.empty) { + auto bi_main_terms_split_arr = + bookindex_section.split(rgx.bi_main_terms_split); + foreach (bi_main_terms_content; bi_main_terms_split_arr) { + auto bi_main_term_and_rest = + bi_main_terms_content.split(rgx.bi_main_term_plus_rest_split); + if (auto m = bi_main_term_and_rest[0].match( + rgx.bi_term_and_obj_cite_numbers_match) + ) { + main_term = m.captures[1].strip; + obj_cite_number_offset = m.captures[2].to!int; + obj_cite_number_endpoint=(obj_cite_number + obj_cite_number_offset); + obj_cite_numbers ~= (obj_cite_number.to!string ~ "-" ~ to!string(obj_cite_number_endpoint) + ~ ":" ~ segment_anchor_tag); + } else { + main_term = bi_main_term_and_rest[0].strip; + obj_cite_numbers ~= obj_cite_number.to!string + ~ ":" ~ segment_anchor_tag; + } + bi[main_term]["_a"] ~= obj_cite_numbers; + obj_cite_numbers=null; + if (bi_main_term_and_rest.length > 1) { + auto bi_sub_terms_split_arr = + bi_main_term_and_rest[1].split( + rgx.bi_sub_terms_plus_obj_cite_number_offset_split + ); + foreach (sub_terms_bits; bi_sub_terms_split_arr) { + if (auto m = sub_terms_bits.match(rgx.bi_term_and_obj_cite_numbers_match)) { + sub_term = m.captures[1].strip; + obj_cite_number_offset = m.captures[2].to!int; + obj_cite_number_endpoint=(obj_cite_number + obj_cite_number_offset); + obj_cite_numbers ~= (obj_cite_number.to!string ~ " - " ~ to!string(obj_cite_number_endpoint) + ~ ":" ~ segment_anchor_tag); + } else { + sub_term = sub_terms_bits.strip; + obj_cite_numbers ~= to!string(obj_cite_number) + ~ ":" ~ segment_anchor_tag; + } + if (!empty(sub_term)) { + bi[main_term][sub_term] ~= obj_cite_numbers; + } + obj_cite_numbers=null; + } + } + } + } + hash_nugget = bi; + return hash_nugget; + } + invariant() { + } + } + struct BookIndexReportIndent { + int mkn, skn; + auto bookindex_report_indented(BI)( + BI bookindex_unordered_hashes + ) { + debug(asserts) { + static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); + } + auto mainkeys= + bookindex_unordered_hashes.byKey.array.sort().release; + foreach (mainkey; mainkeys) { + debug(bookindex1) { + writeln(mainkey); + } + auto subkeys= + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + debug(bookindex1) { + writeln(" ", subkey); + writeln(" ", to!string( + bookindex_unordered_hashes[mainkey][subkey] + )); + } + ++skn; + } + ++mkn; + } + } + } + struct BookIndexReportSection { + int mkn, skn; + auto rgx = Rgx(); + auto munge = ObjInlineMarkupMunge(); + auto bookindex_write_section(BI)( + BI bookindex_unordered_hashes + ) { + debug(asserts) { + static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); + } + auto mainkeys=bookindex_unordered_hashes.byKey.array.sort().release; + foreach (mainkey; mainkeys) { + write("_0_1 !{", mainkey, "}! "); + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + auto go = (ref_).replaceAll(rgx.book_index_go, "$1"); + write(" {", ref_, "}#", go, ", "); + } + writeln(" \\\\"); + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys= + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + write(" ", subkey, ", "); + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + auto go = (ref_).replaceAll(rgx.book_index_go, "$1"); + write(" {", ref_, "}#", go, ", "); + } + writeln(" \\\\"); + ++skn; + } + ++mkn; + } + } + auto bookindex_build_abstraction_section(BI,N,B)( + BI bookindex_unordered_hashes, + N obj_cite_number, + B opt_action_bool, + ) { + debug(asserts) { + static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); + static assert(is(typeof(obj_cite_number) == int)); + static assert(is(typeof(opt_action_bool) == bool[string])); + } + mixin SiSUnode; + mixin InternalMarkup; + auto mkup = InlineMarkup(); + string type_is; + string lev; + int heading_lev_markup, heading_lev_collapsed; + string attrib; + int[string] indent; + auto mainkeys = + bookindex_unordered_hashes.byKey.array.sort().release; + ObjGenericComposite[][string] bookindex_section; + ObjGenericComposite comp_obj_heading_, comp_obj_para; + auto node_para_int_ = node_metadata_para_int; + auto node_para_str_ = node_metadata_para_str; + if ((mainkeys.length > 0) + && (opt_action_bool["backmatter"] + && opt_action_bool["section_bookindex"])) { + string bi_tmp_seg, bi_tmp_scroll; + string[] bi_tmp_tags; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Book Index"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "_part_book_index"; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading.inline_links = true; + bookindex_section["scroll"] ~= comp_obj_heading_; + bookindex_section["seg"] ~= comp_obj_heading_; + ++obj_cite_number; + ++mkn; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Index"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "bookindex"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 2; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading.inline_links = false; + comp_obj_heading_.anchor_tags = ["bookindex"]; + bookindex_section["scroll"] ~= comp_obj_heading_; + bookindex_section["seg"] ~= comp_obj_heading_; + ++obj_cite_number; + ++mkn; + import std.array : appender; + auto buffer = appender!(char[])(); + string[dchar] transTable = [' ' : "_"]; + foreach (mainkey; mainkeys) { + bi_tmp_tags = [""]; + bi_tmp_scroll = "!{" ~ mainkey ~ "}! "; + buffer.clear(); + bi_tmp_tags ~= translate(mainkey, transTable); + bi_tmp_seg = "!{" ~ mainkey ~ "}! "; + auto bkidx_lnk_seg(string locs) { + string markup = ""; + if (auto m = locs.matchFirst(rgx.book_index_go_seg)) { + markup = + munge.url_links("{ " ~ m["link"] ~ " }" + ~ mkup.mark_internal_site_lnk ~ m["seg"] ~ ".fnSuffix" + ~ "#" ~ m["ocn"] ~ ", "); + } else { + writeln(__LINE__, ": ", locs); + } + return markup; + } + auto bkidx_lnk_scroll(string locs) { + string markup = ""; + if (auto m = locs.matchFirst(rgx.book_index_go)) { + markup = + munge.url_links("{ " ~ m["link"] ~ " }" + ~ mkup.mark_internal_site_lnk + ~ "#" ~ m["ocn"] ~ ", "); + } else { + writeln(__LINE__, ": ", locs); + } + return markup; + } + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + bi_tmp_scroll ~= bkidx_lnk_scroll(ref_); + bi_tmp_seg ~= bkidx_lnk_seg(ref_); + } + bi_tmp_scroll ~= " \\\\\n "; + bi_tmp_seg ~= " \\\\\n "; + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys = + bookindex_unordered_hashes[mainkey].byKey.array.sort().release; + foreach (subkey; subkeys) { + bi_tmp_scroll ~= subkey ~ ", "; + buffer.clear(); + bi_tmp_tags ~= translate(subkey, transTable); + bi_tmp_seg ~= subkey ~ ", "; + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + bi_tmp_scroll ~= bkidx_lnk_scroll(ref_); + bi_tmp_seg ~= bkidx_lnk_seg(ref_); + } + bi_tmp_scroll ~= " \\\\\n "; + bi_tmp_seg ~= " \\\\\n "; + ++skn; + } + bi_tmp_scroll = (bi_tmp_scroll).replaceFirst(rgx.trailing_linebreak, ""); + bi_tmp_seg = (bi_tmp_seg).replaceFirst(rgx.trailing_linebreak, ""); + comp_obj_para = comp_obj_para.init; + comp_obj_para.use = "backmatter"; + comp_obj_para.is_of = "para"; + comp_obj_para.is_a = "bookindex"; + comp_obj_para.text = bi_tmp_scroll.to!string.strip; + comp_obj_para.ocn = obj_cite_number; + comp_obj_para.obj_cite_number = (obj_cite_number==0) ? "" : to!string(obj_cite_number); + comp_obj_para.anchor_tags = bi_tmp_tags; + comp_obj_para.indent_hang = 0; + comp_obj_para.indent_base = 1; + comp_obj_para.bullet = false; + comp_obj_para.inline_links = true; + bookindex_section["scroll"] ~= comp_obj_para; + comp_obj_para.text = bi_tmp_seg.to!string.strip; + bookindex_section["seg"] ~= comp_obj_para; + ++obj_cite_number; + ++mkn; + } + } else { // no book index, (figure out what to do here) + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.text = "(skip) there is no Book Index"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + bookindex_section["scroll"] ~= comp_obj_heading_; + bookindex_section["seg"] ~= comp_obj_heading_; + } + auto t = tuple(bookindex_section, obj_cite_number); + return t; + } + } + /+ +/ + struct NotesSection { + string[string] object_notes; + int previous_count; + int mkn; + auto rgx = Rgx(); + private auto gather_notes_for_endnote_section( + ObjGenericComposite[] contents_am, + string segment_anchor_tag_that_object_belongs_to, + int cntr, + ) + in { + assert((contents_am[cntr].is_a == "para") + || (contents_am[cntr].is_a == "heading") + || (contents_am[cntr].is_a == "quote") + || (contents_am[cntr].is_a == "group") + || (contents_am[cntr].is_a == "block") + || (contents_am[cntr].is_a == "verse")); + assert(cntr >= previous_count); + previous_count=cntr; + assert( + (contents_am[cntr].text).match( + rgx.inline_notes_delimiter_al_regular_number_note) + ); + } + body { + mixin InternalMarkup; + auto mkup = InlineMarkup(); + auto munge = ObjInlineMarkupMunge(); + foreach( + m; + (contents_am[cntr].text).matchAll( + rgx.inline_notes_delimiter_al_regular_number_note + ) + ) { + debug(endnotes_build) { + writeln( + "{^{", m.captures[1], ".}^}" + ~ mkup.mark_internal_site_lnk, + segment_anchor_tag_that_object_belongs_to, + ".fnSuffix#noteref_\n ", m.captures[1], " ", + m.captures[2]); // sometimes need segment name (segmented html & epub) + } + // TODO NEXT you need anchor for segments at this point -> + object_notes["anchor"] ~= "note_" ~ m.captures[1] ~ "』"; + object_notes["notes"] ~= (segment_anchor_tag_that_object_belongs_to.empty) + ? (munge.url_links( + "{^{" ~ m.captures[1] ~ ".}^}#noteref_" + ~ m.captures[1]) ~ " " + ~ m.captures[2] ~ "』" + ) + : (munge.url_links( + "{^{" ~ m.captures[1] ~ ".}^}" + ~ mkup.mark_internal_site_lnk + ~ segment_anchor_tag_that_object_belongs_to + ~ ".fnSuffix#noteref_" + ~ m.captures[1]) ~ " " + ~ m.captures[2] ~ "』" + ); + } + return object_notes; + } + private auto gathered_notes() + in { + } + body { + string[][string] endnotes_; + if (object_notes.length > 1) { + endnotes_["notes"] = (object_notes["notes"].split(rgx.break_string))[0..$-1]; + endnotes_["anchor"] = (object_notes["anchor"].split(rgx.break_string))[0..$-1]; + } else { + endnotes_["notes"] = []; + endnotes_["anchor"] = []; + } + return endnotes_; + } + private auto endnote_objects( + int obj_cite_number, + bool[string] opt_action_bool, + ) + in { + } + body { + mixin SiSUnode; + ObjGenericComposite[] the_endnotes_section; + auto endnotes_ = gathered_notes(); + string type_is; + string lev, lev_markup_number, lev_collapsed_number; + string attrib; + int[string] indent; + ObjGenericComposite comp_obj_heading_; + if ((endnotes_["notes"].length > 0) + && (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"])) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Endnotes"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "_part_endnotes"; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_endnotes_section ~= comp_obj_heading_; + ++obj_cite_number; + ++mkn; + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "backmatter"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "Endnotes"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.segment_anchor_tag = "endnotes"; + comp_obj_heading_.marked_up_level = "1"; + comp_obj_heading_.heading_lev_markup = 4; + comp_obj_heading_.heading_lev_collapsed = 2; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + comp_obj_heading_.anchor_tags = ["endnotes"]; + the_endnotes_section ~= comp_obj_heading_; + ++obj_cite_number; + ++mkn; + } else { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.use = "empty"; + comp_obj_heading_.is_of = "para"; + comp_obj_heading_.is_a = "heading"; + comp_obj_heading_.text = "(skip) there are no Endnotes"; + comp_obj_heading_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_heading_.marked_up_level = "B"; + comp_obj_heading_.heading_lev_markup = 1; + comp_obj_heading_.heading_lev_collapsed = 1; + comp_obj_heading_.parent_ocn = 1; + comp_obj_heading_.parent_lev_markup = 0; + the_endnotes_section ~= comp_obj_heading_; + } + if (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"]) { + ObjGenericComposite comp_obj_endnote_; + comp_obj_endnote_ = comp_obj_endnote_.init; + comp_obj_endnote_.use = "backmatter"; + comp_obj_endnote_.is_of = "para"; + comp_obj_endnote_.is_a = "endnote"; + comp_obj_endnote_.ocn = 0; + comp_obj_heading_.obj_cite_number = ""; + comp_obj_endnote_.indent_hang = 0; + comp_obj_endnote_.indent_base = 0; + comp_obj_endnote_.bullet = false; + foreach (i, endnote; endnotes_["notes"]) { + auto m = endnote.matchFirst(rgx.note_ref); + string notenumber = m.captures[1].to!string; + string anchor_tag = "note_" ~ notenumber; + comp_obj_endnote_.anchor_tags = [ endnotes_["anchor"][i] ]; + comp_obj_endnote_.inline_links = true; + comp_obj_endnote_.text = endnote.strip; + the_endnotes_section ~= comp_obj_endnote_; + } + } + auto t = tuple(the_endnotes_section, obj_cite_number); + return t; + } + } + /+ +/ + struct Bibliography { + public JSONValue[] _bibliography_(Bi,BJ)( + return ref Bi biblio_unsorted_incomplete, + return ref BJ bib_arr_json + ) + in { + debug(asserts) { + static assert(is(typeof(biblio_unsorted_incomplete) == string[])); + static assert(is(typeof(bib_arr_json) == JSONValue[])); + } + } + body { + JSONValue[] biblio_unsorted = + _biblio_unsorted_complete_(biblio_unsorted_incomplete, bib_arr_json); + biblio_arr_json = []; + biblio_unsorted_incomplete = []; + JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); + biblio_debug(biblio_sorted__); + debug(biblio0) { + writeln("---"); + writeln("unsorted incomplete: ", biblio_unsorted_incomplete.length); + writeln("json: ", bib_arr_json.length); + writeln("unsorted: ", biblio_unsorted.length); + writeln("sorted: ", biblio_sorted__.length); + int cntr; + int[7] x; + while (cntr < x.length) { + writeln(cntr, ": ", biblio_sorted__[cntr]["fulltitle"]); + cntr++; + } + } + return biblio_sorted__; + } + final private JSONValue[] _biblio_unsorted_complete_(Bi,BJ)( + Bi biblio_unordered, + return ref BJ bib_arr_json + ) { + debug(asserts) { + static assert(is(typeof(biblio_unordered) == string[])); + 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 + +/ + JSONValue j = parseJSON(bibent); + if (!empty(j["fulltitle"].str)) { + if (!empty(j["author_raw"].str)) { + j["deemed_author"]=j["author_arr"][0]; + } else if (!empty(j["editor_raw"].str)) { + j["deemed_author"]=j["editor_arr"][0]; + } + j["sortby_deemed_author_year_title"] = ( + j["deemed_author"].str ~ + "; " ~ + j["year"].str ~ + "; " ~ + j["fulltitle"].str + ); + } + bib_arr_json ~= j; + } + JSONValue[] biblio_unsorted_array_of_json_objects = + bib_arr_json.dup; + destroy(bib_arr_json); + return biblio_unsorted_array_of_json_objects; + } + final private JSONValue[] biblio_sort(BJ)(BJ biblio_unordered) { + debug(asserts) { + static assert(is(typeof(biblio_unordered) == JSONValue[])); + } + JSONValue[] biblio_sorted_; + biblio_sorted_ = + sort!((a, b){ + return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); + })(biblio_unordered).array; + debug(bibliosorted) { + foreach (j; biblio_sorted_) { + if (!empty(j["fulltitle"].str)) { + writeln(j["sortby_deemed_author_year_title"]); + } + } + } + return biblio_sorted_; + } + void biblio_debug(BJ)(BJ biblio_sorted) { + debug(asserts) { + static assert(is(typeof(biblio_sorted) == JSONValue[])); + } + debug(biblio0) { + foreach (j; biblio_sorted) { + if (!empty(j["fulltitle"].str)) { + writeln(j["sortby_deemed_author_year_title"]); + } + } + } + } + } + /+ +/ + struct NodeStructureMetadata { + int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; + int obj_cite_number; + int[string] p_; // p_ parent_ + auto rgx = Rgx(); + ObjGenericComposite node_location_emitter(Lv,Ta,N,C,P,I)( + Lv lev_markup_number, + Ta segment_anchor_tag, + N obj_cite_number_, + C cntr_, + P ptr_, + I is_ + ) + in { + debug(asserts) { + static assert(is(typeof(lev_markup_number) == string)); + static assert(is(typeof(segment_anchor_tag) == string)); + static assert(is(typeof(obj_cite_number_) == int)); + static assert(is(typeof(cntr_) == int)); + static assert(is(typeof(ptr_) == int)); + static assert(is(typeof(is_) == string)); + } + assert(is_ != "heading"); + assert(obj_cite_number_.to!int >= 0); + } + body { + assert(is_ != "heading"); // should not be necessary + assert(obj_cite_number_.to!int >= 0); // should not be necessary + int obj_cite_number = obj_cite_number_.to!int; + if (lv7 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_4; + p_["obj_cite_number"] = lv7; + } else if (lv6 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_3; + p_["obj_cite_number"] = lv6; + } else if (lv5 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_2; + p_["obj_cite_number"] = lv5; + } else { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_1; + p_["obj_cite_number"] = lv4; + } + ObjGenericComposite comp_obj_location; + comp_obj_location = comp_obj_location.init; + comp_obj_location.is_a = is_; + comp_obj_location.ocn = obj_cite_number_; + comp_obj_location.segment_anchor_tag = segment_anchor_tag.to!string; + comp_obj_location.parent_ocn = p_["obj_cite_number"]; + comp_obj_location.parent_lev_markup = p_["lev_markup_number"]; + debug(node) { + if (lev_markup_number.match(rgx.levels_numbered_headings)) { + writeln("x ", _node.to!string); + } else { + writeln("- ", _node.to!string); + } + } + assert(comp_obj_location.parent_lev_markup >= 4); + assert(comp_obj_location.parent_lev_markup <= 7); + assert(comp_obj_location.parent_ocn >= 0); + return comp_obj_location; + } + invariant() { + } + ObjGenericComposite node_emitter_heading(T,L,Lm,Lc,Ta,N,C,P,LA,I,PSn,fNr,fNs,fL)( + T _text, + L lev, + Lm lev_markup_number, + Lc lev_collapsed_number, + Ta segment_anchor_tag, + N obj_cite_number_, + C cntr_, + P ptr_, + LA lv_ancestors, + I is_, + PSn html_segnames_ptr, + fNr flag_notes_reg, + fNs flag_notes_star, + fL flag_links, + ) + in { + debug(asserts) { + static assert(is(typeof(_text) == string)); + static assert(is(typeof(lev) == string)); + static assert(is(typeof(lev_markup_number) == string)); + static assert(is(typeof(lev_collapsed_number) == string)); + static assert(is(typeof(segment_anchor_tag) == string)); + static assert(is(typeof(obj_cite_number_) == int)); + static assert(is(typeof(cntr_) == int)); + static assert(is(typeof(ptr_) == int)); + static assert(is(typeof(lv_ancestors) == string[])); + static assert(is(typeof(is_) == string)); + static assert(is(typeof(html_segnames_ptr) == int)); + } + assert(is_ == "heading"); + assert(to!int(obj_cite_number_) >= 0); + assert( + lev_markup_number.match(rgx.levels_numbered), + ("not a valid heading level: " ~ lev_markup_number ~ " at " ~ obj_cite_number_.to!string) + ); + if (lev_markup_number.match(rgx.levels_numbered)) { + if (lev_markup_number.to!int == 0) { + assert(obj_cite_number_.to!int == 1); + } + } + } + body { + int obj_cite_number = obj_cite_number_.to!int; + switch (lev_markup_number.to!int) { + case 0: + lv = DocStructMarkupHeading.h_sect_A; + lv0 = obj_cite_number; + lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] = 0; + p_["obj_cite_number"] = 0; + break; + case 1: + lv = DocStructMarkupHeading.h_sect_B; + lv1 = obj_cite_number; + lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_A; + p_["obj_cite_number"] = lv0; + break; + case 2: + lv = DocStructMarkupHeading.h_sect_C; + lv2 = obj_cite_number; + lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_B; + p_["obj_cite_number"] = lv1; + break; + case 3: + lv = DocStructMarkupHeading.h_sect_D; + lv3=obj_cite_number; + lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_C; + p_["obj_cite_number"] = lv2; + break; + case 4: + lv = DocStructMarkupHeading.h_text_1; + lv4 = obj_cite_number; + lv5=0; lv6=0; lv7=0; + if (lv3 > State.off) { + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_D; + p_["obj_cite_number"] = lv3; + } else if (lv2 > State.off) { + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_C; + p_["obj_cite_number"] = lv2; + } else if (lv1 > State.off) { + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_B; + p_["obj_cite_number"] = lv1; + } else { + p_["lev_markup_number"] = + DocStructMarkupHeading.h_sect_A; + p_["obj_cite_number"] = lv0; + } + break; + case 5: + lv = DocStructMarkupHeading.h_text_2; + lv5 = obj_cite_number; + lv6=0; lv7=0; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_text_1; + p_["obj_cite_number"] = lv4; + break; + case 6: + lv = DocStructMarkupHeading.h_text_3; + lv6 = obj_cite_number; + lv7=0; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_text_2; + p_["obj_cite_number"] = lv5; + break; + case 7: + lv = DocStructMarkupHeading.h_text_4; + lv7 = obj_cite_number; + p_["lev_markup_number"] = + DocStructMarkupHeading.h_text_3; + p_["obj_cite_number"] = lv6; + break; + default: + break; + } + ObjGenericComposite _comp_obj_heading_; + _comp_obj_heading_ = _comp_obj_heading_.init; + _comp_obj_heading_.use = "body"; + _comp_obj_heading_.is_of = "para"; + _comp_obj_heading_.is_a = "heading"; + _comp_obj_heading_.text = _text.to!string.strip; + _comp_obj_heading_.ocn = obj_cite_number_; + _comp_obj_heading_.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; + _comp_obj_heading_.segment_anchor_tag = segment_anchor_tag.to!string; + _comp_obj_heading_.marked_up_level = lev; + _comp_obj_heading_.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); + _comp_obj_heading_.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); + _comp_obj_heading_.parent_ocn = p_["obj_cite_number"]; + _comp_obj_heading_.parent_lev_markup = p_["lev_markup_number"]; + _comp_obj_heading_.heading_ancestors_text = lv_ancestors; + _comp_obj_heading_.ptr_doc_object = cntr_; + _comp_obj_heading_.ptr_html_segnames = ((lev_markup_number == "4") ? html_segnames_ptr : 0); + _comp_obj_heading_.ptr_heading = ptr_; + _comp_obj_heading_.inline_notes_reg = flag_notes_reg; + _comp_obj_heading_.inline_notes_star = flag_notes_star; + _comp_obj_heading_.inline_links = flag_links; + debug(node) { + if (lev_markup_number.match(rgx.levels_numbered_headings)) { + writeln("* ", _node.to!string); + } + } + debug(nodeheading) { + if (lev_markup_number.match(rgx.levels_numbered_headings)) { + writeln("* ", _node.to!string); + } + } + assert(_comp_obj_heading_.parent_lev_markup <= 7); + assert(_comp_obj_heading_.parent_ocn >= 0); + if (lev_markup_number.match(rgx.levels_numbered_headings)) { + assert(_comp_obj_heading_.heading_lev_markup <= 7); + assert(_comp_obj_heading_.ocn >= 0); + if (_comp_obj_heading_.parent_lev_markup > 0) { + assert(_comp_obj_heading_.parent_lev_markup < _comp_obj_heading_.heading_lev_markup); + if (_comp_obj_heading_.ocn != 0) { + assert(_comp_obj_heading_.parent_ocn < _comp_obj_heading_.ocn); + } + } + if (_comp_obj_heading_.heading_lev_markup == 0) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_B); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_C); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_1) { + assert(_comp_obj_heading_.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_2) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_1); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_3) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_2); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_4) { + assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_3); + } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_5) { + } + } + return _comp_obj_heading_; + } + invariant() { + } + } + /+ abstraction functions emitters ↑ +/ + /+ ↓ abstraction functions assertions +/ + auto assertions_doc_structure(O,Lv)( + O an_object, + Lv lv + ) { + debug(asserts) { + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(lv) == int[string])); + } + if (lv["h3"] > State.off) { + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h2"] > State.off); + } else if (lv["h2"] > State.off) { + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h3"] == State.off); + } else if (lv["h1"] > State.off) { + assert(lv["h0"] > State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + } else if (lv["h0"] > State.off) { + assert(lv["h1"] == State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + } else { + assert(lv["h0"] == State.off); + assert(lv["h1"] == State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + } + if (lv["h7"] > State.off) { + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + assert(lv["h6"] > State.off); + } else if (lv["h6"] > State.off) { + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + assert(lv["h7"] == State.off); + } else if (lv["h5"] > State.off) { + assert(lv["h4"] > State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } else if (lv["h4"] > State.off) { + assert(lv["h5"] == State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } else { + assert(lv["h4"] == State.off); + assert(lv["h5"] == State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } + if (lv["h0"] == State.off) { + assert(lv["h1"] == State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + assert(lv["h4"] == State.off); + assert(lv["h5"] == State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } + if (lv["h1"] == State.off) { + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + } + if (lv["h2"] == State.off) { + assert(lv["h3"] == State.off); + } + if (lv["h3"] == State.off) { + } + if (lv["h4"] == State.off) { + assert(lv["h5"] == State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } + if (lv["h5"] == State.off) { + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } + if (lv["h6"] == State.off) { + assert(lv["h7"] == State.off); + } + if (lv["h7"] == State.off) { + } + switch ((an_object["lev"]).to!string) { + case "A": + if (lv["h0"] == State.off) { + assert(lv["h1"] == State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + assert(lv["h4"] == State.off); + assert(lv["h5"] == State.off); + assert(lv["h6"] == State.off); + assert(lv["h7"] == State.off); + } else { // (lv["h0"] > State.off) + assert(lv["h0"] == State.off,"error should not enter level A a second time"); + } + break; + case "B": + if (lv["h1"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h2"] == State.off); + assert(lv["h3"] == State.off); + } else { // (lv["h1"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + } + break; + case "C": + if (lv["h2"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h3"] == State.off); + } else { // (lv["h2"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h2"] > State.off); + } + break; + case "D": + if (lv["h3"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h2"] > State.off); + } else { // (lv["h3"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h1"] > State.off); + assert(lv["h2"] > State.off); + assert(lv["h3"] > State.off); + } + break; + case "1": + if (lv["h4"] == State.off) { + assert(lv["h0"] > State.off); + } else { // (lv["h4"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + } + break; + case "2": + if (lv["h5"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + } else { // (lv["h5"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + } + break; + case "3": + if (lv["h6"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + } else { // (lv["h6"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + assert(lv["h6"] > State.off); + } + break; + case "4": + if (lv["h7"] == State.off) { + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + assert(lv["h6"] > State.off); + } else { // (lv["h7"] > State.off) + assert(lv["h0"] > State.off); + assert(lv["h4"] > State.off); + assert(lv["h5"] > State.off); + assert(lv["h6"] > State.off); + assert(lv["h7"] > State.off); + } + break; + default: + break; + } + } + auto assertions_flag_types_block_status_none_or_closed(T)(T type) { + debug(asserts) { + static assert(is(typeof(type) == int[string])); + } + assert( + (type["code"] == TriState.off) + || (type["code"] == TriState.closing), + "code block status: off or closing"); + assert( + (type["poem"] == TriState.off) + || (type["poem"] == TriState.closing), + "poem status: off or closing"); + assert( + (type["table"] == TriState.off) + || (type["table"] == TriState.closing), + "table status: off or closing"); + assert( + (type["group"] == TriState.off) + || (type["group"] == TriState.closing), + "group block status: off or closing"); + assert( + (type["block"] == TriState.off) + || (type["block"] == TriState.closing), + "block status: off or closing"); + } + /+ abstraction functions assertions ↑ +/ +} /+ ← closed: template SiSUdocAbstraction +/ +template docSectKeysSeq() { + auto docSectKeysSeq(string[][string] document_section_keys_sequenced) { + struct doc_sect_keys_seq { + auto seg() { + return document_section_keys_sequenced["seg"]; + } + auto scroll() { + return document_section_keys_sequenced["scroll"]; + } + } + return doc_sect_keys_seq(); + } +} diff --git a/src/sdp/ao/abstraction.d b/src/sdp/ao/abstraction.d new file mode 100644 index 0000000..17b1dff --- /dev/null +++ b/src/sdp/ao/abstraction.d @@ -0,0 +1,132 @@ +module sdp.ao.abstraction; +template SiSUabstraction() { + /+ sdp: sisu document parser, see http://sisudoc.org +/ + import sdp.ao; + import + std.getopt, + std.process; + import + sdp.ao.abstraction_summary, + sdp.ao.abstract_doc_source, + sdp.ao.conf_make_meta, + // sdp.ao.conf_make_meta_native, + sdp.ao.conf_make_meta_sdlang, + sdp.ao.defaults, + sdp.ao.doc_debugs, + sdp.ao.read_config_files, + sdp.ao.read_source_files, + sdp.ao.rgx, + sdp.output.hub, + sdp.output.paths_source; + + + mixin SiSUrgxInit; + mixin SiSUregisters; + mixin SiSUheaderExtractSDLang; + mixin SiSUnode; + mixin SiSUbiblio; + mixin SiSUrgxInitFlags; + mixin outputHub; + enum headBody { header, body_content, insert_filelist } + enum makeMeta { make, meta } + enum docAbst { doc_abstraction, section_keys, segnames, segnames_0_4, images } + auto rgx = Rgx(); + auto SiSUabstraction(Fn,O,E)(Fn fn_src, O opts, E env){ + auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); + auto sdl_root_doc_make = ConfigHub!()("sisu_document_make", env); + auto confsdl = HeaderExtractSDL(); + auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); + auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); + /+ ↓ read file (filename with path) +/ + /+ ↓ file tuple of header and content +/ + auto _header_body_inserts = + SiSUrawMarkupContent!()(fn_src); + static assert(!isTypeTuple!(_header_body_inserts)); + static assert(_header_body_inserts.length==3); + debug(header_and_body) { + writeln(header); + writeln(_header_body_inserts.length); + writeln(_header_body_inserts.length[headBody.body_content][0]); + } + /+ ↓ split header into make and meta +/ + auto _make_and_meta = + SiSUheaderExtractHub!()(_header_body_inserts[headBody.header], conf_doc_make_aa); + static assert(!isTypeTuple!(_make_and_meta)); + static assert(_make_and_meta.length==2); + /+ ↓ document abstraction: process document, return abstraction as tuple +/ + auto da = SiSUdocAbstraction!()( + (_header_body_inserts[headBody.body_content]), + (_make_and_meta[makeMeta.make]), + (_make_and_meta[makeMeta.meta]), + opts + ); + static assert(!isTypeTuple!(da)); + static assert(da.length==5); + auto doc_abstraction = da[docAbst.doc_abstraction]; /+ head ~ toc ~ body ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~ blurb; +/ + auto _document_section_keys_sequenced = da[docAbst.section_keys]; + string[] _doc_html_segnames = da[docAbst.segnames]; + string[] _doc_epub_segnames_0_4 = da[docAbst.segnames_0_4]; + auto _images = da[docAbst.images]; + struct DocumentMatters { + auto keys_seq() { + /+ contains .seg & .scroll sequences +/ + auto _k = _document_section_keys_sequenced; + return _k; + } + string[] segnames() { + string[] _k = _doc_html_segnames; + return _k; + } + string[] segnames_lv_0_to_4() { + string[] _k = _doc_epub_segnames_0_4; + return _k; + } + auto dochead_make() { + string[string][string] _k = _make_and_meta[makeMeta.make]; + return _k; + } + auto dochead_meta() { + 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; + } + auto language() { + string _k; + if (auto m = fn_src.match(rgx.language_code_and_filename)) { + _k = m.captures[1]; + } else { + _k = "en"; + } + return _k; + } + auto file_insert_list() { + string[] _k = _header_body_inserts[headBody.insert_filelist]; + return _k; + } + auto image_list() { + auto _k = _images; + return _k; + } + auto opt_action_bool() { + bool[string] _k = opts; + return _k; + } + auto environment() { + auto _k = env; + return _k; + } + } + auto doc_matters = DocumentMatters(); + auto t = tuple(doc_abstraction, doc_matters); + static assert(t.length==2); + return t; + } +} diff --git a/src/sdp/ao/abstraction_summary.d b/src/sdp/ao/abstraction_summary.d new file mode 100644 index 0000000..2cc6967 --- /dev/null +++ b/src/sdp/ao/abstraction_summary.d @@ -0,0 +1,81 @@ +module sdp.ao.abstraction_summary; +template SiSUabstractionSummary() { + auto SiSUabstractionSummary(S,T)( + auto return ref const S doc_abstraction, + auto return ref T doc_matters, + ) { + import + sdp.ao.defaults, + sdp.ao.rgx; + import + std.array, + std.exception, + std.stdio, + std.regex, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; + mixin InternalMarkup; + auto markup = InlineMarkup(); + if (doc_matters.opt_action_bool["verbose"]) { + string[string] check = [ + "last_obj_cite_number" : "NA [debug \"checkdoc\" not run]", + ]; + foreach (k; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[k]) { + if (obj.use != "empty") { + if (!empty(obj.obj_cite_number)) { + check["last_obj_cite_number"] = obj.obj_cite_number; + } + } + } + } + auto min_repeat_number = 66; + auto char_repeat_number = (doc_matters.dochead_meta["title"]["full"].length + + doc_matters.dochead_meta["creator"]["author"].length + 4); + char_repeat_number = (char_repeat_number > min_repeat_number) + ? char_repeat_number + : min_repeat_number; + writefln( + "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n%30-s%10-d\n(%s: %s)\n%s", + markup.repeat_character_by_number_provided("-", char_repeat_number), + doc_matters.dochead_meta["title"]["full"], + doc_matters.dochead_meta["creator"]["author"], + doc_matters.source_filename, + markup.repeat_character_by_number_provided("-", char_repeat_number), + "length toc arr:", + to!int(doc_abstraction["toc_seg"].length), + "length doc_abstraction arr:", + to!int(doc_abstraction["body"].length), + "last obj_cite_number:", + to!int(check["last_obj_cite_number"]), + "length endnotes:", + (doc_abstraction["endnotes"].length > 1) + ? (to!int(doc_abstraction["endnotes"].length)) + : 0, + "length glossary:", + (doc_abstraction["glossary"].length > 1) + ? (to!int(doc_abstraction["glossary"].length)) + : 0, + "length biblio:", + (doc_abstraction["bibliography"].length > 1) + ? (to!int(doc_abstraction["bibliography"].length)) + : 0, + "length bookindex:", + (doc_abstraction["bookindex_seg"].length > 1) + ? (to!int(doc_abstraction["bookindex_seg"].length)) + : 0, + "length blurb:", + (doc_abstraction["blurb"].length > 1) + ? (to!int(doc_abstraction["blurb"].length)) + : 0, + __FILE__, + __LINE__, + markup.repeat_character_by_number_provided("-", min_repeat_number), + ); + } + } +} diff --git a/src/sdp/ao/conf_make_meta.d b/src/sdp/ao/conf_make_meta.d new file mode 100644 index 0000000..0f6d27d --- /dev/null +++ b/src/sdp/ao/conf_make_meta.d @@ -0,0 +1,47 @@ +/++ + extract native/orig header return associative array
+ + the header is passed as text (lopped off top of a sisu markup file until the + required first heading ^A~), determine whether is a native header or sdlang one + with a regex check if whether it contains the "native header" required tag/field + @title: then process accordingly as a "native header" or "sdlang header" + converting the metadata and make instructions to a common json format used by + program internally. Moved to associative array. ++/ +module sdp.ao.conf_make_meta; +template SiSUheaderExtractHub() { + import + std.exception, + std.regex, + std.stdio, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import sdlang; + import + sdp.ao.conf_make_meta_native, + sdp.ao.conf_make_meta_sdlang, + sdp.ao.rgx; + mixin SiSUrgxInit; + mixin SiSUheaderExtractNative; + mixin SiSUheaderExtractSDLang; + auto rgx = Rgx(); + auto SiSUheaderExtractHub(Src, DocMake)( + Src header_src, + DocMake conf_doc_make_aa + ) { + debug(asserts){ + static assert(is(typeof(header_src) == char[])); + static assert(is(typeof(conf_doc_make_aa) == string[string][string])); + } + auto head_native = HeaderDocMetadataAndMakeNativeToAA(); + auto head_sdlang = HeaderExtractSDL(); + auto header_make_and_meta_tuple = (header_src.match(rgx.native_header_meta_title)) + ? (head_native.headerNativeToAA(header_src)) + : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa)); + static assert(!isTypeTuple!(header_make_and_meta_tuple)); + static assert(header_make_and_meta_tuple.length==2); + return header_make_and_meta_tuple; + } +} diff --git a/src/sdp/ao/conf_make_meta_native.d b/src/sdp/ao/conf_make_meta_native.d new file mode 100644 index 0000000..8954c9a --- /dev/null +++ b/src/sdp/ao/conf_make_meta_native.d @@ -0,0 +1,330 @@ +/++ + native headers using
@title:
:subtitle:
type tags
+ extract native/orig header return associative array ++/ +module sdp.ao.conf_make_meta_native; +template SiSUheaderExtractNative() { + import + std.exception, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import + sdp.ao.defaults, + sdp.ao.rgx; + struct HeaderDocMetadataAndMakeNativeToAA { + mixin SiSUregisters; + mixin SiSUrgxInitFlags; + mixin SiSUrgxInit; + auto rgx = Rgx(); + enum State { off, on } + string hm, hs; + auto header_metadata_and_make_aa(H,Me,Ma)( + H header, + Me dochead_meta, + Ma dochead_make + ) + in { + debug(asserts){ + static assert(is(typeof(header) == string)); + static assert(is(typeof(dochead_meta) == string[string][string])); + static assert(is(typeof(dochead_make) == string[string][string])); + } + } + body { + scope(exit) { + destroy(header); + destroy(dochead_meta); + destroy(dochead_make); + } + if (auto t = header.match(rgx.native_header_main)) { + char[][] header_obj_spl = + (cast(char[]) header).split(rgx.line_delimiter_ws_strip); + auto hm = to!string(t.captures[1]); + if (hm.match(rgx.main_headers)) { + foreach (line; header_obj_spl) { + if (auto m = line.match(rgx.native_header_main)) { + if (!empty(m.captures[2])) { + if (hm == "creator") { + dochead_meta[hm]["author"] = + to!string(m.captures[2]); + } else if (hm == "title") { + dochead_meta[hm]["main"] = + to!string(m.captures[2]); + } else if (hm == "publisher") { + dochead_meta[hm]["name"] = + to!string(m.captures[2]); + } + } + } else if (auto s = match(line, rgx.native_header_sub)) { + if (!empty(s.captures[2])) { + auto hs = to!string(s.captures[1]); + if ((hm == "make" ) + && (dochead_make[hm])) { + switch (hm) { + case "make": + if (hs.match(rgx.native_subhead_make)) { + if (dochead_make[hm][hs]) { + dochead_make[hm][hs] = to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + default: + break; + } + } else if (dochead_meta[hm]) { + switch (hm) { + case "creator": + if (hs.match(rgx.native_subhead_creator)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "title": + if (hs.match(rgx.native_subhead_title)) { + if ((hs == "subtitle") + && (dochead_meta[hm]["sub"])) { + dochead_meta[hm]["sub"] = + to!string(s.captures[2]); + } else if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "rights": + if (hs.match(rgx.native_subhead_rights)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "date": + if (hs.match(rgx.native_subhead_date)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "original": + if (hs.match(rgx.native_subhead_original)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "classify": + if (hs.match(rgx.native_subhead_classify)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "identifier": + if (hs.match(rgx.native_subhead_identifier)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "notes": + if (hs.match(rgx.native_subhead_notes)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "publisher": + if (hs.match(rgx.native_subhead_publisher)) { + if (dochead_meta[hm][hs]) { + dochead_meta[hm][hs] = + to!string(s.captures[2]); + } + } else { + writeln("not a valid header type:", hm, ":", hs); + destroy(hm); + destroy(hs); + } + break; + case "links": + destroy(hm); + destroy(hs); + break; + default: + break; + } + } + } + } + } + } else { + writeln("not a valid header type:", hm); + } + } + auto t = tuple(dochead_meta, dochead_make); + static assert(t.length==2); + return t; + } + private auto native_header_extract(L,Lo,O,T)( + L line, + return ref Lo line_occur, + return ref O an_object, + return ref T type + ) { + debug(asserts){ + static assert(is(typeof(line) == char[])); + static assert(is(typeof(line_occur) == int[string])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + if (line.matchFirst(rgx.native_header_make)) { /+ matched header_make +/ + debug(header1) { /+ writeln(line); +/ } + type["header"] = State.on; + type["header_make"] = State.on; + type["header_meta"] = State.off; + ++line_occur["header_make"]; + an_object["body_nugget"] ~= line ~= "\n"; + } else if (line.matchFirst(rgx.native_header)) { /+ matched header_metadata +/ + /+ (generic header match and not previously caught by header_make) +/ + debug(header1) { /+ writeln(line); +/ } + type["header"] = State.on; + type["header_make"] = State.off; + type["header_meta"] = State.on; + ++line_occur["header_meta"]; + an_object["body_nugget"] ~= line ~= "\n"; + } else if (type["header_make"] == State.on + && (line_occur["header_make"] > State.off)) { /+ header_make flag set +/ + if (line.matchFirst(rgx.native_header_sub)) { /+ sub-header +/ + debug(header1) { /+ writeln(line); +/ } + ++line_occur["header_make"]; + an_object["body_nugget"] ~= line ~= "\n"; + } + } else if (type["header_meta"] == State.on + && (line_occur["header_meta"] > State.off)) { /+ header_metadata flag set +/ + if (line.matchFirst(rgx.native_header_sub)) { /+ sub-header +/ + debug(header1) { /+ writeln(line); +/ } + ++line_occur["header_meta"]; + an_object["body_nugget"] ~= line ~= "\n"; + } + } + return an_object; + } + auto header_reset_states_common(Lo,O,T)( + return ref Lo line_occur, + return ref O an_object, + return ref T type + ) { + debug(asserts){ + static assert(is(typeof(line_occur) == int[string])); + static assert(is(typeof(an_object) == string[string])); + static assert(is(typeof(type) == int[string])); + } + line_occur["header_make"] = State.off; + line_occur["header_meta"] = State.off; + type["header"] = State.off; + an_object.remove("body_nugget"); + an_object.remove("is"); + an_object.remove("attrib"); + } + private auto headerNativeToAA(Hn)(Hn src_header) { + debug(asserts){ + static assert(is(typeof(src_header) == char[])); + } + auto type = flags_type_init; + type = [ + "header" : State.off, + "header_make" : State.off, + "header_meta" : State.off, + ]; + string[string] an_object; + int[string] line_occur; + auto dochead_make = make_aa; + auto dochead_meta = meta_aa; + auto set_header = HeaderDocMetadataAndMakeNativeToAA(); + char[][] source_header_arr = + (cast(char[]) src_header).split(rgx.newline_eol_delimiter); + foreach(header_line; source_header_arr) { + if (auto m = header_line.matchFirst(rgx.comment)) { + /+ matched comment +/ + debug(comment) { + } + header_reset_states_common(line_occur, an_object, type); + } else if ((header_line.matchFirst(rgx.native_header)) + || (type["header_make"] == State.on + && (line_occur["header_make"] > State.off)) + || (type["header_meta"] == State.on + && (line_occur["header_meta"] > State.off))) { + if (header_line.length == 0) { + /+ header_make instructions (current line empty) +/ + auto dochead_metadata_and_make = + set_header.header_metadata_and_make_aa(strip(an_object["body_nugget"]), dochead_meta, dochead_make); + static assert(!isTypeTuple!(dochead_metadata_and_make)); + dochead_meta = dochead_metadata_and_make[0]; + dochead_make = dochead_metadata_and_make[1]; + header_reset_states_common(line_occur, an_object, type); + type["header_make"] = State.off; + type["header_meta"] = State.off; + debug(headersdlang) { + writeln(dochead_metadata_and_make); + } + } else { + an_object = native_header_extract(header_line, line_occur, an_object, type); + } + } + } + auto t = tuple( + dochead_make, + dochead_meta, + ); + return t; + } + } +} diff --git a/src/sdp/ao/conf_make_meta_sdlang.d b/src/sdp/ao/conf_make_meta_sdlang.d new file mode 100644 index 0000000..567853e --- /dev/null +++ b/src/sdp/ao/conf_make_meta_sdlang.d @@ -0,0 +1,150 @@ +/++ + sdlang headers
+ extract sdlang header return sdlang ++/ +module sdp.ao.conf_make_meta_sdlang; +template SiSUheaderExtractSDLang() { + import + std.exception, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import + sdp.ao.defaults, + sdp.ao.rgx; + struct HeaderExtractSDL { + mixin SiSUregisters; + mixin SiSUrgxInit; + auto rgx = Rgx(); + private auto sdlangToAAmake(C,Tag)(C conf, Tag conf_sdlang) { + debug(asserts){ + static assert(is(typeof(conf) == string[string][string])); + } + foreach (maintag, subtags; conf) { + foreach (subtag, content; subtags) { + if (!(conf_sdlang.maybe.tags[maintag].empty)) { + if (!(conf_sdlang.tags[maintag][0].maybe.attributes[subtag].empty) + && (conf_sdlang.tags[maintag][0].attributes[subtag][0].value.length > 0)) { + debug(headersdlang) { + writeln(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); + } + conf[maintag][subtag] = + to!string(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); + } + } + } + } + return conf; + } + private auto configSettingsSDLangToAAmake(Tag)(Tag conf_sdlang) { + auto conf = sdlangToAAmake(conf_aa, conf_sdlang); + return conf; + } + private auto documentMakeSDLangToAAmake(Tag)(Tag document_make_sdlang) { + auto dochead_make = sdlangToAAmake(make_aa, document_make_sdlang); + return dochead_make; + } + final private auto headerMakeSDLang(Hs)(Hs src_header) { + debug(asserts){ + static assert(is(typeof(src_header) == string)); + } + scope(failure) { + stderr.writefln( + "%s\n%s\n%s:%s failed here:\n src_header: %s", + __MODULE__, __FUNCTION__, + __FILE__, __LINE__, + src_header, + ); + } + Tag sdl_root_header; + try { + sdl_root_header = parseSource(src_header); + } + catch(ParseException e) { + stderr.writeln("SDLang problem with this document header:"); + stderr.writeln(src_header); + // Error messages of the form: + // myFile.sdl(5:28): Error: Invalid integer suffix. + stderr.writeln(e.msg); + } + debug(sdlang) { + writeln("header SDL:"); + writeln(sdl_root_header.toSDLDocument()); + } + return sdl_root_header; + } + private auto headerSDLangGet(Hs)(Hs src_header) { + debug(asserts){ + static assert(is(typeof(src_header) == char[])); + } + char[][] source_header_arr = + (cast(char[]) src_header).split(rgx.newline_eol_delimiter); + char[] header_clean; + foreach(header_line; source_header_arr) { + if (!match(header_line, rgx.comments)) { + header_clean ~= header_line ~ "\n"; + } + } + /+ get sdlang tags +/ + auto header_sdlang=headerMakeSDLang(to!string(header_clean)); + debug(sdlang) { + writeln("--------------"); + stdout.rawWrite( header_sdlang.toSDLDocument() ); + writeln("--------------"); + Value test = header_sdlang.tags["title"][0].values[0]; + assert(test == typeid(string)); + // writeln(header_sdlang.maybe.tags["title"]); + // writeln(header_sdlang.maybe.tags["title"][0].maybe.attributes["subtitle"]); + } + return header_sdlang; // sdlang.ast.Tag + } + private auto headerSDLangToAAmake(Tag,Ma)(Tag header_sdlang, Ma dochead_make) { + debug(asserts){ + static assert(is(typeof(dochead_make) == string[string][string])); + } + dochead_make = sdlangToAAmake(dochead_make, header_sdlang); + auto dochead_meta = sdlangToAAmake(meta_aa, header_sdlang); + if (dochead_meta["title"]["main"].empty) { + dochead_meta["title"]["main"] = + to!string(header_sdlang.maybe.tags["title"][0].values[0]); + } + if (!(dochead_meta["title"]["subtitle"].empty) + && (dochead_meta["title"]["sub"].empty)) { + dochead_meta["title"]["sub"] ~= dochead_meta["title"]["subtitle"]; + } + dochead_meta["title"].remove("subtitle"); + if (dochead_meta["title"]["sub"].empty) { + dochead_meta["title"]["full"] ~= dochead_meta["title"]["main"]; + } else { + dochead_meta["title"]["full"] ~= format( + "%s - %s", + dochead_meta["title"]["main"], + dochead_meta["title"]["sub"], + ); + } + dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"]; + string[] authors_arr; + auto authors_raw_arr = dochead_meta["creator"]["author"].split(rgx.arr_delimiter); + foreach (author_raw; authors_raw_arr) { + authors_arr ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); + } + dochead_meta["creator"]["author"] = join(authors_arr, ", ").chomp.chomp; + auto t = tuple(dochead_make, dochead_meta); + static assert(t.length==2); + return t; + } + private auto headerSDLangToAA(Hs,Ma)(Hs header_sdlang_src, Ma conf_doc_make_aa) { + debug(asserts){ + static assert(is(typeof(header_sdlang_src) == char[])); + static assert(is(typeof(conf_doc_make_aa) == string[string][string])); + } + auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); + auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa); + return header_aa_tuple; + } + } +} diff --git a/src/sdp/ao/defaults.d b/src/sdp/ao/defaults.d new file mode 100644 index 0000000..aa9fc2c --- /dev/null +++ b/src/sdp/ao/defaults.d @@ -0,0 +1,493 @@ +/++ + default settings ++/ +module sdp.ao.defaults; +template SiSUregisters() { + 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; + 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_; + } + 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_; + } + 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_; + } + auto ptr_head_main = + [ + "classify", + "creator", + "date", + "identifier", + "links", + "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 = `{ + }`; +} +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; + } +} +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" : "", + ]; + 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; + } +} +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; + } + } +} +template InternalMarkup() { + struct InlineMarkup { + auto en_a_o = "【"; auto en_a_c = "】"; + auto en_b_o = "〖"; auto en_b_c = "〗"; + auto lnk_o = "┥"; auto lnk_c = "┝"; + auto url_o = "┤"; auto url_c = "├"; + auto mark_internal_site_lnk = "¤"; + auto nbsp = "░"; + auto br_line = "┘"; + auto br_nl = "┙"; + auto br_paragraph = "┚"; + 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 = "┚"; + auto tc_p = "┆"; + 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; + } + } +} +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_); + } + } +} diff --git a/src/sdp/ao/doc_debugs.d b/src/sdp/ao/doc_debugs.d new file mode 100644 index 0000000..d42d903 --- /dev/null +++ b/src/sdp/ao/doc_debugs.d @@ -0,0 +1,659 @@ +/++ + output debugs ++/ +module sdp.ao.doc_debugs; +template SiSUdebugs() { + import + sdp.ao.defaults, + sdp.ao.rgx; + import + std.algorithm, + std.array, + std.container, + std.exception, + std.json, + std.stdio, + std.file, + std.path, + std.range, + std.regex, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + auto SiSUdebugs(S,T)( + auto return ref const S contents, + auto return ref T doc_matters, + ) { + mixin SiSUrgxInit; + mixin InternalMarkup; + auto rgx = Rgx(); + auto markup = InlineMarkup(); + string key; + debug(parent) { + writefln( + "%s:%s", + __FILE__, + __LINE__, + ); + foreach (key; doc_matters.keys_seq.seg) { + foreach (obj; contents[key]) { + if (obj.use != "empty") { + if (obj.is_a == "heading") { + writefln( + "%s node: %s heading: %s %s", + obj.obj_cite_number, + obj.node, + obj.heading_lev_markup, + obj.text, + ); + } + } + } + } + } + debug(dumpdoc) { + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + foreach (obj; contents) { + if (obj.use != "empty") { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(section_head) { + key="head"; + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(section_toc) { + key="toc_seg"; + out_toc(contents, key); + } + debug(section_toc_seg) { + key="toc_seg"; + out_toc(contents, key); + } + debug(section_toc_scroll) { + key="toc_scroll"; + out_toc(contents, key); + } + debug(segnames) { + writeln(__LINE__); + out_segnames(contents, doc_matters); + } + debug(section_body) { + key="body"; + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(toc_nav_dom) { + enum DomTags { none, open, close, close_and_open, open_still, } + foreach (sect; doc_matters.keys_seq.seg) { + foreach (obj; contents[sect]) { + if (obj.is_a == "heading") { + foreach_reverse (k; 0 .. 7) { + switch (obj.dom_markedup[k]) { + case DomTags.close : + writeln(markup.indent_by_spaces_provided(k), ""); + break; + case DomTags.close_and_open : + writeln(markup.indent_by_spaces_provided(k), ""); + writeln(markup.indent_by_spaces_provided(k), + "<", k, ">", obj.text, + " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); + break; + case DomTags.open : + writeln(markup.indent_by_spaces_provided(k), + "<", k, ">", obj.text, + " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); + break; + default : + break; + } + } + } + } + } + writeln("--------------------"); + foreach (sect; doc_matters.keys_seq.seg) { + foreach (obj; contents[sect]) { + if (obj.is_a == "heading") { + foreach_reverse (k; 0 .. 7) { + switch (obj.dom_collapsed[k]) { + case DomTags.close : + writeln(markup.indent_by_spaces_provided(k), ""); + break; + case DomTags.close_and_open : + writeln(markup.indent_by_spaces_provided(k), ""); + writeln(markup.indent_by_spaces_provided(k), + "<", k, ">", obj.text, + " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); + break; + case DomTags.open : + writeln(markup.indent_by_spaces_provided(k), + "<", k, ">", obj.text, + " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); + break; + default : + break; + } + } + } + } + } + } + debug(section_endnotes) { + key="endnotes"; + out_endnotes(contents, key); + } + debug(section_endnotes_seg) { + key="endnotes"; + out_endnotes(contents, key); + } + debug(section_glossary) { + key="glossary"; + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(section_bibliography) { + key="bibliography"; + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(section_bookindex) { + key="bookindex_seg"; + out_bookindex(contents, key); + } + debug(section_bookindex_seg) { + key="bookindex_seg"; + out_bookindex(contents, key); + } + debug(section_bookindex_scroll) { + key="bookindex_scroll"; + out_bookindex(contents, key); + } + debug(blurb_section) { + key="blurb"; + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(objects) { + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + foreach (obj; contents) { + if (obj.use != "empty") { + writefln( + "* [%s][%s] %s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + debug(headermakejson) { + writefln( + "%s\n%s\n%s", + "document header, metadata & make instructions:", + doc_matters.dochead_meta, + ptr_head_main, + ); + foreach (main_header; ptr_head_main) { + switch (main_header) { + case "make": + foreach (sub_header; ptr_head_sub_make) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + default: + break; + } + } + } + debug(headermetadatajson) { + writefln( + "%s\n%s\n%s", + "document header, metadata & make instructions:", + doc_matters.dochead_meta, + ptr_head_main, + ); + foreach (main_header; ptr_head_main) { + switch (main_header) { + case "creator": + foreach (sub_header; ptr_head_sub_creator) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "title": + foreach (sub_header; ptr_head_sub_title) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "rights": + foreach (sub_header; ptr_head_sub_rights) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "date": + foreach (sub_header; ptr_head_sub_date) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "original": + foreach (sub_header; ptr_head_sub_original) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "classify": + foreach (sub_header; ptr_head_sub_classify) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "identifier": + foreach (sub_header; ptr_head_sub_identifier) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "notes": + foreach (sub_header; ptr_head_sub_notes) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + case "publisher": + foreach (sub_header; ptr_head_sub_publisher) { + if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { + writefln( + "%s:%s: %s", + main_header, + sub_header, + doc_matters.dochead_meta[main_header][sub_header] + ); + } + } + break; + default: + break; + } + } + } + debug(anchor) { + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + foreach (k; doc_matters.keys_seq.seg) { + foreach (obj; contents[k]) { + if (obj.is_a == "heading") { + writefln( + "%s~ [%s] %s %s", + obj.marked_up_level, + obj.obj_cite_number, + obj.anchor_tags, + // "[", obj["is"], "] ", + obj.text + ); + } + } + } + } + debug(heading) { // heading + foreach (k; doc_matters.keys_seq.seg) { + foreach (o; contents[k]) { + if (o.is_a == "heading") { + writefln( + "%s* %s\n (markup level: %s; collapsed level: %s)", + replicate(" ", o.heading_lev_markup), + strip(o.text), + o.heading_lev_markup, + o.heading_lev_collapsed, + ); + } + } + } + } + debug(headings) { + writefln( + "%s\n%s:%s", + "-------------------------------", + __FILE__, + __LINE__, + ); + foreach (k; doc_matters.keys_seq.seg) { + foreach (obj; contents[k]) { + if (obj.is_a == "heading") { + writefln( + "%s~ [%s] %s", + obj.marked_up_level, + obj.obj_cite_number, + // "[", obj["is"], "] ", + obj.text + ); + } + } + } + } + debug(summary) { + string[string] check = [ + "last_obj_cite_number" : "NA [debug \"checkdoc\" not run]", + ]; + } + debug(checkdoc) { + if ((doc_matters.opt_action_bool["debug"])) { + debug(checkdoc) { + if (auto mfn=match(doc_matters.source_filename, rgx.src_fn)) { + if (doc_matters.opt_action_bool["assertions"]) { + switch (mfn.captures[2]) { + // live manual: + case "live-manual.ssm": + assert(check["last_obj_cite_number"] == + "1019","last obj_cite_number should be: 1019 (check test, document is frequently updated)"); // ok + break; + // sisu_markup: + case "sisu_markup.sst": + assert(check["last_obj_cite_number"] == + "297","last obj_cite_number expected to be: 297 rather than " ~ check["last_obj_cite_number"]); // ok + // assert(check["last_obj_cite_number"] == "297","last obj_cite_number expected to be: 297 rather than " ~ check["last_obj_cite_number"]); + // notes for first divergance study sisu headings 247 250 + // sisu has issue with code that contains heading 1~ which results in no obj_cite_number! ?? + // sisu currently has incorrect last body obj_cite_number of 294! + // bug in sisu? attend + break; + // sisu-markup-samples: + case "accelerando.charles_stross.sst": + assert(check["last_obj_cite_number"] == + "2861","last obj_cite_number expected to be: 2861 rather than " ~ check["last_obj_cite_number"]); // ok + break; + case "alices_adventures_in_wonderland.lewis_carroll.sst": + assert(check["last_obj_cite_number"] == + "805","last obj_cite_number expected to be: 805 rather than " ~ check["last_obj_cite_number"]); // 808 + break; + case "autonomy_markup0.sst": + assert(check["last_obj_cite_number"] == + "77","last obj_cite_number expected to be: 77 rather than " ~ check["last_obj_cite_number"]); // ok endnotes + // assert(check["last_obj_cite_number"] == "78","last obj_cite_number expected to be: 78 rather than " ~ check["last_obj_cite_number"]); + break; + case "content.cory_doctorow.sst": + assert(check["last_obj_cite_number"] == + "953","last obj_cite_number expected to be: 953 rather than " ~ check["last_obj_cite_number"]); // 1007 way off, check obj_cite_number off switches + // assert(check["last_obj_cite_number"] == "953","last obj_cite_number expected to be: 953 rather than " ~ check["last_obj_cite_number"]); + break; + case "democratizing_innovation.eric_von_hippel.sst": + // fixed ERROR! range violation, broken check! endnotes, bookindex, biblio + // error in bookindex ... (ch1; ch6; ch8 ) + assert(check["last_obj_cite_number"] == + "905","last obj_cite_number expected to be: 905 rather than " ~ check["last_obj_cite_number"]); // 911 + break; + case "down_and_out_in_the_magic_kingdom.cory_doctorow.sst": + assert(check["last_obj_cite_number"] == + "1417","last obj_cite_number expected to be: 1417 rather than " ~ check["last_obj_cite_number"]); // 1455 check obj_cite_number off switches + break; + case "for_the_win.cory_doctorow.sst": + assert(check["last_obj_cite_number"] == + "3510","last obj_cite_number expected to be: 3510 rather than " ~ check["last_obj_cite_number"]); // 3569 check obj_cite_number off switches + break; + case "free_as_in_freedom_2.richard_stallman_and_the_free_software_revolution.sam_williams.richard_stallman.sst": + assert(check["last_obj_cite_number"] == + "1082","last obj_cite_number expected to be: 1082 rather than " ~ check["last_obj_cite_number"]); // check 1079 too few + break; + case "free_culture.lawrence_lessig.sst": + assert(check["last_obj_cite_number"] == + "1330","last obj_cite_number expected to be: 1330 rather than " ~ check["last_obj_cite_number"]); // 1312 + // fixed ERROR! range violation, broken check! + // error in bookindex ... sections piracy (ch1) & property (ch10 market concentration) fixed + break; + case "free_for_all.peter_wayner.sst": // endnotes, bookindex, biblio + assert(check["last_obj_cite_number"] == + "1559","last obj_cite_number expected to be: 1559 rather than " ~ check["last_obj_cite_number"]); // 1560, check obj_cite_number off switches, has endnotes so 2 too many + // assert(check["last_obj_cite_number"] == "1559","last obj_cite_number expected to be: 1559 rather than " ~ check["last_obj_cite_number"]); + break; + case "gpl2.fsf.sst": + assert(check["last_obj_cite_number"] == + "65","last obj_cite_number expected to be: 65 rather than " ~ check["last_obj_cite_number"]); // ok endnotes? check + // assert(check["last_obj_cite_number"] == "66","last obj_cite_number expected to be: 66 rather than " ~ check["last_obj_cite_number"]); + break; + case "gpl3.fsf.sst": + assert(check["last_obj_cite_number"] == + "123","last obj_cite_number expected to be: 123 rather than " ~ check["last_obj_cite_number"]); // ok + break; + case "gullivers_travels.jonathan_swift.sst": + assert(check["last_obj_cite_number"] == + "668","last obj_cite_number expected to be: 668 rather than " ~ check["last_obj_cite_number"]); // 674 + break; + case "little_brother.cory_doctorow.sst": + assert(check["last_obj_cite_number"] == + "3130","last obj_cite_number expected to be: 3130 rather than " ~ check["last_obj_cite_number"]); // 3204, check obj_cite_number off switches + break; + case "the_cathedral_and_the_bazaar.eric_s_raymond.sst": + assert(check["last_obj_cite_number"] == + "258","last obj_cite_number expected to be: 258 rather than " ~ check["last_obj_cite_number"]); // ok + break; + case "the_public_domain.james_boyle.sst": + assert(check["last_obj_cite_number"] == + "970","last obj_cite_number expected to be: 970 rather than " ~ check["last_obj_cite_number"]); // 978 + break; + case "the_wealth_of_networks.yochai_benkler.sst": // endnotes, bookindex + assert(check["last_obj_cite_number"] == + "829","last obj_cite_number expected to be: 829 rather than " ~ check["last_obj_cite_number"]); // ok + // assert(check["last_obj_cite_number"] == "832","last obj_cite_number expected to be: 832 rather than " ~ check["last_obj_cite_number"]); + // has endnotes and bookindex, issue with sisu.rb + break; + case "through_the_looking_glass.lewis_carroll.sst": + assert(check["last_obj_cite_number"] == + "949","last obj_cite_number expected to be: 949 rather than " ~ check["last_obj_cite_number"]); // 955 + break; + case "two_bits.christopher_kelty.sst": // endnotes, bookindex, biblio + assert(check["last_obj_cite_number"] == + "1190","last obj_cite_number expected to be: 1190 rather than " ~ check["last_obj_cite_number"]); // 1191 + // assert(check["last_obj_cite_number"] == "1193","last obj_cite_number expected to be: 1193 rather than " ~ check["last_obj_cite_number"]); // 1191 ok? + // has endnotes and bookindex, issue with sisu.rb + break; + // fixed ERROR! range violation! + // error in bookindex ... (ch3 the movement) + case "un_contracts_international_sale_of_goods_convention_1980.sst": + assert(check["last_obj_cite_number"] == + "377","last obj_cite_number expected to be: 377 rather than " ~ check["last_obj_cite_number"]); // ok + break; + case "viral_spiral.david_bollier.sst": // endnotes, bookindex + assert(check["last_obj_cite_number"] == + "1078","last obj_cite_number expected to be: 1078 rather than " ~ check["last_obj_cite_number"]); // 1100 + // fixed ERROR! range violation! + // error in bookindex ... (ch7 ... building the cc machine, an extra semi colon) + break; + default: + writeln(doc_matters.source_filename); + break; + } + } + } + } + debug(checkdoc) { + void out_segnames(S,T)( + auto return ref const S contents, + auto return ref T doc_matters, + ) { + foreach (key; doc_matters.keys_seq.seg) { + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + if (obj.heading_lev_markup == 4) { + writeln(obj.ptr_html_segnames, ". (", doc_matters.segnames[obj.ptr_html_segnames], ") -> ", obj.text); + } + } + } + } + } + } + debug(checkdoc) { + void out_toc(S)( + auto return ref const S contents, + string key, + ) { + if (contents[key].length > 1) { + string indent_spaces; + foreach (obj; contents[key]) { + indent_spaces=markup.indent_by_spaces_provided(obj.indent_hang); + writefln( + "%s%s", + indent_spaces, + obj.text + ); + } + } + } + } + debug(checkdoc) { + void out_endnotes(S)( + auto return ref const S contents, + string key, + ) { + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s]\n%s", + obj.is_a, + obj.text + ); + } + } + } + } + debug(checkdoc) { + void out_bookindex(S)( + auto return ref const S contents, + string key, + ) { + if (contents[key].length > 1) { + foreach (obj; contents[key]) { + writefln( + "[%s][%s]\n%s", + obj.obj_cite_number, + obj.is_a, + obj.text + ); + } + } + } + } + } + } + } +} diff --git a/src/sdp/ao/object_setter.d b/src/sdp/ao/object_setter.d new file mode 100644 index 0000000..b05ac98 --- /dev/null +++ b/src/sdp/ao/object_setter.d @@ -0,0 +1,64 @@ +/++ + object setter: + setting of sisu objects for downstream processing + ao_object_setter.d ++/ +module sdp.ao.object_setter; +template ObjectSetter() { + /+ structs +/ + struct HeadingAttrib { + string lev = "9"; + int heading_lev_markup = 9; + int heading_lev_collapsed = 9; + int[] closes_lev_collapsed = []; + int[] closes_lev_markup = []; + int array_ptr = 0; + int heading_array_ptr_segments = 0; + } + struct ObjGenericComposite { + // size_t id; + string use = ""; + string is_of = ""; + string is_a = ""; + string text = ""; + string obj_cite_number = ""; + string[] anchor_tags = []; + int indent_base = 0; + int indent_hang = 0; + bool bullet = false; + bool inline_links = false; + bool inline_notes_reg = false; + bool inline_notes_star = false; + string language = ""; // not implemented, consider + string code_block_syntax = ""; + int table_number_of_columns = 0; + double[] table_column_widths = []; + string[] table_column_aligns = []; + bool table_heading = false; + bool table_walls = false; // not implemented + int ocn = 0; + string segment_anchor_tag = ""; + string segname_prev = ""; + string segname_next = ""; + int parent_lev_markup = 0; + int parent_ocn = 0; + int[] ancestors = []; + string marked_up_level = "9"; + int heading_lev_markup = 9; + int heading_lev_collapsed = 9; + int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ]; + string[] lev4_subtoc = []; + int heading_array_ptr = 0; + int ptr_doc_object = 0; + int ptr_html_segnames = 0; + int ptr_heading = 0; + int array_ptr = 0; + int heading_array_ptr_segments = 0; + string[string][string] node; + } + struct TheObjects { + ObjGenericComposite[] oca; + } +} diff --git a/src/sdp/ao/package.d b/src/sdp/ao/package.d new file mode 100644 index 0000000..63b4f3e --- /dev/null +++ b/src/sdp/ao/package.d @@ -0,0 +1,17 @@ +module sdp.ao; +public import + sdp.ao.defaults, + sdp.ao.rgx; +/+ std +/ +public import + std.array, + std.exception, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + // std.uni, + std.utf, + std.conv : to; diff --git a/src/sdp/ao/read_config_files.d b/src/sdp/ao/read_config_files.d new file mode 100644 index 0000000..57213c4 --- /dev/null +++ b/src/sdp/ao/read_config_files.d @@ -0,0 +1,87 @@ +/++ + read configuration files
+ - read config files
+ ao_config_files.d ++/ +module sdp.ao.read_config_files; +template ConfigIn() { + import + sdp.ao, + std.file, + std.path; + final string ConfigIn(C,E)(C conf_sdl, E env) { + string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; + string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; + string dot_home = chainPath(to!string(env["home"]), ".sisu").array; + string[] possible_config_path_locations = [ + dot_pwd, + underscore_pwd, + dot_home, + "/etc/sisu" + ]; + string config_file_str; + foreach(pth; possible_config_path_locations) { + auto conf_file = format( + "%s/%s", + pth, + conf_sdl, + ); + try { + if (exists(conf_file)) { + debug(configfile) { + writeln(conf_file); + } + config_file_str = conf_file.readText; + break; + } + } + catch (ErrnoException ex) { + } + catch (FileException ex) { + } + } + return config_file_str; + } +} +/+ + ++/ +template ConfigSDLang() { + import sdlang; + import + sdp.ao, + std.file, + std.path; + auto ConfigSDLang(string configuration, string conf_sdl_filename) { + Tag sdl_root_conf; + try { + sdl_root_conf = parseSource(configuration); + } + catch(ParseException e) { + stderr.writeln("SDLang problem with content for ", conf_sdl_filename); + stderr.writeln(e.msg); + } + debug(sdlang) { + Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; + assert(output_dir_structure_by.type == typeid(string)); + writeln(output_dir_structure_by); + writeln("conf SDL:"); + writeln(sdl_root_conf.toSDLDocument()); + } + return sdl_root_conf; + } +} +/+ ++/ +template ConfigHub() { + import + sdp.ao, + std.file, + std.path; + + final auto ConfigHub(C,E)(C conf_sdl, E env) { + auto configuration = ConfigIn!()(conf_sdl, env); + auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); + return sdl_root; + } +} diff --git a/src/sdp/ao/read_source_files.d b/src/sdp/ao/read_source_files.d new file mode 100644 index 0000000..3b348f3 --- /dev/null +++ b/src/sdp/ao/read_source_files.d @@ -0,0 +1,294 @@ +/++ + module ao_read_source_files;
+ - open markup files
+ - if master file scan for addional files to import/insert ++/ +module sdp.ao.read_source_files; +template SiSUrawMarkupContent() { + import + sdp.ao.rgx; + import + sdp.ao, + std.file, + std.path; + mixin SiSUrgxInit; + auto rgx = Rgx(); + auto rawsrc = RawMarkupContent(); + auto SiSUrawMarkupContent(Fn)(Fn fn_src) { + auto _0_header_1_body_content_2_insert_filelist_tuple = + rawsrc.sourceContentSplitIntoHeaderAndBody(rawsrc.sourceContent(fn_src), fn_src); + return _0_header_1_body_content_2_insert_filelist_tuple; + } + struct RawMarkupContent { + final sourceContent(in string fn_src) { + auto raw = MarkupRawUnit(); + auto source_txt_str = + raw.markupSourceReadIn(fn_src); + return source_txt_str; + } + final auto sourceContentSplitIntoHeaderAndBody(in string source_txt_str, in string fn_src="") { + auto raw = MarkupRawUnit(); + string[] insert_file_list; + auto t = + raw.markupSourceHeaderContentRawLineTupleArray(source_txt_str); + auto header_raw = t[0]; + auto sourcefile_body_content = t[1]; + if (fn_src.match(rgx.src_fn_master)) { // filename with path needed if master file (.ssm) not otherwise + auto ins = Inserts(); + auto tu = + ins.scan_master_src_for_insert_files_and_import_content(sourcefile_body_content, fn_src); + static assert(!isTypeTuple!(tu)); + sourcefile_body_content = tu[0]; + insert_file_list = tu[1].dup; + } + t = tuple( + header_raw, + sourcefile_body_content, + insert_file_list + ); + static assert(t.length==3); + return t; + } + } + struct MarkupRawUnit { + import std.file; + final private string readInMarkupSource(in char[] fn_src) { + enforce( + exists(fn_src)!=0, + "file not found" + ); + string source_txt_str; + try { + if (exists(fn_src)) { + source_txt_str = fn_src.readText; + } + } + catch (ErrnoException ex) { + } + catch (UTFException ex) { + // Handle validation errors + } + catch (FileException ex) { + // Handle errors + } + std.utf.validate(source_txt_str); + return source_txt_str; + } + final private char[][] header0Content1(in string src_text) { + /+ split string on _first_ match of "^:?A~\s" into [header, content] array/tuple +/ + char[][] header_and_content; + auto m = (cast(char[]) src_text).matchFirst(rgx.heading_a); + header_and_content ~= m.pre; + header_and_content ~= m.hit ~ m.post; + assert(header_and_content.length == 2, + "document markup is broken, header body split == " + ~ header_and_content.length.to!string + ~ "; (header / body array split should == 2 (split is on level A~))" + ); + return header_and_content; + } + final private char[][] markupSourceLineArray(in char[] src_text) { + char[][] source_line_arr = + (cast(char[]) src_text).split(rgx.newline_eol_strip_preceding); + return source_line_arr; + } + auto markupSourceReadIn(in string fn_src) { + auto rgx = Rgx(); + enforce( + fn_src.match(rgx.src_pth), + "not a sisu markup filename" + ); + auto source_txt_str = readInMarkupSource(fn_src); + return source_txt_str; + } + auto markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) { + string[] file_insert_list = []; + auto hc = header0Content1(source_txt_str); + auto header = hc[0]; + char[] source_txt = hc[1]; + auto source_line_arr = markupSourceLineArray(source_txt); + auto t = tuple( + header, + source_line_arr, + file_insert_list + ); + return t; + } + final char[][] getInsertMarkupSourceContentRawLineArray( + in char[] fn_src, + Regex!(char) rgx_file + ) { + enforce( + fn_src.match(rgx_file), + "not a sisu markup filename" + ); + auto source_txt_str = readInMarkupSource(fn_src); + auto source_line_arr = markupSourceLineArray(source_txt_str); + return source_line_arr; + } + } + struct Inserts { + import sdp.ao.defaults; + auto scan_subdoc_source( + char[][] markup_sourcefile_insert_content, + string fn_src + ) { + mixin SiSUrgxInitFlags; + char[][] contents_insert; + auto type1 = flags_type_init; + auto fn_pth_full = fn_src.match(rgx.src_pth); + auto markup_src_file_path = fn_pth_full.captures[1]; + foreach (line; markup_sourcefile_insert_content) { + if (type1["curly_code"] == 1) { + type1["header_make"] = 0; + type1["header_meta"] = 0; + if (line.matchFirst(rgx.block_curly_code_close)) { + type1["curly_code"] = 0; + } + contents_insert ~= line; + } else if (line.matchFirst(rgx.block_curly_code_open)) { + type1["curly_code"] = 1; + type1["header_make"] = 0; + type1["header_meta"] = 0; + contents_insert ~= line; + } else if (type1["tic_code"] == 1) { + type1["header_make"] = 0; + type1["header_meta"] = 0; + if (line.matchFirst(rgx.block_tic_close)) { + type1["tic_code"] = 0; + } + contents_insert ~= line; + } else if (line.matchFirst(rgx.block_tic_code_open)) { + type1["tic_code"] = 1; + type1["header_make"] = 0; + type1["header_meta"] = 0; + contents_insert ~= line; + } else if ( + (type1["header_make"] == 1) + && line.matchFirst(rgx.native_header_sub) + ) { + type1["header_make"] = 1; + type1["header_meta"] = 0; + } else if ( + (type1["header_meta"] == 1) + && line.matchFirst(rgx.native_header_sub) + ) { + type1["header_meta"] = 1; + type1["header_make"] = 0; + } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { + type1["header_make"] = 0; + type1["header_meta"] = 0; + auto insert_fn = m.captures[2]; + auto insert_sub_pth = m.captures[1]; + auto fn_src_insert = + chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; + auto raw = MarkupRawUnit(); + auto markup_sourcesubfile_insert_content = + raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); + debug(insert_file) { + tell_l("red", line); + tell_l("red", fn_src_insert); + tell_l("fuchsia", "ERROR"); + writeln( + " length contents insert array: ", + markup_sourcesubfile_insert_content.length + ); + } + auto ins = Inserts(); + /+ + 1. load file, + 2. read lines; + 3. scan lines, + 4. if filename insert, and insert filename + 5. repeat 1 + 6. else + 7. add line to new array; + +/ + } else { + type1["header_make"] = 0; + type1["header_meta"] = 0; + contents_insert ~= line; + } + } // end src subdoc (inserts) loop + return contents_insert; + } + auto scan_master_src_for_insert_files_and_import_content( + char[][] sourcefile_body_content, + string fn_src + ) { + mixin SiSUrgxInitFlags; + char[][] contents; + auto type = flags_type_init; + auto fn_pth_full = fn_src.match(rgx.src_pth); + auto markup_src_file_path = fn_pth_full.captures[1]; + string[] insert_file_list =[]; + foreach (line; sourcefile_body_content) { + if (type["curly_code"] == 1) { + if (line.matchFirst(rgx.block_curly_code_close)) { + type["curly_code"] = 0; + } + contents ~= line; + } else if (line.matchFirst(rgx.block_curly_code_open)) { + type["curly_code"] = 1; + contents ~= line; + } else if (type["tic_code"] == 1) { + if (line.matchFirst(rgx.block_tic_close)) { + type["tic_code"] = 0; + } + contents ~= line; + } else if (line.matchFirst(rgx.block_tic_code_open)) { + type["tic_code"] = 1; + contents ~= line; + } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { + auto insert_fn = m.captures[2]; + auto insert_sub_pth = m.captures[1]; + auto fn_src_insert = + chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; + insert_file_list ~= to!string(fn_src_insert); + auto raw = MarkupRawUnit(); + /+ TODO +/ + if (auto ma = line.match(rgx.src_fn_text)) { + /+ .sst when inserted, not used: headers and heading level ^:?A~ so remove +/ + writeln(__LINE__); writeln(ma); + } + auto markup_sourcefile_insert_content = + raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); + debug(insert_file) { + tell_l("red", line); + tell_l("red", fn_src_insert); + writeln( + " length contents insert array: ", + markup_sourcefile_insert_content.length + ); + } + auto ins = Inserts(); + auto contents_insert = ins.scan_subdoc_source( + markup_sourcefile_insert_content, + to!string(fn_src_insert) + ); + contents ~= contents_insert; + /+ + 1. load file, + 2. read lines; + 3. scan lines, + 4. if filename insert, and insert filename + 5. repeat 1 + 6. else + 7. add line to new array; + +/ + } else { + contents ~= line; + } + } // end src doc loop + debug(insert_file) { + writeln(__LINE__); + writeln(contents.length); + } + auto t = tuple( + contents, + insert_file_list + ); + return t; + } + } +} diff --git a/src/sdp/ao/rgx.d b/src/sdp/ao/rgx.d new file mode 100644 index 0000000..3f74329 --- /dev/null +++ b/src/sdp/ao/rgx.d @@ -0,0 +1,246 @@ +/++ + regex: regular expressions used in sisu document parser ++/ +module sdp.ao.rgx; +template SiSUrgxInit() { + import sdp.ao.defaults; + struct Rgx { + /+ misc +/ + static true_dollar = ctRegex!(`\$`, "gm"); + static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); + static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); + static within_quotes = ctRegex!(`"(.+?)"`); + static make_heading_delimiter = ctRegex!(`[;][ ]*`); + static arr_delimiter = ctRegex!(`[ ]*[;][ ]*`); + static name_delimiter = ctRegex!(`^([^,]+)[ ]*,[ ]+(.+?)$`); + static book_index_go = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); + static book_index_go_scroll = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); + static book_index_go_seg = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?):(?P[a-z0-9_-]+)"); + static book_index_go_seg_ = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)(:(?P[a-z0-9_-]+))?"); + static book_index_go_seg_anchorless = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); + static trailing_comma = ctRegex!(",[ ]*$"); + static trailing_linebreak = ctRegex!(",[ ]{1,2}\\\\\\\\\n[ ]{4}$","m"); + static newline_eol_delimiter = ctRegex!("\n"); + static newline_eol_strip_preceding = ctRegex!("[ ]*\n"); + static newline_eol_delimiter_only = ctRegex!("^\n"); + static line_delimiter_ws_strip = ctRegex!("[ ]*\n[ ]*"); + static para_delimiter = ctRegex!("\n[ ]*\n+"); + static table_col_delimiter = ctRegex!("[ ]*\n+", "mg"); + static table_row_delimiter = ctRegex!("\n[ ]*\n+", "mg"); + static table_row_delimiter_special = ctRegex!("[ ]*\n", "mg"); + static table_col_delimiter_special = ctRegex!("[ ]*[|][ ]*", "mg"); + static levels_markup = ctRegex!(`^[A-D1-4]$`); + static levels_numbered = ctRegex!(`^[0-9]$`); + static levels_numbered_headings = ctRegex!(`^[0-7]$`); + static numeric = ctRegex!(`[ 0-9,.-]+`); + static numeric_col = ctRegex!(`^[ 0-9,.$£₤Є€€¥-]+$`); + /+ comments +/ + static comment = ctRegex!(`^%+ `); + static comments = ctRegex!(`^%+ |^%+$`); + /+ header +/ + static main_headers = + ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m"); + static native_header = ctRegex!(`^@([a-z_]+):(?:\s|$)`); + static native_header_make = ctRegex!(`^@(make):(?:\s|$)`); + static native_header_meta = + ctRegex!(`^@(?:creator|title|rights|date|original|classify|identifier|notes|publisher|links):(?:\s|$)`); + static native_header_main = ctRegex!(`^@(?P
[a-z_]+):\s*(?P.*)`, "m"); + static native_header_sub = ctRegex!(`^[ ]*:(?P[a-z_]+):\s+(?P.+)`, "m"); + static native_header_meta_title = ctRegex!(`^@title:\s`, "m"); + static variable_doc_title = ctRegex!(`@title`); + static variable_doc_author = ctRegex!(`@author|@creator`); + static raw_author_munge = ctRegex!(`(\S.+?),\s+(.+)`,"i"); + /+ 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"); + /+ 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"); + 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+(.+?)$`); + 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])?[*]) `); + /+ blocked markup +/ + static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); + static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); + /+ 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"); + /+ blocked markup curly +/ + static block_curly_open = ctRegex!(`^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)`); + static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); // extract additional info + static block_curly_code_close = ctRegex!(`^([}]code)`); + static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); + static block_curly_poem_close = ctRegex!(`^([}]poem)`); + static block_curly_group_open = ctRegex!(`^(group[{].*?$)`); + static block_curly_group_close = ctRegex!(`^([}]group)`); + static block_curly_block_open = ctRegex!(`^(block[{].*?$)`); + static block_curly_block_close = ctRegex!(`^([}]block)`); + static block_curly_quote_open = ctRegex!(`^(quote[{].*?$)`); + static block_curly_quote_close = ctRegex!(`^([}]quote)`); + static block_curly_table_open = ctRegex!(`^table[{](.*)`); + static block_curly_table_close = ctRegex!(`^([}]table)`); + static block_curly_table_special_markup = ctRegex!(`^[{]table((~h)?(?P(?:[ ]+[0-9]+;)+))[}]`, "mg"); + static table_head_instructions = ctRegex!(`(?Ph)?(?:[ ]+c(?P[0-9]);)?(?P(?:[ ]+[0-9]+[lr]?;)+)`); + static table_col_widths_and_alignment = ctRegex!(`(?P[0-9]+)(?P[lr]?)`); + static table_col_widths = ctRegex!(`(?P[0-9]+)`); + static table_col_align = ctRegex!(`(?P[lr]?)`); + static table_col_align_match = ctRegex!(`(?P[lr])`); + static table_col_separator = ctRegex!(`┊`); + static table_col_separator_nl = ctRegex!(`[┊]$`, "mg"); + /+ inline markup footnotes endnotes +/ + static inline_notes_curly_gen = ctRegex!(`~\{.+?\}~`, "m"); + static inline_notes_curly = ctRegex!(`~\{\s*(.+?)\}~`, "mg"); + static inline_curly_delimiter_open_and_close_regular = ctRegex!(`~\{\s*|\s*\}~`, "m"); + static inline_notes_delimiter_curly_regular = ctRegex!(`~\{[ ]*(.+?)\}~`, "m"); + static inline_notes_curly_sp = ctRegex!(`~\{[*+]+\s+(.+?)\}~`, "m"); + static inline_notes_curly_sp_asterisk = ctRegex!(`~\{[*]+\s+(.+?)\}~`, "m"); + static inline_notes_curly_sp_plus = ctRegex!(`~\{[+]+\s+(.+?)\}~`, "m"); + static inline_note_curly_delimiters = ctRegex!(`(~\{[*+]?\s*)(.+?)(\}~)`, "mg"); + static inline_notes_square = ctRegex!(`~\[\s*(.+?)\]~`, "mg"); + static inline_text_and_note_square_sp = ctRegex!(`(.+?)~\[[*+]+\s+(.+?)\]~`, "mg"); + static inline_text_and_note_square = ctRegex!(`(.+?)~\[\s*(.+?)\]~`, "mg"); + static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "mg"); + static inline_curly_delimiter_open_regular = ctRegex!(`~\{\s*`, "m"); + static inline_curly_delimiter_open_symbol_star = ctRegex!(`~\{[*]\s`, "m"); + static inline_curly_delimiter_open_symbol_plus = ctRegex!(`~\{[+]\s`, "m"); + static inline_curly_delimiter_open_star_or_plus = ctRegex!(`~\{[+*]`, "m"); + static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); + static inline_text_and_note_curly = ctRegex!(`(?P.+?)(?:(?:[~])[{][*+ ]*)(?P.+?)(?:[}][~])`, "mg"); + static note_ref = ctRegex!(`^\S+?noteref_([0-9]+)`, "mg"); // {^{73.}^}#noteref_73 + static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_#]`, "mg"); + static inline_url = ctRegex!(`((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]\S*)`, "mg"); + static inline_link_naked_url = ctRegex!(`(?P^|[ ])(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!'"]?(?:[ ]|$))`, "mg"); + static inline_link_markup_regular = ctRegex!(`(?P^|[ ])\{\s*(?P.+?)\s*\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); + static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); + static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+)`, "mg"); + static image = ctRegex!(`([a-zA-Z0-9._-]+?\.(?:png|gif|jpg))`, "mg"); + /+ inline markup book index +/ + static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); + static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); + static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); + /+ 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"); + /+ 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!(`^--[+~-]#$`); + /+ ignore outside code blocks +/ + static skip_from_regular_parse = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); + /+ 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]+)`); + /+ json +/ + static tailing_comma = ctRegex!(`,$`, "m"); + /+ 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)$`); + /+ 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+)`); + /+ 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)$"); + static newline = ctRegex!("\n", "mg"); + static strip_br = ctRegex!("^
\n|
\n*$"); + static space = ctRegex!(`[ ]`, "mg"); + static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); + static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); + 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"); + static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); + static src_fn = + ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); + static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); + static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); + static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); + static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); + static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); + /+ inline markup footnotes endnotes +/ + static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); + static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); + static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); + static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); + static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); + static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); + static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); + static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); + static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); + static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); + static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); + static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); + static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); + /+ 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"); + /+ inline markup font face mod +/ + static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); + static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); + static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); + static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); + static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); + static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); + static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); + static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); + static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); + static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); + static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); + static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + /+ table delimiters +/ + static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); + static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); + } +} diff --git a/src/sdp/ao_abstract_doc_source.d b/src/sdp/ao_abstract_doc_source.d deleted file mode 100644 index ab7cc99..0000000 --- a/src/sdp/ao_abstract_doc_source.d +++ /dev/null @@ -1,5554 +0,0 @@ -/++ - document abstraction: - abstraction of sisu markup for downstream processing - ao_abstract_doc_source.d -+/ -module sdp.ao_abstract_doc_source; -template SiSUdocAbstraction() { - /+ ↓ abstraction imports +/ - import - sdp.ao_defaults, - sdp.ao_object_setter, - sdp.ao_rgx, - sdp.output_hub; - 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; - /+ ↓ abstraction mixins +/ - mixin ObjectSetter; - mixin InternalMarkup; - mixin SiSUrgxInit; - /+ ↓ abstraction struct init +/ - /+ initialize +/ - ObjGenericComposite[][string] the_table_of_contents_section; - ObjGenericComposite[] the_document_head_section, the_document_body_section, the_bibliography_section, the_glossary_section, the_blurb_section; - ObjGenericComposite[] the_dom_tail_section; - string[string] an_object, processing; - string an_object_key; - string[] anchor_tags; - string anchor_tag_; - string segment_anchor_tag_that_object_belongs_to; - string segment_anchor_tag_that_object_belongs_to_uri; - /+ enum +/ - enum State { off, on } - enum TriState { off, on, closing } - enum DocStructMarkupHeading { - h_sect_A, - h_sect_B, - h_sect_C, - h_sect_D, - h_text_1, - h_text_2, - h_text_3, - h_text_4, - h_text_5, // extra level, drop - content_non_header - } // header section A-D; header text 1-4 - /+ biblio variables +/ - string biblio_tag_name, biblio_tag_entry, st; - string[] biblio_arr_json; - string biblio_entry_str_json; - JSONValue[] bib_arr_json; - int bib_entry; - /+ counters +/ - int cntr, previous_count, previous_length; - bool reset_note_numbers=true; - int[string] line_occur; - int html_segnames_ptr=0; - int html_segnames_ptr_cntr=0; - int verse_line, heading_ptr; - /+ paragraph attributes +/ - int[string] indent; - bool bullet = true; - string content_non_header = "8"; - auto obj_im = ObjInlineMarkup(); - auto obj_att = ObjAttributes(); - /+ ocn +/ - int obj_cite_number, obj_cite_number_; - auto object_citation_number = OCNemitter(); - int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_markedup_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_collapsed_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - enum DomTags { none, open, close, close_and_open, open_still, } - void heading_ancestors(O)( - auto return ref O obj, - return ref string[] lv_ancestors, - ) { - switch (obj.heading_lev_markup) { - case 0: - lv_ancestors[0] = obj.text.to!string; - foreach(k; 1..8) { - lv_ancestors[k] = ""; - } - goto default; - case 1: - lv_ancestors[1] = obj.text.to!string; - foreach(k; 2..8) { - lv_ancestors[k] = ""; - } - goto default; - case 2: - lv_ancestors[2] = obj.text.to!string; - foreach(k; 3..8) { - lv_ancestors[k] = ""; - } - goto default; - case 3: - lv_ancestors[3] = obj.text.to!string; - foreach(k; 4..8) { - lv_ancestors[k] = ""; - } - goto default; - case 4: - lv_ancestors[4] = obj.text.to!string; - foreach(k; 5..8) { - lv_ancestors[k] = ""; - } - goto default; - case 5: - lv_ancestors[5] = obj.text.to!string; - foreach(k; 6..8) { - lv_ancestors[k] = ""; - } - goto default; - case 6: - lv_ancestors[6] = obj.text.to!string; - lv_ancestors[7] = ""; - goto default; - case 7: - lv_ancestors[7] = obj.text.to!string; - goto default; - default: - obj.heading_ancestors_text = lv_ancestors.dup; - } - } - auto dom_set_markup_tags(int[] dom, int lev) { - foreach (i; 0 .. 8) { - if (i < lev) { - if (dom[i] == DomTags.open - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.open_still; - } else if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } - } else if (i == lev) { - if (lev == 0 - && dom[i] == DomTags.open_still - ) { - dom[i] = DomTags.close; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close_and_open; - } else { - dom[i] = DomTags.open; - } - } else if (i > lev) { - if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close; - } - } - } - debug(dom_magic_numbers) { - writeln("marked up: ", lev, ": ", dom); - } - return dom; - } - auto dom_set_collapsed_tags(int[] dom, int lev) { - foreach (i; 0 .. 8) { - if (i < lev) { - if (dom[i] == DomTags.open - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.open_still; - } else if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } - } else if (i == lev) { - if (lev == 0 - && dom[i] == DomTags.open_still - ) { - dom[i] = DomTags.close; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close_and_open; - } else { - dom[i] = DomTags.open; - } - } else if (i > lev) { - if (dom[i] == DomTags.close) { - dom[i] = DomTags.none; - } else if (dom[i] == DomTags.open - || dom[i] == DomTags.open_still - || dom[i] == DomTags.close_and_open - ) { - dom[i] = DomTags.close; - } - } - } - debug(dom_magic_numbers) { - writeln("collapsed: ", lev, ": ", dom); - } - return dom; - } - int ocn_emit(int ocn_status_flag) { - return object_citation_number.ocn_emitter(ocn_status_flag); - } - /+ book index variables +/ - string book_idx_tmp; - string[][string][string] bookindex_unordered_hashes; - /+ node +/ - ObjGenericComposite comp_obj_heading, comp_obj_location, comp_obj_block, comp_obj_code, comp_obj_poem_ocn, comp_obj_comment; - auto node_construct = NodeStructureMetadata(); - enum sObj { content, anchor_tags, notes_reg, notes_star, links } - /+ ↓ abstract marked up document +/ - auto SiSUdocAbstraction(Src,Make,Meta,Opt)( - Src markup_sourcefile_content, - Make dochead_make_aa, - Meta dochead_meta_aa, - Opt opt_action_bool, - ) { - auto rgx = Rgx(); - debug(asserts) { - static assert(is(typeof(markup_sourcefile_content) == char[][])); - static assert(is(typeof(dochead_make_aa) == string[string][string])); - static assert(is(typeof(dochead_meta_aa) == string[string][string])); - static assert(is(typeof(opt_action_bool) == bool[string])); - } - /+ ↓ abstraction init +/ - scope(success) { - } - scope(failure) { - } - scope(exit) { - destroy(the_document_head_section); - destroy(the_table_of_contents_section); - destroy(the_document_body_section); - destroy(the_bibliography_section); - destroy(an_object); - destroy(processing); - destroy(biblio_arr_json); - previous_length=0; - reset_note_numbers=true; - } - mixin SiSUrgxInitFlags; - mixin SiSUnode; - auto node_para_int_ = node_metadata_para_int; - auto node_para_str_ = node_metadata_para_str; - ObjGenericComposite comp_obj_heading_, comp_obj_para, comp_obj_toc; - line_occur = [ - "heading" : 0, - "para" : 0, - "glossary" : 0, - "blurb" : 0, - ]; - auto type = flags_type_init; - string[string] obj_cite_number_poem = [ - "start" : "", - "end" : "" - ]; - string[] lv_ancestors = [ "", "", "", "", "", "", "", "", ]; - int[string] lv = [ - "lv" : State.off, - "h0" : State.off, - "h1" : State.off, - "h2" : State.off, - "h3" : State.off, - "h4" : State.off, - "h5" : State.off, - "h6" : State.off, - "h7" : State.off, - "lev_int_collapsed" : 0, - ]; - int[string] collapsed_lev = [ - "h0" : State.off, - "h1" : State.off, - "h2" : State.off, - "h3" : State.off, - "h4" : State.off, - "h5" : State.off, - "h6" : State.off, - "h7" : State.off - ]; - string[string] heading_match_str = [ - "h_A": "^(none)", - "h_B": "^(none)", - "h_C": "^(none)", - "h_D": "^(none)", - "h_1": "^(none)", - "h_2": "^(none)", - "h_3": "^(none)", - "h_4": "^(none)" - ]; - auto heading_match_rgx = [ - "h_A": regex(r"^(none)"), - "h_B": regex(r"^(none)"), - "h_C": regex(r"^(none)"), - "h_D": regex(r"^(none)"), - "h_1": regex(r"^(none)"), - "h_2": regex(r"^(none)"), - "h_3": regex(r"^(none)"), - "h_4": regex(r"^(none)") - ]; - string _anchor_tag; - string toc_txt_; - an_object["glossary_nugget"] = ""; - an_object["blurb_nugget"] = ""; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "frontmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Table of Contents"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "toc"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.ptr_html_segnames = html_segnames_ptr; - comp_obj_heading_.anchor_tags = ["toc"]; - auto toc_head = comp_obj_heading_; - html_segnames_ptr_cntr++; - the_table_of_contents_section = [ - "seg": [toc_head], - "scroll": [toc_head], - ]; - auto mkup = InlineMarkup(); - auto munge = ObjInlineMarkupMunge(); - auto note_section = NotesSection(); - auto bookindex_extract_hash = BookIndexNuggetHash(); - string[][string] lev4_subtoc; - string[] html_segnames=["toc"]; - int cnt1 = 1; int cnt2 = 1; int cnt3 = 1; - /+ abstraction init ↑ +/ - /+ ↓ loop markup document/text line by line +/ - srcDocLoop: - foreach (line; markup_sourcefile_content) { - /+ ↓ markup document/text line by line +/ - /+ scope +/ - scope(exit) { - } - scope(failure) { - stderr.writefln( - "%s\n%s\n%s:%s failed here:\n line: %s", - __MODULE__, __FUNCTION__, - __FILE__, __LINE__, - line, - ); - } - 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)) - +/ - debug(source) { // source lines - writeln(line); - } - debug(srclines) { - if (!line.empty) { // source lines, not empty - writefln( - "* %s", - line - ); - } - } - if (!line.empty) { - _check_ocn_status_(line, type); - } - if (type["code"] == TriState.on) { - /+ block object: code +/ - _code_block_(line, an_object, type); - continue; - } else if (!matchFirst(line, rgx.skip_from_regular_parse)) { - /+ object other than "code block" object - (includes regular text paragraph, headings & blocks other than code) +/ - /+ heading, glossary, blurb, poem, group, block, quote, table +/ - if (line.matchFirst(rgx.heading_biblio) - || (type["biblio_section"] == State.on - && (!(line.matchFirst(rgx.heading_blurb_glossary))) - && (!(line.matchFirst(rgx.heading))) - && (!(line.matchFirst(rgx.comment))))) { - /+ within section (block object): biblio +/ - type["glossary_section"] = State.off; - type["biblio_section"] = State.on; - type["blurb_section"] = State.off; - if (opt_action_bool["backmatter"] && opt_action_bool["section_biblio"]) { - _biblio_block_(line, type, bib_entry, biblio_entry_str_json, biblio_arr_json); - debug(bibliobuild) { - writeln("- ", biblio_entry_str_json); - writeln("-> ", biblio_arr_json.length); - } - } - continue; - } else if (line.matchFirst(rgx.heading_glossary) - || (type["glossary_section"] == State.on - && (!(line.matchFirst(rgx.heading_biblio_blurb))) - && (!(line.matchFirst(rgx.heading))) - && (!(line.matchFirst(rgx.comment))))) { - /+ within section (block object): glossary +/ - debug(glossary) { - writeln(__LINE__); - writeln(line); - } - type["glossary_section"] = State.on; - type["biblio_section"] = State.off; - type["blurb_section"] = State.off; - if (opt_action_bool["backmatter"] && opt_action_bool["section_glossary"]) { - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="glossary_nugget"; // - if (line.matchFirst(rgx.heading_glossary)) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "_part_glossary"; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_glossary_section ~= comp_obj_heading_; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "glossary"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 2; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.anchor_tags = ["glossary"]; - the_glossary_section ~= comp_obj_heading_; - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - comp_obj_para = comp_obj_para.init; - comp_obj_para.use = "backmatter"; - comp_obj_para.is_of = "para"; - comp_obj_para.is_a = "glossary"; - comp_obj_para.text = line.to!string.strip; - comp_obj_para.ocn = 0; - comp_obj_para.obj_cite_number = ""; - comp_obj_para.indent_hang = indent["hang_position"]; - comp_obj_para.indent_base = indent["base_position"]; - comp_obj_para.bullet = bullet; - the_glossary_section ~= comp_obj_para; - } - type["ocn_status"] = TriState.off; - } - continue; - } else if (line.matchFirst(rgx.heading_blurb) - || (type["blurb_section"] == State.on - && (!(line.matchFirst(rgx.heading_biblio_glossary))) - && (!(line.matchFirst(rgx.heading))) - && (!(line.matchFirst(rgx.comment))))) { - /+ within section (block object): blurb +/ - debug(blurb) { - writeln(__LINE__); - writeln(line); - } - type["glossary_section"] = State.off; - type["biblio_section"] = State.off; - type["blurb_section"] = State.on; - if (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"]) { - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - type["para"] = State.on; - line_occur["para"] = State.off; - an_object_key="blurb_nugget"; - if (line.matchFirst(rgx.heading_blurb)) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "_part_blurb"; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_blurb_section ~= comp_obj_heading_; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "blurb"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 2; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.anchor_tags = ["blurb"]; - the_blurb_section ~= comp_obj_heading_; - } else if (line.matchFirst(rgx.heading) - && (opt_action_bool["backmatter"] && opt_action_bool["section_blurb"])) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = line.to!string; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "blurb"; - comp_obj_heading_.marked_up_level = an_object["lev"].to!string; - comp_obj_heading_.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv - comp_obj_heading_.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_blurb_section ~= comp_obj_heading_; - } else { - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - comp_obj_para = comp_obj_para.init; - comp_obj_para.use = "backmatter"; - comp_obj_para.is_of = "para"; - comp_obj_para.is_a = "blurb"; - comp_obj_para.text = line.to!string.strip; - comp_obj_para.ocn = 0; - comp_obj_para.obj_cite_number = ""; - comp_obj_para.indent_hang = indent["hang_position"]; - comp_obj_para.indent_base = indent["base_position"]; - comp_obj_para.bullet = bullet; - the_blurb_section ~= comp_obj_para; - } - type["ocn_status"] = TriState.off; - } - continue; - } else if (type["quote"] == TriState.on) { - /+ within block object: quote +/ - _quote_block_(line, an_object, type); - continue; - /+ within block object: group +/ - } else if (type["group"] == TriState.on) { - /+ within block object: group +/ - line = (line) - .replaceAll(rgx.para_delimiter, mkup.br_paragraph ~ "$1"); - _group_block_(line, an_object, type); - continue; - } else if (type["block"] == TriState.on) { - /+ within block object: block +/ - if (auto m = line.match(rgx.spaces_line_start)) { - line = (line) - .replaceAll(rgx.spaces_line_start, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); - } - if (auto m = line.match(rgx.spaces_multiple)) { - line = (line) - .replaceAll(rgx.spaces_multiple, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); - } - _block_block_(line, an_object, type); - continue; - } else if (type["poem"] == TriState.on) { - /+ within block object: poem +/ - _poem_block_(line, an_object, type, cntr, obj_cite_number_poem, dochead_make_aa); - continue; - } else if (type["table"] == TriState.on) { - /+ within block object: table +/ - _table_block_(line, an_object, type, dochead_make_aa); - continue; - } else { - /+ not within a block group +/ - assert( - (type["blocks"] == TriState.off) - || (type["blocks"] == TriState.closing), - "block status: none or closed" - ); - assertions_flag_types_block_status_none_or_closed(type); - if (line.matchFirst(rgx.block_open)) { - if (line.matchFirst(rgx.block_poem_open)) { - /+ poem to verse exceptions! +/ - object_reset(an_object); - processing.remove("verse"); - obj_cite_number_poem["start"] = obj_cite_number.to!string; - } - _start_block_(line, type, obj_cite_number_poem); - continue; - } else if (!line.empty) { - /+ line not empty +/ - /+ non blocks (headings, paragraphs) & closed blocks +/ - assert( - !line.empty, - "line tested, line not empty surely:\n \"" ~ line ~ "\"" - ); - assert( - (type["blocks"] == TriState.off) - || (type["blocks"] == TriState.closing), - "code block status: none or closed" - ); - if (type["blocks"] == TriState.closing) { - debug(check) { // block - writeln(__LINE__); - writeln(line); - } - assert( - line.matchFirst(rgx.book_index) - || line.matchFirst(rgx.book_index_open) - || type["book_index"] == State.on, - "\nblocks closed, unless followed by book index, non-matching line:\n \"" - ~ line ~ "\"" - ); - } - if (line.matchFirst(rgx.book_index) - || line.matchFirst(rgx.book_index_open) - || type["book_index"] == State.on ) { - /+ book_index +/ - _book_index_(line, book_idx_tmp, an_object, type, opt_action_bool); - } else { - /+ not book_index +/ - an_object_key="body_nugget"; - if (auto m = matchFirst(line, rgx.comment)) { - /+ matched comment +/ - debug(comment) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; - comp_obj_comment = comp_obj_comment.init; - comp_obj_comment.use = "comment"; - comp_obj_comment.is_of = "comment"; - comp_obj_comment.is_a = "comment"; - comp_obj_comment.text = an_object[an_object_key].strip; - the_document_body_section ~= comp_obj_comment; - _common_reset_(line_occur, an_object, type); - processing.remove("verse"); - ++cntr; - } else if (((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((type["para"] == State.off) - && (type["heading"] == State.off))) { - /+ heading or para but neither flag nor line exists +/ - if ((dochead_make_aa["make"]["headings"].length > 2) - && (type["make_headings"] == State.off)) { - /+ heading found +/ - _heading_found_(line, dochead_make_aa["make"]["headings"], heading_match_str, heading_match_rgx, type); - } - if ((type["make_headings"] == State.on) - && ((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((type["para"] == State.off) - && (type["heading"] == State.off))) { - /+ heading make set +/ - 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?) - +/ - if (line.matchFirst(rgx.heading)) { - /+ heading match +/ - _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, type, dochead_meta_aa); - } else if (line_occur["para"] == State.off) { - /+ para match +/ - an_object_key="body_nugget"; - _para_match_(line, an_object, an_object_key, indent, bullet, type, line_occur); - } - } else if (line_occur["heading"] > State.off) { - /+ heading +/ - debug(heading) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; - ++line_occur["heading"]; - } else if (line_occur["para"] > State.off) { - /+ paragraph +/ - debug(para) { - writeln(an_object_key, "-> ", line); - } - an_object[an_object_key] ~= " " ~ line; - ++line_occur["para"]; - } - } - } else if (type["blocks"] == TriState.closing) { - /+ line empty, with blocks flag +/ - _block_flag_line_empty_( - bookindex_extract_hash, - line, - an_object, - the_document_body_section, - bookindex_unordered_hashes, - obj_cite_number, - comp_obj_heading, - cntr, - type, - obj_cite_number_poem, - dochead_make_aa - ); - } else { - /+ line.empty, post contents, empty variables: +/ - assert( - line.empty, - "\nline should be empty:\n \"" - ~ line ~ "\"" - ); - assert( - (type["blocks"] == State.off), - "code block status: none" - ); - if ((type["heading"] == State.on) - && (line_occur["heading"] > State.off)) { - /+ heading object (current line empty) +/ - obj_cite_number = (an_object["lev_markup_number"].to!int == 0) - ? (ocn_emit(3)) - : (obj_cite_number = ocn_emit(type["ocn_status"])); - an_object["is"] = "heading"; - an_object_key="body_nugget"; - auto substantive_object_and_anchor_tags_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_object_and_anchor_tags_tuple[sObj.content]; - anchor_tags = substantive_object_and_anchor_tags_tuple[sObj.anchor_tags]; - if (an_object["lev_markup_number"].to!int == 4) { - segment_anchor_tag_that_object_belongs_to = anchor_tags[0]; - segment_anchor_tag_that_object_belongs_to_uri = anchor_tags[0] ~ ".fnSuffix"; - anchor_tag_ = anchor_tags[0]; - } else if (an_object["lev_markup_number"].to!int > 4) { - segment_anchor_tag_that_object_belongs_to = anchor_tag_; - segment_anchor_tag_that_object_belongs_to_uri = anchor_tag_ ~ ".fnSuffix#" ~ obj_cite_number.to!string; - } else if (an_object["lev_markup_number"].to!int < 4) { - string segn; - switch (an_object["lev_markup_number"].to!int) { - case 0: - segn = "_the_title"; - goto default; - case 1: - segn = "_part_" ~ cnt1.to!string; - ++cnt1; - goto default; - case 2: - segn = "_part_" ~ cnt1.to!string ~ "_" ~ cnt2.to!string; - ++cnt2; - goto default; - case 3: - segn = "_part_" ~ cnt1.to!string ~ "_" ~ cnt2.to!string ~ "_" ~ cnt3.to!string; - ++cnt3; - goto default; - default: - segment_anchor_tag_that_object_belongs_to = segn; - segment_anchor_tag_that_object_belongs_to_uri = segn ~ ".fnSuffix"; - break; - } - } - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash(an_object["bookindex_nugget"], obj_cite_number, segment_anchor_tag_that_object_belongs_to); - /+ (incrementally build toc) table of contents here! +/ - _anchor_tag=to!string(obj_cite_number); - the_table_of_contents_section = obj_im.table_of_contents_gather_headings( - an_object, - dochead_make_aa, - segment_anchor_tag_that_object_belongs_to, - _anchor_tag, - lev4_subtoc, - the_table_of_contents_section, - ); - if (an_object["lev_markup_number"] == "4") { - html_segnames ~= segment_anchor_tag_that_object_belongs_to; - html_segnames_ptr = html_segnames_ptr_cntr; - html_segnames_ptr_cntr++; - } - auto comp_obj_heading = - node_construct.node_emitter_heading( - an_object["substantive"], // string - an_object["lev"], // string - an_object["lev_markup_number"], // string - an_object["lev_collapsed_number"], // string - segment_anchor_tag_that_object_belongs_to, // string - obj_cite_number, // int - cntr, // int - heading_ptr, // int - lv_ancestors, // string[] - an_object["is"], // string - html_segnames_ptr, // int - substantive_object_and_anchor_tags_tuple[sObj.notes_reg], - substantive_object_and_anchor_tags_tuple[sObj.notes_star], - substantive_object_and_anchor_tags_tuple[sObj.links], - ); - ++heading_ptr; - debug(segments) { - writeln(an_object["lev_markup_number"]); - writeln(segment_anchor_tag_that_object_belongs_to); - } - the_document_body_section ~= comp_obj_heading; - debug(objectrelated1) { // check - writeln(line); - } - _common_reset_(line_occur, an_object, type); - an_object.remove("lev"); - an_object.remove("lev_markup_number"); - processing.remove("verse"); - ++cntr; - } else if ((type["para"] == State.on) - && (line_occur["para"] > State.off)) { - /+ paragraph object (current line empty) +/ - obj_cite_number = ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash(an_object["bookindex_nugget"], obj_cite_number, segment_anchor_tag_that_object_belongs_to); - an_object["is"] = "para"; - auto comp_obj_heading = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"], - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_para = comp_obj_para.init; - comp_obj_para.use = "body"; - comp_obj_para.is_of = "para"; - comp_obj_para.is_a = "para"; - comp_obj_para.text = an_object["substantive"].to!string.strip; - comp_obj_para.ocn = obj_cite_number; - comp_obj_para.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_para.indent_hang = indent["hang_position"]; - comp_obj_para.indent_base = indent["base_position"]; - comp_obj_para.bullet = bullet; - comp_obj_para.anchor_tags = anchor_tags; - comp_obj_para.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_para.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_para.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_para; - _common_reset_(line_occur, an_object, type); - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - processing.remove("verse"); - ++cntr; - } else { - assert( - line == null, - "line variable should be empty, should not occur" - ); - } - } // close else for line empty - } // close else for not the above - } // close after non code, other blocks or regular text - /+ unless (the_document_body_section.length == 0) ? +/ - if (the_document_body_section.length > 0) { - if (((the_document_body_section[$-1].is_a == "para") - || (the_document_body_section[$-1].is_a == "heading") - || (the_document_body_section[$-1].is_a == "quote") - || (the_document_body_section[$-1].is_a == "group") - || (the_document_body_section[$-1].is_a == "block") - || (the_document_body_section[$-1].is_a == "verse")) - && (the_document_body_section.length > previous_length)) { - if ((the_document_body_section[$-1].is_a == "heading") - && (the_document_body_section[$-1].heading_lev_markup < 5)) { - type["biblio_section"] = State.off; - type["glossary_section"] = State.off; - type["blurb_section"] = State.off; - } - if (the_document_body_section[$-1].is_a == "verse") { - /+ scan for endnotes for whole poem (each verse in poem) +/ - foreach (i; previous_length .. the_document_body_section.length) { - if (the_document_body_section[i].is_a == "verse") { - if ((the_document_body_section[i].text).match( - rgx.inline_notes_delimiter_al_regular_number_note - )) { - note_section.gather_notes_for_endnote_section( - the_document_body_section, - segment_anchor_tag_that_object_belongs_to, - to!int(i), - ); - } - } - } - } else { - /+ scan object for endnotes +/ - previous_length = the_document_body_section.length.to!int; - if ((the_document_body_section[$-1].text).match( - rgx.inline_notes_delimiter_al_regular_number_note - )) { - previous_count=(the_document_body_section.length -1).to!int; - note_section.gather_notes_for_endnote_section( - the_document_body_section, - segment_anchor_tag_that_object_belongs_to, - to!int(the_document_body_section.length-1), - ); - } - } - previous_length = the_document_body_section.length.to!int; - } - } - } /+ ← closed: loop markup document/text line by line +/ - /+ ↓ post loop markup document/text +/ - auto en_tuple = - note_section.endnote_objects(obj_cite_number, opt_action_bool); - static assert(!isTypeTuple!(en_tuple)); - auto the_endnotes_section = en_tuple[0]; - obj_cite_number = en_tuple[1]; - debug(endnotes) { - writefln( - "%s %s", - __LINE__, - the_endnotes_section.length - ); - foreach (o; the_endnotes_section) { - writeln(o); - } - } - if (an_object["glossary_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "empty"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Glossary section"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_glossary_section ~= comp_obj_heading_; - } else { - writeln("gloss"); - } - debug(glossary) { - foreach (gloss; the_glossary_section) { - writeln(gloss.text); - } - } - auto biblio_unsorted_incomplete = biblio_arr_json.dup; - auto biblio = Bibliography(); - auto biblio_ordered = - biblio._bibliography_(biblio_unsorted_incomplete, bib_arr_json); - if (biblio_ordered.length > 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "_part_bibliography"; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - 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"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "bibliography"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 2; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.anchor_tags = ["bibliography"]; - the_bibliography_section ~= comp_obj_heading_; - } else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "empty"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Bibliography"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_bibliography_section ~= comp_obj_heading_; - } - string out_; - foreach (entry; biblio_ordered) { - out_ = format( - "%s \"%s\"%s%s%s%s%s%s%s%s%s.", - ((entry["author"].str.empty) ? entry["editor"].str : entry["author"].str), - entry["fulltitle"].str, - ((entry["journal"].str.empty) ? "" : ", /{" ~ entry["journal"].str ~ "}/"), - ((entry["volume"].str.empty) ? "" : ", " ~ entry["volume"].str), - ((entry["in"].str.empty) ? "" : ", " ~ entry["in"].str), - ((!(entry["author"].str.empty) && (!(entry["editor"].str.empty))) ? entry["editor"].str : ""), - ", " ~ entry["year"].str, - ((entry["pages"].str.empty) ? "" : ", " ~ entry["pages"].str), - ((entry["publisher"].str.empty) ? "" : ", " ~ entry["publisher"].str), - ((entry["place"].str.empty) ? "" : ", " ~ entry["place"].str), - ((entry["url"].str.empty) ? "" : ", [" ~ entry["url"].str ~ "]"), - ); - comp_obj_para = comp_obj_para.init; - comp_obj_para.use = "backmatter"; - comp_obj_para.is_of = "para"; - comp_obj_para.is_a = "bibliography"; - comp_obj_para.text = out_.to!string.strip; - comp_obj_para.ocn = 0; - comp_obj_para.obj_cite_number = ""; - comp_obj_para.indent_hang = 0; - comp_obj_para.indent_base = 1; - comp_obj_para.bullet = bullet; - comp_obj_para.anchor_tags = anchor_tags; - the_bibliography_section ~= comp_obj_para; - } - debug(bibliosection) { - foreach (o; the_bibliography_section) { - writeln(o.text); - } - } - auto bi = BookIndexReportSection(); - auto bi_tuple = - bi.bookindex_build_abstraction_section( - bookindex_unordered_hashes, - obj_cite_number, - opt_action_bool, - ); - destroy(bookindex_unordered_hashes); - static assert(!isTypeTuple!(bi_tuple)); - auto the_bookindex_section = bi_tuple[0]; - obj_cite_number = bi_tuple[1]; - debug(bookindex) { - foreach (bi_entry; the_bookindex_section["seg"]) { - writeln(bi_entry); - } - } - if (an_object["blurb_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "empty"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Blurb section"; - comp_obj_heading_.ocn = 0; - comp_obj_para.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = ""; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_blurb_section ~= comp_obj_heading_; - } - debug(blurb) { - foreach (blurb; the_blurb_section) { - writeln(blurb.text); - } - } - indent=[ - "hang_position" : 1, - "base_position" : 1, - ]; - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.use = "frontmatter"; - comp_obj_toc.is_of = "para"; - comp_obj_toc.is_a = "toc"; - comp_obj_toc.ocn = 0; - comp_obj_toc.obj_cite_number = ""; - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.bullet = false; - if (the_endnotes_section.length > 1) { - toc_txt_ = format( - "{ %s }%s%s%s", - "Endnotes", - mkup.mark_internal_site_lnk, - "endnotes", // segment_anchor_tag_that_object_belongs_to - ".fnSuffix", - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - } - if (the_glossary_section.length > 1) { - toc_txt_ = format( - "{ %s }%s%s%s", - "Glossary", - mkup.mark_internal_site_lnk, - "glossary", // segment_anchor_tag_that_object_belongs_to - ".fnSuffix", - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - toc_txt_ = format( - "{ %s }#%s", - "Glossary", - "glossary", // _anchor_tag - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } - if (the_bibliography_section.length > 1){ - toc_txt_ = format( - "{ %s }%s%s%s", - "Bibliography", - mkup.mark_internal_site_lnk, - "bibliography", // segment_anchor_tag_that_object_belongs_to - ".fnSuffix", - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - - toc_txt_ = format( - "{ %s }#%s", - "Bibliography", - "bibliography", // _anchor_tag - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } - if (the_bookindex_section["seg"].length > 1) { - toc_txt_ = format( - "{ %s }%s%s%s", - "Book Index", - mkup.mark_internal_site_lnk, - "bookindex", // segment_anchor_tag_that_object_belongs_to - ".fnSuffix", - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - } - if (the_bookindex_section["scroll"].length > 1) { - toc_txt_ = format( - "{ %s }#%s", - "Book Index", - "bookindex", // _anchor_tag - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } - if (the_blurb_section.length > 1) { - toc_txt_ = format( - "{ %s }%s%s%s", - "Blurb", - mkup.mark_internal_site_lnk, - "blurb", // segment_anchor_tag_that_object_belongs_to - ".fnSuffix", - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - toc_txt_ = format( - "{ %s }#%s", - "Blurb", - "blurb", // _anchor_tag - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.inline_links = true; - comp_obj_toc.text = toc_txt_.to!string.strip; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } - debug(toc) { - writefln( - "%s %s", - __LINE__, - the_table_of_contents_section["seg"].length - ); - foreach (toc_linked_heading; the_table_of_contents_section["seg"]) { - writeln(mkup.indent_by_spaces_provided(toc_linked_heading.indent_hang), toc_linked_heading.text); - } - } - debug(tocscroll) { - writefln( - "%s %s", - __LINE__, - the_table_of_contents_section["seg"].length - ); - foreach (toc_linked_heading; the_table_of_contents_section["scroll"]) { - writeln(mkup.indent_by_spaces_provided(toc_linked_heading.indent_hang), toc_linked_heading.text); - } - } - the_document_head_section ~= the_document_body_section[0]; - the_document_body_section=the_document_body_section[1..$]; - if (the_endnotes_section.length > 1) { - html_segnames ~= "endnotes"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref section; the_endnotes_section) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; - } - if (the_glossary_section.length > 1) { - html_segnames ~= "glossary"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref section; the_glossary_section) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; - } - if (the_bibliography_section.length > 1) { - html_segnames ~= "bibliography"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref section; the_bibliography_section) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; - } - if (the_bookindex_section["scroll"].length > 1) { - html_segnames ~= "bookindex"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref section; the_bookindex_section["scroll"]) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - foreach (ref section; the_bookindex_section["seg"]) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; - } - if (the_blurb_section.length > 1) { - html_segnames ~= "blurb"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref section; the_blurb_section) { - if (section.heading_lev_markup == 4) { - section.ptr_html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; - } - string[] _images; - auto extract_images(S)(S content_block) { - string[] images_; - if (auto m = content_block.matchAll(rgx.image)) { - images_ ~= m.captures[1]; - } - return images_; - } - string[] segnames_0_4; - foreach (ref obj; the_document_head_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - if (the_table_of_contents_section["scroll"].length > 1) { - dom_markedup_buffer = dom_markedup.dup; - dom_collapsed_buffer = dom_collapsed.dup; - foreach (ref obj; the_table_of_contents_section["scroll"]) { - if (obj.is_a == "heading") { - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - dom_markedup = dom_markedup_buffer.dup; - dom_collapsed = dom_collapsed_buffer.dup; - foreach (ref obj; the_table_of_contents_section["seg"]) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - } - /+ multiple 1~ levels, loop through document body +/ - if (the_document_body_section.length > 1) { - foreach (ref obj; the_document_body_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.lev4_subtoc = lev4_subtoc[obj.segment_anchor_tag]; - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } else if (obj.is_a == "para") { - _images ~= extract_images(obj.text); - } - } - } - auto images=uniq(_images.sort()); - /+ optional only one 1~ level +/ - if (the_endnotes_section.length > 1) { - dom_markedup_buffer = dom_markedup.dup; - dom_collapsed_buffer = dom_collapsed.dup; - dom_markedup = dom_markedup_buffer.dup; - dom_collapsed = dom_collapsed_buffer.dup; - foreach (ref obj; the_endnotes_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - } - /+ optional only one 1~ level +/ - if (the_glossary_section.length > 1) { - foreach (ref obj; the_glossary_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - } - /+ optional only one 1~ level +/ - if (the_bibliography_section.length > 1) { - foreach (ref obj; the_bibliography_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - } - /+ optional only one 1~ level +/ - if (the_bookindex_section["scroll"].length > 1) { - dom_markedup_buffer = dom_markedup.dup; - dom_collapsed_buffer = dom_collapsed.dup; - foreach (ref obj; the_bookindex_section["scroll"]) { - if (obj.is_a == "heading") { - debug(dom) { - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - dom_markedup = dom_markedup_buffer.dup; - dom_collapsed = dom_collapsed_buffer.dup; - foreach (ref obj; the_bookindex_section["seg"]) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - } - /+ optional only one 1~ level +/ - if (the_blurb_section.length > 1) { - foreach (ref obj; the_blurb_section) { - if (obj.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.heading_lev_markup <= 4) { - segnames_0_4 ~= obj.segment_anchor_tag; - if (obj.heading_lev_markup == 4) { - obj.segname_prev = html_segnames[obj.ptr_html_segnames - 1]; - if (html_segnames.length > obj.ptr_html_segnames + 1) { - obj.segname_next = html_segnames[obj.ptr_html_segnames + 1]; - } - assert(obj.segment_anchor_tag == html_segnames[obj.ptr_html_segnames]); - } - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - obj.dom_markedup = - dom_set_markup_tags(dom_markedup, obj.heading_lev_markup).dup; - obj.dom_collapsed = - dom_set_collapsed_tags(dom_collapsed, obj.heading_lev_collapsed).dup; - } - heading_ancestors(obj, lv_ancestors); - } - } - /+ TODO - - note create/insert heading object sole purpose eof close all open tags - sort out: - - obj.dom_markedup = dom_markedup; - - obj.dom_collapsed = dom_collapsed; - +/ - dom_markedup = dom_set_markup_tags(dom_markedup, 0); - dom_collapsed = dom_set_collapsed_tags(dom_collapsed, 0); - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "empty"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.ocn = 0; - comp_obj_para.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = ""; - comp_obj_heading_.marked_up_level = ""; - comp_obj_heading_.heading_lev_markup = 9; - comp_obj_heading_.heading_lev_collapsed = 9; - comp_obj_heading_.parent_ocn = 0; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.dom_markedup = dom_markedup.dup; - comp_obj_heading_.dom_collapsed = dom_collapsed.dup; - the_dom_tail_section ~= comp_obj_heading_; - } - auto document_the = [ - "head": the_document_head_section, - "toc_seg": the_table_of_contents_section["seg"], - "toc_scroll": the_table_of_contents_section["scroll"], - /+ substantive/body: +/ - "body": the_document_body_section, - /+ backmatter: +/ - "endnotes": the_endnotes_section, - "glossary": the_glossary_section, - "bibliography": the_bibliography_section, - "bookindex_scroll": the_bookindex_section["scroll"], - "bookindex_seg": the_bookindex_section["seg"], - "blurb": the_blurb_section, - /+ dom tail only +/ - "tail": the_dom_tail_section, - ]; - string[][string] document_section_keys_sequenced = [ - "seg": ["head", "toc_seg", "body",], - "scroll": ["head", "toc_scroll", "body",] - ]; - if (document_the["endnotes"].length > 1) { - document_section_keys_sequenced["seg"] ~= "endnotes"; - document_section_keys_sequenced["scroll"] ~= "endnotes"; - } - if (document_the["glossary"].length > 1) { - document_section_keys_sequenced["seg"] ~= "glossary"; - document_section_keys_sequenced["scroll"] ~= "glossary"; - } - if (document_the["bibliography"].length > 1) { - document_section_keys_sequenced["seg"] ~= "bibliography"; - document_section_keys_sequenced["scroll"] ~= "bibliography"; - } - if (document_the["bookindex_seg"].length > 1) { - document_section_keys_sequenced["seg"] ~= "bookindex_seg"; - } - if (document_the["bookindex_scroll"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "bookindex_scroll"; - } - if (document_the["blurb"].length > 1) { - document_section_keys_sequenced["seg"] ~= "blurb"; - document_section_keys_sequenced["scroll"] ~= "blurb"; - } - if ((opt_action_bool["html"]) - || (opt_action_bool["html_scroll"]) - || (opt_action_bool["html_seg"]) - || (opt_action_bool["epub"])) { - document_section_keys_sequenced["seg"] ~= "tail"; - document_section_keys_sequenced["scroll"] ~= "tail"; - } - auto segnames = html_segnames.dup; - destroy(the_document_head_section); - destroy(the_table_of_contents_section); - destroy(the_document_body_section); - destroy(the_endnotes_section); - destroy(the_glossary_section); - destroy(the_bibliography_section); - destroy(the_bookindex_section); - destroy(the_blurb_section); - destroy(html_segnames); - destroy(bookindex_unordered_hashes); - destroy(an_object); - biblio_arr_json = []; - obj_cite_number=0; - obj_cite_number_=0; - html_segnames_ptr=0; - html_segnames_ptr_cntr=0; - content_non_header = "8"; - dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - dom_markedup_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - dom_collapsed_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; - auto t = tuple( - document_the, - docSectKeysSeq!()(document_section_keys_sequenced), - segnames, - segnames_0_4, - images, - ); - return t; - /+ post loop markup document/text ↑ +/ - } /+ ← closed: abstract doc source +/ - /+ ↓ abstraction functions +/ - auto object_reset(O)(ref O an_object) { - debug(asserts) { - static assert(is(typeof(an_object) == string[string])); - } - an_object.remove("body_nugget"); - an_object.remove("substantive"); - an_object.remove("is"); - an_object.remove("attrib"); - an_object.remove("bookindex_nugget"); - } - auto _common_reset_(L,O,T)( - return ref L line_occur, - return ref O an_object, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line_occur) == int[string])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - line_occur["heading"] = State.off; - line_occur["para"] = State.off; - type["heading"] = State.off; - type["para"] = State.off; - object_reset(an_object); - } - void _check_ocn_status_(L,T)( - L line, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if ((!line.empty) && (type["ocn_status_multi_obj"] == TriState.off)) { - /+ not multi-line object, check whether obj_cite_number is on or turned off +/ - if (line.matchFirst(rgx.obj_cite_number_block_marks)) { - /+ switch off obj_cite_number +/ - if (line.matchFirst(rgx.obj_cite_number_off_block)) { - type["ocn_status_multi_obj"] = TriState.on; - debug(ocnoff) { - writeln(line); - } - } - if (line.matchFirst(rgx.obj_cite_number_off_block_dh)) { - type["ocn_status_multi_obj"] = TriState.closing; - debug(ocnoff) { - writeln(line); - } - } - } else { - if (type["ocn_status_multi_obj"] == TriState.off) { - if (line.matchFirst(rgx.obj_cite_number_off)) { - type["ocn_status"] = TriState.on; - } else if (line.matchFirst(rgx.obj_cite_number_off_dh)) { - type["ocn_status"] = TriState.closing; - } else { - type["ocn_status"] = TriState.off; - } - } else { - type["ocn_status"] = - type["ocn_status_multi_obj"]; - } - } - } else if ((!line.empty) && (type["ocn_status_multi_obj"] > TriState.off)) { - if (line.matchFirst(rgx.obj_cite_number_off_block_close)) { - type["ocn_status_multi_obj"] = TriState.off; - type["ocn_status"] = TriState.off; - debug(ocnoff) { - writeln(line); - } - } - } - } - void _start_block_(L,T,N)( - L line, - return ref T type, - N obj_cite_number_poem - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(type) == int[string])); - static assert(is(typeof(obj_cite_number_poem) == string[string])); - } - auto rgx = Rgx(); - string code_block_syntax = ""; - bool code_block_numbered = false; - if (auto m = line.matchFirst(rgx.block_curly_code_open)) { - /+ curly code open +/ - code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; - code_block_numbered = (m.captures[2] == "#") ? true : false; - debug(code) { // code (curly) open - writefln( - "* [code curly] %s", - line - ); - } - type["blocks"] = TriState.on; - type["code"] = TriState.on; - type["curly_code"] = TriState.on; - } else if (line.matchFirst(rgx.block_curly_poem_open)) { - /+ curly poem open +/ - debug(poem) { // poem (curly) open - writefln( - "* [poem curly] %s", - line - ); - } - obj_cite_number_poem["start"] = - obj_cite_number.to!string; - type["blocks"] = TriState.on; - type["verse_new"] = State.on; - type["poem"] = TriState.on; - type["curly_poem"] = TriState.on; - } else if (line.matchFirst(rgx.block_curly_group_open)) { - /+ curly group open +/ - debug(group) { // group (curly) open - writefln( - "* [group curly] %s", - line - ); - } - type["blocks"] = TriState.on; - type["group"] = TriState.on; - type["curly_group"] = TriState.on; - } else if (line.matchFirst(rgx.block_curly_block_open)) { - /+ curly block open +/ - debug(block) { // block (curly) open - writefln( - "* [block curly] %s", - line - ); - } - type["blocks"] = TriState.on; - type["block"] = TriState.on; - type["curly_block"] = TriState.on; - } else if (line.matchFirst(rgx.block_curly_quote_open)) { - /+ curly quote open +/ - debug(quote) { // quote (curly) open - writefln( - "* [quote curly] %s", - line - ); - } - type["blocks"] = TriState.on; - type["quote"] = TriState.on; - type["curly_quote"] = TriState.on; - } else if (auto m = line.matchFirst(rgx.block_curly_table_open)) { - /+ curly table open +/ - debug(table) { // table (curly) open - writefln( - "* [table curly] %s", - line - ); - } - an_object["table_head"] = m.captures[1].to!string; - an_object["block_type"] = "curly"; - type["blocks"] = TriState.on; - type["table"] = TriState.on; - type["curly_table"] = TriState.on; - } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { - /+ table: special table block markup syntax! +/ - an_object["table_head"] = m.captures[1].to!string; - an_object["block_type"] = "special"; - type["blocks"] = TriState.on; - type["table"] = TriState.on; - type["curly_table_special_markup"] = TriState.on; - } else if (auto m = line.matchFirst(rgx.block_tic_code_open)) { - /+ tic code open +/ - code_block_syntax = (m.captures[1]) ? m.captures[1].to!string : ""; - code_block_numbered = (m.captures[2] == "#") ? true : false; - debug(code) { // code (tic) open - writefln( - "* [code tic] %s", - line - ); - } - type["blocks"] = TriState.on; - type["code"] = TriState.on; - type["tic_code"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_poem_open)) { - /+ tic poem open +/ - debug(poem) { // poem (tic) open - writefln( - "* [poem tic] %s", - line - ); - } - obj_cite_number_poem["start"] = obj_cite_number.to!string; - type["blocks"] = TriState.on; - type["verse_new"] = State.on; - type["poem"] = TriState.on; - type["tic_poem"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_group_open)) { - /+ tic group open +/ - debug(group) { // group (tic) open - writefln( - "* [group tic] %s", - line - ); - } - type["blocks"] = TriState.on; - type["group"] = TriState.on; - type["tic_group"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_block_open)) { - /+ tic block open +/ - debug(block) { // block (tic) open - writefln( - "* [block tic] %s", - line - ); - } - type["blocks"] = TriState.on; - type["block"] = TriState.on; - type["tic_block"] = TriState.on; - } else if (line.matchFirst(rgx.block_tic_quote_open)) { - /+ tic quote open +/ - debug(quote) { // quote (tic) open - writefln( - "* [quote tic] %s", - line - ); - } - type["blocks"] = TriState.on; - type["quote"] = TriState.on; - type["tic_quote"] = TriState.on; - } else if (auto m = line.matchFirst(rgx.block_tic_table_open)) { - /+ tic table open +/ - debug(table) { // table (tic) open - writefln( - "* [table tic] %s", - line - ); - } - an_object["table_head"] = m.captures[1].to!string; - an_object["block_type"] = "tic"; - type["blocks"] = TriState.on; - type["table"] = TriState.on; - type["tic_table"] = TriState.on; - } - } - void _quote_block_(L,O,T)( - return ref L line, - return ref O an_object, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if (type["curly_quote"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_quote_close)) { - 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; - } else { - debug(quote) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) - } - } else if (type["tic_quote"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - 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; - } else { - debug(quote) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) - } - } - } - void _group_block_(L,O,T)( - return ref L line, - return ref O an_object, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if (type["curly_group"] == State.on) { - if (line.matchFirst(rgx.block_curly_group_close)) { - 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; - } else { - debug(group) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) - } - } else if (type["tic_group"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - 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; - } else { - debug(group) { // group - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) - } - } - } - void _block_block_(L,O,T)( - return ref L line, - return ref O an_object, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if (type["curly_block"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_block_close)) { - 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; - } else { - debug(block) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) - } - } else if (type["tic_block"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - 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; - } else { - debug(block) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) - } - } - } - void _poem_block_(L,O,T,C,N,Ma)( - L line, - return ref O an_object, - return ref T type, - return ref C cntr, - N obj_cite_number_poem, - Ma dochead_make_aa, - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - static assert(is(typeof(cntr) == int)); - static assert(is(typeof(obj_cite_number_poem) == string[string])); - static assert(is(typeof(dochead_make_aa) == string[string][string])); - } - auto rgx = Rgx(); - if (type["curly_poem"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_poem_close)) { - if (an_object_key in an_object - || processing.length > 0) { - an_object[an_object_key] = ""; - debug(poem) { // poem (curly) close - writefln( - "* [poem curly] %s", - line - ); - } - if (processing.length > 0) { - an_object[an_object_key] = processing["verse"]; - } - debug(poem) { // poem (curly) close - writeln(__LINE__); - writefln( - "* %s %s", - obj_cite_number, - line - ); - } - if (an_object.length > 0) { - debug(poem) { // poem (curly) close - writeln( - obj_cite_number, - an_object[an_object_key] - ); - } - an_object["is"] = "verse"; - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "verse"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - } - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - obj_cite_number_poem["end"] = - obj_cite_number.to!string; - type["blocks"] = TriState.closing; - type["poem"] = TriState.closing; - type["curly_poem"] = TriState.off; - } else { - processing["verse"] ~= line ~= "\n"; - if (type["verse_new"] == State.on) { - obj_cite_number = - 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; - } - if (type["verse_new"] == State.on) { - verse_line=1; - an_object[an_object_key] = processing["verse"]; - debug(poem) { // poem verse - writefln( - "* %s curly\n%s", - obj_cite_number, - an_object[an_object_key] - ); - } - processing.remove("verse"); - an_object["is"] = "verse"; - auto comp_obj_location = node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "verse"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - } - } else if (type["tic_poem"] == TriState.on) { - if (auto m = line.matchFirst(rgx.block_tic_close)) { // tic_poem_close - an_object[an_object_key]="verse"; - debug(poem) { // poem (curly) close - writefln( - "* [poem tic] %s", - line - ); - } - if (processing.length > 0) { - an_object[an_object_key] = processing["verse"]; - } - if (an_object.length > 0) { - debug(poem) { // poem (tic) close - writeln(__LINE__); - writeln(obj_cite_number, line); - } - processing.remove("verse"); - an_object["is"] = "verse"; - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "verse"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - obj_cite_number_poem["end"] = obj_cite_number.to!string; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - type["blocks"] = TriState.closing; - type["poem"] = TriState.closing; - type["tic_poem"] = TriState.off; - } else { - processing["verse"] ~= line ~= "\n"; - if (type["verse_new"] == State.on) { - obj_cite_number = - 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; - } - if (type["verse_new"] == State.on) { - verse_line=1; - an_object[an_object_key] = processing["verse"]; - debug(poem) { // poem (tic) close - writefln( - "* %s tic\n%s", - obj_cite_number, - an_object[an_object_key] - ); - } - processing.remove("verse"); - an_object["is"] = "verse"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "verse"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - } - } - } - void _code_block_(L,O,T)( - return ref L line, - return ref O an_object, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if (type["curly_code"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_code_close)) { - 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; - } else { - debug(code) { // code (curly) line - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // code (curly) line - } - } else if (type["tic_code"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - 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; - } else { - debug(code) { // code (tic) line - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // code (tic) line - } - } - } - void _table_block_(L,O,T,Ma)( - return ref L line, - return ref O an_object, - return ref T type, - return ref Ma dochead_make_aa - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if (type["curly_table"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_table_close)) { - debug(table) { // table (curly) close - writeln(line); - } - type["blocks"] = TriState.closing; - type["table"] = TriState.closing; - type["curly_table"] = TriState.off; - } else { - debug(table) { // table - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) - } - } else if (type["curly_table_special_markup"] == TriState.on) { - if (line.empty) { - type["blocks"] = TriState.off; - type["table"] = TriState.off; - type["curly_table_special_markup"] = TriState.off; - _table_closed_make_special_notation_table_( - line, - an_object, - the_document_body_section, - obj_cite_number, - comp_obj_heading, - cntr, - type, - dochead_make_aa - ); - } else { - debug(table) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; - } - } else if (type["tic_table"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - debug(table) { // table (tic) close - writeln(line); - } - type["blocks"] = TriState.closing; - type["table"] = TriState.closing; - type["tic_table"] = TriState.off; - } else { - debug(table) { // table - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) - } - } - } - final string biblio_tag_map(A)(A abr) { - debug(asserts) { - static assert(is(typeof(abr) == string)); - } - auto btm = [ - "au" : "author_raw", - "ed" : "editor_raw", - "ti" : "fulltitle", - "lng" : "language", - "jo" : "journal", - "vol" : "volume", - "edn" : "edition", - "yr" : "year", - "pl" : "place", - "pb" : "publisher", - "pub" : "publisher", - "pg" : "pages", - "pgs" : "pages", - "sn" : "short_name" - ]; - return btm[abr]; - } - void _biblio_block_( - char[] line, - return ref int[string] type, - return ref int bib_entry, - return ref string biblio_entry_str_json, - return ref string[] biblio_arr_json - ) { - mixin SiSUbiblio; - auto jsn = BibJsnStr(); - auto rgx = Rgx(); - if (line.matchFirst(rgx.heading_biblio)) { - type["biblio_section"] = TriState.on; - type["blurb_section"] = State.off; - type["glossary_section"] = State.off; - } - if (line.empty) { - debug { - debug(biblioblock) { - writeln("---"); - } - debug(biblioblockinclude) { - writeln(biblio_entry_str_json.length); - } - } - if ((bib_entry == State.off) - && (biblio_entry_str_json.empty)) { - bib_entry = State.on; - biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; - } else if (!(biblio_entry_str_json.empty)) { - bib_entry = State.off; - if (!(biblio_entry_str_json == jsn.biblio_entry_tags_jsonstr)) { - auto biblio_entry = parseJSON(biblio_entry_str_json); - if (biblio_entry["fulltitle"].str.empty) { - writeln("check problem entry (Title missing): ", biblio_entry_str_json); - } else if ((biblio_entry["author_raw"].str.empty) && (biblio_entry["editor_raw"].str.empty)) { - writeln("check problem entry (No author and no editor): ", biblio_entry_str_json); - } else { - biblio_arr_json ~= biblio_entry_str_json; - } - biblio_entry_str_json = jsn.biblio_entry_tags_jsonstr; - } - } else { // CHECK ERROR - writeln("?? 2. ERROR ", biblio_entry_str_json, "??"); - biblio_entry_str_json = ""; - } - } else if (line.matchFirst(rgx.biblio_tags)) { - debug(biblioblock) { - writeln(line); - } - auto bt = line.match(rgx.biblio_tags); - bib_entry = State.off; - st = bt.captures[1].to!string; - auto header_tag_value=(bt.captures[2]).to!string; - JSONValue j = parseJSON(biblio_entry_str_json); - biblio_tag_name = (st.match(rgx.biblio_abbreviations)) - ? (biblio_tag_map(st)) - : st; - j.object[biblio_tag_name] = header_tag_value; - debug(bibliounsortedcheckduplicates) { - writeln(biblio_tag_name, ": ", header_tag_value); - writeln("--"); - } - switch (biblio_tag_name) { - case "author_raw": // author_arr author (fn sn) - j["author_arr"] = - header_tag_value.split(rgx.arr_delimiter); - string tmp; - biblioAuthorLoop: - foreach (au; j["author_arr"].array) { - if (auto x = au.str.match(rgx.name_delimiter)) { - tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; - } else { - tmp ~= au.str; - } - } - tmp = (tmp).replace(rgx.trailing_comma, ""); - j["author"].str = tmp; - goto default; - case "editor_raw": // editor_arr editor (fn sn) - j["editor_arr"] = - header_tag_value.split(rgx.arr_delimiter); - string tmp; - biblioEditorLoop: - foreach (ed; j["editor_arr"].array) { - if (auto x = ed.str.match(rgx.name_delimiter)) { - tmp ~= x.captures[2] ~ " " ~ x.captures[1] ~ ", "; - } else { - tmp ~= ed.str; - } - } - tmp = (tmp).replace(rgx.trailing_comma, ""); - j["editor"].str = tmp; - goto default; - case "fulltitle": // title & subtitle - goto default; - default: - break; - } - auto s = j.toString(); - debug(biblio1) { - writefln( - "* %s: %s\n%s", - biblio_tag_name, - biblio_tag_entry, - j[biblio_tag_name] - ); - } - if (line.match(rgx.comment)) { - writeln("ERROR", line, "COMMENT"); - writeln("ERROR", s, "%%"); - } - if (!(match(line, rgx.comment))) { - debug(biblioblockinclude) { - writeln(line); - } - biblio_entry_str_json = s; - } else { - biblio_entry_str_json = ""; - } - header_tag_value=""; - } - } - void _table_closed_make_special_notation_table_( - char[] line, - return ref string[string] an_object, - return ref ObjGenericComposite[] the_document_body_section, - return ref int obj_cite_number, - return ref ObjGenericComposite _comp_obj_heading, - return ref int cntr, - return ref int[string] type, - string[string][string] dochead_make_aa, - ) { - comp_obj_block = comp_obj_block.init; - obj_cite_number = - ocn_emit(type["ocn_status"]); - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - "table" - ); - an_object["is"] = "table"; - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, "body_nugget", dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); - comp_obj_block = table_substantive_munge_special(comp_obj_block, an_object["substantive"]); - the_document_body_section ~= comp_obj_block; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - void _block_flag_line_empty_(B)( - B bookindex_extract_hash, - char[] line, - return ref string[string] an_object, - return ref ObjGenericComposite[] the_document_body_section, - return ref string[][string][string] bookindex_unordered_hashes, - return ref int obj_cite_number, - return ref ObjGenericComposite _comp_obj_heading, - return ref int cntr, - return ref int[string] type, - string[string] obj_cite_number_poem, - string[string][string] dochead_make_aa, - ) { - assert( - line.empty, - "\nline should be empty:\n \"" - ~ line ~ "\"" - ); - assert( - (type["blocks"] == TriState.closing), - "code block status: closed" - ); - assertions_flag_types_block_status_none_or_closed(type); - if (type["quote"] == TriState.closing) { - obj_cite_number = - ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "quote"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "quote"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - type["blocks"] = TriState.off; - type["quote"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } else if (type["group"] == TriState.closing) { - obj_cite_number = - ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "group"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "group"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - type["blocks"] = TriState.off; - type["group"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } else if (type["block"] == TriState.closing) { - obj_cite_number = ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "block"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.use = "body"; - comp_obj_block.is_of = "block"; - comp_obj_block.is_a = "block"; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - type["blocks"] = TriState.off; - type["block"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } else if (type["poem"] == TriState.closing) { - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "verse"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - comp_obj_poem_ocn = comp_obj_poem_ocn.init; - comp_obj_poem_ocn.use = "body"; - comp_obj_poem_ocn.is_of = "block"; - comp_obj_poem_ocn.is_a = "poem"; - comp_obj_poem_ocn.ocn = obj_cite_number; - comp_obj_poem_ocn.obj_cite_number = (obj_cite_number_poem["start"], obj_cite_number_poem["end"]); - comp_obj_poem_ocn.text = ""; - the_document_body_section ~= comp_obj_poem_ocn; - type["blocks"] = TriState.off; - type["poem"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - } else if (type["code"] == TriState.closing) { - obj_cite_number = - ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "code"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tags = substantive_obj_misc_tuple[sObj.anchor_tags]; - comp_obj_code = comp_obj_code.init; - comp_obj_code.use = "body"; - comp_obj_code.is_of = "block"; - comp_obj_code.is_a = "code"; - comp_obj_code.ocn = obj_cite_number; - comp_obj_code.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_code.text = an_object["substantive"]; - comp_obj_code.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_code.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_code.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_code; - type["blocks"] = TriState.off; - type["code"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } else if (type["table"] == TriState.closing) { - comp_obj_block = comp_obj_block.init; - obj_cite_number = - ocn_emit(type["ocn_status"]); - an_object["bookindex_nugget"] = - ("bookindex_nugget" in an_object) ? an_object["bookindex_nugget"] : ""; - bookindex_unordered_hashes = - bookindex_extract_hash.bookindex_nugget_hash( - an_object["bookindex_nugget"], - obj_cite_number, - segment_anchor_tag_that_object_belongs_to - ); - an_object["is"] = "table"; - auto comp_obj_location = - node_construct.node_location_emitter( - content_non_header, - segment_anchor_tag_that_object_belongs_to, - obj_cite_number, - cntr, - heading_ptr-1, - an_object["is"] - ); - auto substantive_obj_misc_tuple = - obj_im.obj_inline_markup_and_anchor_tags_and_misc(an_object, an_object_key, dochead_make_aa); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.ocn = obj_cite_number; - comp_obj_block.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - comp_obj_block = table_instructions(comp_obj_block, an_object["table_head"]); - comp_obj_block = table_substantive_munge(comp_obj_block, an_object["substantive"]); - the_document_body_section ~= comp_obj_block; - type["blocks"] = TriState.off; - type["table"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - } - auto _book_index_(L,I,O,T,B)( - L line, - return ref I book_idx_tmp, - return ref O an_object, - return ref T type, - B opt_action_bool, - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(book_idx_tmp) == string)); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - static assert(is(typeof(opt_action_bool) == bool[string])); - } - auto rgx = Rgx(); - if (auto m = line.match(rgx.book_index)) { - /+ match book_index +/ - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - m.captures[1].to!string, - ); - } - an_object["bookindex_nugget"] = m.captures[1].to!string; - } else if (auto m = line.match(rgx.book_index_open)) { - /+ match open book_index +/ - type["book_index"] = State.on; - if (opt_action_bool["backmatter"] && opt_action_bool["section_bookindex"]) { - book_idx_tmp = m.captures[1].to!string; - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); - } - } - } else if (type["book_index"] == State.on ) { - /+ book_index flag set +/ - if (auto m = line.match(rgx.book_index_close)) { - type["book_index"] = State.off; - if (opt_action_bool["backmatter"] - && opt_action_bool["section_bookindex"]) { - an_object["bookindex_nugget"] = book_idx_tmp ~ m.captures[1].to!string; - debug(bookindexmatch) { // book index - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); - } - } - book_idx_tmp = ""; - } else { - if (opt_action_bool["backmatter"] - && opt_action_bool["section_bookindex"]) { - book_idx_tmp ~= line; - } - } - } - } - auto _heading_found_(L,X,H,R,T)( - L line, - X dochead_make_identify_unmarked_headings, - return ref H heading_match_str, - return ref R heading_match_rgx, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(dochead_make_identify_unmarked_headings) == string)); - static assert(is(typeof(heading_match_str) == string[string])); - static assert(is(typeof(heading_match_rgx) == Regex!(char)[string])); - static assert(is(typeof(type) == int[string])); - } - auto rgx = Rgx(); - if ((dochead_make_identify_unmarked_headings.length > 2) - && (type["make_headings"] == State.off)) { - /+ headings found +/ - debug(headingsfound) { - writeln(dochead_make_identify_unmarked_headings); - } - char[][] make_headings_spl = - (cast(char[]) dochead_make_identify_unmarked_headings) - .split(rgx.make_heading_delimiter); - debug(headingsfound) { - writeln(make_headings_spl.length); - writeln(make_headings_spl); - } - switch (make_headings_spl.length) { - case 7 : - if (!empty(make_headings_spl[6])) { - heading_match_str["h_4"] = - "^(" ~ make_headings_spl[6].to!string ~ ")"; - heading_match_rgx["h_4"] = - regex(heading_match_str["h_4"]); - } - goto case; - case 6 : - if (!empty(make_headings_spl[5])) { - heading_match_str["h_3"] = - "^(" ~ make_headings_spl[5].to!string ~ ")"; - heading_match_rgx["h_3"] = - regex(heading_match_str["h_3"]); - } - goto case; - case 5 : - if (!empty(make_headings_spl[4])) { - heading_match_str["h_2"] = - "^(" ~ make_headings_spl[4].to!string ~ ")"; - heading_match_rgx["h_2"] = - regex(heading_match_str["h_2"]); - } - goto case; - case 4 : - if (!empty(make_headings_spl[3])) { - heading_match_str["h_1"] = - "^(" ~ make_headings_spl[3].to!string ~ ")"; - heading_match_rgx["h_1"] = - regex(heading_match_str["h_1"]); - } - goto case; - case 3 : - if (!empty(make_headings_spl[2])) { - heading_match_str["h_D"] = - "^(" ~ make_headings_spl[2].to!string ~ ")"; - heading_match_rgx["h_D"] = - regex(heading_match_str["h_D"]); - } - goto case; - case 2 : - if (!empty(make_headings_spl[1])) { - heading_match_str["h_C"] = - "^(" ~ make_headings_spl[1].to!string ~ ")"; - heading_match_rgx["h_C"] = - regex(heading_match_str["h_C"]); - } - goto case; - case 1 : - if (!empty(make_headings_spl[0])) { - heading_match_str["h_B"] = - "^(" ~ make_headings_spl[0].to!string ~ ")"; - heading_match_rgx["h_B"] = - regex(heading_match_str["h_B"]); - } - break; - default: - break; - } - type["make_headings"] = State.on; - } - } - auto _heading_make_set_(L,C,R,T)( - L line, - C line_occur, - return ref R heading_match_rgx, - return ref T type - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(line_occur) == int[string])); - static assert(is(typeof(heading_match_rgx) == Regex!(char)[string])); - static assert(is(typeof(type) == int[string])); - } - if ((type["make_headings"] == State.on) - && ((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((type["para"] == State.off) - && (type["heading"] == State.off))) { - /+ heading make set +/ - if (line.matchFirst(heading_match_rgx["h_B"])) { - line = "B~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_C"])) { - line = "C~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_D"])) { - line = "D~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_1"])) { - line = "1~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_2"])) { - line = "2~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_3"])) { - line = "3~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - if (line.matchFirst(heading_match_rgx["h_4"])) { - line = "4~ " ~ line; - debug(headingsfound) { - writeln(line); - } - } - } - return line; - } - auto _heading_matched_(L,C,O,K,Lv,Lc,T,Me)( - return ref L line, - return ref C line_occur, - return ref O an_object, - return ref K an_object_key, - return ref Lv lv, - return ref Lc collapsed_lev, - return ref T type, - return ref Me dochead_meta_aa, - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(line_occur) == int[string])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(an_object_key) == string)); - static assert(is(typeof(lv) == int[string])); - static assert(is(typeof(collapsed_lev) == int[string])); - static assert(is(typeof(type) == int[string])); - static assert(is(typeof(dochead_meta_aa) == string[string][string])); - } - auto rgx = Rgx(); - if (auto m = line.match(rgx.heading)) { - /+ heading match +/ - type["heading"] = State.on; - if (line.match(rgx.heading_seg_and_above)) { - type["biblio_section"] = State.off; - type["glossary_section"] = State.off; - type["blurb_section"] = State.off; - } - type["para"] = State.off; - ++line_occur["heading"]; - an_object[an_object_key] ~= line ~= "\n"; - an_object["lev"] ~= m.captures[1]; - assertions_doc_structure(an_object, lv); // includes most of the logic for collapsed levels - switch (an_object["lev"]) { - case "A": - an_object[an_object_key]=(an_object[an_object_key]) - .replaceFirst(rgx.variable_doc_title, - (dochead_meta_aa["title"]["full"] ~ ",")) - .replaceFirst(rgx.variable_doc_author, - dochead_meta_aa["creator"]["author"]); - collapsed_lev["h0"] = 0; - an_object["lev_collapsed_number"] = - collapsed_lev["h0"].to!string; - lv["lv"] = DocStructMarkupHeading.h_sect_A; - ++lv["h0"]; - lv["h1"] = State.off; - lv["h2"] = State.off; - lv["h3"] = State.off; - lv["h4"] = State.off; - lv["h5"] = State.off; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "B": - collapsed_lev["h1"] = collapsed_lev["h0"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h1"].to!string; - lv["lv"] = DocStructMarkupHeading.h_sect_B; - ++lv["h1"]; - lv["h2"] = State.off; - lv["h3"] = State.off; - lv["h4"] = State.off; - lv["h5"] = State.off; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "C": - collapsed_lev["h2"] = collapsed_lev["h1"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h2"].to!string; - lv["lv"] = DocStructMarkupHeading.h_sect_C; - ++lv["h2"]; - lv["h3"] = State.off; - lv["h4"] = State.off; - lv["h5"] = State.off; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "D": - collapsed_lev["h3"] = collapsed_lev["h2"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h3"].to!string; - lv["lv"] = DocStructMarkupHeading.h_sect_D; - ++lv["h3"]; - lv["h4"] = State.off; - lv["h5"] = State.off; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "1": - if (lv["h3"] > State.off) { - collapsed_lev["h4"] = collapsed_lev["h3"] + 1; - } else if (lv["h2"] > State.off) { - collapsed_lev["h4"] = collapsed_lev["h2"] + 1; - } else if (lv["h1"] > State.off) { - collapsed_lev["h4"] = collapsed_lev["h1"] + 1; - } else if (lv["h0"] > State.off) { - collapsed_lev["h4"] = collapsed_lev["h0"] + 1; - } - an_object["lev_collapsed_number"] = - collapsed_lev["h4"].to!string; - lv["lv"] = DocStructMarkupHeading.h_text_1; - ++lv["h4"]; - lv["h5"] = State.off; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "2": - if (lv["h5"] > State.off) { - an_object["lev_collapsed_number"] = - collapsed_lev["h5"].to!string; - } else if (lv["h4"] > State.off) { - collapsed_lev["h5"] = collapsed_lev["h4"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h5"].to!string; - } - lv["lv"] = DocStructMarkupHeading.h_text_2; - ++lv["h5"]; - lv["h6"] = State.off; - lv["h7"] = State.off; - goto default; - case "3": - if (lv["h6"] > State.off) { - an_object["lev_collapsed_number"] = - collapsed_lev["h6"].to!string; - } else if (lv["h5"] > State.off) { - collapsed_lev["h6"] = collapsed_lev["h5"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h6"].to!string; - } - lv["lv"] = DocStructMarkupHeading.h_text_3; - ++lv["h6"]; - lv["h7"] = State.off; - goto default; - case "4": - if (lv["h7"] > State.off) { - an_object["lev_collapsed_number"] = - collapsed_lev["h7"].to!string; - } else if (lv["h6"] > State.off) { - collapsed_lev["h7"] = collapsed_lev["h6"] + 1; - an_object["lev_collapsed_number"] = - collapsed_lev["h7"].to!string; - } - lv["lv"] = DocStructMarkupHeading.h_text_4; - ++lv["h7"]; - goto default; - default: - an_object["lev_markup_number"] = lv["lv"].to!string; - } - debug(heading) { // heading - writeln(line.strip); - } - } - } - void _para_match_(L,O,K,I,B,T,C)( - return ref L line, - return ref O an_object, - return ref K an_object_key, - return ref I indent, - return ref B bullet, - return ref T type, - return ref C line_occur, - ) { - debug(asserts) { - static assert(is(typeof(line) == char[])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(an_object_key) == string)); - static assert(is(typeof(indent) == int[string])); - static assert(is(typeof(bullet) == bool)); - static assert(is(typeof(type) == int[string])); - static assert(is(typeof(line_occur) == int[string])); - } - auto rgx = Rgx(); - if (line_occur["para"] == State.off) { - line = font_faces_line(line); - /+ para matches +/ - type["para"] = State.on; - an_object[an_object_key] ~= line; // body_nugget - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - if (auto m = line.matchFirst(rgx.para_indent)) { - debug(paraindent) { // para indent - writeln(line); - } - indent["hang_position"] = (m.captures[1]).to!int; - indent["base_position"] = 0; - } else if (line.matchFirst(rgx.para_bullet)) { - debug(parabullet) { // para bullet - writeln(line); - } - bullet = true; - } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { - debug(paraindenthang) { // para indent hang - writeln(line); - } - indent=[ - "hang_position" : (m.captures[1]).to!int, - "base_position" : (m.captures[2]).to!int, - ]; - } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { - debug(parabulletindent) { // para bullet indent - writeln(line); - } - indent=[ - "hang_position" : (m.captures[1]).to!int, - "base_position" : 0, - ]; - bullet = true; - } - ++line_occur["para"]; - } - } - auto font_faces_line(T)( - return ref T textline, - ) { - auto rgx = Rgx(); - if (textline.match(rgx.inline_faces_line)) { - textline = (textline) - .replaceFirst(rgx.inline_emphasis_line, ("*{$1}*$2")) - .replaceFirst(rgx.inline_bold_line, ("!{$1}!$2")) - .replaceFirst(rgx.inline_underscore_line, ("_{$1}_$2")) - .replaceFirst(rgx.inline_italics_line, ("/{$1}/$2")); - } - return textline; - } - auto table_instructions(O,H)( - return ref O table_object, - return ref H table_head, - ) { - auto rgx = Rgx(); - table_object.use = "body"; - table_object.is_of = "block"; - table_object.is_a = "table"; - table_object.inline_notes_reg = false; - table_object.inline_notes_star = false; - table_object.inline_links = false; - if (auto m = table_head.matchFirst(rgx.table_head_instructions)) { - table_object.table_heading = ((m["c_heading"].length > 0) && (m["c_heading"] == "h")) ? true : false; - table_object.table_number_of_columns = ((m["c_num"].length > 0) && (m["c_num"].to!int > 0)) ? m["c_num"].to!int : 0; // double check, may be obsolete - foreach (cw; m["c_widths"].matchAll(rgx.table_col_widths)) { - auto x = cw.hit.matchFirst(rgx.table_col_widths_and_alignment); - table_object.table_column_widths ~= x["width"].to!int; - table_object.table_column_aligns ~= (x["align"].empty) ? "" : x["align"]; - } - } - return table_object; - } - auto table_array_munge(O,T)( - return ref O table_object, - return ref T table_array, - ) { - auto rgx = Rgx(); - auto mng = InlineMarkup(); - string _table_substantive; - ulong col_num; - ulong col_num_; - ulong col_num_chk = 0; - foreach(idx_r, row; table_array) { - debug(table_dev) { - writeln("row ", idx_r); - } - col_num_ = 0; - if (col_num == 0 - || col_num < row.length) { - col_num = row.length; - } - if (col_num_chk == 0) { - col_num_chk = col_num; - } else if (col_num == 1) { - debug(table_dev) { - writeln("table note: "); - } - } else if (col_num_chk != col_num) { - debug(table_dev) { - writeln("warning irregular number of columns: ", col_num_chk, " != ", col_num); - } - } else { - } - foreach(idx_c, col; row) { - debug(table_dev) { - write(idx_c, ", "); - } - col_num_ = idx_c; - _table_substantive ~= col ~ mng.tc_s; - if (idx_r == 0 && comp_obj_block.table_heading) { - } else if (idx_r == 1 && col.match(rgx.numeric_col)) { - if ((comp_obj_block.table_column_aligns.length > idx_c) - && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { - comp_obj_block.table_column_aligns[idx_c] - = comp_obj_block.table_column_aligns[idx_c]; - } else if (comp_obj_block.table_column_aligns.length > idx_c) { - comp_obj_block.table_column_aligns[idx_c] = "r"; - } else { - comp_obj_block.table_column_aligns ~= "r"; - } - } else if (idx_r == 1) { - if ((comp_obj_block.table_column_aligns.length > idx_c) - && (comp_obj_block.table_column_aligns[idx_c].matchFirst(rgx.table_col_align_match))) { - comp_obj_block.table_column_aligns[idx_c] - = comp_obj_block.table_column_aligns[idx_c]; - } else if (comp_obj_block.table_column_aligns.length > idx_c) { - comp_obj_block.table_column_aligns[idx_c] = "l"; - } else { - comp_obj_block.table_column_aligns ~= "l"; - } - } - } - debug(table_dev) { - writeln(""); - } - if (col_num_chk > 0 && (col_num != col_num_chk)) { - } else if (col_num == col_num_chk){ - } else { - col_num_chk = col_num; - } - _table_substantive = _table_substantive.replaceFirst(rgx.table_col_separator_nl, "\n"); - } - if (comp_obj_block.table_number_of_columns != col_num) { - if (comp_obj_block.table_number_of_columns == 0) { - comp_obj_block.table_number_of_columns = (col_num).to!int; - } else { - debug(table_dev) { - writeln(comp_obj_block.table_number_of_columns, " != ", col_num); - } - } - } - if (table_object.table_number_of_columns == 0 - && table_object.table_column_widths.length > 0) { - writeln(__LINE__, " ERROR"); - } - if (table_object.table_number_of_columns > 0 - && table_object.table_column_widths.length == 0) { - double col_w = (100.00 / table_object.table_number_of_columns); - foreach (i; 0..table_object.table_number_of_columns) { - table_object.table_column_widths ~= col_w; - } - } else if (table_object.table_number_of_columns - != table_object.table_column_widths.length) { - debug(table_dev) { - writeln(m.hit); // further logic required - } - if (table_object.table_number_of_columns > table_object.table_column_widths.length) { - double col_w = (100.00 - (table_object.table_column_widths).sum) - / (table_object.table_number_of_columns - table_object.table_column_widths.length); - foreach (i; 0..table_object.table_column_widths.length) { - table_object.table_column_widths ~= col_w; - } - foreach (i; 0..(table_object.table_number_of_columns - table_object.table_column_widths.length)) { - table_object.table_column_widths ~= col_w; - } - } else if (table_object.table_number_of_columns < table_object.table_column_widths.length) { - writeln(__LINE__, " warning, ERROR"); - } - } - if (table_object.table_column_widths.sum > 101 - || table_object.table_column_widths.sum < 95 ) { - writeln("sum: ", table_object.table_column_widths.sum, - ", array: ", table_object.table_column_widths, - ", cols: ", table_object.table_number_of_columns); - writeln(_table_substantive); - } - debug(table_res) { - writeln("aligns: ", comp_obj_block.table_column_aligns, "\n", - "no. of columns: ", comp_obj_block.table_number_of_columns, "\n", - "col widths: ", comp_obj_block.table_column_widths, - " sum: ", comp_obj_block.table_column_widths.sum, "\n", - _table_substantive); - } - comp_obj_block.text = _table_substantive; - return table_object; - } - auto table_array_munge_open_close(O,T)( - return ref O table_object, - return ref T table_array, - ) { - auto rgx = Rgx(); - auto mng = InlineMarkup(); - string _table_substantive; - foreach(row; table_array) { - foreach(col; row) { - _table_substantive ~= mng.tc_o ~ col ~ mng.tc_c; - } - _table_substantive ~= "\n"; - } - debug(table_dev) { - writeln(_table_substantive); - } - comp_obj_block.text = _table_substantive; - return table_object; - } - auto table_substantive_munge(O,T)( - return ref O table_object, - return ref T table_substantive, - ) { - auto rgx = Rgx(); - auto munge = ObjInlineMarkupMunge(); - string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter); - string[] _table_cols; - string[][] _table; - foreach(col; _table_rows) { - _table_cols = col.split(rgx.table_col_delimiter); - _table ~= _table_cols; - } - table_object = table_array_munge(table_object, _table); - return table_object; - } - auto table_substantive_munge_special(O,T)( - return ref O table_object, - return ref T table_substantive, - ) { - auto rgx = Rgx(); - auto munge = ObjInlineMarkupMunge(); - string[] _table_rows = (table_substantive).split(rgx.table_row_delimiter_special); - string[] _table_cols; - string[][] _table; - foreach(col; _table_rows) { - _table_cols = col.split(rgx.table_col_delimiter_special); - _table ~= _table_cols; - } - table_object = table_array_munge(table_object, _table); - return table_object; - } - /+ abstraction functions ↑ +/ - /+ ↓ abstraction function emitters +/ - struct OCNemitter { - int obj_cite_number, obj_cite_number_; - int ocn_emitter(int ocn_status_flag) - in { assert(ocn_status_flag <= 3); } - body { - if (ocn_status_flag == 3) { - obj_cite_number = obj_cite_number_ = 1; - } else { - obj_cite_number=(ocn_status_flag == 0) - ? ++obj_cite_number_ - : 0; - } - assert(obj_cite_number >= 0); - return obj_cite_number; - } - invariant() { - } - } - /+ +/ - struct ObjInlineMarkupMunge { - string[string] obj_txt; - int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; - string asterisks_; - string obj_txt_out, tail, note; - auto rgx = Rgx(); - auto mkup = InlineMarkup(); - int stage_reset_note_numbers = true; - private auto initialize_note_numbers() { - n_foot = 0; - n_foot_reg = 0; - n_foot_sp_asterisk = 0; - n_foot_sp_plus = 0; - } - string url_links(Ot)(Ot obj_txt_in) { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - /+ url matched +/ - if (obj_txt_in.match(rgx.inline_url_generic)) { - /+ link: naked url: http://url +/ - if (obj_txt_in.match(rgx.inline_link_naked_url)) { - obj_txt_in = (obj_txt_in).replaceAll( - rgx.inline_link_naked_url, - ("$1" - ~ mkup.lnk_o ~ "$2" ~ mkup.lnk_c - ~ mkup.url_o ~ "$2" ~ mkup.url_c - ~ "$3") // ("$1{ $2 }$2$3") - ); - } - /+ link with helper for endnote including the url: - {~^ link which includes url as footnote }http://url - maps to: - { link which includes url as footnote }http://url~{ { http://url }http://url }~ - +/ - if (obj_txt_in.match(rgx.inline_link_endnote_url_helper)) { - obj_txt_in = (obj_txt_in).replaceAll( - rgx.inline_link_endnote_url_helper_punctuated, - (mkup.lnk_o ~ "$1" ~ mkup.lnk_c - ~ mkup.url_o ~ "$2" ~ mkup.url_c - ~ "~{ " ~ mkup.lnk_o ~ " $2 " ~ mkup.lnk_c - ~ mkup.url_o ~ "$2" ~ mkup.url_c - ~ " }~$3") // ("{ $1 }$2~{ { $2 }$2 }~$3") - ); - obj_txt_in = (obj_txt_in).replaceAll( - rgx.inline_link_endnote_url_helper, - (mkup.lnk_o ~ "$1" ~ mkup.lnk_c - ~ mkup.url_o ~ "$2" ~ mkup.url_c - ~ "~{ " ~ mkup.lnk_o ~ " $2 " ~ mkup.lnk_c - ~ mkup.url_o ~ "$2" ~ mkup.url_c - ~ " }~") // ("{ $1 }$2~{ { $2 }$2 }~") - ); - } - /+ link with regular markup: - { linked text or image }http://url - +/ - if (obj_txt_in.match(rgx.inline_link_markup_regular)) { - obj_txt_in = (obj_txt_in).replaceAll( - rgx.inline_link_markup_regular, - ("$1" - ~ mkup.lnk_o ~ "$2" ~ mkup.lnk_c - ~ mkup.url_o ~ "$3" ~ mkup.url_c - ~ "$4") // ("$1{ $2 }$3$4") - ); - } - } - return obj_txt_in; - } - auto footnotes_endnotes_markup_and_number_or_stars(Ot)(Ot obj_txt_in, bool reset_note_numbers) { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - /+ endnotes (regular) +/ - bool flg_notes_reg = false; - bool flg_notes_star = false; - obj_txt_in = (obj_txt_in).replaceAll( - rgx.inline_notes_curly, - (mkup.en_a_o ~ " $1" ~ mkup.en_a_c) - ); - if (!(stage_reset_note_numbers) && reset_note_numbers) { - stage_reset_note_numbers = true; - } - if (obj_txt_in.match(rgx.inline_notes_al_gen)) { - if (auto m = obj_txt_in.matchAll(rgx.inline_text_and_note_al_)) { - if (stage_reset_note_numbers) { - n_foot = 0; - n_foot_reg = 0; - n_foot_sp_asterisk = 0; - n_foot_sp_plus = 0; - } - stage_reset_note_numbers = false; - foreach(n; m) { - if (n.hit.to!string.match(rgx.inline_al_delimiter_open_symbol_star)) { - flg_notes_star = true; - ++n_foot_sp_asterisk; - asterisks_ = "*"; - n_foot=n_foot_sp_asterisk; - obj_txt_out ~= n.hit.to!string.replaceFirst( - rgx.inline_al_delimiter_open_symbol_star, - (mkup.en_a_o ~ replicate(asterisks_, n_foot_sp_asterisk) ~ " ") - ) ~ "\n"; - } else if (n.hit.to!string.match(rgx.inline_al_delimiter_open_regular)) { - flg_notes_reg = true; - ++n_foot_reg; - n_foot=n_foot_reg; - obj_txt_out ~= n.hit.to!string.replaceFirst( - rgx.inline_al_delimiter_open_regular, - (mkup.en_a_o ~ to!string(n_foot) ~ " ") - ) ~ "\n"; - } else { - obj_txt_out ~= n.hit.to!string ~ "\n"; - } - } - } - } else { - obj_txt_out = obj_txt_in; - } - auto t = tuple( - obj_txt_out, - flg_notes_reg, - flg_notes_star, - ); - return t; - } - private auto object_notes_and_links_(Ot)(Ot obj_txt_in, bool reset_note_numbers=false) - in { - debug(asserts) { - assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt_out = ""; - bool urls = false; - tail = ""; - /+ special endnotes +/ - obj_txt_in = obj_txt_in.replaceAll( - rgx.inline_notes_curly_sp_asterisk, - (mkup.en_a_o ~ "*" ~ " $1" ~ mkup.en_a_c) - ); - obj_txt_in = - obj_txt_in.replaceAll( - rgx.inline_notes_curly_sp_plus, - (mkup.en_a_o ~ "+" ~ " $1" ~ mkup.en_a_c) - ); - /+ url matched +/ - if (obj_txt_in.match(rgx.inline_url)) { - urls = true; - obj_txt_in = url_links(obj_txt_in); - } - auto ftn = footnotes_endnotes_markup_and_number_or_stars(obj_txt_in, reset_note_numbers); - obj_txt_out = ftn[0]; - debug(footnotes) { - writeln(obj_txt_out, tail); - } - obj_txt_out = obj_txt_out ~ tail; - debug(footnotesdone) { - foreach(m; matchAll(obj_txt_out, - (mkup.en_a_o ~ `\s*(.+?)` ~ mkup.en_a_c))) { - writeln(m.captures[1]); - writeln(m.hit); - } - } - auto t = tuple( - obj_txt_out, - ftn[1], - ftn[2], - urls, - ); - return t; - } - auto init() - in { } - body { - auto t = object_notes_and_links_(""); - return t; - } - invariant() { - } - auto munge_heading(Ot)(Ot obj_txt_in, bool reset_note_numbers=false) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=(obj_txt_in) - .replaceFirst(rgx.heading, "") - .replaceFirst(rgx.obj_cite_number_off_all, "") - .strip; - auto t = object_notes_and_links_(obj_txt["munge"], reset_note_numbers); - debug(munge) { - writeln(__LINE__); - writeln(obj_txt_in); - writeln(__LINE__); - writeln(obj_txt["munge"].to!string); - } - return t; - } - invariant() { - } - auto munge_para(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=(obj_txt_in) - .replaceFirst(rgx.para_attribs, "") - .replaceFirst(rgx.obj_cite_number_off_all, ""); - auto t = object_notes_and_links_(obj_txt["munge"]); - debug(munge) { - writeln(__LINE__); - writeln(obj_txt_in); - writeln(__LINE__); - writeln(obj_txt["munge"].to!string); - } - return t; - } - string munge_quote(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - auto munge_group(string obj_txt_in) - in { } - body { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } - auto munge_block(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } - auto munge_verse(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } - string munge_code(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt_in = (obj_txt_in).replaceAll(rgx.space, mkup.nbsp); - obj_txt["munge"] = obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string munge_table(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - string munge_comment(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } - } - struct ObjInlineMarkup { - auto rgx = Rgx(); - auto munge = ObjInlineMarkupMunge(); - string[string] obj_txt; - auto obj_inline_markup_and_anchor_tags_and_misc(O,K,Ma)( - O obj_, - K obj_key_, - Ma dochead_make_aa - ) - in { - debug(asserts) { - static assert(is(typeof(obj_) == string[string])); - static assert(is(typeof(obj_key_) == string)); - static assert(is(typeof(dochead_make_aa) == string[string][string])); - } - } - body { - obj_txt["munge"] = obj_[obj_key_].dup; - obj_txt["munge"] = (obj_["is"].match(ctRegex!(`verse|code`))) - ? obj_txt["munge"] - : strip(obj_txt["munge"]); - static __gshared string[] anchor_tags_ = []; - auto x = munge.init; - bool[string] obj_notes_and_links; - obj_notes_and_links["notes_reg"] = false; - obj_notes_and_links["notes_star"] = false; - obj_notes_and_links["links"] = false; - switch (obj_["is"]) { - case "heading": - static __gshared string anchor_tag = ""; - 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)) { - anchor_tag = m.captures[1]; - anchor_tags_ ~= anchor_tag; - } else if (obj_["lev"] == "1") { - writeln("heading anchor tag missing: ", obj_txt["munge"]); - } - x =munge.munge_heading(obj_txt["munge"], reset_note_numbers); - reset_note_numbers=false; - goto default; - case "para": - x = munge.munge_para(obj_txt["munge"]); - goto default; - case "group": - x = munge.munge_group(obj_txt["munge"]); - goto default; - case "block": - x = munge.munge_block(obj_txt["munge"]); - goto default; - case "verse": - x = munge.munge_verse(obj_txt["munge"]); - goto default; - case "code": - obj_txt["munge"] = munge.munge_code(obj_txt["munge"]); - break; - case "table": - obj_txt["munge"] = munge.munge_table(obj_txt["munge"]); - break; - case "quote": - obj_txt["munge"] = munge.munge_quote(obj_txt["munge"]); - break; - case "comment": - obj_txt["munge"] = munge.munge_comment(obj_txt["munge"]); - break; - case "doc_end_reset": - munge.initialize_note_numbers(); - break; - default: - /+ para, heading, group, block, verse +/ - obj_txt["munge"] = x[0]; - obj_notes_and_links["notes_reg"] = x[1]; - obj_notes_and_links["notes_star"] = x[2]; - obj_notes_and_links["links"] = x[3]; - break; - } - auto t = tuple( - obj_txt["munge"], - anchor_tags_, - obj_notes_and_links["notes_reg"], - obj_notes_and_links["notes_star"], - obj_notes_and_links["links"], - ); - anchor_tags_=[]; - return t; - } - invariant() { - } - auto _clean_heading_toc_(Toc)( - Toc heading_toc_, - ) { - debug(asserts) { - static assert(is(typeof(heading_toc_) == char[])); - } - auto m = (cast(char[]) heading_toc_).matchFirst(rgx.heading); - heading_toc_ = (m.post).replaceAll( - rgx.inline_notes_curly_gen, - ""); - return heading_toc_; - }; - auto table_of_contents_gather_headings(O,Ma,Ts,Ta,X,Toc)( - O obj_, - Ma dochead_make_aa, - Ts segment_anchor_tag_that_object_belongs_to, - Ta _anchor_tag, - return ref X lev4_subtoc, - Toc the_table_of_contents_section, - ) - in { - debug(asserts) { - static assert(is(typeof(obj_) == string[string])); - static assert(is(typeof(dochead_make_aa) == string[string][string])); - static assert(is(typeof(segment_anchor_tag_that_object_belongs_to) == string)); - static assert(is(typeof(_anchor_tag) == string)); - static assert(is(typeof(lev4_subtoc) == string[][string])); - static assert(is(typeof(the_table_of_contents_section) == ObjGenericComposite[][string])); - } - } - body { - ObjGenericComposite comp_obj_toc; - mixin InternalMarkup; - auto mkup = InlineMarkup(); - char[] heading_toc_ = (obj_["substantive"].dup.strip.to!(char[])).replaceAll(rgx.inline_notes_al, ""); - heading_toc_ = _clean_heading_toc_(heading_toc_); - auto attrib=""; - string toc_txt_, subtoc_txt_; - int[string] indent; - if (obj_["lev_markup_number"].to!int > 0) { - indent=[ - "hang_position" : obj_["lev_markup_number"].to!int, - "base_position" : obj_["lev_markup_number"].to!int, - ]; - toc_txt_ = format( - "{ %s }#%s", - heading_toc_, - _anchor_tag, - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.use = "frontmatter"; - comp_obj_toc.is_of = "para"; - comp_obj_toc.is_a = "toc"; - comp_obj_toc.ocn = 0; - comp_obj_toc.obj_cite_number = ""; - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.bullet = false; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } else { - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.use = "frontmatter"; - comp_obj_toc.is_of = "para"; - comp_obj_toc.is_a = "toc"; - comp_obj_toc.ocn = 0; - comp_obj_toc.obj_cite_number = ""; - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.bullet = false; - comp_obj_toc.text = "Table of Contents"; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["scroll"] ~= comp_obj_toc; - } - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.use = "frontmatter"; - comp_obj_toc.is_of = "para"; - comp_obj_toc.is_a = "toc"; - comp_obj_toc.ocn = 0; - comp_obj_toc.obj_cite_number = ""; - comp_obj_toc.bullet = false; - comp_obj_toc.inline_links = true; - switch (obj_["lev_markup_number"].to!int) { - case 0: - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - toc_txt_ = "{ Table of Contents }" ~ mkup.mark_internal_site_lnk ~ "toc.fnSuffix"; - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - break; - case 1: .. case 3: - indent=[ - "hang_position" : obj_["lev_markup_number"].to!int, - "base_position" : obj_["lev_markup_number"].to!int, - ]; - toc_txt_ = format( - "%s", - heading_toc_, - ); - toc_txt_= munge.url_links(toc_txt_); - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - break; - case 4: - toc_txt_ = format( - "{ %s }%s%s%s", - heading_toc_, - mkup.mark_internal_site_lnk, - segment_anchor_tag_that_object_belongs_to, - ".fnSuffix", - ); - lev4_subtoc[segment_anchor_tag_that_object_belongs_to] = []; - toc_txt_= munge.url_links(toc_txt_); - indent=[ - "hang_position" : obj_["lev_markup_number"].to!int, - "base_position" : obj_["lev_markup_number"].to!int, - ]; - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - break; - case 5: .. case 7: - toc_txt_ = format( - "{ %s }%s%s%s#%s", - heading_toc_, - mkup.mark_internal_site_lnk, - segment_anchor_tag_that_object_belongs_to, - ".fnSuffix", - _anchor_tag, - ); - subtoc_txt_ = format( - "{ %s }#%s", - heading_toc_, - _anchor_tag, - ); - lev4_subtoc[segment_anchor_tag_that_object_belongs_to] - ~= obj_["lev_markup_number"] ~ "~ " ~ subtoc_txt_.to!string.strip; - toc_txt_= munge.url_links(toc_txt_); - indent=[ - "hang_position" : obj_["lev_markup_number"].to!int, - "base_position" : obj_["lev_markup_number"].to!int, - ]; - comp_obj_toc.indent_hang = indent["hang_position"]; - comp_obj_toc.indent_base = indent["base_position"]; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.inline_links = true; - the_table_of_contents_section["seg"] ~= comp_obj_toc; - break; - default: - break; - } - return the_table_of_contents_section; - } - invariant() { - } - private: - static string _configured_auto_heading_numbering_and_segment_anchor_tags(M,O,Ma)( - M munge_, - O obj_, - Ma dochead_make_aa - ) { - debug(asserts) { - static assert(is(typeof(munge_) == string)); - static assert(is(typeof(obj_) == string[string])); - static assert(is(typeof(dochead_make_aa) == string[string][string])); - } - if (dochead_make_aa["make"]["num_top"].length > 0) { - static __gshared int heading_num_top_level=9; - static __gshared int heading_num_depth=2; - static __gshared int heading_num_0 = 0; - static __gshared int heading_num_1 = 0; - static __gshared int heading_num_2 = 0; - static __gshared int heading_num_3 = 0; - static __gshared string heading_number_auto_composite = ""; - if (heading_num_top_level==9) { - if (dochead_make_aa["make"]["num_depth"].length > 0) { - heading_num_depth = dochead_make_aa["make"]["num_depth"].to!uint; - } - switch (dochead_make_aa["make"]["num_top"]) { - case "A": - break; - case "B": - heading_num_top_level=1; - break; - case "C": - heading_num_top_level=2; - break; - case "D": - heading_num_top_level=3; - break; - case "1": - heading_num_top_level=4; - break; - case "2": - heading_num_top_level=5; - break; - case "3": - heading_num_top_level=6; - break; - case "4": - heading_num_top_level=7; - break; - default: - break; - } - } - /+ num_depth minimum 0 (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ - if ( - heading_num_top_level - > obj_["lev_markup_number"].to!uint - ) { - heading_num_0 = 0; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if ( - heading_num_top_level - == obj_["lev_markup_number"].to!uint - ) { - heading_num_0 ++; - heading_num_1 = 0; - heading_num_2 = 0; - heading_num_3 = 0; - } else if ( - heading_num_top_level - == (obj_["lev_markup_number"].to!uint - 1) - ) { - heading_num_1 ++; - heading_num_2 = 0; - heading_num_3 = 0; - } else if ( - heading_num_top_level - == (obj_["lev_markup_number"].to!uint - 2) - ) { - heading_num_2 ++; - heading_num_3 = 0; - } else if ( - heading_num_top_level - == (obj_["lev_markup_number"].to!uint - 3) - ) { - heading_num_3 ++; - } - if (heading_num_3 > 0) { - heading_number_auto_composite = - (heading_num_depth == 3) - ? ( heading_num_0.to!string ~ "." - ~ heading_num_1.to!string ~ "." - ~ heading_num_2.to!string ~ "." - ~ heading_num_3.to!string - ) - : ""; - } else if (heading_num_2 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 2) - && (heading_num_depth <= 3)) - ? ( heading_num_0.to!string ~ "." - ~ heading_num_1.to!string ~ "." - ~ heading_num_2.to!string - ) - : ""; - } else if (heading_num_1 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 1) - && (heading_num_depth <= 3)) - ? ( heading_num_0.to!string ~ "." - ~ heading_num_1.to!string - ) - : ""; - } else if (heading_num_0 > 0) { - heading_number_auto_composite = - ((heading_num_depth >= 0) - && (heading_num_depth <= 3)) - ? (heading_num_0.to!string) - : ""; - } else { - heading_number_auto_composite = ""; - } - debug(heading_number_auto) { - writeln(heading_number_auto_composite); - } - if (!(munge_.match(rgx.heading_anchor_tag)) - && !empty(heading_number_auto_composite)) { - munge_=(munge_) - .replaceFirst(rgx.heading, - "$1~$2 " ~ heading_number_auto_composite ~ ". ") - .replaceFirst(rgx.heading_marker_missing_tag, - "$1~" ~ heading_number_auto_composite ~ " "); - } - } - return munge_; - } - static string _make_segment_anchor_tags_if_none_provided(M,Lv)(M munge_, Lv lev_) { - debug(asserts) { - static assert(is(typeof(munge_) == string)); - static assert(is(typeof(lev_) == string)); - } - if (!(munge_.match(rgx.heading_anchor_tag))) { - if (munge_.match(rgx.heading_identify_anchor_tag)) { - if (auto m = munge_.match(rgx.heading_extract_named_anchor_tag)) { - munge_=(munge_).replaceFirst( - rgx.heading_marker_missing_tag, - "$1~" ~ m.captures[1].toLower ~ "_" ~ m.captures[2] ~ " "); - } else if (auto m = munge_.match(rgx.heading_extract_unnamed_anchor_tag)) { - munge_=(munge_).replaceFirst( - rgx.heading_marker_missing_tag, - "$1~" ~ "s" ~ m.captures[1] ~ " "); - } - } else if (lev_ == "1") { // (if not successful) manufacture a unique anchor tag for lev=="1" - static __gshared int heading_num_lev1 = 0; - heading_num_lev1 ++; - munge_=(munge_).replaceFirst( - rgx.heading_marker_missing_tag, - "$1~" ~ "x" ~ heading_num_lev1.to!string ~ " "); - } - } - return munge_; - } - unittest { - string txt_lev="1"; - string txt_in, txt_out; - - txt_in = "1~copyright Copyright"; - txt_out ="1~copyright Copyright"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in = "1~ 6. Writing Copyright Licenses"; - txt_out ="1~s6 6. Writing Copyright Licenses"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ 1. Reinforcing trends"; - txt_out= "1~s1 1. Reinforcing trends"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ 11 SCIENCE AS A COMMONS"; - txt_out= "1~s11 11 SCIENCE AS A COMMONS"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ Chapter 1"; - txt_out="1~chapter_1 Chapter 1"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ Chapter 1."; - txt_out="1~chapter_1 Chapter 1."; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ Chapter 1: Done"; - txt_out="1~chapter_1 Chapter 1: Done"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; - txt_out= "1~chapter_11 Chapter 11 - The Battle Over the Institutional Ecology of the Digital Environment"; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ CHAPTER I."; - txt_out="1~x1 CHAPTER I."; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - - txt_in= "1~ CHAPTER II."; - txt_out="1~x2 CHAPTER II."; - assert(_make_segment_anchor_tags_if_none_provided(txt_in, txt_lev) == txt_out); - } - } - /+ +/ - struct ObjAttributes { - string[string] _obj_attrib; - string obj_attributes(Oi,OR,OH)( - Oi obj_is_, - OR obj_raw, - OH _comp_obj_heading, - ) - in { - debug(asserts) { - static assert(is(typeof(obj_is_) == string)); - static assert(is(typeof(obj_raw) == string)); - static assert(is(typeof(_comp_obj_heading) == ObjGenericComposite)); - } - } - body { - scope(exit) { - destroy(obj_is_); - destroy(obj_raw); - destroy(_comp_obj_heading); - } - _obj_attrib["json"] ="{"; - switch (obj_is_) { - case "heading": - _obj_attrib["json"] ~= _heading(obj_raw); - break; - case "para": - _obj_attrib["json"] ~= _para_and_blocks(obj_raw) - ~ _para(obj_raw); - break; - case "code": - _obj_attrib["json"] ~= _code(obj_raw); - break; - case "group": - _obj_attrib["json"] ~= _para_and_blocks(obj_raw) - ~ _group(obj_raw); - break; - case "block": - _obj_attrib["json"] ~= _para_and_blocks(obj_raw) - ~ _block(obj_raw); - break; - case "verse": - _obj_attrib["json"] ~= _verse(obj_raw); - break; - case "quote": - _obj_attrib["json"] ~= _quote(obj_raw); - break; - case "table": - _obj_attrib["json"] ~= _table(obj_raw); - break; - case "comment": - _obj_attrib["json"] ~= _comment(obj_raw); - break; - default: - _obj_attrib["json"] ~= _para(obj_raw); - break; - } - _obj_attrib["json"] ~=" }"; - _obj_attrib["json"]=_set_additional_values_parse_as_json(_obj_attrib["json"], obj_is_, _comp_obj_heading); - debug(structattrib) { - if (oa_j["is"].str() == "heading") { - writeln(_obj_attrib["json"]); - writeln( - "is: ", oa_j["is"].str(), - "; obj_cite_number: ", oa_j["obj_cite_number"].integer() - ); - } - } - return _obj_attrib["json"]; - } - invariant() { - } - private: - string _obj_attributes; - string _para_and_blocks(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - if (obj_txt_in.matchFirst(rgx.para_bullet)) { - _obj_attributes =" \"bullet\": \"true\"," - ~ " \"indent_hang\": 0," - ~ " \"indent_base\": 0,"; - } else if (auto m = obj_txt_in.matchFirst(rgx.para_bullet_indent)) { - _obj_attributes =" \"bullet\": \"true\"," - ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," - ~ " \"indent_base\": " ~ m.captures[1].to!string ~ ","; - } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent_hang)) { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," - ~ " \"indent_base\": " ~ m.captures[2].to!string ~ ","; - } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent)) { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m.captures[1].to!string ~ "," - ~ " \"indent_base\": " ~ m.captures[1].to!string ~ ","; - } else { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": 0," - ~ " \"indent_base\": 0,"; - } - return _obj_attributes; - } - string _heading(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"heading\""; - return _obj_attributes; - } - invariant() { - } - string _para(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"para\""; - return _obj_attributes; - } - invariant() { - } - string _quote(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"quote\""; - return _obj_attributes; - } - invariant() { - } - string _group(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"group\""; - return _obj_attributes; - } - invariant() { - } - string _block(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"block\""; - return _obj_attributes; - } - invariant() { - } - string _verse(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"verse\""; - return _obj_attributes; - } - invariant() { - } - string _code(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"code\""; - return _obj_attributes; - } - invariant() { - } - string _table(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"table\""; - return _obj_attributes; - } - invariant() { - } - string _comment(Ot)(Ot obj_txt_in) - in { - debug(asserts) { - static assert(is(typeof(obj_txt_in) == string)); - } - } - body { - _obj_attributes = " \"use\": \"comment\"," - ~ " \"of\": \"comment\"," - ~ " \"is\": \"comment\""; - return _obj_attributes; - } - invariant() { - } - string _set_additional_values_parse_as_json(OA,Oi,OH)( - OA _obj_attrib, - Oi obj_is_, - OH _comp_obj_heading, - ) { - debug(asserts) { - static assert(is(typeof(_obj_attrib) == string)); - static assert(is(typeof(obj_is_) == string)); - static assert(is(typeof(_comp_obj_heading) == ObjGenericComposite)); - } - JSONValue oa_j = parseJSON(_obj_attrib); - assert( - (oa_j.type == JSON_TYPE.OBJECT) - ); - if (obj_is_ == "heading") { - oa_j.object["obj_cite_number"] = _comp_obj_heading.ocn; - oa_j.object["lev_markup_number"] = _comp_obj_heading.heading_lev_markup; - oa_j.object["lev_collapsed_number"] = _comp_obj_heading.heading_lev_collapsed; - oa_j.object["heading_ptr"] = - _comp_obj_heading.ptr_heading; - oa_j.object["doc_object_ptr"] = - _comp_obj_heading.ptr_doc_object; - } - oa_j.object["parent_obj_cite_number"] = _comp_obj_heading.parent_ocn; - oa_j.object["parent_lev_markup_number"] = _comp_obj_heading.parent_lev_markup; - _obj_attrib = oa_j.toString(); - return _obj_attrib; - } - } - /+ +/ - struct BookIndexNuggetHash { - string main_term, sub_term, sub_term_bits; - int obj_cite_number_offset, obj_cite_number_endpoint; - string[] obj_cite_numbers; - string[][string][string] bi; - string[][string][string] hash_nugget; - string[] bi_main_terms_split_arr; - string[][string][string] bookindex_nugget_hash(BI,N,S)( - BI bookindex_section, - N obj_cite_number, - S segment_anchor_tag, - ) - in { - debug(asserts) { - static assert(is(typeof(bookindex_section) == string)); - static assert(is(typeof(obj_cite_number) == int)); - } - debug(bookindexraw) { - if (!bookindex_section.empty) { - writeln( - "* [bookindex] ", - "[", obj_cite_number.to!string, ": ", segment_anchor_tag, "] ", bookindex_section - ); - } - } - } - body { - auto rgx = Rgx(); - if (!bookindex_section.empty) { - auto bi_main_terms_split_arr = - bookindex_section.split(rgx.bi_main_terms_split); - foreach (bi_main_terms_content; bi_main_terms_split_arr) { - auto bi_main_term_and_rest = - bi_main_terms_content.split(rgx.bi_main_term_plus_rest_split); - if (auto m = bi_main_term_and_rest[0].match( - rgx.bi_term_and_obj_cite_numbers_match) - ) { - main_term = m.captures[1].strip; - obj_cite_number_offset = m.captures[2].to!int; - obj_cite_number_endpoint=(obj_cite_number + obj_cite_number_offset); - obj_cite_numbers ~= (obj_cite_number.to!string ~ "-" ~ to!string(obj_cite_number_endpoint) - ~ ":" ~ segment_anchor_tag); - } else { - main_term = bi_main_term_and_rest[0].strip; - obj_cite_numbers ~= obj_cite_number.to!string - ~ ":" ~ segment_anchor_tag; - } - bi[main_term]["_a"] ~= obj_cite_numbers; - obj_cite_numbers=null; - if (bi_main_term_and_rest.length > 1) { - auto bi_sub_terms_split_arr = - bi_main_term_and_rest[1].split( - rgx.bi_sub_terms_plus_obj_cite_number_offset_split - ); - foreach (sub_terms_bits; bi_sub_terms_split_arr) { - if (auto m = sub_terms_bits.match(rgx.bi_term_and_obj_cite_numbers_match)) { - sub_term = m.captures[1].strip; - obj_cite_number_offset = m.captures[2].to!int; - obj_cite_number_endpoint=(obj_cite_number + obj_cite_number_offset); - obj_cite_numbers ~= (obj_cite_number.to!string ~ " - " ~ to!string(obj_cite_number_endpoint) - ~ ":" ~ segment_anchor_tag); - } else { - sub_term = sub_terms_bits.strip; - obj_cite_numbers ~= to!string(obj_cite_number) - ~ ":" ~ segment_anchor_tag; - } - if (!empty(sub_term)) { - bi[main_term][sub_term] ~= obj_cite_numbers; - } - obj_cite_numbers=null; - } - } - } - } - hash_nugget = bi; - return hash_nugget; - } - invariant() { - } - } - struct BookIndexReportIndent { - int mkn, skn; - auto bookindex_report_indented(BI)( - BI bookindex_unordered_hashes - ) { - debug(asserts) { - static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); - } - auto mainkeys= - bookindex_unordered_hashes.byKey.array.sort().release; - foreach (mainkey; mainkeys) { - debug(bookindex1) { - writeln(mainkey); - } - auto subkeys= - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - debug(bookindex1) { - writeln(" ", subkey); - writeln(" ", to!string( - bookindex_unordered_hashes[mainkey][subkey] - )); - } - ++skn; - } - ++mkn; - } - } - } - struct BookIndexReportSection { - int mkn, skn; - auto rgx = Rgx(); - auto munge = ObjInlineMarkupMunge(); - auto bookindex_write_section(BI)( - BI bookindex_unordered_hashes - ) { - debug(asserts) { - static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); - } - auto mainkeys=bookindex_unordered_hashes.byKey.array.sort().release; - foreach (mainkey; mainkeys) { - write("_0_1 !{", mainkey, "}! "); - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - auto go = (ref_).replaceAll(rgx.book_index_go, "$1"); - write(" {", ref_, "}#", go, ", "); - } - writeln(" \\\\"); - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys= - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - write(" ", subkey, ", "); - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - auto go = (ref_).replaceAll(rgx.book_index_go, "$1"); - write(" {", ref_, "}#", go, ", "); - } - writeln(" \\\\"); - ++skn; - } - ++mkn; - } - } - auto bookindex_build_abstraction_section(BI,N,B)( - BI bookindex_unordered_hashes, - N obj_cite_number, - B opt_action_bool, - ) { - debug(asserts) { - static assert(is(typeof(bookindex_unordered_hashes) == string[][string][string])); - static assert(is(typeof(obj_cite_number) == int)); - static assert(is(typeof(opt_action_bool) == bool[string])); - } - mixin SiSUnode; - mixin InternalMarkup; - auto mkup = InlineMarkup(); - string type_is; - string lev; - int heading_lev_markup, heading_lev_collapsed; - string attrib; - int[string] indent; - auto mainkeys = - bookindex_unordered_hashes.byKey.array.sort().release; - ObjGenericComposite[][string] bookindex_section; - ObjGenericComposite comp_obj_heading_, comp_obj_para; - auto node_para_int_ = node_metadata_para_int; - auto node_para_str_ = node_metadata_para_str; - if ((mainkeys.length > 0) - && (opt_action_bool["backmatter"] - && opt_action_bool["section_bookindex"])) { - string bi_tmp_seg, bi_tmp_scroll; - string[] bi_tmp_tags; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Book Index"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "_part_book_index"; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading.inline_links = true; - bookindex_section["scroll"] ~= comp_obj_heading_; - bookindex_section["seg"] ~= comp_obj_heading_; - ++obj_cite_number; - ++mkn; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Index"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "bookindex"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 2; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading.inline_links = false; - comp_obj_heading_.anchor_tags = ["bookindex"]; - bookindex_section["scroll"] ~= comp_obj_heading_; - bookindex_section["seg"] ~= comp_obj_heading_; - ++obj_cite_number; - ++mkn; - import std.array : appender; - auto buffer = appender!(char[])(); - string[dchar] transTable = [' ' : "_"]; - foreach (mainkey; mainkeys) { - bi_tmp_tags = [""]; - bi_tmp_scroll = "!{" ~ mainkey ~ "}! "; - buffer.clear(); - bi_tmp_tags ~= translate(mainkey, transTable); - bi_tmp_seg = "!{" ~ mainkey ~ "}! "; - auto bkidx_lnk_seg(string locs) { - string markup = ""; - if (auto m = locs.matchFirst(rgx.book_index_go_seg)) { - markup = - munge.url_links("{ " ~ m["link"] ~ " }" - ~ mkup.mark_internal_site_lnk ~ m["seg"] ~ ".fnSuffix" - ~ "#" ~ m["ocn"] ~ ", "); - } else { - writeln(__LINE__, ": ", locs); - } - return markup; - } - auto bkidx_lnk_scroll(string locs) { - string markup = ""; - if (auto m = locs.matchFirst(rgx.book_index_go)) { - markup = - munge.url_links("{ " ~ m["link"] ~ " }" - ~ mkup.mark_internal_site_lnk - ~ "#" ~ m["ocn"] ~ ", "); - } else { - writeln(__LINE__, ": ", locs); - } - return markup; - } - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - bi_tmp_scroll ~= bkidx_lnk_scroll(ref_); - bi_tmp_seg ~= bkidx_lnk_seg(ref_); - } - bi_tmp_scroll ~= " \\\\\n "; - bi_tmp_seg ~= " \\\\\n "; - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys = - bookindex_unordered_hashes[mainkey].byKey.array.sort().release; - foreach (subkey; subkeys) { - bi_tmp_scroll ~= subkey ~ ", "; - buffer.clear(); - bi_tmp_tags ~= translate(subkey, transTable); - bi_tmp_seg ~= subkey ~ ", "; - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - bi_tmp_scroll ~= bkidx_lnk_scroll(ref_); - bi_tmp_seg ~= bkidx_lnk_seg(ref_); - } - bi_tmp_scroll ~= " \\\\\n "; - bi_tmp_seg ~= " \\\\\n "; - ++skn; - } - bi_tmp_scroll = (bi_tmp_scroll).replaceFirst(rgx.trailing_linebreak, ""); - bi_tmp_seg = (bi_tmp_seg).replaceFirst(rgx.trailing_linebreak, ""); - comp_obj_para = comp_obj_para.init; - comp_obj_para.use = "backmatter"; - comp_obj_para.is_of = "para"; - comp_obj_para.is_a = "bookindex"; - comp_obj_para.text = bi_tmp_scroll.to!string.strip; - comp_obj_para.ocn = obj_cite_number; - comp_obj_para.obj_cite_number = (obj_cite_number==0) ? "" : to!string(obj_cite_number); - comp_obj_para.anchor_tags = bi_tmp_tags; - comp_obj_para.indent_hang = 0; - comp_obj_para.indent_base = 1; - comp_obj_para.bullet = false; - comp_obj_para.inline_links = true; - bookindex_section["scroll"] ~= comp_obj_para; - comp_obj_para.text = bi_tmp_seg.to!string.strip; - bookindex_section["seg"] ~= comp_obj_para; - ++obj_cite_number; - ++mkn; - } - } else { // no book index, (figure out what to do here) - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.text = "(skip) there is no Book Index"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - bookindex_section["scroll"] ~= comp_obj_heading_; - bookindex_section["seg"] ~= comp_obj_heading_; - } - auto t = tuple(bookindex_section, obj_cite_number); - return t; - } - } - /+ +/ - struct NotesSection { - string[string] object_notes; - int previous_count; - int mkn; - auto rgx = Rgx(); - private auto gather_notes_for_endnote_section( - ObjGenericComposite[] contents_am, - string segment_anchor_tag_that_object_belongs_to, - int cntr, - ) - in { - assert((contents_am[cntr].is_a == "para") - || (contents_am[cntr].is_a == "heading") - || (contents_am[cntr].is_a == "quote") - || (contents_am[cntr].is_a == "group") - || (contents_am[cntr].is_a == "block") - || (contents_am[cntr].is_a == "verse")); - assert(cntr >= previous_count); - previous_count=cntr; - assert( - (contents_am[cntr].text).match( - rgx.inline_notes_delimiter_al_regular_number_note) - ); - } - body { - mixin InternalMarkup; - auto mkup = InlineMarkup(); - auto munge = ObjInlineMarkupMunge(); - foreach( - m; - (contents_am[cntr].text).matchAll( - rgx.inline_notes_delimiter_al_regular_number_note - ) - ) { - debug(endnotes_build) { - writeln( - "{^{", m.captures[1], ".}^}" - ~ mkup.mark_internal_site_lnk, - segment_anchor_tag_that_object_belongs_to, - ".fnSuffix#noteref_\n ", m.captures[1], " ", - m.captures[2]); // sometimes need segment name (segmented html & epub) - } - // TODO NEXT you need anchor for segments at this point -> - object_notes["anchor"] ~= "note_" ~ m.captures[1] ~ "』"; - object_notes["notes"] ~= (segment_anchor_tag_that_object_belongs_to.empty) - ? (munge.url_links( - "{^{" ~ m.captures[1] ~ ".}^}#noteref_" - ~ m.captures[1]) ~ " " - ~ m.captures[2] ~ "』" - ) - : (munge.url_links( - "{^{" ~ m.captures[1] ~ ".}^}" - ~ mkup.mark_internal_site_lnk - ~ segment_anchor_tag_that_object_belongs_to - ~ ".fnSuffix#noteref_" - ~ m.captures[1]) ~ " " - ~ m.captures[2] ~ "』" - ); - } - return object_notes; - } - private auto gathered_notes() - in { - } - body { - string[][string] endnotes_; - if (object_notes.length > 1) { - endnotes_["notes"] = (object_notes["notes"].split(rgx.break_string))[0..$-1]; - endnotes_["anchor"] = (object_notes["anchor"].split(rgx.break_string))[0..$-1]; - } else { - endnotes_["notes"] = []; - endnotes_["anchor"] = []; - } - return endnotes_; - } - private auto endnote_objects( - int obj_cite_number, - bool[string] opt_action_bool, - ) - in { - } - body { - mixin SiSUnode; - ObjGenericComposite[] the_endnotes_section; - auto endnotes_ = gathered_notes(); - string type_is; - string lev, lev_markup_number, lev_collapsed_number; - string attrib; - int[string] indent; - ObjGenericComposite comp_obj_heading_; - if ((endnotes_["notes"].length > 0) - && (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"])) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "_part_endnotes"; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_endnotes_section ~= comp_obj_heading_; - ++obj_cite_number; - ++mkn; - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "backmatter"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.segment_anchor_tag = "endnotes"; - comp_obj_heading_.marked_up_level = "1"; - comp_obj_heading_.heading_lev_markup = 4; - comp_obj_heading_.heading_lev_collapsed = 2; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - comp_obj_heading_.anchor_tags = ["endnotes"]; - the_endnotes_section ~= comp_obj_heading_; - ++obj_cite_number; - ++mkn; - } else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.use = "empty"; - comp_obj_heading_.is_of = "para"; - comp_obj_heading_.is_a = "heading"; - comp_obj_heading_.text = "(skip) there are no Endnotes"; - comp_obj_heading_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_heading_.marked_up_level = "B"; - comp_obj_heading_.heading_lev_markup = 1; - comp_obj_heading_.heading_lev_collapsed = 1; - comp_obj_heading_.parent_ocn = 1; - comp_obj_heading_.parent_lev_markup = 0; - the_endnotes_section ~= comp_obj_heading_; - } - if (opt_action_bool["backmatter"] && opt_action_bool["section_endnotes"]) { - ObjGenericComposite comp_obj_endnote_; - comp_obj_endnote_ = comp_obj_endnote_.init; - comp_obj_endnote_.use = "backmatter"; - comp_obj_endnote_.is_of = "para"; - comp_obj_endnote_.is_a = "endnote"; - comp_obj_endnote_.ocn = 0; - comp_obj_heading_.obj_cite_number = ""; - comp_obj_endnote_.indent_hang = 0; - comp_obj_endnote_.indent_base = 0; - comp_obj_endnote_.bullet = false; - foreach (i, endnote; endnotes_["notes"]) { - auto m = endnote.matchFirst(rgx.note_ref); - string notenumber = m.captures[1].to!string; - string anchor_tag = "note_" ~ notenumber; - comp_obj_endnote_.anchor_tags = [ endnotes_["anchor"][i] ]; - comp_obj_endnote_.inline_links = true; - comp_obj_endnote_.text = endnote.strip; - the_endnotes_section ~= comp_obj_endnote_; - } - } - auto t = tuple(the_endnotes_section, obj_cite_number); - return t; - } - } - /+ +/ - struct Bibliography { - public JSONValue[] _bibliography_(Bi,BJ)( - return ref Bi biblio_unsorted_incomplete, - return ref BJ bib_arr_json - ) - in { - debug(asserts) { - static assert(is(typeof(biblio_unsorted_incomplete) == string[])); - static assert(is(typeof(bib_arr_json) == JSONValue[])); - } - } - body { - JSONValue[] biblio_unsorted = - _biblio_unsorted_complete_(biblio_unsorted_incomplete, bib_arr_json); - biblio_arr_json = []; - biblio_unsorted_incomplete = []; - JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); - biblio_debug(biblio_sorted__); - debug(biblio0) { - writeln("---"); - writeln("unsorted incomplete: ", biblio_unsorted_incomplete.length); - writeln("json: ", bib_arr_json.length); - writeln("unsorted: ", biblio_unsorted.length); - writeln("sorted: ", biblio_sorted__.length); - int cntr; - int[7] x; - while (cntr < x.length) { - writeln(cntr, ": ", biblio_sorted__[cntr]["fulltitle"]); - cntr++; - } - } - return biblio_sorted__; - } - final private JSONValue[] _biblio_unsorted_complete_(Bi,BJ)( - Bi biblio_unordered, - return ref BJ bib_arr_json - ) { - debug(asserts) { - static assert(is(typeof(biblio_unordered) == string[])); - 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 - +/ - JSONValue j = parseJSON(bibent); - if (!empty(j["fulltitle"].str)) { - if (!empty(j["author_raw"].str)) { - j["deemed_author"]=j["author_arr"][0]; - } else if (!empty(j["editor_raw"].str)) { - j["deemed_author"]=j["editor_arr"][0]; - } - j["sortby_deemed_author_year_title"] = ( - j["deemed_author"].str ~ - "; " ~ - j["year"].str ~ - "; " ~ - j["fulltitle"].str - ); - } - bib_arr_json ~= j; - } - JSONValue[] biblio_unsorted_array_of_json_objects = - bib_arr_json.dup; - destroy(bib_arr_json); - return biblio_unsorted_array_of_json_objects; - } - final private JSONValue[] biblio_sort(BJ)(BJ biblio_unordered) { - debug(asserts) { - static assert(is(typeof(biblio_unordered) == JSONValue[])); - } - JSONValue[] biblio_sorted_; - biblio_sorted_ = - sort!((a, b){ - return ((a["sortby_deemed_author_year_title"].str) < (b["sortby_deemed_author_year_title"].str)); - })(biblio_unordered).array; - debug(bibliosorted) { - foreach (j; biblio_sorted_) { - if (!empty(j["fulltitle"].str)) { - writeln(j["sortby_deemed_author_year_title"]); - } - } - } - return biblio_sorted_; - } - void biblio_debug(BJ)(BJ biblio_sorted) { - debug(asserts) { - static assert(is(typeof(biblio_sorted) == JSONValue[])); - } - debug(biblio0) { - foreach (j; biblio_sorted) { - if (!empty(j["fulltitle"].str)) { - writeln(j["sortby_deemed_author_year_title"]); - } - } - } - } - } - /+ +/ - struct NodeStructureMetadata { - int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; - int obj_cite_number; - int[string] p_; // p_ parent_ - auto rgx = Rgx(); - ObjGenericComposite node_location_emitter(Lv,Ta,N,C,P,I)( - Lv lev_markup_number, - Ta segment_anchor_tag, - N obj_cite_number_, - C cntr_, - P ptr_, - I is_ - ) - in { - debug(asserts) { - static assert(is(typeof(lev_markup_number) == string)); - static assert(is(typeof(segment_anchor_tag) == string)); - static assert(is(typeof(obj_cite_number_) == int)); - static assert(is(typeof(cntr_) == int)); - static assert(is(typeof(ptr_) == int)); - static assert(is(typeof(is_) == string)); - } - assert(is_ != "heading"); - assert(obj_cite_number_.to!int >= 0); - } - body { - assert(is_ != "heading"); // should not be necessary - assert(obj_cite_number_.to!int >= 0); // should not be necessary - int obj_cite_number = obj_cite_number_.to!int; - if (lv7 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_4; - p_["obj_cite_number"] = lv7; - } else if (lv6 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_3; - p_["obj_cite_number"] = lv6; - } else if (lv5 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_2; - p_["obj_cite_number"] = lv5; - } else { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_1; - p_["obj_cite_number"] = lv4; - } - ObjGenericComposite comp_obj_location; - comp_obj_location = comp_obj_location.init; - comp_obj_location.is_a = is_; - comp_obj_location.ocn = obj_cite_number_; - comp_obj_location.segment_anchor_tag = segment_anchor_tag.to!string; - comp_obj_location.parent_ocn = p_["obj_cite_number"]; - comp_obj_location.parent_lev_markup = p_["lev_markup_number"]; - debug(node) { - if (lev_markup_number.match(rgx.levels_numbered_headings)) { - writeln("x ", _node.to!string); - } else { - writeln("- ", _node.to!string); - } - } - assert(comp_obj_location.parent_lev_markup >= 4); - assert(comp_obj_location.parent_lev_markup <= 7); - assert(comp_obj_location.parent_ocn >= 0); - return comp_obj_location; - } - invariant() { - } - ObjGenericComposite node_emitter_heading(T,L,Lm,Lc,Ta,N,C,P,LA,I,PSn,fNr,fNs,fL)( - T _text, - L lev, - Lm lev_markup_number, - Lc lev_collapsed_number, - Ta segment_anchor_tag, - N obj_cite_number_, - C cntr_, - P ptr_, - LA lv_ancestors, - I is_, - PSn html_segnames_ptr, - fNr flag_notes_reg, - fNs flag_notes_star, - fL flag_links, - ) - in { - debug(asserts) { - static assert(is(typeof(_text) == string)); - static assert(is(typeof(lev) == string)); - static assert(is(typeof(lev_markup_number) == string)); - static assert(is(typeof(lev_collapsed_number) == string)); - static assert(is(typeof(segment_anchor_tag) == string)); - static assert(is(typeof(obj_cite_number_) == int)); - static assert(is(typeof(cntr_) == int)); - static assert(is(typeof(ptr_) == int)); - static assert(is(typeof(lv_ancestors) == string[])); - static assert(is(typeof(is_) == string)); - static assert(is(typeof(html_segnames_ptr) == int)); - } - assert(is_ == "heading"); - assert(to!int(obj_cite_number_) >= 0); - assert( - lev_markup_number.match(rgx.levels_numbered), - ("not a valid heading level: " ~ lev_markup_number ~ " at " ~ obj_cite_number_.to!string) - ); - if (lev_markup_number.match(rgx.levels_numbered)) { - if (lev_markup_number.to!int == 0) { - assert(obj_cite_number_.to!int == 1); - } - } - } - body { - int obj_cite_number = obj_cite_number_.to!int; - switch (lev_markup_number.to!int) { - case 0: - lv = DocStructMarkupHeading.h_sect_A; - lv0 = obj_cite_number; - lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] = 0; - p_["obj_cite_number"] = 0; - break; - case 1: - lv = DocStructMarkupHeading.h_sect_B; - lv1 = obj_cite_number; - lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_A; - p_["obj_cite_number"] = lv0; - break; - case 2: - lv = DocStructMarkupHeading.h_sect_C; - lv2 = obj_cite_number; - lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_B; - p_["obj_cite_number"] = lv1; - break; - case 3: - lv = DocStructMarkupHeading.h_sect_D; - lv3=obj_cite_number; - lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_C; - p_["obj_cite_number"] = lv2; - break; - case 4: - lv = DocStructMarkupHeading.h_text_1; - lv4 = obj_cite_number; - lv5=0; lv6=0; lv7=0; - if (lv3 > State.off) { - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_D; - p_["obj_cite_number"] = lv3; - } else if (lv2 > State.off) { - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_C; - p_["obj_cite_number"] = lv2; - } else if (lv1 > State.off) { - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_B; - p_["obj_cite_number"] = lv1; - } else { - p_["lev_markup_number"] = - DocStructMarkupHeading.h_sect_A; - p_["obj_cite_number"] = lv0; - } - break; - case 5: - lv = DocStructMarkupHeading.h_text_2; - lv5 = obj_cite_number; - lv6=0; lv7=0; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_text_1; - p_["obj_cite_number"] = lv4; - break; - case 6: - lv = DocStructMarkupHeading.h_text_3; - lv6 = obj_cite_number; - lv7=0; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_text_2; - p_["obj_cite_number"] = lv5; - break; - case 7: - lv = DocStructMarkupHeading.h_text_4; - lv7 = obj_cite_number; - p_["lev_markup_number"] = - DocStructMarkupHeading.h_text_3; - p_["obj_cite_number"] = lv6; - break; - default: - break; - } - ObjGenericComposite _comp_obj_heading_; - _comp_obj_heading_ = _comp_obj_heading_.init; - _comp_obj_heading_.use = "body"; - _comp_obj_heading_.is_of = "para"; - _comp_obj_heading_.is_a = "heading"; - _comp_obj_heading_.text = _text.to!string.strip; - _comp_obj_heading_.ocn = obj_cite_number_; - _comp_obj_heading_.obj_cite_number = (obj_cite_number==0) ? "" : obj_cite_number.to!string; - _comp_obj_heading_.segment_anchor_tag = segment_anchor_tag.to!string; - _comp_obj_heading_.marked_up_level = lev; - _comp_obj_heading_.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); - _comp_obj_heading_.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); - _comp_obj_heading_.parent_ocn = p_["obj_cite_number"]; - _comp_obj_heading_.parent_lev_markup = p_["lev_markup_number"]; - _comp_obj_heading_.heading_ancestors_text = lv_ancestors; - _comp_obj_heading_.ptr_doc_object = cntr_; - _comp_obj_heading_.ptr_html_segnames = ((lev_markup_number == "4") ? html_segnames_ptr : 0); - _comp_obj_heading_.ptr_heading = ptr_; - _comp_obj_heading_.inline_notes_reg = flag_notes_reg; - _comp_obj_heading_.inline_notes_star = flag_notes_star; - _comp_obj_heading_.inline_links = flag_links; - debug(node) { - if (lev_markup_number.match(rgx.levels_numbered_headings)) { - writeln("* ", _node.to!string); - } - } - debug(nodeheading) { - if (lev_markup_number.match(rgx.levels_numbered_headings)) { - writeln("* ", _node.to!string); - } - } - assert(_comp_obj_heading_.parent_lev_markup <= 7); - assert(_comp_obj_heading_.parent_ocn >= 0); - if (lev_markup_number.match(rgx.levels_numbered_headings)) { - assert(_comp_obj_heading_.heading_lev_markup <= 7); - assert(_comp_obj_heading_.ocn >= 0); - if (_comp_obj_heading_.parent_lev_markup > 0) { - assert(_comp_obj_heading_.parent_lev_markup < _comp_obj_heading_.heading_lev_markup); - if (_comp_obj_heading_.ocn != 0) { - assert(_comp_obj_heading_.parent_ocn < _comp_obj_heading_.ocn); - } - } - if (_comp_obj_heading_.heading_lev_markup == 0) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_B); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_sect_C); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_1) { - assert(_comp_obj_heading_.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_2) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_1); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_3) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_2); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_4) { - assert(_comp_obj_heading_.parent_lev_markup == DocStructMarkupHeading.h_text_3); - } else if (_comp_obj_heading_.heading_lev_markup == DocStructMarkupHeading.h_text_5) { - } - } - return _comp_obj_heading_; - } - invariant() { - } - } - /+ abstraction functions emitters ↑ +/ - /+ ↓ abstraction functions assertions +/ - auto assertions_doc_structure(O,Lv)( - O an_object, - Lv lv - ) { - debug(asserts) { - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(lv) == int[string])); - } - if (lv["h3"] > State.off) { - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h2"] > State.off); - } else if (lv["h2"] > State.off) { - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h3"] == State.off); - } else if (lv["h1"] > State.off) { - assert(lv["h0"] > State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - } else if (lv["h0"] > State.off) { - assert(lv["h1"] == State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - } else { - assert(lv["h0"] == State.off); - assert(lv["h1"] == State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - } - if (lv["h7"] > State.off) { - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - assert(lv["h6"] > State.off); - } else if (lv["h6"] > State.off) { - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - assert(lv["h7"] == State.off); - } else if (lv["h5"] > State.off) { - assert(lv["h4"] > State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } else if (lv["h4"] > State.off) { - assert(lv["h5"] == State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } else { - assert(lv["h4"] == State.off); - assert(lv["h5"] == State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } - if (lv["h0"] == State.off) { - assert(lv["h1"] == State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - assert(lv["h4"] == State.off); - assert(lv["h5"] == State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } - if (lv["h1"] == State.off) { - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - } - if (lv["h2"] == State.off) { - assert(lv["h3"] == State.off); - } - if (lv["h3"] == State.off) { - } - if (lv["h4"] == State.off) { - assert(lv["h5"] == State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } - if (lv["h5"] == State.off) { - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } - if (lv["h6"] == State.off) { - assert(lv["h7"] == State.off); - } - if (lv["h7"] == State.off) { - } - switch ((an_object["lev"]).to!string) { - case "A": - if (lv["h0"] == State.off) { - assert(lv["h1"] == State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - assert(lv["h4"] == State.off); - assert(lv["h5"] == State.off); - assert(lv["h6"] == State.off); - assert(lv["h7"] == State.off); - } else { // (lv["h0"] > State.off) - assert(lv["h0"] == State.off,"error should not enter level A a second time"); - } - break; - case "B": - if (lv["h1"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h2"] == State.off); - assert(lv["h3"] == State.off); - } else { // (lv["h1"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - } - break; - case "C": - if (lv["h2"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h3"] == State.off); - } else { // (lv["h2"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h2"] > State.off); - } - break; - case "D": - if (lv["h3"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h2"] > State.off); - } else { // (lv["h3"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h1"] > State.off); - assert(lv["h2"] > State.off); - assert(lv["h3"] > State.off); - } - break; - case "1": - if (lv["h4"] == State.off) { - assert(lv["h0"] > State.off); - } else { // (lv["h4"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - } - break; - case "2": - if (lv["h5"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - } else { // (lv["h5"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - } - break; - case "3": - if (lv["h6"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - } else { // (lv["h6"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - assert(lv["h6"] > State.off); - } - break; - case "4": - if (lv["h7"] == State.off) { - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - assert(lv["h6"] > State.off); - } else { // (lv["h7"] > State.off) - assert(lv["h0"] > State.off); - assert(lv["h4"] > State.off); - assert(lv["h5"] > State.off); - assert(lv["h6"] > State.off); - assert(lv["h7"] > State.off); - } - break; - default: - break; - } - } - auto assertions_flag_types_block_status_none_or_closed(T)(T type) { - debug(asserts) { - static assert(is(typeof(type) == int[string])); - } - assert( - (type["code"] == TriState.off) - || (type["code"] == TriState.closing), - "code block status: off or closing"); - assert( - (type["poem"] == TriState.off) - || (type["poem"] == TriState.closing), - "poem status: off or closing"); - assert( - (type["table"] == TriState.off) - || (type["table"] == TriState.closing), - "table status: off or closing"); - assert( - (type["group"] == TriState.off) - || (type["group"] == TriState.closing), - "group block status: off or closing"); - assert( - (type["block"] == TriState.off) - || (type["block"] == TriState.closing), - "block status: off or closing"); - } - /+ abstraction functions assertions ↑ +/ -} /+ ← closed: template SiSUdocAbstraction +/ -template docSectKeysSeq() { - auto docSectKeysSeq(string[][string] document_section_keys_sequenced) { - struct doc_sect_keys_seq { - auto seg() { - return document_section_keys_sequenced["seg"]; - } - auto scroll() { - return document_section_keys_sequenced["scroll"]; - } - } - return doc_sect_keys_seq(); - } -} diff --git a/src/sdp/ao_conf_make_meta.d b/src/sdp/ao_conf_make_meta.d deleted file mode 100644 index 52cc98d..0000000 --- a/src/sdp/ao_conf_make_meta.d +++ /dev/null @@ -1,47 +0,0 @@ -/++ - extract native/orig header return associative array
- - the header is passed as text (lopped off top of a sisu markup file until the - required first heading ^A~), determine whether is a native header or sdlang one - with a regex check if whether it contains the "native header" required tag/field - @title: then process accordingly as a "native header" or "sdlang header" - converting the metadata and make instructions to a common json format used by - program internally. Moved to associative array. -+/ -module sdp.ao_conf_make_meta; -template SiSUheaderExtractHub() { - private import - std.exception, - std.regex, - std.stdio, - std.traits, - std.typecons, - std.utf, - std.conv : to; - private import sdlang; - private import - sdp.ao_rgx, - sdp.ao_conf_make_meta_native, - sdp.ao_conf_make_meta_sdlang; - mixin SiSUrgxInit; - mixin SiSUheaderExtractNative; - mixin SiSUheaderExtractSDLang; - auto rgx = Rgx(); - auto SiSUheaderExtractHub(Src, DocMake)( - Src header_src, - DocMake conf_doc_make_aa - ) { - debug(asserts){ - static assert(is(typeof(header_src) == char[])); - static assert(is(typeof(conf_doc_make_aa) == string[string][string])); - } - auto head_native = HeaderDocMetadataAndMakeNativeToAA(); - auto head_sdlang = HeaderExtractSDL(); - auto header_make_and_meta_tuple = (header_src.match(rgx.native_header_meta_title)) - ? (head_native.headerNativeToAA(header_src)) - : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa)); - static assert(!isTypeTuple!(header_make_and_meta_tuple)); - static assert(header_make_and_meta_tuple.length==2); - return header_make_and_meta_tuple; - } -} diff --git a/src/sdp/ao_conf_make_meta_native.d b/src/sdp/ao_conf_make_meta_native.d deleted file mode 100644 index 899b59f..0000000 --- a/src/sdp/ao_conf_make_meta_native.d +++ /dev/null @@ -1,330 +0,0 @@ -/++ - native headers using
@title:
:subtitle:
type tags
- extract native/orig header return associative array -+/ -module sdp.ao_conf_make_meta_native; -template SiSUheaderExtractNative() { - private import - std.exception, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.utf, - std.conv : to; - private import - sdp.ao_rgx, - sdp.ao_defaults; - struct HeaderDocMetadataAndMakeNativeToAA { - mixin SiSUregisters; - mixin SiSUrgxInitFlags; - mixin SiSUrgxInit; - auto rgx = Rgx(); - enum State { off, on } - string hm, hs; - auto header_metadata_and_make_aa(H,Me,Ma)( - H header, - Me dochead_meta, - Ma dochead_make - ) - in { - debug(asserts){ - static assert(is(typeof(header) == string)); - static assert(is(typeof(dochead_meta) == string[string][string])); - static assert(is(typeof(dochead_make) == string[string][string])); - } - } - body { - scope(exit) { - destroy(header); - destroy(dochead_meta); - destroy(dochead_make); - } - if (auto t = header.match(rgx.native_header_main)) { - char[][] header_obj_spl = - (cast(char[]) header).split(rgx.line_delimiter_ws_strip); - auto hm = to!string(t.captures[1]); - if (hm.match(rgx.main_headers)) { - foreach (line; header_obj_spl) { - if (auto m = line.match(rgx.native_header_main)) { - if (!empty(m.captures[2])) { - if (hm == "creator") { - dochead_meta[hm]["author"] = - to!string(m.captures[2]); - } else if (hm == "title") { - dochead_meta[hm]["main"] = - to!string(m.captures[2]); - } else if (hm == "publisher") { - dochead_meta[hm]["name"] = - to!string(m.captures[2]); - } - } - } else if (auto s = match(line, rgx.native_header_sub)) { - if (!empty(s.captures[2])) { - auto hs = to!string(s.captures[1]); - if ((hm == "make" ) - && (dochead_make[hm])) { - switch (hm) { - case "make": - if (hs.match(rgx.native_subhead_make)) { - if (dochead_make[hm][hs]) { - dochead_make[hm][hs] = to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - default: - break; - } - } else if (dochead_meta[hm]) { - switch (hm) { - case "creator": - if (hs.match(rgx.native_subhead_creator)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "title": - if (hs.match(rgx.native_subhead_title)) { - if ((hs == "subtitle") - && (dochead_meta[hm]["sub"])) { - dochead_meta[hm]["sub"] = - to!string(s.captures[2]); - } else if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "rights": - if (hs.match(rgx.native_subhead_rights)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "date": - if (hs.match(rgx.native_subhead_date)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "original": - if (hs.match(rgx.native_subhead_original)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "classify": - if (hs.match(rgx.native_subhead_classify)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "identifier": - if (hs.match(rgx.native_subhead_identifier)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "notes": - if (hs.match(rgx.native_subhead_notes)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "publisher": - if (hs.match(rgx.native_subhead_publisher)) { - if (dochead_meta[hm][hs]) { - dochead_meta[hm][hs] = - to!string(s.captures[2]); - } - } else { - writeln("not a valid header type:", hm, ":", hs); - destroy(hm); - destroy(hs); - } - break; - case "links": - destroy(hm); - destroy(hs); - break; - default: - break; - } - } - } - } - } - } else { - writeln("not a valid header type:", hm); - } - } - auto t = tuple(dochead_meta, dochead_make); - static assert(t.length==2); - return t; - } - private auto native_header_extract(L,Lo,O,T)( - L line, - return ref Lo line_occur, - return ref O an_object, - return ref T type - ) { - debug(asserts){ - static assert(is(typeof(line) == char[])); - static assert(is(typeof(line_occur) == int[string])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - if (line.matchFirst(rgx.native_header_make)) { /+ matched header_make +/ - debug(header1) { /+ writeln(line); +/ } - type["header"] = State.on; - type["header_make"] = State.on; - type["header_meta"] = State.off; - ++line_occur["header_make"]; - an_object["body_nugget"] ~= line ~= "\n"; - } else if (line.matchFirst(rgx.native_header)) { /+ matched header_metadata +/ - /+ (generic header match and not previously caught by header_make) +/ - debug(header1) { /+ writeln(line); +/ } - type["header"] = State.on; - type["header_make"] = State.off; - type["header_meta"] = State.on; - ++line_occur["header_meta"]; - an_object["body_nugget"] ~= line ~= "\n"; - } else if (type["header_make"] == State.on - && (line_occur["header_make"] > State.off)) { /+ header_make flag set +/ - if (line.matchFirst(rgx.native_header_sub)) { /+ sub-header +/ - debug(header1) { /+ writeln(line); +/ } - ++line_occur["header_make"]; - an_object["body_nugget"] ~= line ~= "\n"; - } - } else if (type["header_meta"] == State.on - && (line_occur["header_meta"] > State.off)) { /+ header_metadata flag set +/ - if (line.matchFirst(rgx.native_header_sub)) { /+ sub-header +/ - debug(header1) { /+ writeln(line); +/ } - ++line_occur["header_meta"]; - an_object["body_nugget"] ~= line ~= "\n"; - } - } - return an_object; - } - auto header_reset_states_common(Lo,O,T)( - return ref Lo line_occur, - return ref O an_object, - return ref T type - ) { - debug(asserts){ - static assert(is(typeof(line_occur) == int[string])); - static assert(is(typeof(an_object) == string[string])); - static assert(is(typeof(type) == int[string])); - } - line_occur["header_make"] = State.off; - line_occur["header_meta"] = State.off; - type["header"] = State.off; - an_object.remove("body_nugget"); - an_object.remove("is"); - an_object.remove("attrib"); - } - private auto headerNativeToAA(Hn)(Hn src_header) { - debug(asserts){ - static assert(is(typeof(src_header) == char[])); - } - auto type = flags_type_init; - type = [ - "header" : State.off, - "header_make" : State.off, - "header_meta" : State.off, - ]; - string[string] an_object; - int[string] line_occur; - auto dochead_make = make_aa; - auto dochead_meta = meta_aa; - auto set_header = HeaderDocMetadataAndMakeNativeToAA(); - char[][] source_header_arr = - (cast(char[]) src_header).split(rgx.newline_eol_delimiter); - foreach(header_line; source_header_arr) { - if (auto m = header_line.matchFirst(rgx.comment)) { - /+ matched comment +/ - debug(comment) { - } - header_reset_states_common(line_occur, an_object, type); - } else if ((header_line.matchFirst(rgx.native_header)) - || (type["header_make"] == State.on - && (line_occur["header_make"] > State.off)) - || (type["header_meta"] == State.on - && (line_occur["header_meta"] > State.off))) { - if (header_line.length == 0) { - /+ header_make instructions (current line empty) +/ - auto dochead_metadata_and_make = - set_header.header_metadata_and_make_aa(strip(an_object["body_nugget"]), dochead_meta, dochead_make); - static assert(!isTypeTuple!(dochead_metadata_and_make)); - dochead_meta = dochead_metadata_and_make[0]; - dochead_make = dochead_metadata_and_make[1]; - header_reset_states_common(line_occur, an_object, type); - type["header_make"] = State.off; - type["header_meta"] = State.off; - debug(headersdlang) { - writeln(dochead_metadata_and_make); - } - } else { - an_object = native_header_extract(header_line, line_occur, an_object, type); - } - } - } - auto t = tuple( - dochead_make, - dochead_meta, - ); - return t; - } - } -} diff --git a/src/sdp/ao_conf_make_meta_sdlang.d b/src/sdp/ao_conf_make_meta_sdlang.d deleted file mode 100644 index 1fb8993..0000000 --- a/src/sdp/ao_conf_make_meta_sdlang.d +++ /dev/null @@ -1,150 +0,0 @@ -/++ - sdlang headers
- extract sdlang header return sdlang -+/ -module sdp.ao_conf_make_meta_sdlang; -template SiSUheaderExtractSDLang() { - private import - std.exception, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.utf, - std.conv : to; - private import - sdp.ao_rgx, - sdp.ao_defaults; - struct HeaderExtractSDL { - mixin SiSUregisters; - mixin SiSUrgxInit; - auto rgx = Rgx(); - private auto sdlangToAAmake(C,Tag)(C conf, Tag conf_sdlang) { - debug(asserts){ - static assert(is(typeof(conf) == string[string][string])); - } - foreach (maintag, subtags; conf) { - foreach (subtag, content; subtags) { - if (!(conf_sdlang.maybe.tags[maintag].empty)) { - if (!(conf_sdlang.tags[maintag][0].maybe.attributes[subtag].empty) - && (conf_sdlang.tags[maintag][0].attributes[subtag][0].value.length > 0)) { - debug(headersdlang) { - writeln(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); - } - conf[maintag][subtag] = - to!string(conf_sdlang.tags[maintag][0].attributes[subtag][0].value); - } - } - } - } - return conf; - } - private auto configSettingsSDLangToAAmake(Tag)(Tag conf_sdlang) { - auto conf = sdlangToAAmake(conf_aa, conf_sdlang); - return conf; - } - private auto documentMakeSDLangToAAmake(Tag)(Tag document_make_sdlang) { - auto dochead_make = sdlangToAAmake(make_aa, document_make_sdlang); - return dochead_make; - } - final private auto headerMakeSDLang(Hs)(Hs src_header) { - debug(asserts){ - static assert(is(typeof(src_header) == string)); - } - scope(failure) { - stderr.writefln( - "%s\n%s\n%s:%s failed here:\n src_header: %s", - __MODULE__, __FUNCTION__, - __FILE__, __LINE__, - src_header, - ); - } - Tag sdl_root_header; - try { - sdl_root_header = parseSource(src_header); - } - catch(ParseException e) { - stderr.writeln("SDLang problem with this document header:"); - stderr.writeln(src_header); - // Error messages of the form: - // myFile.sdl(5:28): Error: Invalid integer suffix. - stderr.writeln(e.msg); - } - debug(sdlang) { - writeln("header SDL:"); - writeln(sdl_root_header.toSDLDocument()); - } - return sdl_root_header; - } - private auto headerSDLangGet(Hs)(Hs src_header) { - debug(asserts){ - static assert(is(typeof(src_header) == char[])); - } - char[][] source_header_arr = - (cast(char[]) src_header).split(rgx.newline_eol_delimiter); - char[] header_clean; - foreach(header_line; source_header_arr) { - if (!match(header_line, rgx.comments)) { - header_clean ~= header_line ~ "\n"; - } - } - /+ get sdlang tags +/ - auto header_sdlang=headerMakeSDLang(to!string(header_clean)); - debug(sdlang) { - writeln("--------------"); - stdout.rawWrite( header_sdlang.toSDLDocument() ); - writeln("--------------"); - Value test = header_sdlang.tags["title"][0].values[0]; - assert(test == typeid(string)); - // writeln(header_sdlang.maybe.tags["title"]); - // writeln(header_sdlang.maybe.tags["title"][0].maybe.attributes["subtitle"]); - } - return header_sdlang; // sdlang.ast.Tag - } - private auto headerSDLangToAAmake(Tag,Ma)(Tag header_sdlang, Ma dochead_make) { - debug(asserts){ - static assert(is(typeof(dochead_make) == string[string][string])); - } - dochead_make = sdlangToAAmake(dochead_make, header_sdlang); - auto dochead_meta = sdlangToAAmake(meta_aa, header_sdlang); - if (dochead_meta["title"]["main"].empty) { - dochead_meta["title"]["main"] = - to!string(header_sdlang.maybe.tags["title"][0].values[0]); - } - if (!(dochead_meta["title"]["subtitle"].empty) - && (dochead_meta["title"]["sub"].empty)) { - dochead_meta["title"]["sub"] ~= dochead_meta["title"]["subtitle"]; - } - dochead_meta["title"].remove("subtitle"); - if (dochead_meta["title"]["sub"].empty) { - dochead_meta["title"]["full"] ~= dochead_meta["title"]["main"]; - } else { - dochead_meta["title"]["full"] ~= format( - "%s - %s", - dochead_meta["title"]["main"], - dochead_meta["title"]["sub"], - ); - } - dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"]; - string[] authors_arr; - auto authors_raw_arr = dochead_meta["creator"]["author"].split(rgx.arr_delimiter); - foreach (author_raw; authors_raw_arr) { - authors_arr ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); - } - dochead_meta["creator"]["author"] = join(authors_arr, ", ").chomp.chomp; - auto t = tuple(dochead_make, dochead_meta); - static assert(t.length==2); - return t; - } - private auto headerSDLangToAA(Hs,Ma)(Hs header_sdlang_src, Ma conf_doc_make_aa) { - debug(asserts){ - static assert(is(typeof(header_sdlang_src) == char[])); - static assert(is(typeof(conf_doc_make_aa) == string[string][string])); - } - auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); - auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa); - return header_aa_tuple; - } - } -} diff --git a/src/sdp/ao_defaults.d b/src/sdp/ao_defaults.d deleted file mode 100644 index 6363fdc..0000000 --- a/src/sdp/ao_defaults.d +++ /dev/null @@ -1,493 +0,0 @@ -/++ - default settings -+/ -module sdp.ao_defaults; -template SiSUregisters() { - 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; - 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_; - } - 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_; - } - 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_; - } - auto ptr_head_main = - [ - "classify", - "creator", - "date", - "identifier", - "links", - "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 = `{ - }`; -} -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; - } -} -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" : "", - ]; - 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; - } -} -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; - } - } -} -template InternalMarkup() { - struct InlineMarkup { - auto en_a_o = "【"; auto en_a_c = "】"; - auto en_b_o = "〖"; auto en_b_c = "〗"; - auto lnk_o = "┥"; auto lnk_c = "┝"; - auto url_o = "┤"; auto url_c = "├"; - auto mark_internal_site_lnk = "¤"; - auto nbsp = "░"; - auto br_line = "┘"; - auto br_nl = "┙"; - auto br_paragraph = "┚"; - 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 = "┚"; - auto tc_p = "┆"; - 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; - } - } -} -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_); - } - } -} diff --git a/src/sdp/ao_doc_debugs.d b/src/sdp/ao_doc_debugs.d deleted file mode 100644 index 2c78c76..0000000 --- a/src/sdp/ao_doc_debugs.d +++ /dev/null @@ -1,660 +0,0 @@ -/++ - output debugs -+/ -module sdp.ao_doc_debugs; -template SiSUdebugs() { - import - sdp.ao_defaults, - sdp.ao_rgx; - private import - std.algorithm, - std.array, - std.container, - std.exception, - std.json, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - auto SiSUdebugs(S,T)( - auto return ref const S contents, - auto return ref T doc_matters, - ) { - mixin SiSUrgxInit; - mixin InternalMarkup; - auto rgx = Rgx(); - auto markup = InlineMarkup(); - string key; - debug(parent) { - writefln( - "%s:%s", - __FILE__, - __LINE__, - ); - foreach (key; doc_matters.keys_seq.seg) { - foreach (obj; contents[key]) { - if (obj.use != "empty") { - if (obj.is_a == "heading") { - writefln( - "%s node: %s heading: %s %s", - obj.obj_cite_number, - obj.node, - obj.heading_lev_markup, - obj.text, - ); - } - } - } - } - } - debug(dumpdoc) { - writefln( - "%s\n%s:%s", - "-------------------------------", - __FILE__, - __LINE__, - ); - foreach (obj; contents) { - if (obj.use != "empty") { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(section_head) { - key="head"; - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(section_toc) { - key="toc_seg"; - out_toc(contents, key); - } - debug(section_toc_seg) { - key="toc_seg"; - out_toc(contents, key); - } - debug(section_toc_scroll) { - key="toc_scroll"; - out_toc(contents, key); - } - debug(segnames) { - writeln(__LINE__); - out_segnames(contents, doc_matters); - } - debug(section_body) { - key="body"; - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(toc_nav_dom) { - enum DomTags { none, open, close, close_and_open, open_still, } - foreach (sect; doc_matters.keys_seq.seg) { - foreach (obj; contents[sect]) { - if (obj.is_a == "heading") { - foreach_reverse (k; 0 .. 7) { - switch (obj.dom_markedup[k]) { - case DomTags.close : - writeln(markup.indent_by_spaces_provided(k), ""); - break; - case DomTags.close_and_open : - writeln(markup.indent_by_spaces_provided(k), ""); - writeln(markup.indent_by_spaces_provided(k), - "<", k, ">", obj.text, - " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); - break; - case DomTags.open : - writeln(markup.indent_by_spaces_provided(k), - "<", k, ">", obj.text, - " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); - break; - default : - break; - } - } - } - } - } - writeln("--------------------"); - foreach (sect; doc_matters.keys_seq.seg) { - foreach (obj; contents[sect]) { - if (obj.is_a == "heading") { - foreach_reverse (k; 0 .. 7) { - switch (obj.dom_collapsed[k]) { - case DomTags.close : - writeln(markup.indent_by_spaces_provided(k), ""); - break; - case DomTags.close_and_open : - writeln(markup.indent_by_spaces_provided(k), ""); - writeln(markup.indent_by_spaces_provided(k), - "<", k, ">", obj.text, - " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); - break; - case DomTags.open : - writeln(markup.indent_by_spaces_provided(k), - "<", k, ">", obj.text, - " file: ", obj.segment_anchor_tag, ".xhtml#", obj.ocn); - break; - default : - break; - } - } - } - } - } - } - debug(section_endnotes) { - key="endnotes"; - out_endnotes(contents, key); - } - debug(section_endnotes_seg) { - key="endnotes"; - out_endnotes(contents, key); - } - debug(section_glossary) { - key="glossary"; - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(section_bibliography) { - key="bibliography"; - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(section_bookindex) { - key="bookindex_seg"; - out_bookindex(contents, key); - } - debug(section_bookindex_seg) { - key="bookindex_seg"; - out_bookindex(contents, key); - } - debug(section_bookindex_scroll) { - key="bookindex_scroll"; - out_bookindex(contents, key); - } - debug(blurb_section) { - key="blurb"; - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(objects) { - writefln( - "%s\n%s:%s", - "-------------------------------", - __FILE__, - __LINE__, - ); - foreach (obj; contents) { - if (obj.use != "empty") { - writefln( - "* [%s][%s] %s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - debug(headermakejson) { - writefln( - "%s\n%s\n%s", - "document header, metadata & make instructions:", - doc_matters.dochead_meta, - ptr_head_main, - ); - foreach (main_header; ptr_head_main) { - switch (main_header) { - case "make": - foreach (sub_header; ptr_head_sub_make) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - default: - break; - } - } - } - debug(headermetadatajson) { - writefln( - "%s\n%s\n%s", - "document header, metadata & make instructions:", - doc_matters.dochead_meta, - ptr_head_main, - ); - foreach (main_header; ptr_head_main) { - switch (main_header) { - case "creator": - foreach (sub_header; ptr_head_sub_creator) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "title": - foreach (sub_header; ptr_head_sub_title) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "rights": - foreach (sub_header; ptr_head_sub_rights) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "date": - foreach (sub_header; ptr_head_sub_date) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "original": - foreach (sub_header; ptr_head_sub_original) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "classify": - foreach (sub_header; ptr_head_sub_classify) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "identifier": - foreach (sub_header; ptr_head_sub_identifier) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "notes": - foreach (sub_header; ptr_head_sub_notes) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - case "publisher": - foreach (sub_header; ptr_head_sub_publisher) { - if (doc_matters.dochead_meta[main_header][sub_header].to!string.length > 2) { - writefln( - "%s:%s: %s", - main_header, - sub_header, - doc_matters.dochead_meta[main_header][sub_header] - ); - } - } - break; - default: - break; - } - } - } - debug(anchor) { - writefln( - "%s\n%s:%s", - "-------------------------------", - __FILE__, - __LINE__, - ); - foreach (k; doc_matters.keys_seq.seg) { - foreach (obj; contents[k]) { - if (obj.is_a == "heading") { - writefln( - "%s~ [%s] %s %s", - obj.marked_up_level, - obj.obj_cite_number, - obj.anchor_tags, - // "[", obj["is"], "] ", - obj.text - ); - } - } - } - } - debug(heading) { // heading - foreach (k; doc_matters.keys_seq.seg) { - foreach (o; contents[k]) { - if (o.is_a == "heading") { - writefln( - "%s* %s\n (markup level: %s; collapsed level: %s)", - replicate(" ", o.heading_lev_markup), - strip(o.text), - o.heading_lev_markup, - o.heading_lev_collapsed, - ); - } - } - } - } - debug(headings) { - writefln( - "%s\n%s:%s", - "-------------------------------", - __FILE__, - __LINE__, - ); - foreach (k; doc_matters.keys_seq.seg) { - foreach (obj; contents[k]) { - if (obj.is_a == "heading") { - writefln( - "%s~ [%s] %s", - obj.marked_up_level, - obj.obj_cite_number, - // "[", obj["is"], "] ", - obj.text - ); - } - } - } - } - debug(summary) { - string[string] check = [ - "last_obj_cite_number" : "NA [debug \"checkdoc\" not run]", - ]; - } - debug(checkdoc) { - if ((doc_matters.opt_action_bool["debug"])) { - debug(checkdoc) { - if (auto mfn=match(doc_matters.source_filename, rgx.src_fn)) { - if (doc_matters.opt_action_bool["assertions"]) { - switch (mfn.captures[2]) { - // live manual: - case "live-manual.ssm": - assert(check["last_obj_cite_number"] == - "1019","last obj_cite_number should be: 1019 (check test, document is frequently updated)"); // ok - break; - // sisu_markup: - case "sisu_markup.sst": - assert(check["last_obj_cite_number"] == - "297","last obj_cite_number expected to be: 297 rather than " ~ check["last_obj_cite_number"]); // ok - // assert(check["last_obj_cite_number"] == "297","last obj_cite_number expected to be: 297 rather than " ~ check["last_obj_cite_number"]); - // notes for first divergance study sisu headings 247 250 - // sisu has issue with code that contains heading 1~ which results in no obj_cite_number! ?? - // sisu currently has incorrect last body obj_cite_number of 294! - // bug in sisu? attend - break; - // sisu-markup-samples: - case "accelerando.charles_stross.sst": - assert(check["last_obj_cite_number"] == - "2861","last obj_cite_number expected to be: 2861 rather than " ~ check["last_obj_cite_number"]); // ok - break; - case "alices_adventures_in_wonderland.lewis_carroll.sst": - assert(check["last_obj_cite_number"] == - "805","last obj_cite_number expected to be: 805 rather than " ~ check["last_obj_cite_number"]); // 808 - break; - case "autonomy_markup0.sst": - assert(check["last_obj_cite_number"] == - "77","last obj_cite_number expected to be: 77 rather than " ~ check["last_obj_cite_number"]); // ok endnotes - // assert(check["last_obj_cite_number"] == "78","last obj_cite_number expected to be: 78 rather than " ~ check["last_obj_cite_number"]); - break; - case "content.cory_doctorow.sst": - assert(check["last_obj_cite_number"] == - "953","last obj_cite_number expected to be: 953 rather than " ~ check["last_obj_cite_number"]); // 1007 way off, check obj_cite_number off switches - // assert(check["last_obj_cite_number"] == "953","last obj_cite_number expected to be: 953 rather than " ~ check["last_obj_cite_number"]); - break; - case "democratizing_innovation.eric_von_hippel.sst": - // fixed ERROR! range violation, broken check! endnotes, bookindex, biblio - // error in bookindex ... (ch1; ch6; ch8 ) - assert(check["last_obj_cite_number"] == - "905","last obj_cite_number expected to be: 905 rather than " ~ check["last_obj_cite_number"]); // 911 - break; - case "down_and_out_in_the_magic_kingdom.cory_doctorow.sst": - assert(check["last_obj_cite_number"] == - "1417","last obj_cite_number expected to be: 1417 rather than " ~ check["last_obj_cite_number"]); // 1455 check obj_cite_number off switches - break; - case "for_the_win.cory_doctorow.sst": - assert(check["last_obj_cite_number"] == - "3510","last obj_cite_number expected to be: 3510 rather than " ~ check["last_obj_cite_number"]); // 3569 check obj_cite_number off switches - break; - case "free_as_in_freedom_2.richard_stallman_and_the_free_software_revolution.sam_williams.richard_stallman.sst": - assert(check["last_obj_cite_number"] == - "1082","last obj_cite_number expected to be: 1082 rather than " ~ check["last_obj_cite_number"]); // check 1079 too few - break; - case "free_culture.lawrence_lessig.sst": - assert(check["last_obj_cite_number"] == - "1330","last obj_cite_number expected to be: 1330 rather than " ~ check["last_obj_cite_number"]); // 1312 - // fixed ERROR! range violation, broken check! - // error in bookindex ... sections piracy (ch1) & property (ch10 market concentration) fixed - break; - case "free_for_all.peter_wayner.sst": // endnotes, bookindex, biblio - assert(check["last_obj_cite_number"] == - "1559","last obj_cite_number expected to be: 1559 rather than " ~ check["last_obj_cite_number"]); // 1560, check obj_cite_number off switches, has endnotes so 2 too many - // assert(check["last_obj_cite_number"] == "1559","last obj_cite_number expected to be: 1559 rather than " ~ check["last_obj_cite_number"]); - break; - case "gpl2.fsf.sst": - assert(check["last_obj_cite_number"] == - "65","last obj_cite_number expected to be: 65 rather than " ~ check["last_obj_cite_number"]); // ok endnotes? check - // assert(check["last_obj_cite_number"] == "66","last obj_cite_number expected to be: 66 rather than " ~ check["last_obj_cite_number"]); - break; - case "gpl3.fsf.sst": - assert(check["last_obj_cite_number"] == - "123","last obj_cite_number expected to be: 123 rather than " ~ check["last_obj_cite_number"]); // ok - break; - case "gullivers_travels.jonathan_swift.sst": - assert(check["last_obj_cite_number"] == - "668","last obj_cite_number expected to be: 668 rather than " ~ check["last_obj_cite_number"]); // 674 - break; - case "little_brother.cory_doctorow.sst": - assert(check["last_obj_cite_number"] == - "3130","last obj_cite_number expected to be: 3130 rather than " ~ check["last_obj_cite_number"]); // 3204, check obj_cite_number off switches - break; - case "the_cathedral_and_the_bazaar.eric_s_raymond.sst": - assert(check["last_obj_cite_number"] == - "258","last obj_cite_number expected to be: 258 rather than " ~ check["last_obj_cite_number"]); // ok - break; - case "the_public_domain.james_boyle.sst": - assert(check["last_obj_cite_number"] == - "970","last obj_cite_number expected to be: 970 rather than " ~ check["last_obj_cite_number"]); // 978 - break; - case "the_wealth_of_networks.yochai_benkler.sst": // endnotes, bookindex - assert(check["last_obj_cite_number"] == - "829","last obj_cite_number expected to be: 829 rather than " ~ check["last_obj_cite_number"]); // ok - // assert(check["last_obj_cite_number"] == "832","last obj_cite_number expected to be: 832 rather than " ~ check["last_obj_cite_number"]); - // has endnotes and bookindex, issue with sisu.rb - break; - case "through_the_looking_glass.lewis_carroll.sst": - assert(check["last_obj_cite_number"] == - "949","last obj_cite_number expected to be: 949 rather than " ~ check["last_obj_cite_number"]); // 955 - break; - case "two_bits.christopher_kelty.sst": // endnotes, bookindex, biblio - assert(check["last_obj_cite_number"] == - "1190","last obj_cite_number expected to be: 1190 rather than " ~ check["last_obj_cite_number"]); // 1191 - // assert(check["last_obj_cite_number"] == "1193","last obj_cite_number expected to be: 1193 rather than " ~ check["last_obj_cite_number"]); // 1191 ok? - // has endnotes and bookindex, issue with sisu.rb - break; - // fixed ERROR! range violation! - // error in bookindex ... (ch3 the movement) - case "un_contracts_international_sale_of_goods_convention_1980.sst": - assert(check["last_obj_cite_number"] == - "377","last obj_cite_number expected to be: 377 rather than " ~ check["last_obj_cite_number"]); // ok - break; - case "viral_spiral.david_bollier.sst": // endnotes, bookindex - assert(check["last_obj_cite_number"] == - "1078","last obj_cite_number expected to be: 1078 rather than " ~ check["last_obj_cite_number"]); // 1100 - // fixed ERROR! range violation! - // error in bookindex ... (ch7 ... building the cc machine, an extra semi colon) - break; - default: - writeln(doc_matters.source_filename); - break; - } - } - } - } - debug(checkdoc) { - void out_segnames(S,T)( - auto return ref const S contents, - auto return ref T doc_matters, - ) { - foreach (key; doc_matters.keys_seq.seg) { - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - if (obj.heading_lev_markup == 4) { - writeln(obj.ptr_html_segnames, ". (", doc_matters.segnames[obj.ptr_html_segnames], ") -> ", obj.text); - } - } - } - } - } - } - debug(checkdoc) { - void out_toc(S)( - auto return ref const S contents, - string key, - ) { - if (contents[key].length > 1) { - string indent_spaces; - foreach (obj; contents[key]) { - indent_spaces=markup.indent_by_spaces_provided(obj.indent_hang); - writefln( - "%s%s", - indent_spaces, - obj.text - ); - } - } - } - } - debug(checkdoc) { - void out_endnotes(S)( - auto return ref const S contents, - string key, - ) { - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s]\n%s", - obj.is_a, - obj.text - ); - } - } - } - } - debug(checkdoc) { - void out_bookindex(S)( - auto return ref const S contents, - string key, - ) { - if (contents[key].length > 1) { - foreach (obj; contents[key]) { - writefln( - "[%s][%s]\n%s", - obj.obj_cite_number, - obj.is_a, - obj.text - ); - } - } - } - } - } - } - } -} diff --git a/src/sdp/ao_object_setter.d b/src/sdp/ao_object_setter.d deleted file mode 100644 index a5ddb4a..0000000 --- a/src/sdp/ao_object_setter.d +++ /dev/null @@ -1,64 +0,0 @@ -/++ - object setter: - setting of sisu objects for downstream processing - ao_object_setter.d -+/ -module sdp.ao_object_setter; -template ObjectSetter() { - /+ structs +/ - struct HeadingAttrib { - string lev = "9"; - int heading_lev_markup = 9; - int heading_lev_collapsed = 9; - int[] closes_lev_collapsed = []; - int[] closes_lev_markup = []; - int array_ptr = 0; - int heading_array_ptr_segments = 0; - } - struct ObjGenericComposite { - // size_t id; - string use = ""; - string is_of = ""; - string is_a = ""; - string text = ""; - string obj_cite_number = ""; - string[] anchor_tags = []; - int indent_base = 0; - int indent_hang = 0; - bool bullet = false; - bool inline_links = false; - bool inline_notes_reg = false; - bool inline_notes_star = false; - string language = ""; // not implemented, consider - string code_block_syntax = ""; - int table_number_of_columns = 0; - double[] table_column_widths = []; - string[] table_column_aligns = []; - bool table_heading = false; - bool table_walls = false; // not implemented - int ocn = 0; - string segment_anchor_tag = ""; - string segname_prev = ""; - string segname_next = ""; - int parent_lev_markup = 0; - int parent_ocn = 0; - int[] ancestors = []; - string marked_up_level = "9"; - int heading_lev_markup = 9; - int heading_lev_collapsed = 9; - int[] dom_markedup = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_collapsed = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ]; - string[] lev4_subtoc = []; - int heading_array_ptr = 0; - int ptr_doc_object = 0; - int ptr_html_segnames = 0; - int ptr_heading = 0; - int array_ptr = 0; - int heading_array_ptr_segments = 0; - string[string][string] node; - } - struct TheObjects { - ObjGenericComposite[] oca; - } -} diff --git a/src/sdp/ao_read_config_files.d b/src/sdp/ao_read_config_files.d deleted file mode 100644 index b8d9890..0000000 --- a/src/sdp/ao_read_config_files.d +++ /dev/null @@ -1,124 +0,0 @@ -/++ - read configuration files
- - read config files
- ao_config_files.d -+/ -module sdp.ao_read_config_files; -template ConfigIn() { - private import - std.algorithm, - std.array, - std.container, - std.exception, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - import std.file; - final string ConfigIn(C,E)(C conf_sdl, E env) { - string dot_pwd = chainPath(to!string(env["pwd"]), ".sisu").array; - string underscore_pwd = chainPath(to!string(env["pwd"]), "_sisu").array; - string dot_home = chainPath(to!string(env["home"]), ".sisu").array; - string[] possible_config_path_locations = [ - dot_pwd, - underscore_pwd, - dot_home, - "/etc/sisu" - ]; - string config_file_str; - foreach(pth; possible_config_path_locations) { - auto conf_file = format( - "%s/%s", - pth, - conf_sdl, - ); - try { - if (exists(conf_file)) { - debug(configfile) { - writeln(conf_file); - } - config_file_str = conf_file.readText; - break; - } - } - catch (ErrnoException ex) { - } - catch (FileException ex) { - } - } - return config_file_str; - } -} -/+ - -+/ -template ConfigSDLang() { - import sdlang; - private import - std.algorithm, - std.array, - std.container, - std.exception, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - auto ConfigSDLang(string configuration, string conf_sdl_filename) { - Tag sdl_root_conf; - try { - sdl_root_conf = parseSource(configuration); - } - catch(ParseException e) { - stderr.writeln("SDLang problem with content for ", conf_sdl_filename); - stderr.writeln(e.msg); - } - debug(sdlang) { - Value output_dir_structure_by = sdl_root_conf.tags["output_dir_structure_by"][0].values[0]; - assert(output_dir_structure_by.type == typeid(string)); - writeln(output_dir_structure_by); - writeln("conf SDL:"); - writeln(sdl_root_conf.toSDLDocument()); - } - return sdl_root_conf; - } -} -/+ -+/ -template ConfigHub() { - private import - std.algorithm, - std.array, - std.container, - std.exception, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - - final auto ConfigHub(C,E)(C conf_sdl, E env) { - auto configuration = ConfigIn!()(conf_sdl, env); - auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); - return sdl_root; - } -} diff --git a/src/sdp/ao_read_source_files.d b/src/sdp/ao_read_source_files.d deleted file mode 100644 index b6ad942..0000000 --- a/src/sdp/ao_read_source_files.d +++ /dev/null @@ -1,306 +0,0 @@ -/++ - module ao_read_source_files;
- - open markup files
- - if master file scan for addional files to import/insert -+/ -module sdp.ao_read_source_files; -template SiSUrawMarkupContent() { - private import - sdp.ao_rgx; - private import - std.algorithm, - std.array, - std.container, - std.exception, - std.stdio, - std.file, - std.path, - std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; - mixin SiSUrgxInit; - auto rgx = Rgx(); - auto rawsrc = RawMarkupContent(); - auto SiSUrawMarkupContent(Fn)(Fn fn_src) { - auto _0_header_1_body_content_2_insert_filelist_tuple = - rawsrc.sourceContentSplitIntoHeaderAndBody(rawsrc.sourceContent(fn_src), fn_src); - return _0_header_1_body_content_2_insert_filelist_tuple; - } - struct RawMarkupContent { - final sourceContent(in string fn_src) { - auto raw = MarkupRawUnit(); - auto source_txt_str = - raw.markupSourceReadIn(fn_src); - return source_txt_str; - } - final auto sourceContentSplitIntoHeaderAndBody(in string source_txt_str, in string fn_src="") { - auto raw = MarkupRawUnit(); - string[] insert_file_list; - auto t = - raw.markupSourceHeaderContentRawLineTupleArray(source_txt_str); - auto header_raw = t[0]; - auto sourcefile_body_content = t[1]; - if (fn_src.match(rgx.src_fn_master)) { // filename with path needed if master file (.ssm) not otherwise - auto ins = Inserts(); - auto tu = - ins.scan_master_src_for_insert_files_and_import_content(sourcefile_body_content, fn_src); - static assert(!isTypeTuple!(tu)); - sourcefile_body_content = tu[0]; - insert_file_list = tu[1].dup; - } - t = tuple( - header_raw, - sourcefile_body_content, - insert_file_list - ); - static assert(t.length==3); - return t; - } - } - struct MarkupRawUnit { - private import std.file; - final private string readInMarkupSource(in char[] fn_src) { - enforce( - exists(fn_src)!=0, - "file not found" - ); - string source_txt_str; - try { - if (exists(fn_src)) { - source_txt_str = fn_src.readText; - } - } - catch (ErrnoException ex) { - } - catch (UTFException ex) { - // Handle validation errors - } - catch (FileException ex) { - // Handle errors - } - std.utf.validate(source_txt_str); - return source_txt_str; - } - final private char[][] header0Content1(in string src_text) { - /+ split string on _first_ match of "^:?A~\s" into [header, content] array/tuple +/ - char[][] header_and_content; - auto m = (cast(char[]) src_text).matchFirst(rgx.heading_a); - header_and_content ~= m.pre; - header_and_content ~= m.hit ~ m.post; - assert(header_and_content.length == 2, - "document markup is broken, header body split == " - ~ header_and_content.length.to!string - ~ "; (header / body array split should == 2 (split is on level A~))" - ); - return header_and_content; - } - final private char[][] markupSourceLineArray(in char[] src_text) { - char[][] source_line_arr = - (cast(char[]) src_text).split(rgx.newline_eol_strip_preceding); - return source_line_arr; - } - auto markupSourceReadIn(in string fn_src) { - auto rgx = Rgx(); - enforce( - fn_src.match(rgx.src_pth), - "not a sisu markup filename" - ); - auto source_txt_str = readInMarkupSource(fn_src); - return source_txt_str; - } - auto markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) { - string[] file_insert_list = []; - auto hc = header0Content1(source_txt_str); - auto header = hc[0]; - char[] source_txt = hc[1]; - auto source_line_arr = markupSourceLineArray(source_txt); - auto t = tuple( - header, - source_line_arr, - file_insert_list - ); - return t; - } - final char[][] getInsertMarkupSourceContentRawLineArray( - in char[] fn_src, - Regex!(char) rgx_file - ) { - enforce( - fn_src.match(rgx_file), - "not a sisu markup filename" - ); - auto source_txt_str = readInMarkupSource(fn_src); - auto source_line_arr = markupSourceLineArray(source_txt_str); - return source_line_arr; - } - } - struct Inserts { - private import sdp.ao_defaults; - auto scan_subdoc_source( - char[][] markup_sourcefile_insert_content, - string fn_src - ) { - mixin SiSUrgxInitFlags; - char[][] contents_insert; - auto type1 = flags_type_init; - auto fn_pth_full = fn_src.match(rgx.src_pth); - auto markup_src_file_path = fn_pth_full.captures[1]; - foreach (line; markup_sourcefile_insert_content) { - if (type1["curly_code"] == 1) { - type1["header_make"] = 0; - type1["header_meta"] = 0; - if (line.matchFirst(rgx.block_curly_code_close)) { - type1["curly_code"] = 0; - } - contents_insert ~= line; - } else if (line.matchFirst(rgx.block_curly_code_open)) { - type1["curly_code"] = 1; - type1["header_make"] = 0; - type1["header_meta"] = 0; - contents_insert ~= line; - } else if (type1["tic_code"] == 1) { - type1["header_make"] = 0; - type1["header_meta"] = 0; - if (line.matchFirst(rgx.block_tic_close)) { - type1["tic_code"] = 0; - } - contents_insert ~= line; - } else if (line.matchFirst(rgx.block_tic_code_open)) { - type1["tic_code"] = 1; - type1["header_make"] = 0; - type1["header_meta"] = 0; - contents_insert ~= line; - } else if ( - (type1["header_make"] == 1) - && line.matchFirst(rgx.native_header_sub) - ) { - type1["header_make"] = 1; - type1["header_meta"] = 0; - } else if ( - (type1["header_meta"] == 1) - && line.matchFirst(rgx.native_header_sub) - ) { - type1["header_meta"] = 1; - type1["header_make"] = 0; - } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { - type1["header_make"] = 0; - type1["header_meta"] = 0; - auto insert_fn = m.captures[2]; - auto insert_sub_pth = m.captures[1]; - auto fn_src_insert = - chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; - auto raw = MarkupRawUnit(); - auto markup_sourcesubfile_insert_content = - raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); - debug(insert_file) { - tell_l("red", line); - tell_l("red", fn_src_insert); - tell_l("fuchsia", "ERROR"); - writeln( - " length contents insert array: ", - markup_sourcesubfile_insert_content.length - ); - } - auto ins = Inserts(); - /+ - 1. load file, - 2. read lines; - 3. scan lines, - 4. if filename insert, and insert filename - 5. repeat 1 - 6. else - 7. add line to new array; - +/ - } else { - type1["header_make"] = 0; - type1["header_meta"] = 0; - contents_insert ~= line; - } - } // end src subdoc (inserts) loop - return contents_insert; - } - auto scan_master_src_for_insert_files_and_import_content( - char[][] sourcefile_body_content, - string fn_src - ) { - mixin SiSUrgxInitFlags; - char[][] contents; - auto type = flags_type_init; - auto fn_pth_full = fn_src.match(rgx.src_pth); - auto markup_src_file_path = fn_pth_full.captures[1]; - string[] insert_file_list =[]; - foreach (line; sourcefile_body_content) { - if (type["curly_code"] == 1) { - if (line.matchFirst(rgx.block_curly_code_close)) { - type["curly_code"] = 0; - } - contents ~= line; - } else if (line.matchFirst(rgx.block_curly_code_open)) { - type["curly_code"] = 1; - contents ~= line; - } else if (type["tic_code"] == 1) { - if (line.matchFirst(rgx.block_tic_close)) { - type["tic_code"] = 0; - } - contents ~= line; - } else if (line.matchFirst(rgx.block_tic_code_open)) { - type["tic_code"] = 1; - contents ~= line; - } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { - auto insert_fn = m.captures[2]; - auto insert_sub_pth = m.captures[1]; - auto fn_src_insert = - chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; - insert_file_list ~= to!string(fn_src_insert); - auto raw = MarkupRawUnit(); - /+ TODO +/ - if (auto ma = line.match(rgx.src_fn_text)) { - /+ .sst when inserted, not used: headers and heading level ^:?A~ so remove +/ - writeln(__LINE__); writeln(ma); - } - auto markup_sourcefile_insert_content = - raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); - debug(insert_file) { - tell_l("red", line); - tell_l("red", fn_src_insert); - writeln( - " length contents insert array: ", - markup_sourcefile_insert_content.length - ); - } - auto ins = Inserts(); - auto contents_insert = ins.scan_subdoc_source( - markup_sourcefile_insert_content, - to!string(fn_src_insert) - ); - contents ~= contents_insert; - /+ - 1. load file, - 2. read lines; - 3. scan lines, - 4. if filename insert, and insert filename - 5. repeat 1 - 6. else - 7. add line to new array; - +/ - } else { - contents ~= line; - } - } // end src doc loop - debug(insert_file) { - writeln(__LINE__); - writeln(contents.length); - } - auto t = tuple( - contents, - insert_file_list - ); - return t; - } - } -} diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d deleted file mode 100644 index 29a96af..0000000 --- a/src/sdp/ao_rgx.d +++ /dev/null @@ -1,246 +0,0 @@ -/++ - regex: regular expressions used in sisu document parser -+/ -module sdp.ao_rgx; -template SiSUrgxInit() { - private import sdp.ao_defaults; - struct Rgx { - /+ misc +/ - static true_dollar = ctRegex!(`\$`, "gm"); - static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); - static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); - static within_quotes = ctRegex!(`"(.+?)"`); - static make_heading_delimiter = ctRegex!(`[;][ ]*`); - static arr_delimiter = ctRegex!(`[ ]*[;][ ]*`); - static name_delimiter = ctRegex!(`^([^,]+)[ ]*,[ ]+(.+?)$`); - static book_index_go = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); - static book_index_go_scroll = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); - static book_index_go_seg = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?):(?P[a-z0-9_-]+)"); - static book_index_go_seg_ = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)(:(?P[a-z0-9_-]+))?"); - static book_index_go_seg_anchorless = ctRegex!("(?P(?P[0-9]+)(?:-[0-9]+)?)"); - static trailing_comma = ctRegex!(",[ ]*$"); - static trailing_linebreak = ctRegex!(",[ ]{1,2}\\\\\\\\\n[ ]{4}$","m"); - static newline_eol_delimiter = ctRegex!("\n"); - static newline_eol_strip_preceding = ctRegex!("[ ]*\n"); - static newline_eol_delimiter_only = ctRegex!("^\n"); - static line_delimiter_ws_strip = ctRegex!("[ ]*\n[ ]*"); - static para_delimiter = ctRegex!("\n[ ]*\n+"); - static table_col_delimiter = ctRegex!("[ ]*\n+", "mg"); - static table_row_delimiter = ctRegex!("\n[ ]*\n+", "mg"); - static table_row_delimiter_special = ctRegex!("[ ]*\n", "mg"); - static table_col_delimiter_special = ctRegex!("[ ]*[|][ ]*", "mg"); - static levels_markup = ctRegex!(`^[A-D1-4]$`); - static levels_numbered = ctRegex!(`^[0-9]$`); - static levels_numbered_headings = ctRegex!(`^[0-7]$`); - static numeric = ctRegex!(`[ 0-9,.-]+`); - static numeric_col = ctRegex!(`^[ 0-9,.$£₤Є€€¥-]+$`); - /+ comments +/ - static comment = ctRegex!(`^%+ `); - static comments = ctRegex!(`^%+ |^%+$`); - /+ header +/ - static main_headers = - ctRegex!(`^(?:creator|title|rights|date|original|classify|identifier|notes|publisher|make|links)$`, "m"); - static native_header = ctRegex!(`^@([a-z_]+):(?:\s|$)`); - static native_header_make = ctRegex!(`^@(make):(?:\s|$)`); - static native_header_meta = - ctRegex!(`^@(?:creator|title|rights|date|original|classify|identifier|notes|publisher|links):(?:\s|$)`); - static native_header_main = ctRegex!(`^@(?P
[a-z_]+):\s*(?P.*)`, "m"); - static native_header_sub = ctRegex!(`^[ ]*:(?P[a-z_]+):\s+(?P.+)`, "m"); - static native_header_meta_title = ctRegex!(`^@title:\s`, "m"); - static variable_doc_title = ctRegex!(`@title`); - static variable_doc_author = ctRegex!(`@author|@creator`); - static raw_author_munge = ctRegex!(`(\S.+?),\s+(.+)`,"i"); - /+ 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"); - /+ 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"); - 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+(.+?)$`); - 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])?[*]) `); - /+ blocked markup +/ - static block_open = ctRegex!("^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)|^`{3} (code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)|^[{]table(~h)?(?P(?:[ ]+[0-9]+;)+)[}]"); - static block_poem_open = ctRegex!("^((poem[{].*?$)|`{3} poem)"); - /+ 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"); - /+ blocked markup curly +/ - static block_curly_open = ctRegex!(`^((code([.][a-z][0-9a-z_]+)?|poem|group|block|quote|table)[{].*?$)`); - static block_curly_code_open = ctRegex!(`^(?:code(?:[.]([a-z][0-9a-z_]+))?[{]([#]?)\s*$)`); // extract additional info - static block_curly_code_close = ctRegex!(`^([}]code)`); - static block_curly_poem_open = ctRegex!(`^(poem[{].*?$)`); - static block_curly_poem_close = ctRegex!(`^([}]poem)`); - static block_curly_group_open = ctRegex!(`^(group[{].*?$)`); - static block_curly_group_close = ctRegex!(`^([}]group)`); - static block_curly_block_open = ctRegex!(`^(block[{].*?$)`); - static block_curly_block_close = ctRegex!(`^([}]block)`); - static block_curly_quote_open = ctRegex!(`^(quote[{].*?$)`); - static block_curly_quote_close = ctRegex!(`^([}]quote)`); - static block_curly_table_open = ctRegex!(`^table[{](.*)`); - static block_curly_table_close = ctRegex!(`^([}]table)`); - static block_curly_table_special_markup = ctRegex!(`^[{]table((~h)?(?P(?:[ ]+[0-9]+;)+))[}]`, "mg"); - static table_head_instructions = ctRegex!(`(?Ph)?(?:[ ]+c(?P[0-9]);)?(?P(?:[ ]+[0-9]+[lr]?;)+)`); - static table_col_widths_and_alignment = ctRegex!(`(?P[0-9]+)(?P[lr]?)`); - static table_col_widths = ctRegex!(`(?P[0-9]+)`); - static table_col_align = ctRegex!(`(?P[lr]?)`); - static table_col_align_match = ctRegex!(`(?P[lr])`); - static table_col_separator = ctRegex!(`┊`); - static table_col_separator_nl = ctRegex!(`[┊]$`, "mg"); - /+ inline markup footnotes endnotes +/ - static inline_notes_curly_gen = ctRegex!(`~\{.+?\}~`, "m"); - static inline_notes_curly = ctRegex!(`~\{\s*(.+?)\}~`, "mg"); - static inline_curly_delimiter_open_and_close_regular = ctRegex!(`~\{\s*|\s*\}~`, "m"); - static inline_notes_delimiter_curly_regular = ctRegex!(`~\{[ ]*(.+?)\}~`, "m"); - static inline_notes_curly_sp = ctRegex!(`~\{[*+]+\s+(.+?)\}~`, "m"); - static inline_notes_curly_sp_asterisk = ctRegex!(`~\{[*]+\s+(.+?)\}~`, "m"); - static inline_notes_curly_sp_plus = ctRegex!(`~\{[+]+\s+(.+?)\}~`, "m"); - static inline_note_curly_delimiters = ctRegex!(`(~\{[*+]?\s*)(.+?)(\}~)`, "mg"); - static inline_notes_square = ctRegex!(`~\[\s*(.+?)\]~`, "mg"); - static inline_text_and_note_square_sp = ctRegex!(`(.+?)~\[[*+]+\s+(.+?)\]~`, "mg"); - static inline_text_and_note_square = ctRegex!(`(.+?)~\[\s*(.+?)\]~`, "mg"); - static inline_note_square_delimiters = ctRegex!(`(~\[\s*)(.+?)(\]~)`, "mg"); - static inline_curly_delimiter_open_regular = ctRegex!(`~\{\s*`, "m"); - static inline_curly_delimiter_open_symbol_star = ctRegex!(`~\{[*]\s`, "m"); - static inline_curly_delimiter_open_symbol_plus = ctRegex!(`~\{[+]\s`, "m"); - static inline_curly_delimiter_open_star_or_plus = ctRegex!(`~\{[+*]`, "m"); - static inline_curly_delimiter_close_regular = ctRegex!(`\s*\}~`, "m"); - static inline_text_and_note_curly = ctRegex!(`(?P.+?)(?:(?:[~])[{][*+ ]*)(?P.+?)(?:[}][~])`, "mg"); - static note_ref = ctRegex!(`^\S+?noteref_([0-9]+)`, "mg"); // {^{73.}^}#noteref_73 - static inline_url_generic = ctRegex!(`(?:^|[}(\[ ])(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_#]`, "mg"); - static inline_url = ctRegex!(`((?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)[a-zA-Z0-9_]\S*)`, "mg"); - static inline_link_naked_url = ctRegex!(`(?P^|[ ])(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!'"]?(?:[ ]|$))`, "mg"); - static inline_link_markup_regular = ctRegex!(`(?P^|[ ])\{\s*(?P.+?)\s*\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); - static inline_link_endnote_url_helper_punctuated = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+?)(?P[.,;:?!]?(?:[ ]|$))`, "mg"); - static inline_link_endnote_url_helper = ctRegex!(`\{~\^\s+(?P.+?)\}(?P(?:(?:https?|git):\/\/|¤?\.\.\/|¤?\.\/|¤|#)\S+)`, "mg"); - static image = ctRegex!(`([a-zA-Z0-9._-]+?\.(?:png|gif|jpg))`, "mg"); - /+ inline markup book index +/ - static book_index = ctRegex!(`^=\{\s*(.+?)\}$`, "m"); - static book_index_open = ctRegex!(`^=\{\s*([^}]+?)$`); - static book_index_close = ctRegex!(`^(.*?)\}$`, "m"); - /+ 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"); - /+ 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!(`^--[+~-]#$`); - /+ ignore outside code blocks +/ - static skip_from_regular_parse = ctRegex!(`^(--[+~-]#|-[\\]{2}-|=[.\\]{2}=)$`); - /+ 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]+)`); - /+ json +/ - static tailing_comma = ctRegex!(`,$`, "m"); - /+ 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)$`); - /+ 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+)`); - /+ 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)$"); - static newline = ctRegex!("\n", "mg"); - static strip_br = ctRegex!("^
\n|
\n*$"); - static space = ctRegex!(`[ ]`, "mg"); - static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); - static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); - 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"); - static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); - static src_fn = - ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); - static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); - static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); - static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); - static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); - static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); - /+ inline markup footnotes endnotes +/ - static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); - static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); - static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); - static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); - static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); - static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); - static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); - static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); - static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); - static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); - static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); - static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); - static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); - /+ 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"); - /+ inline markup font face mod +/ - static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); - static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); - static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); - static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); - static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); - static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); - static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); - static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); - static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); - static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); - static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); - static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - /+ table delimiters +/ - static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); - static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); - } -} diff --git a/src/sdp/compile_time_info.d b/src/sdp/compile_time_info.d deleted file mode 100644 index cf4d0a5..0000000 --- a/src/sdp/compile_time_info.d +++ /dev/null @@ -1,38 +0,0 @@ -/++ - compile_time_info -+/ -module sdp.compile_time_info; -template CompileTimeInfo() { - version(Windows) { - pragma(msg, "[ Windows compilation ]"); - enum os = "Windows"; - } else version(OSX) { - pragma(msg, "[ Mac OS X POSIX System compilation ]"); - enum os = "OSX"; - } else version(linux) { - pragma(msg, "[ Linux POSIX System compilation ]"); - enum os = "Linux"; - } else version(FreeBSD) { - pragma(msg, "[ FreeBSD POSIX System compilation ]"); - enum os = "FreeBSD"; - } else version(OpenBSD) { - pragma(msg, "[ OpenBSD POSIX System compilation ]"); - enum os = "OpenBSD"; - } else version(NetBSD) { - pragma(msg, "[ NetBSD POSIX System compilation ]"); - enum os = "NetBSD"; - } else version(DragonFlyBSD) { - pragma(msg, "[ DragonFlyBSD POSIX System compilation ]"); - enum os = "DragonFlyBSD"; - } else version(POSIX) { - pragma(msg, "[ POSIX System compilation ]"); - enum os = "POSIX"; - } else { - static assert(0, "OS not listed"); - } - version(D_LP64) { - enum bits = "64 bit"; - } else { - enum bits = "32 bit"; - } -} diff --git a/src/sdp/conf/compile_time_info.d b/src/sdp/conf/compile_time_info.d new file mode 100644 index 0000000..80f6e33 --- /dev/null +++ b/src/sdp/conf/compile_time_info.d @@ -0,0 +1,38 @@ +/++ + compile_time_info ++/ +module sdp.conf.compile_time_info; +template CompileTimeInfo() { + version(Windows) { + pragma(msg, "[ Windows compilation ]"); + enum os = "Windows"; + } else version(OSX) { + pragma(msg, "[ Mac OS X POSIX System compilation ]"); + enum os = "OSX"; + } else version(linux) { + pragma(msg, "[ Linux POSIX System compilation ]"); + enum os = "Linux"; + } else version(FreeBSD) { + pragma(msg, "[ FreeBSD POSIX System compilation ]"); + enum os = "FreeBSD"; + } else version(OpenBSD) { + pragma(msg, "[ OpenBSD POSIX System compilation ]"); + enum os = "OpenBSD"; + } else version(NetBSD) { + pragma(msg, "[ NetBSD POSIX System compilation ]"); + enum os = "NetBSD"; + } else version(DragonFlyBSD) { + pragma(msg, "[ DragonFlyBSD POSIX System compilation ]"); + enum os = "DragonFlyBSD"; + } else version(POSIX) { + pragma(msg, "[ POSIX System compilation ]"); + enum os = "POSIX"; + } else { + static assert(0, "OS not listed"); + } + version(D_LP64) { + enum bits = "64 bit"; + } else { + enum bits = "32 bit"; + } +} diff --git a/src/sdp/create_zip_file.d b/src/sdp/create_zip_file.d deleted file mode 100644 index 93e85ee..0000000 --- a/src/sdp/create_zip_file.d +++ /dev/null @@ -1,17 +0,0 @@ -module sdp.create_zip_file; -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 - } - } -} diff --git a/src/sdp/defaults.d b/src/sdp/defaults.d deleted file mode 100644 index a344f7f..0000000 --- a/src/sdp/defaults.d +++ /dev/null @@ -1,120 +0,0 @@ -/++ - default settings -+/ -module sdp.defaults; - -template InternalMarkup() { - struct InlineMarkup { - auto en_a_o = "【"; auto en_a_c = "】"; - auto en_b_o = "〖"; auto en_b_c = "〗"; - auto lnk_o = "┥"; auto lnk_c = "┝"; - auto url_o = "┤"; auto url_c = "├"; - auto mark_internal_site_lnk = "¤"; - auto nbsp = "░"; - auto br_line = "┘"; - auto br_nl = "┙"; - auto br_paragraph = "┚"; - 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 = "┚"; - auto tc_p = "┆"; - 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; - } - } -} -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_); - } - } -} diff --git a/src/sdp/imports_for_ao.d b/src/sdp/imports_for_ao.d deleted file mode 100644 index 34aa1e1..0000000 --- a/src/sdp/imports_for_ao.d +++ /dev/null @@ -1,41 +0,0 @@ -module sdp.imports_for_ao; -public import - sdp.abstraction_summary, - sdp.ao_abstract_doc_source, - sdp.ao_conf_make_meta, - sdp.ao_conf_make_meta_native, - sdp.ao_conf_make_meta_sdlang, - sdp.ao_defaults, - sdp.ao_doc_debugs, - sdp.ao_read_config_files, - sdp.ao_read_source_files, - sdp.ao_rgx, - sdp.output_hub, - sdp.paths_source; -/+ sdlang http://sdlang.org +/ -public import sdlang; -/+ aarchive https://github.com/rcythr/archive +/ -public import - archive.core, - archive.zip; -/+ std +/ -public import - // std.algorithm, - std.array, - // std.container, - std.digest.sha, - std.exception, - std.getopt, - std.process, - std.stdio, - // std.file, - // std.path, - std.range, - // std.range, - std.regex, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; diff --git a/src/sdp/imports_for_output.d b/src/sdp/imports_for_output.d deleted file mode 100644 index 20b3ba1..0000000 --- a/src/sdp/imports_for_output.d +++ /dev/null @@ -1,28 +0,0 @@ -module sdp.imports_for_output; -public 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; -public import - sdp.defaults, - sdp.output_epub3, - sdp.output_html, - sdp.output_rgx, - sdp.output_xmls, - sdp.source_sisupod, - sdp.create_zip_file, - sdp.paths_output; diff --git a/src/sdp/output/create_zip_file.d b/src/sdp/output/create_zip_file.d new file mode 100644 index 0000000..5380744 --- /dev/null +++ b/src/sdp/output/create_zip_file.d @@ -0,0 +1,17 @@ +module sdp.output.create_zip_file; +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 + } + } +} diff --git a/src/sdp/output/defaults.d b/src/sdp/output/defaults.d new file mode 100644 index 0000000..82a8d1a --- /dev/null +++ b/src/sdp/output/defaults.d @@ -0,0 +1,120 @@ +/++ + default settings ++/ +module sdp.output.defaults; + +template InternalMarkup() { + struct InlineMarkup { + auto en_a_o = "【"; auto en_a_c = "】"; + auto en_b_o = "〖"; auto en_b_c = "〗"; + auto lnk_o = "┥"; auto lnk_c = "┝"; + auto url_o = "┤"; auto url_c = "├"; + auto mark_internal_site_lnk = "¤"; + auto nbsp = "░"; + auto br_line = "┘"; + auto br_nl = "┙"; + auto br_paragraph = "┚"; + 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 = "┚"; + auto tc_p = "┆"; + 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; + } + } +} +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_); + } + } +} diff --git a/src/sdp/output/epub3.d b/src/sdp/output/epub3.d new file mode 100644 index 0000000..0f91c86 --- /dev/null +++ b/src/sdp/output/epub3.d @@ -0,0 +1,756 @@ +module sdp.output.epub3; +template outputEPub3() { + import sdp.output; + import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; + import + sdp.output.create_zip_file, + sdp.output.xmls, + sdp.output.xmls_css; + mixin InternalMarkup; + mixin outputXHTMLs; + string epub3_mimetypes() { + string o; + o = format(q"¶application/epub+zip¶") ~ "\n"; + return o; + } + string epub3_container_xml() { + string o; + o = format(q"¶¶") ~ "\n"; + o ~= format(q"¶ + + + ¶") ~ "\n\n"; + 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"¶ + + + + %s + main + %s + subtitle + %s + %s + %s + Copyright: %s + %s + urn:uuid:%s + + + + + + + + + + ¶", + uuid, + doc_matters.dochead_meta["title"]["full"], + doc_matters.dochead_meta["title"]["main"], + (doc_matters.dochead_meta["title"]["sub"].empty) + ? "" : doc_matters.dochead_meta["title"]["sub"], + (doc_matters.dochead_meta["creator"]["author"].empty) + ? "" : doc_matters.dochead_meta["creator"]["author"], + (doc_matters.dochead_meta["creator"]["author"].empty) + ? "" : doc_matters.dochead_meta["creator"]["author"], + doc_matters.language, + (doc_matters.dochead_meta["date"]["published"].empty) + ? "" : doc_matters.dochead_meta["date"]["published"], + (doc_matters.dochead_meta["rights"]["copyright"].empty) + ? "" : doc_matters.dochead_meta["rights"]["copyright"], + uuid, + uuid, + uuid, + (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), + ); + content ~= " " ~ "" ~ "\n "; + content ~= parts["manifest_documents"]; + // TODO sort jpg & png + content ~= " " ~ "" ~ "\n "; + foreach (image; doc_matters.image_list) { + content ~= format(q"¶ + ¶", + image.baseName.stripExtension, + (pth_epub3.doc_oebps_image(doc_matters.source_filename)).chompPrefix("OEBPS/"), + image, + image.extension.chompPrefix("."), + ); + } + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["spine"]; + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["guide"]; + content ~= " " ~ "" ~ "\n "; + content ~= "" ~ ""; + return content; + } + string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { + enum DomTags { none, open, close, close_and_open, open_still, } + auto markup = InlineMarkup(); + auto rgx = Rgx(); + string toc =format(" + + %s + + +
+
+

Contents

+
+ +
+ + \n"; + return toc; + } + string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { + int counter = 0; + string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere + auto markup = InlineMarkup(); + auto rgx = Rgx(); + enum DomTags { none, open, close, close_and_open, open_still, } + string toc = format(q"¶ + + + + %s%s + + + + + + + + + %s + + + %s + + ¶", + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" + : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author + uuid, // uuid + "3", // content depth + doc_matters.dochead_meta["title"]["full"], // title + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" + : doc_matters.dochead_meta["creator"]["author"], // author + ); + foreach (sect; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[sect]) { + if (obj.is_a == "heading") { + string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip; + string hashtag =(obj.heading_lev_markup <= 4) ? "" : ("#" ~ obj.ocn.to!string); + foreach_reverse (k; 0 .. 7) { + switch (obj.dom_markedup[k]) { + case DomTags.close : + toc ~= "\n "; + break; + case DomTags.close_and_open : + ++counter; + toc ~= "\n "; + toc ~= format(q"¶ + + + %s + + ¶", + counter, + _txt, + obj.segment_anchor_tag, + hashtag, + ); + break; + case DomTags.open : + ++counter; + toc ~= format(q"¶ + + + %s + + ¶", + counter, + _txt, + obj.segment_anchor_tag, + hashtag, + ); + break; + default : + break; + } + } + } + } + } + toc ~= format(q"¶ + ¶"); + return toc; + } + + void outputEPub3(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, + ) { + mixin SiSUoutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[][string] doc_epub3; + string[][string] doc_epub3_endnotes; + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string[string] oepbs_content_parts; + string suffix = ".xhtml"; + string[] doc_parts_; + foreach (part; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); + if (obj.is_a == "heading") { + switch (obj.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.heading_lev_markup) { + case 0: + top_level_headings[0] = ""; + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 1: + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 2: + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 3: + top_level_headings[3] = ""; + goto default; + default: + doc_parts_ ~= obj.segment_anchor_tag; + doc_epub3[obj.segment_anchor_tag] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); + doc_epub3[obj.segment_anchor_tag] ~= t[0]; + doc_epub3_endnotes[obj.segment_anchor_tag] ~= t[1]; + break; + } + break; + case 4: + segment_filename = obj.segment_anchor_tag; + doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case 5: .. case 7: + auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + } + break; + } + } else { + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "toc": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "para": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= to!string(t[0]); + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "group": + auto t = xhtml_format.group_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= to!string(t[0]); + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "block": + auto t = xhtml_format.block_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= to!string(t[0]); + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "poem": + break; + case "verse": + auto t = xhtml_format.verse_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= to!string(t[0]); + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "code": + doc_epub3[segment_filename] ~= xhtml_format.code(obj, _txt); + break; + case "table": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "endnote": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + break; + case "glossary": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "bibliography": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "blurb": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_epub3[segment_filename] ~= t[0]; + doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + } + break; + } + } + if (obj.is_a == "heading") { + if (obj.heading_lev_markup <= 4) { + oepbs_content_parts["manifest_documents"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + obj.segment_anchor_tag, + ); + oepbs_content_parts["spine"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + ); + oepbs_content_parts["guide"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + obj.segment_anchor_tag, + ); + } else if (obj.heading_lev_markup > 4) { + oepbs_content_parts["manifest_documents"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + oepbs_content_parts["spine"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + oepbs_content_parts["guide"] ~= + format(q"¶ + ¶", + obj.segment_anchor_tag, + obj.obj_cite_number, + obj.segment_anchor_tag, + obj.obj_cite_number, + ); + } + } + } + } + /+ epub specific documents +/ + auto mimetypes = epub3_mimetypes; + auto meta_inf_container_xml = epub3_container_xml; + auto oebps_toc_ncx = epub2_oebps_toc_ncx(doc_abstraction, doc_matters); + auto oebps_toc_nav_xhtml = epub3_oebps_toc_nav_xhtml(doc_abstraction, doc_matters); + auto oebps_content_opf = epub3_oebps_content(doc_abstraction, doc_matters, oepbs_content_parts); + epub3_write_output_files( + doc_matters, + doc_epub3, + doc_epub3_endnotes, + mimetypes, + meta_inf_container_xml, + oebps_toc_nav_xhtml, + oebps_toc_ncx, + oebps_content_opf, + doc_parts_, + ); + } + void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( + M doc_matters, + D doc_epub3, + E doc_epub3_endnotes, + Mt mimetypes, + Mic meta_inf_container_xml, + Otnx oebps_toc_nav_xhtml, + Otn oebps_toc_ncx, + Oc oebps_content_opf, + string[] doc_parts_, + ) { + debug(asserts) { + static assert(is(typeof(doc_epub3) == string[][string])); + static assert(is(typeof(mimetypes) == string)); + static assert(is(typeof(meta_inf_container_xml) == string)); + static assert(is(typeof(oebps_toc_nav_xhtml) == string)); + static assert(is(typeof(oebps_toc_ncx) == string)); + static assert(is(typeof(oebps_content_opf) == string)); + } + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_epub3 = SiSUpathsEPUB!()(src_path_info, lng); + auto xhtml_format = outputXHTMLs(); + /+ zip file +/ + auto fn_epub = pth_epub3.epub_file(doc_matters.source_filename); + auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); + /+ zip archive member files +/ + try { + if (!exists(pth_epub3.base)) { + pth_epub3.base.mkdirRecurse; + } + debug(epub_output) { + if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename))) { + pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename))) { + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename).mkdirRecurse; + } + } + { /+ OEBPS/[segments].xhtml (the document contents) +/ + foreach (seg_filename; doc_matters.segnames_lv_0_to_4) { + string fn = pth_epub3.fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + debug(epub_output) { + string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); + auto f = File(fn_dbg, "w"); + } + foreach (docseg; doc_epub3[seg_filename]) { + debug(epub_output) { f.writeln(docseg); } + zip_data.write(docseg.dup); + } + foreach (docseg; doc_epub3_endnotes[seg_filename]) { + debug(epub_output) { f.writeln(docseg); } + zip_data.write(docseg.dup); + } + debug(epub_output) { f.writeln(xhtml_format.tail); } + zip_data.write(xhtml_format.tail.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + /+ create the zip file +/ + createZipFile!()(fn_epub, zip.build()); + } + } + string fn; + debug(epub_output) { string fn_dbg; } + File f; + { /+ mimetypes (identify zip file type) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.source_filename); + File(fn_dbg, "w").writeln(mimetypes); + } + fn = pth_epub3.fn_mimetypes(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(mimetypes.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + { /+ META-INF/container.xml (identify doc root) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.source_filename); + File(fn_dbg, "w").writeln(meta_inf_container_xml); + } + fn = pth_epub3.fn_dmi_container_xml(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(meta_inf_container_xml.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); + } + fn = pth_epub3.fn_oebps_toc_nav_xhtml(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_toc_nav_xhtml.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/toc.ncx (navigation toc epub2) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_toc_ncx); + } + fn = pth_epub3.fn_oebps_toc_ncx(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_toc_ncx.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/content.opf (doc manifest) +/ + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.source_filename); + File(fn_dbg, "w").writeln(oebps_content_opf); + } + fn = pth_epub3.fn_oebps_content_opf(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(oebps_content_opf.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + { /+ OEBPS/_sisu/image (images) +/ + foreach (image; doc_matters.image_list) { + debug(epub_output) { + 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_output) { + debug(epub_images) { + writeln( + doc_matters.src_path_info.image_root, image, " -> ", + pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename), "/", image + ); + } + } + auto fn_src = doc_matters.src_path_info.image_root ~ image; + auto fn_out = pth_epub3.doc_oebps_image(doc_matters.source_filename).to!string ~ "/" ~ image; + if (exists(fn_src)) { + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write(cast(char[]) ((fn_src).read)); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + } + } + } + { /+ OEBPS/epub.css +/ + auto css = SiSUcss(); + debug(epub_output) { + fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.source_filename); + File(fn_dbg, "w").writeln(css.epub_css); + } + fn = pth_epub3.fn_oebps_css(doc_matters.source_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(css.epub_css.dup); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + } + catch (ErrnoException ex) { + // Handle error + } + debug(epub_archive) { + if (exists(fn_epub)) { + try { + auto zipped = new ZipArchive((fn_epub).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln(filename, " length ", data.length); + } + } + catch (ZipException ex) { + // Handle errors + } + } + } + } + +} diff --git a/src/sdp/output/html.d b/src/sdp/output/html.d new file mode 100644 index 0000000..6712469 --- /dev/null +++ b/src/sdp/output/html.d @@ -0,0 +1,447 @@ +module sdp.output.html; +template outputHTML() { + import sdp.output; + import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; + import + sdp.output.create_zip_file, + sdp.output.xmls, + sdp.output.xmls_css; + mixin outputXHTMLs; + + void scroll(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, + ) { + mixin SiSUoutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[] doc_html; + string[] doc; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.scroll) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "toc": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "para": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + doc_html ~= xhtml_format.quote_scroll(obj, _txt); + break; + case "group": + doc_html ~= xhtml_format.group_scroll(obj, _txt); + break; + case "block": + doc_html ~= xhtml_format.block_scroll(obj, _txt); + break; + case "poem": + break; + case "verse": + doc_html ~= xhtml_format.verse_scroll(obj, _txt, suffix); + break; + case "code": + doc_html ~= xhtml_format.code(obj, _txt); + break; + case "table": + doc_html ~= xhtml_format.table(obj, _txt); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "heading": + doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); + break; + case "endnote": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "glossary": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "bibliography": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "bookindex": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + case "blurb": + doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + } + } + } + doc = xhtml_format.html_scroll_head(doc_matters) ~ doc_html ~ xhtml_format.tail; + scroll_write_output(doc_matters, doc); + } + void scroll_write_output(M,C)( + M doc_matters, + C doc, + ) { + debug(asserts) { + static assert(is(typeof(doc) == string[])); + } + string fn_src = doc_matters.source_filename; + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + try { + if (!exists(pth_html.base)) { + pth_html.base.mkdirRecurse; + } + auto f = File(pth_html.fn_scroll(fn_src), "w"); + foreach (o; doc) { + f.writeln(o); + } + } + catch (ErrnoException ex) { + // Handle error + } + } + void seg(D,I)( + auto return ref const D doc_abstraction, + auto return ref I doc_matters, + ) { + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto xhtml_format = outputXHTMLs(); + string[][string] doc_html; + string[][string] doc_html_endnotes; + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string suffix = ".html"; + foreach (part; doc_matters.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj, obj.text); + if (obj.is_a == "heading") { + switch (obj.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.heading_lev_markup) { + case 0: + top_level_headings[0] = ""; + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 1: + top_level_headings[1] = ""; + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 2: + top_level_headings[2] = ""; + top_level_headings[3] = ""; + goto default; + case 3: + top_level_headings[3] = ""; + goto default; + default: + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + top_level_headings[obj.heading_lev_markup] = t[0]; + break; + } + break; + case 4: + segment_filename = obj.segment_anchor_tag; + doc_html[segment_filename] ~= xhtml_format.html_seg_head(doc_matters); + 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, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 5: .. case 7: + auto t = xhtml_format.heading_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); + } + break; + } + } else { + switch (obj.use) { + case "frontmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "toc": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "body": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "para": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + case "block": + switch (obj.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "group": + auto t = xhtml_format.group_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "block": + auto t = xhtml_format.block_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "poem": + break; + case "verse": + auto t = xhtml_format.verse_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= to!string(t[0]); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "code": + doc_html[segment_filename] ~= xhtml_format.code(obj, _txt); + break; + case "table": + doc_html[segment_filename] ~= xhtml_format.table(obj, _txt); + doc_html_endnotes[segment_filename] ~= ""; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "backmatter": + switch (obj.is_of) { + case "para": + switch (obj.is_a) { + case "endnote": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + break; + case "glossary": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bibliography": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "blurb": + auto t = xhtml_format.para_seg(obj, _txt, suffix); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); + } + break; + } + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); + } + break; + } + break; + case "comment": + break; + default: + if ((doc_matters.opt_action_bool["debug"])) { + writeln(__FILE__, ":", __LINE__, ": ", obj.use); + } + break; + } + } + } + } + seg_write_output(doc_matters, doc_html, doc_html_endnotes); + } + void seg_write_output(M,D,E)( + M doc_matters, + D doc_html, + E doc_html_endnotes, + ) { + debug(asserts) { + static assert(is(typeof(doc_html) == string[][string])); + } + mixin SiSUoutputRgxInit; + auto rgx = Rgx(); + auto src_path_info = doc_matters.src_path_info; + string fn_rel_pth = doc_matters.source_filename; + string lng = doc_matters.language; + auto pth_html = SiSUpathsHTML!()(src_path_info, lng); + auto xhtml_format = outputXHTMLs(); + auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); + try { + if (!exists(pth_html.seg(doc_matters.source_filename))) { + pth_html.seg(doc_matters.source_filename).mkdirRecurse; + } + foreach (seg_filename; doc_matters.segnames) { + auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); + foreach (docseg; doc_html[seg_filename]) { + f.writeln(docseg); + } + foreach (docseg; doc_html_endnotes[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); + } + } + catch (ErrnoException ex) { + // handle error + } + } + void css(M)( + auto return ref M doc_matters, + ) { + auto css = SiSUcss(); + auto pth_html = SiSUpathsHTML!()(doc_matters.src_path_info, doc_matters.language); + try { + if (!exists(pth_html.css)) { + (pth_html.css).mkdirRecurse; + } + auto f = File(pth_html.fn_css, "w"); + f.writeln(css.html_css); + } + catch (ErrnoException ex) { + // Handle error + } + } +} diff --git a/src/sdp/output/hub.d b/src/sdp/output/hub.d new file mode 100644 index 0000000..79b8996 --- /dev/null +++ b/src/sdp/output/hub.d @@ -0,0 +1,79 @@ +/++ + output hub
+ check & generate output types requested ++/ +module sdp.output.hub; +template outputHub() { + import sdp.output, + sdp.output.epub3, + sdp.output.html, + sdp.output.xmls, + sdp.output.source_sisupod, + sdp.output.create_zip_file, + sdp.output.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"]) + || (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"); } + } + 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"); + } + } +} diff --git a/src/sdp/output/package.d b/src/sdp/output/package.d new file mode 100644 index 0000000..58a6ae8 --- /dev/null +++ b/src/sdp/output/package.d @@ -0,0 +1,20 @@ +module sdp.output; +public import + std.algorithm, + std.array, + std.container, + std.exception, + std.path, + std.process, + std.range, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + // std.uni, + std.utf; +public import + sdp.output.defaults, + sdp.output.paths_output, + sdp.output.rgx; diff --git a/src/sdp/output/paths_output.d b/src/sdp/output/paths_output.d new file mode 100644 index 0000000..3edcb67 --- /dev/null +++ b/src/sdp/output/paths_output.d @@ -0,0 +1,288 @@ +/++ + default settings ++/ +module sdp.output.paths_output; +import std.array, + std.path, + std.regex, + std.stdio; +import sdp.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!()(); + 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); + } + 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!()(); + 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/output/paths_source.d b/src/sdp/output/paths_source.d new file mode 100644 index 0000000..7658df5 --- /dev/null +++ b/src/sdp/output/paths_source.d @@ -0,0 +1,60 @@ +/++ + read configuration files
+ - read config files
+ ao_config_files.d ++/ +module sdp.output.paths_source; +import std.array, + std.path, + std.regex, + std.stdio; +import sdp.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/output/rgx.d b/src/sdp/output/rgx.d new file mode 100644 index 0000000..6fdc876 --- /dev/null +++ b/src/sdp/output/rgx.d @@ -0,0 +1,73 @@ +/++ + regex: regular expressions used in sisu document parser ++/ +module sdp.output.rgx; +template SiSUoutputRgxInit() { + import sdp.output.defaults; + struct Rgx { + static newline = ctRegex!("\n", "mg"); + static strip_br = ctRegex!("^
\n|
\n*$"); + static space = ctRegex!(`[ ]`, "mg"); + static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); + static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); + 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"); + static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); + static src_fn = + ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); + static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); + static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); + static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); + static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); + static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); + /+ inline markup footnotes endnotes +/ + static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); + static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); + static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); + static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); + static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); + static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); + static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); + static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); + static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); + static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); + static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); + static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); + static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); + /+ 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"); + /+ inline markup font face mod +/ + static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); + static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); + static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); + static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); + static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); + static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); + static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); + static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); + static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); + static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); + static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); + static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); + /+ table delimiters +/ + static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); + static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); + static xhtml_ampersand = ctRegex!(`[&]`); // & + static xhtml_quotation = ctRegex!(`[&]`); // " + static xhtml_less_than = ctRegex!(`[<]`); // < + static xhtml_greater_than = ctRegex!(`[>]`); // > + static xhtml_line_break = ctRegex!(` [\\]{2}`); //
+ } +} diff --git a/src/sdp/output/source_sisupod.d b/src/sdp/output/source_sisupod.d new file mode 100644 index 0000000..6c326ac --- /dev/null +++ b/src/sdp/output/source_sisupod.d @@ -0,0 +1,208 @@ +module sdp.output.source_sisupod; +template SiSUpod() { + import sdp.output; + import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; + import + sdp.output.create_zip_file, + sdp.output.xmls; + void SiSUpod(T)(T doc_matters) { + 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)); + try { + /+ 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; + } + } + debug(sisupod) { + writeln(__LINE__, ": ", + doc_matters.source_filename, " -> ", + pth_sisupod_filesystem.fn_doc( + doc_matters.source_filename, + )); + } + 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( + 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()); + } + } + } + } + } + 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); + } + } + 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 + } + } + + } + catch (ErrnoException ex) { + // Handle error + } + } +} diff --git a/src/sdp/output/xmls.d b/src/sdp/output/xmls.d new file mode 100644 index 0000000..7a057ad --- /dev/null +++ b/src/sdp/output/xmls.d @@ -0,0 +1,800 @@ +module sdp.output.xmls; +template outputXHTMLs() { + import sdp.output; + import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; + import + sdp.output.create_zip_file, + sdp.output.xmls, + sdp.output.xmls_css; + mixin SiSUoutputRgxInit; + struct outputXHTMLs { + auto rgx = Rgx(); + string special_characters(O)( + auto return ref const O obj, + string _txt + ){ + _txt = (_txt) + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_quotation, """) + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.nbsp_char, " "); + if (!(obj.is_a == "code")) { + _txt = (_txt) + .replaceAll(rgx.xhtml_line_break, "
"); + } + return _txt; + } + string font_face(string _txt){ + _txt = (_txt) + .replaceAll(rgx.inline_emphasis, ("$1")) + .replaceAll(rgx.inline_bold, ("$1")) + .replaceAll(rgx.inline_underscore, ("$1")) + .replaceAll(rgx.inline_italics, ("$1")) + .replaceAll(rgx.inline_superscript, ("$1")) + .replaceAll(rgx.inline_subscript, ("$1")) + .replaceAll(rgx.inline_strike, ("$1")) + .replaceAll(rgx.inline_insert, ("$1")) + .replaceAll(rgx.inline_mono, ("$1")) + .replaceAll(rgx.inline_cite, ("$1")); + return _txt; + } + string _xhtml_anchor_tags(const(string[]) anchor_tags) { + string tags=""; + if (anchor_tags.length > 0) { + foreach (tag; anchor_tags) { + if (!(tag.empty)) { + tags ~= ""; + } + } + } + return tags; + } + auto html_scroll_head(Dm)( + Dm doc_matters, + ) { + string o; + o = format(q"¶ + + + + + %s%s + + + + + + + + + + + + + + + + + + + + + ¶", + doc_matters.dochead_meta["title"]["full"], + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : ", " ~ doc_matters.dochead_meta["creator"]["author"], + doc_matters.language, + ); + return o; + } + auto html_seg_head(Dm)( + Dm doc_matters, + ) { + string o; + o = format(q"¶ + + + + + %s%s + + + + + + + + + + + + + + + + + + + + + + ¶", + doc_matters.dochead_meta["title"]["full"], + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" + : ", " ~ doc_matters.dochead_meta["creator"]["author"], + doc_matters.language, + ); + return o; + } + auto epub3_seg_head(Dm)( + Dm doc_matters, + ) { + string html_base = format(q"¶ + ¶", + ); + string html_simple = format(q"¶ + ¶", + doc_matters.language, + doc_matters.language, + ); + string html_strict = format(q"¶ + ¶", + doc_matters.language, + doc_matters.language, + ); + string o; + o = format(q"¶%s + + + %s%s + + + + + + + + + + + + + + + + + + + + ¶", + html_simple, + doc_matters.dochead_meta["title"]["full"], + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" + : ", " ~ doc_matters.dochead_meta["creator"]["author"], + doc_matters.dochead_meta["title"]["full"], + (doc_matters.dochead_meta["creator"]["author"].empty) ? "" + : ", " ~ doc_matters.dochead_meta["creator"]["author"], + doc_matters.language, + ); + return o; + } + auto tail() { + string o; + o = format(q"¶ + + + ¶"); + return o; + } + auto inline_links(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + string seg_scroll = "seg", + ) { + if (obj.inline_links) { + if ((seg_scroll == "scroll") + && _txt.match(rgx.mark_internal_site_lnk)) { + _txt = (_txt).replaceAll( + rgx.inline_seg_link, + "$1"); + } + _txt = (_txt).replaceAll( + rgx.inline_link_fn_suffix, + ("$1" ~ _suffix)); + _txt = (_txt).replaceAll( + rgx.inline_link, + ("$1")); + _txt = (_txt).replaceAll( + rgx.mark_internal_site_lnk, + "" + ); + } + debug(markup_links) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.inline_links, + "): ", obj.is_a, ": ", + obj.text + ); + } + } + debug(markup) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.inline_links, + "): ", obj.is_a, ": ", + obj.text + ); + } + } + return _txt; + } + auto inline_notes_scroll(O)( + auto return ref const O obj, + string _txt, + ) { + if (obj.inline_notes_reg) { + _txt = (_txt).replaceAll( + rgx.inline_notes_delimiter_al_regular_number_note, + (" $1 ") + ); + } + debug(markup_endnotes) { + if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); + } + } + debug(markup) { + if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); + } + } + return _txt; + } + auto inline_notes_seg(O)( + auto return ref const O obj, + string _txt, + ) { + string[] _endnotes; + if (obj.inline_notes_reg) { + /+ need markup for text, and separated footnote +/ + foreach(m; _txt.matchAll(rgx.inline_notes_delimiter_al_regular_number_note)) { + _endnotes ~= format( + "%s%s%s%s\n %s%s%s%s%s\n %s\n%s", + "

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

" + ); + } + _txt = (_txt).replaceAll( + rgx.inline_notes_delimiter_al_regular_number_note, + (" $1 ") + ); + } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { + debug(markup) { + writeln(__LINE__, " endnote: ", obj.is_a, ": ", obj.text); + } + } + auto t = tuple( + _txt, + _endnotes, + ); + return t; + } + auto inline_markup_scroll(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + ) { + _txt = inline_links(obj, _txt, _suffix, "scroll"); + _txt = inline_notes_scroll(obj, _txt); + return _txt; + } + auto inline_markup_seg(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + ) { + _txt = inline_links(obj, _txt, _suffix, "seg"); + auto t = inline_notes_seg(obj, _txt); + return t; + } + auto toc_seg(O)( + auto return ref const O obj, + string _txt, + ) { + string o; + o = format(q"¶
+

+ %s +

+
¶", + obj.is_a, + obj.indent_hang, + obj.indent_base, + _txt, + ); + return o; + } + auto heading(O)( + auto return ref const O obj, + string _txt, + string _type="html", + ) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + string _horizontal_rule = "
"; + if ((_type != "html") + || (obj.heading_lev_markup == 0 || obj.heading_lev_markup > 4)) { + _horizontal_rule = ""; + } + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶%s +
+ %s + %s + +
¶", + _horizontal_rule, + obj.heading_lev_markup, + obj.is_a, + tags, + _txt, + obj.heading_lev_markup, + ); + } else { + o = format(q"¶%s +
+ + %s + %s + +
¶", + _horizontal_rule, + obj.obj_cite_number, + obj.obj_cite_number, + obj.heading_lev_markup, + obj.is_a, + obj.obj_cite_number, + obj.obj_cite_number, + tags, + _txt, + obj.heading_lev_markup, + ); + } + return o; + } + auto heading_scroll(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + ) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + _txt = inline_markup_scroll(obj, _txt, _suffix); + string o = heading(obj, _txt); + return o; + } + auto heading_seg(O)( + auto return ref const O obj, + string _txt, + string _suffix = ".html", + string _type = "html", + ) { + auto t = inline_markup_seg(obj, _txt, _suffix); + _txt = t[0]; + string[] _endnotes = t[1]; + string o = heading(obj, _txt, _type); + auto u = tuple( + o, + _endnotes, + ); + return u; + } + auto para(O)( + auto return ref const O obj, + string _txt, + ) { + auto tags = _xhtml_anchor_tags(obj.anchor_tags); + _txt = font_face(_txt); + string o; + _txt = (obj.bullet) ? ("●  " ~ _txt) : _txt; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

%s + %s +

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

%s + %s +

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

+ %s +

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

+ %s +

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

+ %s +

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

+ %s +

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

%s

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

%s

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

%s

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

%s

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

%s + + %s +
+ %s +

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + tags, + _txt, + _note + ); + return o; + } + auto endnote(O)( + auto return ref const O obj, + string _txt, + ) { + string o; + o = format(q"¶

+ %s +

¶", + obj.is_a, + obj.indent_hang, + obj.indent_base, + _txt + ); + return o; + } + auto code(O)( + auto return ref const O obj, + string _txt, + ) { + string o; + if (obj.obj_cite_number.empty) { + o = format(q"¶
+

%s

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

%s

+
¶", + obj.obj_cite_number, + obj.obj_cite_number, + obj.is_a, + obj.obj_cite_number, + _txt + ); + } + return o; + } + } +} diff --git a/src/sdp/output/xmls_css.d b/src/sdp/output/xmls_css.d new file mode 100644 index 0000000..6bb493a --- /dev/null +++ b/src/sdp/output/xmls_css.d @@ -0,0 +1,869 @@ +/++ + default css settings ++/ +module sdp.output.xmls_css; +template SiSUcss() { + auto SiSUcss() { + string css_shared=" + body { + color: black; + background: #ffffff; + background-color: #ffffff; + } + a:link { + color: #003399; + text-decoration: none; + } + a:visited { + color: #003399; + text-decoration: none; + } + a:hover { + color: #000000; + background-color: #f9f9aa; + } + a.lnkocn:link { + color: #777777; + text-decoration: none; + } + a:hover img { + background-color: #ffffff; + } + a:active { + color: #003399; + text-decoration: underline; + } + div { + margin-left: 0; + margin-right: 0; + } + div.p { + margin-left: 5%; + margin-right: 1%; + } + .norm, .bold, .verse, .group, .block, .alt { + line-height: 133%; + margin-left: 0em; + margin-right: 2em; + margin-top: 12px; + margin-bottom: 0px; + padding-left: 0em; + text-indent: 0em; + } + p, h0, h1, h2, h3, h4, h5, h6, h7 { + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-size: 100%; + font-weight: normal; + line-height: 133%; + text-align: justify; + margin-left: 0em; + margin-right: 2em; + text-indent: 0mm; + margin-top: 0.8em; + margin-bottom: 0.8em; + } + /* spaced */ + p.spaced { white-space: pre; } + /* indent */ + p.norm { } + p.i1 { padding-left: 1em; } + p.i2 { padding-left: 2em; } + p.i3 { padding-left: 3em; } + p.i4 { padding-left: 4em; } + p.i5 { padding-left: 5em; } + p.i6 { padding-left: 6em; } + p.i7 { padding-left: 7em; } + p.i8 { padding-left: 8em; } + p.i9 { padding-left: 9em; } + /* hanging indent */ + p[indent=\"h0i0\"] { + padding-left: 0em; + text-indent: 0em; + } + p[indent=\"h0i1\"] { + padding-left: 1em; + text-indent: -1em; + } + p[indent=\"h0i2\"] { + padding-left: 2em; + text-indent: -2em; + } + p[indent=\"h0i3\"] { + padding-left: 3em; + text-indent: -3em; + } + p[indent=\"h0i4\"] { + padding-left: 4em; + text-indent: -4em; + } + p[indent=\"h0i5\"] { + padding-left: 5em; + text-indent: -5em; + } + p[indent=\"h0i6\"] { + padding-left: 6em; + text-indent: -6em; + } + p[indent=\"h0i7\"] { + padding-left: 7em; + text-indent: -7em; + } + p[indent=\"h0i8\"] { + padding-left: 8em; + text-indent: -8em; + } + p[indent=\"h0i9\"] { + padding-left: 9em; + text-indent: -9em; + } + p[indent=\"h1i0\"] { + padding-left: 0em; + text-indent: 1em; + } + p[indent=\"h1i1\"] { + padding-left: 1em; + text-indent: 0em; + } + p[indent=\"h1i2\"] { + padding-left: 2em; + text-indent: -1em; + } + p[indent=\"h1i3\"] { + padding-left: 3em; + text-indent: -2em; + } + p[indent=\"h1i4\"] { + padding-left: 4em; + text-indent: -3em; + } + p[indent=\"h1i5\"] { + padding-left: 5em; + text-indent: -4em; + } + p[indent=\"h1i6\"] { + padding-left: 6em; + text-indent: -5em; + } + p[indent=\"h1i7\"] { + padding-left: 7em; + text-indent: -6em; + } + p[indent=\"h1i8\"] { + padding-left: 8em; + text-indent: -7em; + } + p[indent=\"h1i9\"] { + padding-left: 9em; + text-indent: -8em; + } + p[indent=\"h2i0\"] { + padding-left: 0em; + text-indent: 2em; + } + p[indent=\"h2i1\"] { + padding-left: 1em; + text-indent: 1em; + } + p[indent=\"h2i2\"] { + padding-left: 2em; + text-indent: 0em; + } + p[indent=\"h2i3\"] { + padding-left: 3em; + text-indent: -1em; + } + p[indent=\"h2i4\"] { + padding-left: 4em; + text-indent: -2em; + } + p[indent=\"h2i5\"] { + padding-left: 5em; + text-indent: -3em; + } + p[indent=\"h2i6\"] { + padding-left: 6em; + text-indent: -4em; + } + p[indent=\"h2i7\"] { + padding-left: 7em; + text-indent: -5em; + } + p[indent=\"h2i8\"] { + padding-left: 8em; + text-indent: -6em; + } + p[indent=\"h2i9\"] { + padding-left: 9em; + text-indent: -7em; + } + p[indent=\"h3i0\"] { + padding-left: 0em; + text-indent: 3em; + } + p[indent=\"h3i1\"] { + padding-left: 1em; + text-indent: 2em; + } + p[indent=\"h3i2\"] { + padding-left: 2em; + text-indent: 1em; + } + p[indent=\"h3i3\"] { + padding-left: 3em; + text-indent: 0em; + } + p[indent=\"h3i4\"] { + padding-left: 4em; + text-indent: -1em; + } + p[indent=\"h3i5\"] { + padding-left: 5em; + text-indent: -2em; + } + p[indent=\"h3i6\"] { + padding-left: 6em; + text-indent: -3em; + } + p[indent=\"h3i7\"] { + padding-left: 7em; + text-indent: -4em; + } + p[indent=\"h3i8\"] { + padding-left: 8em; + text-indent: -5em; + } + p[indent=\"h3i9\"] { + padding-left: 9em; + text-indent: -6em; + } + p[indent=\"h4i0\"] { + padding-left: 0em; + text-indent: 4em; + } + p[indent=\"h4i1\"] { + padding-left: 1em; + text-indent: 3em; + } + p[indent=\"h4i2\"] { + padding-left: 2em; + text-indent: 2em; + } + p[indent=\"h4i3\"] { + padding-left: 3em; + text-indent: 1em; + } + p[indent=\"h4i4\"] { + padding-left: 4em; + text-indent: 0em; + } + p[indent=\"h4i5\"] { + padding-left: 5em; + text-indent: -1em; + } + p[indent=\"h4i6\"] { + padding-left: 6em; + text-indent: -2em; + } + p[indent=\"h4i7\"] { + padding-left: 7em; + text-indent: -3em; + } + p[indent=\"h4i8\"] { + padding-left: 8em; + text-indent: -4em; + } + p[indent=\"h4i9\"] { + padding-left: 9em; + text-indent: -5em; + } + p[indent=\"h5i0\"] { + padding-left: 0em; + text-indent: 5em; + } + p[indent=\"h5i1\"] { + padding-left: 1em; + text-indent: 4em; + } + p[indent=\"h5i2\"] { + padding-left: 2em; + text-indent: 3em; + } + p[indent=\"h5i3\"] { + padding-left: 3em; + text-indent: 2em; + } + p[indent=\"h5i4\"] { + padding-left: 4em; + text-indent: 1em; + } + p[indent=\"h5i5\"] { + padding-left: 5em; + text-indent: 0em; + } + p[indent=\"h5i6\"] { + padding-left: 6em; + text-indent: -1em; + } + p[indent=\"h5i7\"] { + padding-left: 7em; + text-indent: -2em; + } + p[indent=\"h5i8\"] { + padding-left: 8em; + text-indent: -3em; + } + p[indent=\"h5i9\"] { + padding-left: 9em; + text-indent: -4em; + } + p[indent=\"h6i0\"] { + padding-left: 0em; + text-indent: 6em; + } + p[indent=\"h6i1\"] { + padding-left: 1em; + text-indent: 5em; + } + p[indent=\"h6i2\"] { + padding-left: 2em; + text-indent: 4em; + } + p[indent=\"h6i3\"] { + padding-left: 3em; + text-indent: 3em; + } + p[indent=\"h6i4\"] { + padding-left: 4em; + text-indent: 2em; + } + p[indent=\"h6i5\"] { + padding-left: 5em; + text-indent: 1em; + } + p[indent=\"h6i6\"] { + padding-left: 6em; + text-indent: 0em; + } + p[indent=\"h6i7\"] { + padding-left: 7em; + text-indent: -1em; + } + p[indent=\"h6i8\"] { + padding-left: 8em; + text-indent: -2em; + } + p[indent=\"h6i9\"] { + padding-left: 9em; + text-indent: -3em; + } + p[indent=\"h7i0\"] { + padding-left: 0em; + text-indent: 7em; + } + p[indent=\"h7i1\"] { + padding-left: 1em; + text-indent: 6em; + } + p[indent=\"h7i2\"] { + padding-left: 2em; + text-indent: 5em; + } + p[indent=\"h7i3\"] { + padding-left: 3em; + text-indent: 4em; + } + p[indent=\"h7i4\"] { + padding-left: 4em; + text-indent: 3em; + } + p[indent=\"h7i5\"] { + padding-left: 5em; + text-indent: 2em; + } + p[indent=\"h7i6\"] { + padding-left: 6em; + text-indent: 1em; + } + p[indent=\"h7i7\"] { + padding-left: 7em; + text-indent: 0em; + } + p[indent=\"h7i8\"] { + padding-left: 8em; + text-indent: -1em; + } + p[indent=\"h7i9\"] { + padding-left: 9em; + text-indent: -2em; + } + p[indent=\"h8i0\"] { + padding-left: 0em; + text-indent: 8em; + } + p[indent=\"h8i1\"] { + padding-left: 1em; + text-indent: 7em; + } + p[indent=\"h8i2\"] { + padding-left: 2em; + text-indent: 6em; + } + p[indent=\"h8i3\"] { + padding-left: 3em; + text-indent: 5em; + } + p[indent=\"h8i4\"] { + padding-left: 4em; + text-indent: 4em; + } + p[indent=\"h8i5\"] { + padding-left: 5em; + text-indent: 3em; + } + p[indent=\"h8i6\"] { + padding-left: 6em; + text-indent: 2em; + } + p[indent=\"h8i7\"] { + padding-left: 7em; + text-indent: 1em; + } + p[indent=\"h8i8\"] { + padding-left: 8em; + text-indent: 0em; + } + p[indent=\"h8i9\"] { + padding-left: 9em; + text-indent: -1em; + } + p[indent=\"h9i0\"] { + padding-left: 0em; + text-indent: 9em; + } + p[indent=\"h9i1\"] { + padding-left: 1em; + text-indent: 8em; + } + p[indent=\"h9i2\"] { + padding-left: 2em; + text-indent: 7em; + } + p[indent=\"h9i3\"] { + padding-left: 3em; + text-indent: 6em; + } + p[indent=\"h9i4\"] { + padding-left: 4em; + text-indent: 5em; + } + p[indent=\"h9i5\"] { + padding-left: 5em; + text-indent: 4em; + } + p[indent=\"h9i6\"] { + padding-left: 6em; + text-indent: 3em; + } + p[indent=\"h9i7\"] { + padding-left: 7em; + text-indent: 2em; + } + p[indent=\"h9i8\"] { + padding-left: 8em; + text-indent: 1em; + } + p[indent=\"h9i9\"] { + padding-left: 9em; + text-indent: 0em; + } + p.block { + white-space: pre; + } + p.group { } + p.alt { } + p.verse { + white-space: pre; + margin-bottom: 6px; + } + p.code { + font-family: inconsolata, andale mono, courier new, courier, monospace; + font-size: 90%; + text-align: left; + background-color: #eeeeee; + white-space: pre; + margin-top: 0px; + margin-bottom: 0px; + } + p.caption { + text-align: left; + font-size: 80%; + display: inline; + } + p.endnote { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-right: 15mm; + } + p.endnote_indent { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-left: 2em; + margin-right: 15mm; + } + p.center { + text-align: center; + } + p.bold { + font-weight: bold; + } + p.bold_left { + font-weight: bold; + text-align: left; + } + p.centerbold { + text-align: center; + font-weight: bold; + } + p.em { + font-weight: bold; + font-style: normal; + background: #fff3b6; + } + p.small { + font-size: 80%; + margin-top: 0px; + margin-bottom: 0px; + margin-right: 6px; + text-align: left; + } + .tiny, .tiny_left, .tiny_right, .tiny_center { + font-size: 10px; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 6px; + text-align: left; + } + p.tiny { } + p.tiny_left { + margin-left: 0px; + margin-right: 0px; + text-align: left; + } + p.tiny_right { + margin-right: 1em; + text-align: right; + } + p.tiny_center { + margin-left: 0px; + margin-right: 0px; + text-align: center; + } + p.concordance_word { + line-height: 150%; + font-weight: bold; + display: inline; + margin-top: 4px; + margin-bottom: 1px; + } + p.concordance_count { + font-size: 80%; + color: #777777; + display: inline; + margin-left: 0em; + } + p.concordance_object { + font-size: 80%; + line-height: 120%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + p.book_index_lev1 { + line-height: 100%; + margin-top: 4px; + margin-bottom: 1px; + } + p.book_index_lev2 { + line-height: 100%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + tt { + font-family: inconsolata, andale mono, courier new, courier, monospace; + background-color: #eeeeee; + } + note { white-space: pre; } + label.ocn { + width: 2%; + float: right; + top: 0; + font-size: 10px; + margin-top: 0px; + margin-bottom: 5px; + color: #777777; + margin-right: 5px; + text-align: right; + background-color: #ffffff; + } + table { } + tr { } + th,td { + vertical-align: top; + text-align: left; + } + th { + font-weight: bold; + } + em { + font-weight: bold; + font-style: italic; + } + p.left,th.left,td.left { + text-align: left; + } + p.small_left,th.small_left,td.small_left { + text-align: left; + font-size: 80%; + } + p.right,th.right,td.right { + text-align: right; + } + ul, li { + list-style-type: none; + list-style: none; + padding-left: 20px; + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-weight: normal; + line-height: 150%; + text-align: left; + text-indent: 0mm; + margin-left: 1em; + margin-right: 2em; + margin-top: 3px; + margin-bottom: 3px; + } + li { + background: url(../image_sys/bullet_09.png) no-repeat 0px 6px; + } + ul { + } + h0, h1, h2, h3, h4, h5, h6, h7 { + font-weight: bold; + line-height: 120%; + text-align: left; + margin-top: 20px; + margin-bottom: 10px; + } + h4.norm, h5.norm, h6.norm, h7.norm { + margin-top: 10px; + margin-bottom: 0px; + } + h0 { font-size: 125%; } + h1 { font-size: 120%; } + h2 { font-size: 115%; } + h3 { font-size: 110%; } + h4 { font-size: 105%; } + h5 { font-size: 100%; } + h6 { font-size: 100%; } + h7 { font-size: 100%; } + h0, h1, h2, h3, h4, h5, h6, h7 { text-shadow: .2em .2em .3em gray; } + h1.i { margin-left: 2em; } + h2.i { margin-left: 3em; } + h3.i { margin-left: 4em; } + h4.i { margin-left: 5em; } + h5.i { margin-left: 6em; } + h6.i { margin-left: 7em; } + h7.i { margin-left: 8em; } + h8.i { margin-left: 9em; } + h9.i { margin-left: 10em; } + .toc { + font-weight: normal; + margin-top: 6px; + margin-bottom: 6px; + } + h0.toc { + margin-left: 1em; + font-size: 120%; + line-height: 150%; + } + h1.toc { + margin-left: 1em; + font-size: 115%; + line-height: 150%; + } + h2.toc { + margin-left: 2em; + font-size: 110%; + line-height: 140%; + } + h3.toc { + margin-left: 3em; + font-size: 105%; + line-height: 120%; + } + h4.toc { + margin-left: 4em; + font-size: 100%; + line-height: 120%; + } + h5.toc { + margin-left: 5em; + font-size: 95%; + line-height: 110%; + } + h6.toc { + margin-left: 6em; + font-size: 90%; + line-height: 110%; + } + h7.toc { + margin-left: 7em; + font-size: 85%; + line-height: 100%; + } + .subtoc { + margin-right: 34%; + font-weight: normal; + } + h5.subtoc { + margin-left: 2em; + font-size: 80%; + margin-top: 2px; + margin-bottom: 2px; + } + h6.subtoc { + margin-left: 3em; + font-size: 75%; + margin-top: 0px; + margin-bottom: 0px; + } + h7.subtoc { + margin-left: 4em; + font-size: 70%; + margin-top: 0px; + margin-bottom: 0px; + } + div.substance { + width: 100%; + background-color: #ffffff; + } + div.ocn { + width: 5%; + float: right; + top: 0; + background-color: #ffffff; + } + div.endnote { + width: 95%; + background-color: #fffffff; + } + div.toc { + position: absolute; + float: left; + margin: 0; + padding: 0; + padding-top: 0.5em; + border: 0; + width: 13em; + background-color: #eeeeee; + margin-right:1em; + } + div.summary { + margin: 0; + padding: 0; + border-left: 13em solid #eeeeee; + padding-left: 1em; + background-color: #eeeeee; + } + div.content, div.main_column { + margin: 0; + padding: 0; + border-left: 13em solid #ffffff; + padding-left: 1em; + padding-right: 1em; + } + div.content0, div.main_column0 { + margin: 0; + padding: 0; + border-left: 0% solid #ffffff; + padding-left: 5%; + } + div.scroll { + margin: 0; + padding: 0; + padding-left: 1em; + padding-right: 1em; + } + div.content:after { + content:' '; + clear:both; + display:block; + height:0; + overflow:hidden + } + div.footer { + clear:left; + padding: 0.5em; + font-size: 80%; + margin: 0; + } + div.toc ul { + list-style: none; + padding: 0; + margin: 0; + } + div.toc li ul a, li ul span.currentlink + { + font-weight: normal; + font-size: 90%; + padding-left: 2em; + background-color: #eeeeee; + } + div.toc a, span.currentlink{ + display:block; + text-decoration: none; + padding-left: 0.5em; + color: #0000aa; + } + hr { + width: 90%; + margin-top: 1.8em; + margin-bottom: 1.8em; + } + span.currentlink { + text-decoration: none; + background-color: #aaaaf9; + } + div.toc a:visited { + color: #0000aa; + } + div.toc a:hover { + color: #000000; + background-color: #f9f9aa; + } + /* in toc no list numbering */ + nav#toc ol { + list-style-type: none; + } +"; + struct _css { + auto html_css() { + string _css = "/* SiSU css html stylesheet */\n" ~ css_shared; + return _css; + } + auto epub_css() { + string _css = "/* SiSU css epub stylesheet */\n" ~ css_shared; + return _css; + } + } + return _css(); + } +} diff --git a/src/sdp/output_epub3.d b/src/sdp/output_epub3.d deleted file mode 100644 index 6cc496c..0000000 --- a/src/sdp/output_epub3.d +++ /dev/null @@ -1,774 +0,0 @@ -module sdp.output_epub3; -template outputEPub3() { - 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.output_xmls_css, - sdp.paths_output; - mixin InternalMarkup; - mixin outputXHTMLs; - string epub3_mimetypes() { - string o; - o = format(q"¶application/epub+zip¶") ~ "\n"; - return o; - } - string epub3_container_xml() { - string o; - o = format(q"¶¶") ~ "\n"; - o ~= format(q"¶ - - - ¶") ~ "\n\n"; - 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"¶ - - - - %s - main - %s - subtitle - %s - %s - %s - Copyright: %s - %s - urn:uuid:%s - - - - - - - - - - ¶", - uuid, - doc_matters.dochead_meta["title"]["full"], - doc_matters.dochead_meta["title"]["main"], - (doc_matters.dochead_meta["title"]["sub"].empty) - ? "" : doc_matters.dochead_meta["title"]["sub"], - (doc_matters.dochead_meta["creator"]["author"].empty) - ? "" : doc_matters.dochead_meta["creator"]["author"], - (doc_matters.dochead_meta["creator"]["author"].empty) - ? "" : doc_matters.dochead_meta["creator"]["author"], - doc_matters.language, - (doc_matters.dochead_meta["date"]["published"].empty) - ? "" : doc_matters.dochead_meta["date"]["published"], - (doc_matters.dochead_meta["rights"]["copyright"].empty) - ? "" : doc_matters.dochead_meta["rights"]["copyright"], - uuid, - uuid, - uuid, - (pth_epub3.fn_oebps_css(doc_matters.source_filename)).chompPrefix("OEBPS/"), - ); - content ~= " " ~ "" ~ "\n "; - content ~= parts["manifest_documents"]; - // TODO sort jpg & png - content ~= " " ~ "" ~ "\n "; - foreach (image; doc_matters.image_list) { - content ~= format(q"¶ - ¶", - image.baseName.stripExtension, - (pth_epub3.doc_oebps_image(doc_matters.source_filename)).chompPrefix("OEBPS/"), - image, - image.extension.chompPrefix("."), - ); - } - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["spine"]; - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["guide"]; - content ~= " " ~ "" ~ "\n "; - content ~= "" ~ ""; - return content; - } - string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { - enum DomTags { none, open, close, close_and_open, open_still, } - auto markup = InlineMarkup(); - auto rgx = Rgx(); - string toc =format(" - - %s - - -
-
-

Contents

-
- -
- - \n"; - return toc; - } - string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { - int counter = 0; - string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere - auto markup = InlineMarkup(); - auto rgx = Rgx(); - enum DomTags { none, open, close, close_and_open, open_still, } - string toc = format(q"¶ - - - - %s%s - - - - - - - - - %s - - - %s - - ¶", - doc_matters.dochead_meta["title"]["full"], // title - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" - : " by " ~ doc_matters.dochead_meta["creator"]["author"], // author - uuid, // uuid - "3", // content depth - doc_matters.dochead_meta["title"]["full"], // title - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" - : doc_matters.dochead_meta["creator"]["author"], // author - ); - foreach (sect; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[sect]) { - if (obj.is_a == "heading") { - string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip; - string hashtag =(obj.heading_lev_markup <= 4) ? "" : ("#" ~ obj.ocn.to!string); - foreach_reverse (k; 0 .. 7) { - switch (obj.dom_markedup[k]) { - case DomTags.close : - toc ~= "\n "; - break; - case DomTags.close_and_open : - ++counter; - toc ~= "\n "; - toc ~= format(q"¶ - - - %s - - ¶", - counter, - _txt, - obj.segment_anchor_tag, - hashtag, - ); - break; - case DomTags.open : - ++counter; - toc ~= format(q"¶ - - - %s - - ¶", - counter, - _txt, - obj.segment_anchor_tag, - hashtag, - ); - break; - default : - break; - } - } - } - } - } - toc ~= format(q"¶ - ¶"); - return toc; - } - - void outputEPub3(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, - ) { - mixin SiSUoutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[][string] doc_epub3; - string[][string] doc_epub3_endnotes; - string[] doc; - string segment_filename; - string[] top_level_headings = ["","","",""]; - string[string] oepbs_content_parts; - string suffix = ".xhtml"; - string[] doc_parts_; - foreach (part; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - string _txt = xhtml_format.special_characters(obj, obj.text); - if (obj.is_a == "heading") { - switch (obj.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.heading_lev_markup) { - case 0: - top_level_headings[0] = ""; - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 1: - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 2: - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 3: - top_level_headings[3] = ""; - goto default; - default: - doc_parts_ ~= obj.segment_anchor_tag; - doc_epub3[obj.segment_anchor_tag] ~= xhtml_format.epub3_seg_head(doc_matters); - auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); - doc_epub3[obj.segment_anchor_tag] ~= t[0]; - doc_epub3_endnotes[obj.segment_anchor_tag] ~= t[1]; - break; - } - break; - case 4: - segment_filename = obj.segment_anchor_tag; - doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters); - auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case 5: .. case 7: - auto t = xhtml_format.heading_seg(obj, _txt, suffix, "epub"); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - } - break; - } - } else { - switch (obj.use) { - case "frontmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "toc": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "para": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= to!string(t[0]); - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "group": - auto t = xhtml_format.group_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= to!string(t[0]); - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "block": - auto t = xhtml_format.block_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= to!string(t[0]); - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "poem": - break; - case "verse": - auto t = xhtml_format.verse_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= to!string(t[0]); - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "code": - doc_epub3[segment_filename] ~= xhtml_format.code(obj, _txt); - break; - case "table": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "endnote": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - break; - case "glossary": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "bibliography": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "blurb": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_epub3[segment_filename] ~= t[0]; - doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - } - break; - } - } - if (obj.is_a == "heading") { - if (obj.heading_lev_markup <= 4) { - oepbs_content_parts["manifest_documents"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - obj.segment_anchor_tag, - ); - oepbs_content_parts["spine"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - ); - oepbs_content_parts["guide"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - obj.segment_anchor_tag, - ); - } else if (obj.heading_lev_markup > 4) { - oepbs_content_parts["manifest_documents"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - oepbs_content_parts["spine"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - oepbs_content_parts["guide"] ~= - format(q"¶ - ¶", - obj.segment_anchor_tag, - obj.obj_cite_number, - obj.segment_anchor_tag, - obj.obj_cite_number, - ); - } - } - } - } - /+ epub specific documents +/ - auto mimetypes = epub3_mimetypes; - auto meta_inf_container_xml = epub3_container_xml; - auto oebps_toc_ncx = epub2_oebps_toc_ncx(doc_abstraction, doc_matters); - auto oebps_toc_nav_xhtml = epub3_oebps_toc_nav_xhtml(doc_abstraction, doc_matters); - auto oebps_content_opf = epub3_oebps_content(doc_abstraction, doc_matters, oepbs_content_parts); - epub3_write_output_files( - doc_matters, - doc_epub3, - doc_epub3_endnotes, - mimetypes, - meta_inf_container_xml, - oebps_toc_nav_xhtml, - oebps_toc_ncx, - oebps_content_opf, - doc_parts_, - ); - } - void epub3_write_output_files(M,D,E,Mt,Mic,Otnx,Otn,Oc)( - M doc_matters, - D doc_epub3, - E doc_epub3_endnotes, - Mt mimetypes, - Mic meta_inf_container_xml, - Otnx oebps_toc_nav_xhtml, - Otn oebps_toc_ncx, - Oc oebps_content_opf, - string[] doc_parts_, - ) { - debug(asserts) { - static assert(is(typeof(doc_epub3) == string[][string])); - static assert(is(typeof(mimetypes) == string)); - static assert(is(typeof(meta_inf_container_xml) == string)); - static assert(is(typeof(oebps_toc_nav_xhtml) == string)); - static assert(is(typeof(oebps_toc_ncx) == string)); - static assert(is(typeof(oebps_content_opf) == string)); - } - auto src_path_info = doc_matters.src_path_info; - string fn_rel_pth = doc_matters.source_filename; - string lng = doc_matters.language; - auto pth_epub3 = SiSUpathsEPUB!()(src_path_info, lng); - auto xhtml_format = outputXHTMLs(); - /+ zip file +/ - auto fn_epub = pth_epub3.epub_file(doc_matters.source_filename); - auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); - /+ zip archive member files +/ - try { - if (!exists(pth_epub3.base)) { - pth_epub3.base.mkdirRecurse; - } - debug(epub_output) { - if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename))) { - pth_epub3.dbg_doc_meta_inf(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename))) { - pth_epub3.dbg_doc_oebps_css(doc_matters.source_filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename))) { - pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename).mkdirRecurse; - } - } - { /+ OEBPS/[segments].xhtml (the document contents) +/ - foreach (seg_filename; doc_matters.segnames_lv_0_to_4) { - string fn = pth_epub3.fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - debug(epub_output) { - string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.source_filename, seg_filename); - auto f = File(fn_dbg, "w"); - } - foreach (docseg; doc_epub3[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } - zip_data.write(docseg.dup); - } - foreach (docseg; doc_epub3_endnotes[seg_filename]) { - debug(epub_output) { f.writeln(docseg); } - zip_data.write(docseg.dup); - } - debug(epub_output) { f.writeln(xhtml_format.tail); } - zip_data.write(xhtml_format.tail.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - /+ create the zip file +/ - createZipFile!()(fn_epub, zip.build()); - } - } - string fn; - debug(epub_output) { string fn_dbg; } - File f; - { /+ mimetypes (identify zip file type) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.source_filename); - File(fn_dbg, "w").writeln(mimetypes); - } - fn = pth_epub3.fn_mimetypes(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(mimetypes.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - { /+ META-INF/container.xml (identify doc root) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.source_filename); - File(fn_dbg, "w").writeln(meta_inf_container_xml); - } - fn = pth_epub3.fn_dmi_container_xml(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(meta_inf_container_xml.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_toc_nav_xhtml); - } - fn = pth_epub3.fn_oebps_toc_nav_xhtml(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_toc_nav_xhtml.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/toc.ncx (navigation toc epub2) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_toc_ncx); - } - fn = pth_epub3.fn_oebps_toc_ncx(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_toc_ncx.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/content.opf (doc manifest) +/ - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.source_filename); - File(fn_dbg, "w").writeln(oebps_content_opf); - } - fn = pth_epub3.fn_oebps_content_opf(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(oebps_content_opf.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - { /+ OEBPS/_sisu/image (images) +/ - foreach (image; doc_matters.image_list) { - debug(epub_output) { - 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_output) { - debug(epub_images) { - writeln( - doc_matters.src_path_info.image_root, image, " -> ", - pth_epub3.dbg_doc_oebps_image(doc_matters.source_filename), "/", image - ); - } - } - auto fn_src = doc_matters.src_path_info.image_root ~ image; - auto fn_out = pth_epub3.doc_oebps_image(doc_matters.source_filename).to!string ~ "/" ~ image; - if (exists(fn_src)) { - { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn_out; - auto zip_data = new OutBuffer(); - zip_data.write(cast(char[]) ((fn_src).read)); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - } - } - } - { /+ OEBPS/epub.css +/ - auto css = SiSUcss(); - debug(epub_output) { - fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.source_filename); - File(fn_dbg, "w").writeln(css.epub_css); - } - fn = pth_epub3.fn_oebps_css(doc_matters.source_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(css.epub_css.dup); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - } - catch (ErrnoException ex) { - // Handle error - } - debug(epub_archive) { - if (exists(fn_epub)) { - try { - auto zipped = new ZipArchive((fn_epub).read); - foreach (filename, member; zipped.directory) { - auto data = zipped.expand(member); - writeln(filename, " length ", data.length); - } - } - catch (ZipException ex) { - // Handle errors - } - } - } - } - -} diff --git a/src/sdp/output_html.d b/src/sdp/output_html.d deleted file mode 100644 index 41d68dd..0000000 --- a/src/sdp/output_html.d +++ /dev/null @@ -1,465 +0,0 @@ -module sdp.output_html; -template outputHTML() { - 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.output_xmls_css, - sdp.paths_output; - mixin outputXHTMLs; - - void scroll(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, - ) { - mixin SiSUoutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[] doc_html; - string[] doc; - string suffix = ".html"; - foreach (part; doc_matters.keys_seq.scroll) { - foreach (obj; doc_abstraction[part]) { - string _txt = xhtml_format.special_characters(obj, obj.text); - switch (obj.use) { - case "frontmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); - break; - case "toc": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); - break; - case "para": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - doc_html ~= xhtml_format.quote_scroll(obj, _txt); - break; - case "group": - doc_html ~= xhtml_format.group_scroll(obj, _txt); - break; - case "block": - doc_html ~= xhtml_format.block_scroll(obj, _txt); - break; - case "poem": - break; - case "verse": - doc_html ~= xhtml_format.verse_scroll(obj, _txt, suffix); - break; - case "code": - doc_html ~= xhtml_format.code(obj, _txt); - break; - case "table": - doc_html ~= xhtml_format.table(obj, _txt); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "heading": - doc_html ~= xhtml_format.heading_scroll(obj, _txt, suffix); - break; - case "endnote": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - case "glossary": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - case "bibliography": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - case "bookindex": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - case "blurb": - doc_html ~= xhtml_format.para_scroll(obj, _txt, suffix); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - break; - } - } - } - doc = xhtml_format.html_scroll_head(doc_matters) ~ doc_html ~ xhtml_format.tail; - scroll_write_output(doc_matters, doc); - } - void scroll_write_output(M,C)( - M doc_matters, - C doc, - ) { - debug(asserts) { - static assert(is(typeof(doc) == string[])); - } - string fn_src = doc_matters.source_filename; - auto src_path_info = doc_matters.src_path_info; - string fn_rel_pth = doc_matters.source_filename; - string lng = doc_matters.language; - auto pth_html = SiSUpathsHTML!()(src_path_info, lng); - try { - if (!exists(pth_html.base)) { - pth_html.base.mkdirRecurse; - } - auto f = File(pth_html.fn_scroll(fn_src), "w"); - foreach (o; doc) { - f.writeln(o); - } - } - catch (ErrnoException ex) { - // Handle error - } - } - void seg(D,I)( - auto return ref const D doc_abstraction, - auto return ref I doc_matters, - ) { - mixin SiSUoutputRgxInit; - auto rgx = Rgx(); - auto xhtml_format = outputXHTMLs(); - string[][string] doc_html; - string[][string] doc_html_endnotes; - string[] doc; - string segment_filename; - string[] top_level_headings = ["","","",""]; - string suffix = ".html"; - foreach (part; doc_matters.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - string _txt = xhtml_format.special_characters(obj, obj.text); - if (obj.is_a == "heading") { - switch (obj.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.heading_lev_markup) { - case 0: - top_level_headings[0] = ""; - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 1: - top_level_headings[1] = ""; - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 2: - top_level_headings[2] = ""; - top_level_headings[3] = ""; - goto default; - case 3: - top_level_headings[3] = ""; - goto default; - default: - auto t = xhtml_format.heading_seg(obj, _txt, suffix); - top_level_headings[obj.heading_lev_markup] = t[0]; - break; - } - break; - case 4: - segment_filename = obj.segment_anchor_tag; - doc_html[segment_filename] ~= xhtml_format.html_seg_head(doc_matters); - 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, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case 5: .. case 7: - auto t = xhtml_format.heading_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); - } - break; - } - } else { - switch (obj.use) { - case "frontmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "toc": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "body": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "para": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - case "block": - switch (obj.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "group": - auto t = xhtml_format.group_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "block": - auto t = xhtml_format.block_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "poem": - break; - case "verse": - auto t = xhtml_format.verse_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= to!string(t[0]); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "code": - doc_html[segment_filename] ~= xhtml_format.code(obj, _txt); - break; - case "table": - doc_html[segment_filename] ~= xhtml_format.table(obj, _txt); - doc_html_endnotes[segment_filename] ~= ""; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "backmatter": - switch (obj.is_of) { - case "para": - switch (obj.is_a) { - case "endnote": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= t[0]; - break; - case "glossary": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "bibliography": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "blurb": - auto t = xhtml_format.para_seg(obj, _txt, suffix); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); - } - break; - } - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); - } - break; - } - break; - case "comment": - break; - default: - if ((doc_matters.opt_action_bool["debug"])) { - writeln(__FILE__, ":", __LINE__, ": ", obj.use); - } - break; - } - } - } - } - seg_write_output(doc_matters, doc_html, doc_html_endnotes); - } - void seg_write_output(M,D,E)( - M doc_matters, - D doc_html, - E doc_html_endnotes, - ) { - debug(asserts) { - static assert(is(typeof(doc_html) == string[][string])); - } - mixin SiSUoutputRgxInit; - auto rgx = Rgx(); - auto src_path_info = doc_matters.src_path_info; - string fn_rel_pth = doc_matters.source_filename; - string lng = doc_matters.language; - auto pth_html = SiSUpathsHTML!()(src_path_info, lng); - auto xhtml_format = outputXHTMLs(); - auto m = doc_matters.source_filename.matchFirst(rgx.src_fn); - try { - if (!exists(pth_html.seg(doc_matters.source_filename))) { - pth_html.seg(doc_matters.source_filename).mkdirRecurse; - } - foreach (seg_filename; doc_matters.segnames) { - auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); - foreach (docseg; doc_html[seg_filename]) { - f.writeln(docseg); - } - foreach (docseg; doc_html_endnotes[seg_filename]) { - f.writeln(docseg); - } - f.writeln(xhtml_format.tail); - } - } - catch (ErrnoException ex) { - // handle error - } - } - void css(M)( - auto return ref M doc_matters, - ) { - auto css = SiSUcss(); - auto pth_html = SiSUpathsHTML!()(doc_matters.src_path_info, doc_matters.language); - try { - if (!exists(pth_html.css)) { - (pth_html.css).mkdirRecurse; - } - auto f = File(pth_html.fn_css, "w"); - f.writeln(css.html_css); - } - catch (ErrnoException ex) { - // Handle error - } - } -} diff --git a/src/sdp/output_hub.d b/src/sdp/output_hub.d deleted file mode 100644 index 0ed1653..0000000 --- a/src/sdp/output_hub.d +++ /dev/null @@ -1,92 +0,0 @@ -/++ - output hub
- check & generate output types requested -+/ -module sdp.output_hub; -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 - sdp.imports_for_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"]) - || (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"); } - } - 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"); - } - } -} diff --git a/src/sdp/output_rgx.d b/src/sdp/output_rgx.d deleted file mode 100644 index af0751e..0000000 --- a/src/sdp/output_rgx.d +++ /dev/null @@ -1,73 +0,0 @@ -/++ - regex: regular expressions used in sisu document parser -+/ -module sdp.output_rgx; -template SiSUoutputRgxInit() { - private import sdp.defaults; - struct Rgx { - static newline = ctRegex!("\n", "mg"); - static strip_br = ctRegex!("^
\n|
\n*$"); - static space = ctRegex!(`[ ]`, "mg"); - static spaces_line_start = ctRegex!(`^(?P[ ]+)`, "mg"); - static spaces_multiple = ctRegex!(`(?P[ ]{2,})`, "mg"); - 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"); - static src_pth = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[tm])$`); - static src_fn = - ctRegex!(`^([a-zA-Z0-9._-]+/)*(?P(?P[a-zA-Z0-9._-]+)[.](?Pss[tm]))$`); - static src_fn_master = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssm)$`); - static src_fn_text = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]sst)$`); - static src_fn_insert = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ssi)$`); - static src_fn_find_inserts = ctRegex!(`^(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[im])$`); - static insert_src_fn_ssi_or_sst = ctRegex!(`^<<\s*(?P[a-zA-Z0-9._-]+/)*(?P[a-zA-Z0-9._-]+[.]ss[ti])$`); - /+ inline markup footnotes endnotes +/ - static inline_notes_al = ctRegex!(`【(?:[*+]\s+|\s*)(.+?)】`, "mg"); - static inline_notes_al_gen = ctRegex!(`【.+?】`, "m"); - static inline_al_delimiter_open_regular = ctRegex!(`【\s`, "m"); - static inline_al_delimiter_open_symbol_star = ctRegex!(`【[*]\s`, "m"); - static inline_al_delimiter_open_symbol_plus = ctRegex!(`【[+]\s`, "m"); - static inline_al_delimiter_close_regular = ctRegex!(`】`, "m"); - static inline_al_delimiter_open_and_close_regular = ctRegex!(`【|】`, "m"); - static inline_notes_delimiter_al_regular = ctRegex!(`【(.+?)】`, "mg"); - static inline_notes_delimiter_al_regular_number_note = ctRegex!(`【(\d+)\s+(.+?)】`, "mg"); - static inline_al_delimiter_open_asterisk = ctRegex!(`【\*`, "m"); - static inline_al_delimiter_open_plus = ctRegex!(`【\+`, "m"); - static inline_text_and_note_al = ctRegex!(`(?P.+?)【(?:[*+ ]*)(?P.+?)】`, "mg"); - static inline_text_and_note_al_ = ctRegex!(`(.+?(?:【[*+]*\s+.+?】|$))`, "mg"); - /+ 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"); - /+ inline markup font face mod +/ - static inline_faces = ctRegex!(`(?P(?P[*!_^,+#-])\{(?P.+?)\}[*!_^,+#-])`, "mg"); - static inline_emphasis = ctRegex!(`\*\{(?P.+?)\}\*`, "mg"); - static inline_bold = ctRegex!(`!\{(?P.+?)\}!`, "mg"); - static inline_underscore = ctRegex!(`_\{(?P.+?)\}_`, "mg"); - static inline_italics = ctRegex!(`/\{(?P.+?)\}/`, "mg"); - static inline_superscript = ctRegex!(`\^\{(?P.+?)\}\^`, "mg"); - static inline_subscript = ctRegex!(`,\{(?P.+?)\},`, "mg"); - static inline_strike = ctRegex!(`-\{(?P.+?)\}-`, "mg"); - static inline_insert = ctRegex!(`\+\{(?P.+?)\}\+`, "mg"); - static inline_mono = ctRegex!(`#\{(?P.+?)\}#`, "mg"); - static inline_cite = ctRegex!(`"\{(?P.+?)\}"`, "mg"); - static inline_faces_line = ctRegex!(`^[*!/_]_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_emphasis_line = ctRegex!(`^\*_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_bold_line = ctRegex!(`^!_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_italics_line = ctRegex!(`^/_ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - static inline_underscore_line = ctRegex!(`^__ (?P.+?)((?: [\\]{2}|[~]#){0,2}$)`); - /+ table delimiters +/ - static table_delimiter_col = ctRegex!("[ ]*[┊][ ]*", "mg"); - static table_delimiter_row = ctRegex!("[ ]*\n", "mg"); - static xhtml_ampersand = ctRegex!(`[&]`); // & - static xhtml_quotation = ctRegex!(`[&]`); // " - static xhtml_less_than = ctRegex!(`[<]`); // < - static xhtml_greater_than = ctRegex!(`[>]`); // > - static xhtml_line_break = ctRegex!(` [\\]{2}`); //
- } -} diff --git a/src/sdp/output_xmls.d b/src/sdp/output_xmls.d deleted file mode 100644 index 373a871..0000000 --- a/src/sdp/output_xmls.d +++ /dev/null @@ -1,818 +0,0 @@ -module sdp.output_xmls; -template outputXHTMLs() { - 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.output_xmls_css, - sdp.paths_output; - mixin SiSUoutputRgxInit; - struct outputXHTMLs { - auto rgx = Rgx(); - string special_characters(O)( - auto return ref const O obj, - string _txt - ){ - _txt = (_txt) - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_quotation, """) - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.nbsp_char, " "); - if (!(obj.is_a == "code")) { - _txt = (_txt) - .replaceAll(rgx.xhtml_line_break, "
"); - } - return _txt; - } - string font_face(string _txt){ - _txt = (_txt) - .replaceAll(rgx.inline_emphasis, ("$1")) - .replaceAll(rgx.inline_bold, ("$1")) - .replaceAll(rgx.inline_underscore, ("$1")) - .replaceAll(rgx.inline_italics, ("$1")) - .replaceAll(rgx.inline_superscript, ("$1")) - .replaceAll(rgx.inline_subscript, ("$1")) - .replaceAll(rgx.inline_strike, ("$1")) - .replaceAll(rgx.inline_insert, ("$1")) - .replaceAll(rgx.inline_mono, ("$1")) - .replaceAll(rgx.inline_cite, ("$1")); - return _txt; - } - string _xhtml_anchor_tags(const(string[]) anchor_tags) { - string tags=""; - if (anchor_tags.length > 0) { - foreach (tag; anchor_tags) { - if (!(tag.empty)) { - tags ~= ""; - } - } - } - return tags; - } - auto html_scroll_head(Dm)( - Dm doc_matters, - ) { - string o; - o = format(q"¶ - - - - - %s%s - - - - - - - - - - - - - - - - - - - - - ¶", - doc_matters.dochead_meta["title"]["full"], - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : ", " ~ doc_matters.dochead_meta["creator"]["author"], - doc_matters.language, - ); - return o; - } - auto html_seg_head(Dm)( - Dm doc_matters, - ) { - string o; - o = format(q"¶ - - - - - %s%s - - - - - - - - - - - - - - - - - - - - - - ¶", - doc_matters.dochead_meta["title"]["full"], - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" - : ", " ~ doc_matters.dochead_meta["creator"]["author"], - doc_matters.language, - ); - return o; - } - auto epub3_seg_head(Dm)( - Dm doc_matters, - ) { - string html_base = format(q"¶ - ¶", - ); - string html_simple = format(q"¶ - ¶", - doc_matters.language, - doc_matters.language, - ); - string html_strict = format(q"¶ - ¶", - doc_matters.language, - doc_matters.language, - ); - string o; - o = format(q"¶%s - - - %s%s - - - - - - - - - - - - - - - - - - - - ¶", - html_simple, - doc_matters.dochead_meta["title"]["full"], - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" - : ", " ~ doc_matters.dochead_meta["creator"]["author"], - doc_matters.dochead_meta["title"]["full"], - (doc_matters.dochead_meta["creator"]["author"].empty) ? "" - : ", " ~ doc_matters.dochead_meta["creator"]["author"], - doc_matters.language, - ); - return o; - } - auto tail() { - string o; - o = format(q"¶ - - - ¶"); - return o; - } - auto inline_links(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - string seg_scroll = "seg", - ) { - if (obj.inline_links) { - if ((seg_scroll == "scroll") - && _txt.match(rgx.mark_internal_site_lnk)) { - _txt = (_txt).replaceAll( - rgx.inline_seg_link, - "$1"); - } - _txt = (_txt).replaceAll( - rgx.inline_link_fn_suffix, - ("$1" ~ _suffix)); - _txt = (_txt).replaceAll( - rgx.inline_link, - ("$1")); - _txt = (_txt).replaceAll( - rgx.mark_internal_site_lnk, - "" - ); - } - debug(markup_links) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.inline_links, - "): ", obj.is_a, ": ", - obj.text - ); - } - } - debug(markup) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.inline_links, - "): ", obj.is_a, ": ", - obj.text - ); - } - } - return _txt; - } - auto inline_notes_scroll(O)( - auto return ref const O obj, - string _txt, - ) { - if (obj.inline_notes_reg) { - _txt = (_txt).replaceAll( - rgx.inline_notes_delimiter_al_regular_number_note, - (" $1 ") - ); - } - debug(markup_endnotes) { - if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); - } - } - debug(markup) { - if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.is_a, ": ", obj.text); - } - } - return _txt; - } - auto inline_notes_seg(O)( - auto return ref const O obj, - string _txt, - ) { - string[] _endnotes; - if (obj.inline_notes_reg) { - /+ need markup for text, and separated footnote +/ - foreach(m; _txt.matchAll(rgx.inline_notes_delimiter_al_regular_number_note)) { - _endnotes ~= format( - "%s%s%s%s\n %s%s%s%s%s\n %s\n%s", - "

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

" - ); - } - _txt = (_txt).replaceAll( - rgx.inline_notes_delimiter_al_regular_number_note, - (" $1 ") - ); - } else if (_txt.match(rgx.inline_notes_delimiter_al_regular_number_note)) { - debug(markup) { - writeln(__LINE__, " endnote: ", obj.is_a, ": ", obj.text); - } - } - auto t = tuple( - _txt, - _endnotes, - ); - return t; - } - auto inline_markup_scroll(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - ) { - _txt = inline_links(obj, _txt, _suffix, "scroll"); - _txt = inline_notes_scroll(obj, _txt); - return _txt; - } - auto inline_markup_seg(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - ) { - _txt = inline_links(obj, _txt, _suffix, "seg"); - auto t = inline_notes_seg(obj, _txt); - return t; - } - auto toc_seg(O)( - auto return ref const O obj, - string _txt, - ) { - string o; - o = format(q"¶
-

- %s -

-
¶", - obj.is_a, - obj.indent_hang, - obj.indent_base, - _txt, - ); - return o; - } - auto heading(O)( - auto return ref const O obj, - string _txt, - string _type="html", - ) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - string _horizontal_rule = "
"; - if ((_type != "html") - || (obj.heading_lev_markup == 0 || obj.heading_lev_markup > 4)) { - _horizontal_rule = ""; - } - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶%s -
- %s - %s - -
¶", - _horizontal_rule, - obj.heading_lev_markup, - obj.is_a, - tags, - _txt, - obj.heading_lev_markup, - ); - } else { - o = format(q"¶%s -
- - %s - %s - -
¶", - _horizontal_rule, - obj.obj_cite_number, - obj.obj_cite_number, - obj.heading_lev_markup, - obj.is_a, - obj.obj_cite_number, - obj.obj_cite_number, - tags, - _txt, - obj.heading_lev_markup, - ); - } - return o; - } - auto heading_scroll(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - ) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - _txt = inline_markup_scroll(obj, _txt, _suffix); - string o = heading(obj, _txt); - return o; - } - auto heading_seg(O)( - auto return ref const O obj, - string _txt, - string _suffix = ".html", - string _type = "html", - ) { - auto t = inline_markup_seg(obj, _txt, _suffix); - _txt = t[0]; - string[] _endnotes = t[1]; - string o = heading(obj, _txt, _type); - auto u = tuple( - o, - _endnotes, - ); - return u; - } - auto para(O)( - auto return ref const O obj, - string _txt, - ) { - auto tags = _xhtml_anchor_tags(obj.anchor_tags); - _txt = font_face(_txt); - string o; - _txt = (obj.bullet) ? ("●  " ~ _txt) : _txt; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

%s - %s -

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

%s - %s -

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

- %s -

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

- %s -

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

- %s -

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

- %s -

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

%s

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

%s

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

%s

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

%s

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

%s - - %s -
- %s -

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - tags, - _txt, - _note - ); - return o; - } - auto endnote(O)( - auto return ref const O obj, - string _txt, - ) { - string o; - o = format(q"¶

- %s -

¶", - obj.is_a, - obj.indent_hang, - obj.indent_base, - _txt - ); - return o; - } - auto code(O)( - auto return ref const O obj, - string _txt, - ) { - string o; - if (obj.obj_cite_number.empty) { - o = format(q"¶
-

%s

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

%s

-
¶", - obj.obj_cite_number, - obj.obj_cite_number, - obj.is_a, - obj.obj_cite_number, - _txt - ); - } - return o; - } - } -} diff --git a/src/sdp/output_xmls_css.d b/src/sdp/output_xmls_css.d deleted file mode 100644 index eb1ab2b..0000000 --- a/src/sdp/output_xmls_css.d +++ /dev/null @@ -1,869 +0,0 @@ -/++ - default css settings -+/ -module sdp.output_xmls_css; -template SiSUcss() { - auto SiSUcss() { - string css_shared=" - body { - color: black; - background: #ffffff; - background-color: #ffffff; - } - a:link { - color: #003399; - text-decoration: none; - } - a:visited { - color: #003399; - text-decoration: none; - } - a:hover { - color: #000000; - background-color: #f9f9aa; - } - a.lnkocn:link { - color: #777777; - text-decoration: none; - } - a:hover img { - background-color: #ffffff; - } - a:active { - color: #003399; - text-decoration: underline; - } - div { - margin-left: 0; - margin-right: 0; - } - div.p { - margin-left: 5%; - margin-right: 1%; - } - .norm, .bold, .verse, .group, .block, .alt { - line-height: 133%; - margin-left: 0em; - margin-right: 2em; - margin-top: 12px; - margin-bottom: 0px; - padding-left: 0em; - text-indent: 0em; - } - p, h0, h1, h2, h3, h4, h5, h6, h7 { - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-size: 100%; - font-weight: normal; - line-height: 133%; - text-align: justify; - margin-left: 0em; - margin-right: 2em; - text-indent: 0mm; - margin-top: 0.8em; - margin-bottom: 0.8em; - } - /* spaced */ - p.spaced { white-space: pre; } - /* indent */ - p.norm { } - p.i1 { padding-left: 1em; } - p.i2 { padding-left: 2em; } - p.i3 { padding-left: 3em; } - p.i4 { padding-left: 4em; } - p.i5 { padding-left: 5em; } - p.i6 { padding-left: 6em; } - p.i7 { padding-left: 7em; } - p.i8 { padding-left: 8em; } - p.i9 { padding-left: 9em; } - /* hanging indent */ - p[indent=\"h0i0\"] { - padding-left: 0em; - text-indent: 0em; - } - p[indent=\"h0i1\"] { - padding-left: 1em; - text-indent: -1em; - } - p[indent=\"h0i2\"] { - padding-left: 2em; - text-indent: -2em; - } - p[indent=\"h0i3\"] { - padding-left: 3em; - text-indent: -3em; - } - p[indent=\"h0i4\"] { - padding-left: 4em; - text-indent: -4em; - } - p[indent=\"h0i5\"] { - padding-left: 5em; - text-indent: -5em; - } - p[indent=\"h0i6\"] { - padding-left: 6em; - text-indent: -6em; - } - p[indent=\"h0i7\"] { - padding-left: 7em; - text-indent: -7em; - } - p[indent=\"h0i8\"] { - padding-left: 8em; - text-indent: -8em; - } - p[indent=\"h0i9\"] { - padding-left: 9em; - text-indent: -9em; - } - p[indent=\"h1i0\"] { - padding-left: 0em; - text-indent: 1em; - } - p[indent=\"h1i1\"] { - padding-left: 1em; - text-indent: 0em; - } - p[indent=\"h1i2\"] { - padding-left: 2em; - text-indent: -1em; - } - p[indent=\"h1i3\"] { - padding-left: 3em; - text-indent: -2em; - } - p[indent=\"h1i4\"] { - padding-left: 4em; - text-indent: -3em; - } - p[indent=\"h1i5\"] { - padding-left: 5em; - text-indent: -4em; - } - p[indent=\"h1i6\"] { - padding-left: 6em; - text-indent: -5em; - } - p[indent=\"h1i7\"] { - padding-left: 7em; - text-indent: -6em; - } - p[indent=\"h1i8\"] { - padding-left: 8em; - text-indent: -7em; - } - p[indent=\"h1i9\"] { - padding-left: 9em; - text-indent: -8em; - } - p[indent=\"h2i0\"] { - padding-left: 0em; - text-indent: 2em; - } - p[indent=\"h2i1\"] { - padding-left: 1em; - text-indent: 1em; - } - p[indent=\"h2i2\"] { - padding-left: 2em; - text-indent: 0em; - } - p[indent=\"h2i3\"] { - padding-left: 3em; - text-indent: -1em; - } - p[indent=\"h2i4\"] { - padding-left: 4em; - text-indent: -2em; - } - p[indent=\"h2i5\"] { - padding-left: 5em; - text-indent: -3em; - } - p[indent=\"h2i6\"] { - padding-left: 6em; - text-indent: -4em; - } - p[indent=\"h2i7\"] { - padding-left: 7em; - text-indent: -5em; - } - p[indent=\"h2i8\"] { - padding-left: 8em; - text-indent: -6em; - } - p[indent=\"h2i9\"] { - padding-left: 9em; - text-indent: -7em; - } - p[indent=\"h3i0\"] { - padding-left: 0em; - text-indent: 3em; - } - p[indent=\"h3i1\"] { - padding-left: 1em; - text-indent: 2em; - } - p[indent=\"h3i2\"] { - padding-left: 2em; - text-indent: 1em; - } - p[indent=\"h3i3\"] { - padding-left: 3em; - text-indent: 0em; - } - p[indent=\"h3i4\"] { - padding-left: 4em; - text-indent: -1em; - } - p[indent=\"h3i5\"] { - padding-left: 5em; - text-indent: -2em; - } - p[indent=\"h3i6\"] { - padding-left: 6em; - text-indent: -3em; - } - p[indent=\"h3i7\"] { - padding-left: 7em; - text-indent: -4em; - } - p[indent=\"h3i8\"] { - padding-left: 8em; - text-indent: -5em; - } - p[indent=\"h3i9\"] { - padding-left: 9em; - text-indent: -6em; - } - p[indent=\"h4i0\"] { - padding-left: 0em; - text-indent: 4em; - } - p[indent=\"h4i1\"] { - padding-left: 1em; - text-indent: 3em; - } - p[indent=\"h4i2\"] { - padding-left: 2em; - text-indent: 2em; - } - p[indent=\"h4i3\"] { - padding-left: 3em; - text-indent: 1em; - } - p[indent=\"h4i4\"] { - padding-left: 4em; - text-indent: 0em; - } - p[indent=\"h4i5\"] { - padding-left: 5em; - text-indent: -1em; - } - p[indent=\"h4i6\"] { - padding-left: 6em; - text-indent: -2em; - } - p[indent=\"h4i7\"] { - padding-left: 7em; - text-indent: -3em; - } - p[indent=\"h4i8\"] { - padding-left: 8em; - text-indent: -4em; - } - p[indent=\"h4i9\"] { - padding-left: 9em; - text-indent: -5em; - } - p[indent=\"h5i0\"] { - padding-left: 0em; - text-indent: 5em; - } - p[indent=\"h5i1\"] { - padding-left: 1em; - text-indent: 4em; - } - p[indent=\"h5i2\"] { - padding-left: 2em; - text-indent: 3em; - } - p[indent=\"h5i3\"] { - padding-left: 3em; - text-indent: 2em; - } - p[indent=\"h5i4\"] { - padding-left: 4em; - text-indent: 1em; - } - p[indent=\"h5i5\"] { - padding-left: 5em; - text-indent: 0em; - } - p[indent=\"h5i6\"] { - padding-left: 6em; - text-indent: -1em; - } - p[indent=\"h5i7\"] { - padding-left: 7em; - text-indent: -2em; - } - p[indent=\"h5i8\"] { - padding-left: 8em; - text-indent: -3em; - } - p[indent=\"h5i9\"] { - padding-left: 9em; - text-indent: -4em; - } - p[indent=\"h6i0\"] { - padding-left: 0em; - text-indent: 6em; - } - p[indent=\"h6i1\"] { - padding-left: 1em; - text-indent: 5em; - } - p[indent=\"h6i2\"] { - padding-left: 2em; - text-indent: 4em; - } - p[indent=\"h6i3\"] { - padding-left: 3em; - text-indent: 3em; - } - p[indent=\"h6i4\"] { - padding-left: 4em; - text-indent: 2em; - } - p[indent=\"h6i5\"] { - padding-left: 5em; - text-indent: 1em; - } - p[indent=\"h6i6\"] { - padding-left: 6em; - text-indent: 0em; - } - p[indent=\"h6i7\"] { - padding-left: 7em; - text-indent: -1em; - } - p[indent=\"h6i8\"] { - padding-left: 8em; - text-indent: -2em; - } - p[indent=\"h6i9\"] { - padding-left: 9em; - text-indent: -3em; - } - p[indent=\"h7i0\"] { - padding-left: 0em; - text-indent: 7em; - } - p[indent=\"h7i1\"] { - padding-left: 1em; - text-indent: 6em; - } - p[indent=\"h7i2\"] { - padding-left: 2em; - text-indent: 5em; - } - p[indent=\"h7i3\"] { - padding-left: 3em; - text-indent: 4em; - } - p[indent=\"h7i4\"] { - padding-left: 4em; - text-indent: 3em; - } - p[indent=\"h7i5\"] { - padding-left: 5em; - text-indent: 2em; - } - p[indent=\"h7i6\"] { - padding-left: 6em; - text-indent: 1em; - } - p[indent=\"h7i7\"] { - padding-left: 7em; - text-indent: 0em; - } - p[indent=\"h7i8\"] { - padding-left: 8em; - text-indent: -1em; - } - p[indent=\"h7i9\"] { - padding-left: 9em; - text-indent: -2em; - } - p[indent=\"h8i0\"] { - padding-left: 0em; - text-indent: 8em; - } - p[indent=\"h8i1\"] { - padding-left: 1em; - text-indent: 7em; - } - p[indent=\"h8i2\"] { - padding-left: 2em; - text-indent: 6em; - } - p[indent=\"h8i3\"] { - padding-left: 3em; - text-indent: 5em; - } - p[indent=\"h8i4\"] { - padding-left: 4em; - text-indent: 4em; - } - p[indent=\"h8i5\"] { - padding-left: 5em; - text-indent: 3em; - } - p[indent=\"h8i6\"] { - padding-left: 6em; - text-indent: 2em; - } - p[indent=\"h8i7\"] { - padding-left: 7em; - text-indent: 1em; - } - p[indent=\"h8i8\"] { - padding-left: 8em; - text-indent: 0em; - } - p[indent=\"h8i9\"] { - padding-left: 9em; - text-indent: -1em; - } - p[indent=\"h9i0\"] { - padding-left: 0em; - text-indent: 9em; - } - p[indent=\"h9i1\"] { - padding-left: 1em; - text-indent: 8em; - } - p[indent=\"h9i2\"] { - padding-left: 2em; - text-indent: 7em; - } - p[indent=\"h9i3\"] { - padding-left: 3em; - text-indent: 6em; - } - p[indent=\"h9i4\"] { - padding-left: 4em; - text-indent: 5em; - } - p[indent=\"h9i5\"] { - padding-left: 5em; - text-indent: 4em; - } - p[indent=\"h9i6\"] { - padding-left: 6em; - text-indent: 3em; - } - p[indent=\"h9i7\"] { - padding-left: 7em; - text-indent: 2em; - } - p[indent=\"h9i8\"] { - padding-left: 8em; - text-indent: 1em; - } - p[indent=\"h9i9\"] { - padding-left: 9em; - text-indent: 0em; - } - p.block { - white-space: pre; - } - p.group { } - p.alt { } - p.verse { - white-space: pre; - margin-bottom: 6px; - } - p.code { - font-family: inconsolata, andale mono, courier new, courier, monospace; - font-size: 90%; - text-align: left; - background-color: #eeeeee; - white-space: pre; - margin-top: 0px; - margin-bottom: 0px; - } - p.caption { - text-align: left; - font-size: 80%; - display: inline; - } - p.endnote { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-right: 15mm; - } - p.endnote_indent { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-left: 2em; - margin-right: 15mm; - } - p.center { - text-align: center; - } - p.bold { - font-weight: bold; - } - p.bold_left { - font-weight: bold; - text-align: left; - } - p.centerbold { - text-align: center; - font-weight: bold; - } - p.em { - font-weight: bold; - font-style: normal; - background: #fff3b6; - } - p.small { - font-size: 80%; - margin-top: 0px; - margin-bottom: 0px; - margin-right: 6px; - text-align: left; - } - .tiny, .tiny_left, .tiny_right, .tiny_center { - font-size: 10px; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 6px; - text-align: left; - } - p.tiny { } - p.tiny_left { - margin-left: 0px; - margin-right: 0px; - text-align: left; - } - p.tiny_right { - margin-right: 1em; - text-align: right; - } - p.tiny_center { - margin-left: 0px; - margin-right: 0px; - text-align: center; - } - p.concordance_word { - line-height: 150%; - font-weight: bold; - display: inline; - margin-top: 4px; - margin-bottom: 1px; - } - p.concordance_count { - font-size: 80%; - color: #777777; - display: inline; - margin-left: 0em; - } - p.concordance_object { - font-size: 80%; - line-height: 120%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - p.book_index_lev1 { - line-height: 100%; - margin-top: 4px; - margin-bottom: 1px; - } - p.book_index_lev2 { - line-height: 100%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - tt { - font-family: inconsolata, andale mono, courier new, courier, monospace; - background-color: #eeeeee; - } - note { white-space: pre; } - label.ocn { - width: 2%; - float: right; - top: 0; - font-size: 10px; - margin-top: 0px; - margin-bottom: 5px; - color: #777777; - margin-right: 5px; - text-align: right; - background-color: #ffffff; - } - table { } - tr { } - th,td { - vertical-align: top; - text-align: left; - } - th { - font-weight: bold; - } - em { - font-weight: bold; - font-style: italic; - } - p.left,th.left,td.left { - text-align: left; - } - p.small_left,th.small_left,td.small_left { - text-align: left; - font-size: 80%; - } - p.right,th.right,td.right { - text-align: right; - } - ul, li { - list-style-type: none; - list-style: none; - padding-left: 20px; - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-weight: normal; - line-height: 150%; - text-align: left; - text-indent: 0mm; - margin-left: 1em; - margin-right: 2em; - margin-top: 3px; - margin-bottom: 3px; - } - li { - background: url(../image_sys/bullet_09.png) no-repeat 0px 6px; - } - ul { - } - h0, h1, h2, h3, h4, h5, h6, h7 { - font-weight: bold; - line-height: 120%; - text-align: left; - margin-top: 20px; - margin-bottom: 10px; - } - h4.norm, h5.norm, h6.norm, h7.norm { - margin-top: 10px; - margin-bottom: 0px; - } - h0 { font-size: 125%; } - h1 { font-size: 120%; } - h2 { font-size: 115%; } - h3 { font-size: 110%; } - h4 { font-size: 105%; } - h5 { font-size: 100%; } - h6 { font-size: 100%; } - h7 { font-size: 100%; } - h0, h1, h2, h3, h4, h5, h6, h7 { text-shadow: .2em .2em .3em gray; } - h1.i { margin-left: 2em; } - h2.i { margin-left: 3em; } - h3.i { margin-left: 4em; } - h4.i { margin-left: 5em; } - h5.i { margin-left: 6em; } - h6.i { margin-left: 7em; } - h7.i { margin-left: 8em; } - h8.i { margin-left: 9em; } - h9.i { margin-left: 10em; } - .toc { - font-weight: normal; - margin-top: 6px; - margin-bottom: 6px; - } - h0.toc { - margin-left: 1em; - font-size: 120%; - line-height: 150%; - } - h1.toc { - margin-left: 1em; - font-size: 115%; - line-height: 150%; - } - h2.toc { - margin-left: 2em; - font-size: 110%; - line-height: 140%; - } - h3.toc { - margin-left: 3em; - font-size: 105%; - line-height: 120%; - } - h4.toc { - margin-left: 4em; - font-size: 100%; - line-height: 120%; - } - h5.toc { - margin-left: 5em; - font-size: 95%; - line-height: 110%; - } - h6.toc { - margin-left: 6em; - font-size: 90%; - line-height: 110%; - } - h7.toc { - margin-left: 7em; - font-size: 85%; - line-height: 100%; - } - .subtoc { - margin-right: 34%; - font-weight: normal; - } - h5.subtoc { - margin-left: 2em; - font-size: 80%; - margin-top: 2px; - margin-bottom: 2px; - } - h6.subtoc { - margin-left: 3em; - font-size: 75%; - margin-top: 0px; - margin-bottom: 0px; - } - h7.subtoc { - margin-left: 4em; - font-size: 70%; - margin-top: 0px; - margin-bottom: 0px; - } - div.substance { - width: 100%; - background-color: #ffffff; - } - div.ocn { - width: 5%; - float: right; - top: 0; - background-color: #ffffff; - } - div.endnote { - width: 95%; - background-color: #fffffff; - } - div.toc { - position: absolute; - float: left; - margin: 0; - padding: 0; - padding-top: 0.5em; - border: 0; - width: 13em; - background-color: #eeeeee; - margin-right:1em; - } - div.summary { - margin: 0; - padding: 0; - border-left: 13em solid #eeeeee; - padding-left: 1em; - background-color: #eeeeee; - } - div.content, div.main_column { - margin: 0; - padding: 0; - border-left: 13em solid #ffffff; - padding-left: 1em; - padding-right: 1em; - } - div.content0, div.main_column0 { - margin: 0; - padding: 0; - border-left: 0% solid #ffffff; - padding-left: 5%; - } - div.scroll { - margin: 0; - padding: 0; - padding-left: 1em; - padding-right: 1em; - } - div.content:after { - content:' '; - clear:both; - display:block; - height:0; - overflow:hidden - } - div.footer { - clear:left; - padding: 0.5em; - font-size: 80%; - margin: 0; - } - div.toc ul { - list-style: none; - padding: 0; - margin: 0; - } - div.toc li ul a, li ul span.currentlink - { - font-weight: normal; - font-size: 90%; - padding-left: 2em; - background-color: #eeeeee; - } - div.toc a, span.currentlink{ - display:block; - text-decoration: none; - padding-left: 0.5em; - color: #0000aa; - } - hr { - width: 90%; - margin-top: 1.8em; - margin-bottom: 1.8em; - } - span.currentlink { - text-decoration: none; - background-color: #aaaaf9; - } - div.toc a:visited { - color: #0000aa; - } - div.toc a:hover { - color: #000000; - background-color: #f9f9aa; - } - /* in toc no list numbering */ - nav#toc ol { - list-style-type: none; - } -"; - struct _css { - auto html_css() { - string _css = "/* SiSU css html stylesheet */\n" ~ css_shared; - return _css; - } - auto epub_css() { - string _css = "/* SiSU css epub stylesheet */\n" ~ css_shared; - return _css; - } - } - return _css(); - } -} diff --git a/src/sdp/paths_output.d b/src/sdp/paths_output.d deleted file mode 100644 index ea68567..0000000 --- a/src/sdp/paths_output.d +++ /dev/null @@ -1,288 +0,0 @@ -/++ - default settings -+/ -module sdp.paths_output; -import std.array, - std.path, - std.regex, - std.stdio; -import sdp.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!()(); - 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); - } - 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!()(); - 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 deleted file mode 100644 index b5a60e8..0000000 --- a/src/sdp/paths_source.d +++ /dev/null @@ -1,60 +0,0 @@ -/++ - read configuration files
- - read config files
- ao_config_files.d -+/ -module sdp.paths_source; -import std.array, - std.path, - std.regex, - std.stdio; -import sdp.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/sisu_d_parser.d b/src/sdp/sisu_d_parser.d new file mode 100755 index 0000000..748ba12 --- /dev/null +++ b/src/sdp/sisu_d_parser.d @@ -0,0 +1,221 @@ +#!/usr/bin/env rdmd +/+ + sdp ++/ +import + sdp.conf.compile_time_info, + sdp.ao.abstraction; +/+ sdp: sisu document parser, see http://sisudoc.org +/ +import sdp.ao; +import + std.getopt, + std.process; +import + sdp.ao.abstraction_summary, + sdp.ao.abstract_doc_source, + sdp.ao.conf_make_meta, + // sdp.ao.conf_make_meta_native, + sdp.ao.conf_make_meta_sdlang, + sdp.ao.defaults, + sdp.ao.doc_debugs, + sdp.ao.read_config_files, + sdp.ao.read_source_files, + sdp.ao.rgx, + sdp.output.hub, + sdp.output.paths_source; + + + +mixin(import("version.txt")); +mixin CompileTimeInfo; +/++ A SiSU document parser writen in D. +/ +void main(string[] args) { + mixin SiSUrgxInit; + mixin SiSUregisters; + mixin SiSUheaderExtractSDLang; + mixin SiSUnode; + mixin SiSUbiblio; + mixin SiSUrgxInitFlags; + mixin outputHub; + string[] fns_src; + string flag_action; + string arg_unrecognized; + enum dAM { abstraction, matters } + auto rgx = Rgx(); + scope(success) { + debug(checkdoc) { + writefln( + "~ run complete, ok ~ (sdp-%s.%s.%s, %s v%s, %s %s)", + ver.major, ver.minor, ver.patch, + __VENDOR__, __VERSION__, + bits, os, + ); + } + } + scope(failure) { + debug(checkdoc) { + stderr.writefln( + "run failure", + ); + } + } + bool[string] _opt_action_bool = [ + "assertions" : false, + "concordance" : false, + "debug" : false, + "digest" : false, + "docbook" : false, + "epub" : false, + "html" : false, + "html_seg" : false, + "html_scroll" : false, + "manifest" : false, + "ocn" : true, + "odt" : false, + "pdf" : false, + "postgresql" : false, + "qrcode" : false, + "sisupod" : false, + "source" : false, + "sqlite" : false, + "text" : false, + "verbose" : false, + "xhtml" : false, + "xml_dom" : false, + "xml_sax" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, + "skip_output" : false, + ]; + auto helpInfo = getopt(args, + std.getopt.config.passThrough, + "assert", "--assert set optional assertions on", &_opt_action_bool["assertions"], + "concordance", "--concordance file for document", &_opt_action_bool["concordance"], + "debug", "--debug only relevant when debug options compiled in", &_opt_action_bool["debug"], + "digest", "--digest hash digest for each object", &_opt_action_bool["digest"], + "docbook", "--docbook process docbook output", &_opt_action_bool["docbook"], + "epub", "--epub process epub output", &_opt_action_bool["epub"], + "html", "--html process html output", &_opt_action_bool["html"], + "html_seg", "--html-seg process html output", &_opt_action_bool["html_seg"], + "html_scroll", "--html-seg process html output", &_opt_action_bool["html_scroll"], + "manifest", "--manifest process manifest output", &_opt_action_bool["manifest"], + "ocn", "--ocn object cite numbers (default)", &_opt_action_bool["ocn"], + "odf", "--odf process odf:odt output", &_opt_action_bool["odt"], + "odt", "--odt process odf:odt output", &_opt_action_bool["odt"], + "pdf", "--pdf process pdf output", &_opt_action_bool["pdf"], + "pg", "--pg process postgresql output", &_opt_action_bool["postgresql"], + "postgresql", "--postgresql process postgresql output", &_opt_action_bool["postgresql"], + "qrcode", "--qrcode with document metadata", &_opt_action_bool["qrcode"], + "sisupod", "--sisupod sisupod source content bundled", &_opt_action_bool["sisupod"], + "source", "--source markup source text content", &_opt_action_bool["source"], + "sqlite", "--sqlite process sqlite output", &_opt_action_bool["sqlite"], + "text", "--text process text output", &_opt_action_bool["text"], + "txt", "--txt process text output", &_opt_action_bool["text"], + "verbose|v", "--verbose output to terminal", &_opt_action_bool["verbose"], + "xhtml", "--xhtml process xhtml output", &_opt_action_bool["xhtml"], + "xml-dom", "--xml-dom process xml dom output", &_opt_action_bool["xml_dom"], + "xml-sax", "--xml-sax process xml sax output", &_opt_action_bool["xml_sax"], + "section-toc", "--section-toc process table of contents (default)", &_opt_action_bool["section_toc"], + "section-body", "--section-body process document body (default)", &_opt_action_bool["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &_opt_action_bool["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &_opt_action_bool["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &_opt_action_bool["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &_opt_action_bool["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &_opt_action_bool["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &_opt_action_bool["backmatter"], + "skip_output", "--skip-output", &_opt_action_bool["skip_output"], + ); + if (helpInfo.helpWanted) { + defaultGetoptPrinter("Some information about the program.", helpInfo.options); + } + foreach(arg; args) { + if (arg.match(rgx.flag_action)) { + flag_action ~= " " ~ arg; // flags not taken by getopt + } else if (arg.match(rgx.src_pth)) { + fns_src ~= arg; // gather input markup source file names for processing + } else { // anything remaining, unused + arg_unrecognized ~= " " ~ arg; + } + } + auto env = [ + "pwd" : environment["PWD"], + "home" : environment["HOME"], + ]; + auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); + auto sdl_root_doc_make = ConfigHub!()("sisu_document_make", env); + auto confsdl = HeaderExtractSDL(); + auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); + auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); + foreach(fn_src; fns_src) { + if (!empty(fn_src)) { + scope(success) { + debug(checkdoc) { + writefln( + "%s\n%s", + "~ document complete, ok ~", + "------------------------------------------------------------------", + ); + } + } + scope(failure) { + debug(checkdoc) { + stderr.writefln( + "~ document run failure ~ (%s v%s)\n\t%s", + __VENDOR__, __VERSION__, + fn_src + ); + } + } + enforce( + fn_src.match(rgx.src_pth), + "not a sisu markup filename" + ); + auto t = + SiSUabstraction!()(fn_src, _opt_action_bool, env); + static assert(!isTypeTuple!(t)); + static assert(t.length==2); + auto doc_abstraction = t[dAM.abstraction]; + auto doc_matters = t[dAM.matters]; + /+ ↓ debugs +/ + if (doc_matters.opt_action_bool["verbose"]) { + SiSUabstractionSummary!()(doc_abstraction, doc_matters); + } + /+ ↓ debugs +/ + if ((doc_matters.opt_action_bool["debug"]) + || (doc_matters.opt_action_bool["verbose"]) + ) { + SiSUdebugs!()(doc_abstraction, doc_matters); + } + /+ ↓ output hub +/ + if (!(_opt_action_bool["skip_output"])) { + outputHub!()(doc_abstraction, doc_matters); + } + scope(exit) { + debug(checkdoc) { + writefln( + "processed file: %s", + fn_src + ); + } + destroy(fn_src); + } + } else { + /+ no recognized filename provided +/ + writeln("no recognized filename"); + break; // terminate, stop + } + } +} +unittest { + /++ + name "sdp" + description "A SiSU document parser writen in D." + homepage "http://sisudoc.org" + +/ +} diff --git a/src/sdp/source_sisupod.d b/src/sdp/source_sisupod.d deleted file mode 100644 index 7babba3..0000000 --- a/src/sdp/source_sisupod.d +++ /dev/null @@ -1,226 +0,0 @@ -module sdp.source_sisupod; -template SiSUpod() { - 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 - sdp.create_zip_file, - sdp.defaults, - sdp.output_rgx, - sdp.output_xmls, - sdp.paths_output; - void SiSUpod(T)(T doc_matters) { - 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)); - try { - /+ 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; - } - } - debug(sisupod) { - writeln(__LINE__, ": ", - doc_matters.source_filename, " -> ", - pth_sisupod_filesystem.fn_doc( - doc_matters.source_filename, - )); - } - 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( - 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()); - } - } - } - } - } - 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); - } - } - 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 - } - } - - } - catch (ErrnoException ex) { - // Handle error - } - } -} diff --git a/src/sisu_d_parser.d b/src/sisu_d_parser.d deleted file mode 100755 index 96e1359..0000000 --- a/src/sisu_d_parser.d +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env rdmd -/+ - sdp -+/ -import - sdp.compile_time_info, - sdp.abstraction; -/+ sdp: sisu document parser, see http://sisudoc.org +/ -import sdp.imports_for_ao; - - - -mixin(import("version.txt")); -mixin CompileTimeInfo; -/++ A SiSU document parser writen in D. +/ -void main(string[] args) { - mixin SiSUrgxInit; - mixin SiSUregisters; - mixin SiSUheaderExtractSDLang; - mixin SiSUnode; - mixin SiSUbiblio; - mixin SiSUrgxInitFlags; - mixin outputHub; - string[] fns_src; - string flag_action; - string arg_unrecognized; - enum dAM { abstraction, matters } - auto rgx = Rgx(); - scope(success) { - debug(checkdoc) { - writefln( - "~ run complete, ok ~ (sdp-%s.%s.%s, %s v%s, %s %s)", - ver.major, ver.minor, ver.patch, - __VENDOR__, __VERSION__, - bits, os, - ); - } - } - scope(failure) { - debug(checkdoc) { - stderr.writefln( - "run failure", - ); - } - } - bool[string] _opt_action_bool = [ - "assertions" : false, - "concordance" : false, - "debug" : false, - "digest" : false, - "docbook" : false, - "epub" : false, - "html" : false, - "html_seg" : false, - "html_scroll" : false, - "manifest" : false, - "ocn" : true, - "odt" : false, - "pdf" : false, - "postgresql" : false, - "qrcode" : false, - "sisupod" : false, - "source" : false, - "sqlite" : false, - "text" : false, - "verbose" : false, - "xhtml" : false, - "xml_dom" : false, - "xml_sax" : false, - "section_toc" : true, - "section_body" : true, - "section_endnotes" : true, - "section_glossary" : true, - "section_biblio" : true, - "section_bookindex" : true, - "section_blurb" : true, - "backmatter" : true, - "skip_output" : false, - ]; - auto helpInfo = getopt(args, - std.getopt.config.passThrough, - "assert", "--assert set optional assertions on", &_opt_action_bool["assertions"], - "concordance", "--concordance file for document", &_opt_action_bool["concordance"], - "debug", "--debug only relevant when debug options compiled in", &_opt_action_bool["debug"], - "digest", "--digest hash digest for each object", &_opt_action_bool["digest"], - "docbook", "--docbook process docbook output", &_opt_action_bool["docbook"], - "epub", "--epub process epub output", &_opt_action_bool["epub"], - "html", "--html process html output", &_opt_action_bool["html"], - "html_seg", "--html-seg process html output", &_opt_action_bool["html_seg"], - "html_scroll", "--html-seg process html output", &_opt_action_bool["html_scroll"], - "manifest", "--manifest process manifest output", &_opt_action_bool["manifest"], - "ocn", "--ocn object cite numbers (default)", &_opt_action_bool["ocn"], - "odf", "--odf process odf:odt output", &_opt_action_bool["odt"], - "odt", "--odt process odf:odt output", &_opt_action_bool["odt"], - "pdf", "--pdf process pdf output", &_opt_action_bool["pdf"], - "pg", "--pg process postgresql output", &_opt_action_bool["postgresql"], - "postgresql", "--postgresql process postgresql output", &_opt_action_bool["postgresql"], - "qrcode", "--qrcode with document metadata", &_opt_action_bool["qrcode"], - "sisupod", "--sisupod sisupod source content bundled", &_opt_action_bool["sisupod"], - "source", "--source markup source text content", &_opt_action_bool["source"], - "sqlite", "--sqlite process sqlite output", &_opt_action_bool["sqlite"], - "text", "--text process text output", &_opt_action_bool["text"], - "txt", "--txt process text output", &_opt_action_bool["text"], - "verbose|v", "--verbose output to terminal", &_opt_action_bool["verbose"], - "xhtml", "--xhtml process xhtml output", &_opt_action_bool["xhtml"], - "xml-dom", "--xml-dom process xml dom output", &_opt_action_bool["xml_dom"], - "xml-sax", "--xml-sax process xml sax output", &_opt_action_bool["xml_sax"], - "section-toc", "--section-toc process table of contents (default)", &_opt_action_bool["section_toc"], - "section-body", "--section-body process document body (default)", &_opt_action_bool["section_body"], - "section-endnotes", "--section-endnotes process document endnotes (default)", &_opt_action_bool["section_endnotes"], - "section-glossary", "--section-glossary process document glossary (default)", &_opt_action_bool["section_glossary"], - "section-biblio", "--section-biblio process document biblio (default)", &_opt_action_bool["section_biblio"], - "section-bookindex", "--section-bookindex process document bookindex (default)", &_opt_action_bool["section_bookindex"], - "section-blurb", "--section-blurb process document blurb (default)", &_opt_action_bool["section_blurb"], - "backmatter", "--section-backmatter process document backmatter (default)", &_opt_action_bool["backmatter"], - "skip_output", "--skip-output", &_opt_action_bool["skip_output"], - ); - if (helpInfo.helpWanted) { - defaultGetoptPrinter("Some information about the program.", helpInfo.options); - } - foreach(arg; args) { - if (arg.match(rgx.flag_action)) { - flag_action ~= " " ~ arg; // flags not taken by getopt - } else if (arg.match(rgx.src_pth)) { - fns_src ~= arg; // gather input markup source file names for processing - } else { // anything remaining, unused - arg_unrecognized ~= " " ~ arg; - } - } - auto env = [ - "pwd" : environment["PWD"], - "home" : environment["HOME"], - ]; - auto sdl_root_configuration = ConfigHub!()("conf.sdl", env); - auto sdl_root_doc_make = ConfigHub!()("sisu_document_make", env); - auto confsdl = HeaderExtractSDL(); - auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration); - auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make); - foreach(fn_src; fns_src) { - if (!empty(fn_src)) { - scope(success) { - debug(checkdoc) { - writefln( - "%s\n%s", - "~ document complete, ok ~", - "------------------------------------------------------------------", - ); - } - } - scope(failure) { - debug(checkdoc) { - stderr.writefln( - "~ document run failure ~ (%s v%s)\n\t%s", - __VENDOR__, __VERSION__, - fn_src - ); - } - } - enforce( - fn_src.match(rgx.src_pth), - "not a sisu markup filename" - ); - auto t = - SiSUabstraction!()(fn_src, _opt_action_bool, env); - static assert(!isTypeTuple!(t)); - static assert(t.length==2); - auto doc_abstraction = t[dAM.abstraction]; - auto doc_matters = t[dAM.matters]; - /+ ↓ debugs +/ - if (doc_matters.opt_action_bool["verbose"]) { - SiSUabstractionSummary!()(doc_abstraction, doc_matters); - } - /+ ↓ debugs +/ - if ((doc_matters.opt_action_bool["debug"]) - || (doc_matters.opt_action_bool["verbose"]) - ) { - SiSUdebugs!()(doc_abstraction, doc_matters); - } - /+ ↓ output hub +/ - if (!(_opt_action_bool["skip_output"])) { - outputHub!()(doc_abstraction, doc_matters); - } - scope(exit) { - debug(checkdoc) { - writefln( - "processed file: %s", - fn_src - ); - } - destroy(fn_src); - } - } else { - /+ no recognized filename provided +/ - writeln("no recognized filename"); - break; // terminate, stop - } - } -} -unittest { - /++ - name "sdp" - description "A SiSU document parser writen in D." - homepage "http://sisudoc.org" - +/ -} diff --git a/views/version.txt b/views/version.txt index ded3634..d5b64a1 100644 --- a/views/version.txt +++ b/views/version.txt @@ -4,4 +4,4 @@ struct Version { int minor; int patch; } -enum ver = Version(0, 15, 0); +enum ver = Version(0, 16, 0); -- cgit v1.2.3