From 8b04ed5fd9118f0defb2f4cd1f80bafce49650b4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 15 Nov 2019 20:38:38 -0500 Subject: org renaming --- org/in_source_files.org | 667 ++++ org/meta_abstraction.org | 7828 --------------------------------------- org/metaverse.org | 7828 +++++++++++++++++++++++++++++++++++++++ org/out_harvest_metadata.org | 862 +++++ org/out_latex.org | 1879 ++++++++++ org/out_odt.org | 2517 +++++++++++++ org/out_sqlite.org | 1931 ++++++++++ org/out_src_pod.org | 443 +++ org/out_xmls.org | 3095 ++++++++++++++++ org/out_xmls_css.org | 2364 ++++++++++++ org/out_zip.org | 45 + org/output_harvest_metadata.org | 862 ----- org/output_latex.org | 1879 ---------- org/output_odt.org | 2517 ------------- org/output_sqlite.org | 1931 ---------- org/output_src_pod.org | 443 --- org/output_xmls.org | 3095 ---------------- org/output_xmls_css.org | 2364 ------------ org/output_zip.org | 45 - org/source_files_read.org | 667 ---- 20 files changed, 21631 insertions(+), 21631 deletions(-) create mode 100644 org/in_source_files.org delete mode 100644 org/meta_abstraction.org create mode 100644 org/metaverse.org create mode 100644 org/out_harvest_metadata.org create mode 100644 org/out_latex.org create mode 100644 org/out_odt.org create mode 100644 org/out_sqlite.org create mode 100644 org/out_src_pod.org create mode 100644 org/out_xmls.org create mode 100644 org/out_xmls_css.org create mode 100644 org/out_zip.org delete mode 100644 org/output_harvest_metadata.org delete mode 100644 org/output_latex.org delete mode 100644 org/output_odt.org delete mode 100644 org/output_sqlite.org delete mode 100644 org/output_src_pod.org delete mode 100644 org/output_xmls.org delete mode 100644 org/output_xmls_css.org delete mode 100644 org/output_zip.org delete mode 100644 org/source_files_read.org (limited to 'org') diff --git a/org/in_source_files.org b/org/in_source_files.org new file mode 100644 index 0000000..121b070 --- /dev/null +++ b/org/in_source_files.org @@ -0,0 +1,667 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) markup source raw +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:sourcefile:read: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +[[./spine.org][spine]] [[./][org/]] +* imports + +#+name: imports_std +#+BEGIN_SRC d +import + doc_reform.meta, + doc_reform.source.paths_source, + std.file, + std.path; +#+END_SRC + +* A. get _config file_ (read in) +** _module template_ :module:config_files: + +#+BEGIN_SRC d :tangle "../src/doc_reform/source/read_config_files.d" +/++ + read configuration files
+ - read config files
+ meta_config_files.d ++/ +module doc_reform.source.read_config_files; +<> +<> +#+END_SRC + +*** 0. read config files (config_local_site & dr_document_make) (yaml) +**** 1. site configuration + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template readConfigSite() { + import + doc_reform.meta.rgx; + <> + mixin DocReformRgxInit; + final auto readConfigSite(M,E)( + M _manifested, + E _env, + string _cli_config_path_set = "" + ) { + static auto rgx = Rgx(); + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env, _cli_config_path_set); + string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; + foreach(conf_fn; [_conf_file_details.config_filename_site]) { + foreach(pth; possible_config_path_locations) { + char[] conf_file; + conf_filename = conf_fn; + if (exists(pth)) { + auto f_attrib = pth.getLinkAttributes; + if ( + possible_config_path_locations.length == 1 + && f_attrib.attrIsFile + ) { + conf_file = pth.to!(char[]); + conf_filename = pth.baseName; + } else if (f_attrib.attrIsDir) { + conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + conf_filename = conf_fn; + } + try { + if (exists(conf_file)) { + if (conf_file.getLinkAttributes.attrIsFile) { + config_file_str = conf_file.readText; + break; + } + } + } catch (ErrnoException ex) { + } catch (FileException ex) { + } + } + } + if (config_file_str.length > 0) { break; } + } + struct _ConfContent { + string filename() { + return conf_filename; + } + string filetype() { + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } + return _ft; + } + string content() { + return config_file_str; + } + } + return _ConfContent(); + } +} +#+END_SRC + +**** 2. document make/config + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template readConfigDoc() { + import + doc_reform.meta.rgx; + <> + mixin DocReformRgxInit; + final auto readConfigDoc(M,E)(M _manifested, E _env) { + static auto rgx = Rgx(); + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.dr_document_make; + foreach(conf_fn; [_conf_file_details.config_filename_document]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + conf_filename = conf_fn; + if (config_file_str.length > 0) { + break; + } + try { + if (exists(conf_file)) { + if (conf_file.getLinkAttributes.attrIsFile) { + config_file_str = conf_file.readText; + break; + } + } + } catch (ErrnoException ex) { + } catch (FileException ex) { + } + } + if (config_file_str.length > 0) { break; } + } + struct _ConfContent { + string filename() { + return conf_filename; + } + string content() { + return config_file_str; + } + string filetype() { + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } + return _ft; + } + } + return _ConfContent(); + } +} +#+END_SRC + +*** 1. YAML config files get + +#+name: meta_config_file_yaml +#+BEGIN_SRC d +static template configYAML() { + import dyaml; // + <> + YAMLDocument configYAML(string configuration, string conf_yaml_filename) { + Node _yaml_conf; + try { + _yaml_conf = Loader.fromString(configuration).load() + } catch(ErrnoException e) { + stderr.writeln("Yaml problem with content for ", conf_yaml_filename); + stderr.writeln(e.msg); + } + return _yaml_conf; + } +} +#+END_SRC + +*** 2. YAML config (config_local_site & dr_document_make) :file:config:hub: + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template configReadSiteYAML() { + <> + final YAMLDocument configReadSiteYAML(M,E)(M _manifested, E _env) { + string _configuration = configReadInSiteYAML!()(_manifested, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string _conf_yaml_fn = _conf_file_details.config_filename_site; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); + return _yaml_conf; + } +} +static template configReadDocYAML() { + <> + final YAMLDocument configReadDocYAML(M,E)(M _manifested, E _env) { + string _configuration = configReadInDocYAML!()(_manifested, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + string _conf_yaml_fn = _conf_file_details.config_filename_document; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); + return _yaml_conf; + } +} +#+END_SRC + +* B. get _markup source_, read file :module:source_files: +** _module template_ (includes tuple) + +#+BEGIN_SRC d :tangle "../src/doc_reform/source/read_source_files.d" +/++ + module source_read_source_files;
+ - open markup files
+ - if master file scan for addional files to import/insert ++/ +module doc_reform.source.read_source_files; +static template DocReformRawMarkupContent() { + import + doc_reform.meta.rgx; + <> + mixin DocReformRgxInit; + static auto rgx = Rgx(); + string[] _images=[]; + auto _extract_images(S)(S content_block) { + string[] images_; + string _content_block = content_block.to!string; + if (auto m = _content_block.matchAll(rgx.image)) { + images_ ~= m.captures[1].to!string; + } + return images_; + } + auto rawsrc = RawMarkupContent(); + auto DocReformRawMarkupContent(O,Fn)(O _opt_action, Fn fn_src) { + auto _0_header_1_body_content_2_insert_filelist_tuple + = rawsrc.sourceContentSplitIntoHeaderAndBody(_opt_action, 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(O)(O _opt_action, in string source_txt_str, in string fn_src="") { + auto raw = MarkupRawUnit(); + string[] insert_file_list; + string[] images_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(_opt_action, sourcefile_body_content, fn_src); + static assert(!isTypeTuple!(tu)); + sourcefile_body_content = tu[0]; + insert_file_list = tu[1].dup; + images_list = tu[2].dup; + } else if (_opt_action.source || _opt_action.pod) { + auto ins = Inserts(); + auto tu + = ins.scan_master_src_for_insert_files_and_import_content(_opt_action, sourcefile_body_content, fn_src); + static assert(!isTypeTuple!(tu)); + images_list = tu[2].dup; + } + string header_type = ""; + if (header_raw.match(rgx.yaml_config)) { + header_type = "yaml"; + } + t = tuple( + header_raw, + sourcefile_body_content, + header_type, + insert_file_list, + images_list + ); + static assert(t.length==5); + return t; + } + } + struct MarkupRawUnit { + import std.file; + <> + <> + <> + <> + <> + <> + } + struct Inserts { + auto scan_subdoc_source(O)( + O _opt_action, + char[][] markup_sourcefile_insert_content, + string fn_src + ) { + mixin DocReformRgxInitFlags; + <> + foreach (line; markup_sourcefile_insert_content) { + <> + } // end src subdoc (inserts) loop + <> + } + auto scan_master_src_for_insert_files_and_import_content(O)( + O _opt_action, + char[][] sourcefile_body_content, + string fn_src + ) { + import std.algorithm; + mixin DocReformRgxInitFlags; + <> + foreach (line; sourcefile_body_content) { + <> + } // end src doc loop + <> + } + } +} +#+END_SRC + +** get markup source, read file :source:markup: +*** read file, source string [#A] :string: + +#+name: meta_markup_source_raw_read_file_source_string +#+BEGIN_SRC d +final private string readInMarkupSource(in char[] fn_src) { + enforce( + exists(fn_src)!=0, + "file not found: «" ~ + fn_src ~ "»" + ); + string source_txt_str; + try { + if (exists(fn_src)) { + if (fn_src.getLinkAttributes.attrIsFile) { + source_txt_str = fn_src.readText; + } else { + } + } + } catch (ErrnoException ex) { + } catch (UTFException ex) { + // Handle validation errors + } catch (FileException ex) { + // Handle errors + } + std.utf.validate(source_txt_str); + return source_txt_str; +} +#+END_SRC + +*** document header & content, array.length == 2 [#A] :array: + +here you split document header and body, an array.length == 2 +split is on first match of level A~ (which is required) + +#+name: meta_markup_source_raw_doc_header_and_content_split +#+BEGIN_SRC d +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; +} +#+END_SRC + +*** source line array :array: + +#+name: meta_markup_source_raw_source_line_array +#+BEGIN_SRC d +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; +} +#+END_SRC + +*** source content raw line array :array: +- used for regular .sst files; master .ssm files and; .ssi inserts +- regex is passed for relevant enforce match + +**** read in file + +#+name: meta_markup_source_raw_read_in_file +#+BEGIN_SRC d +auto markupSourceReadIn(in string fn_src) { + static auto rgx = Rgx(); + enforce( + fn_src.match(rgx.src_pth_sst_or_ssm), + "not a dr markup filename: «" ~ + fn_src ~ "»" + ); + auto source_txt_str = readInMarkupSource(fn_src); + return source_txt_str; +} +#+END_SRC + +**** tuple (a) header, (b) body content, (c) file insert list & (d) image list? + +- header +- body content +- file insert list +- [image list?] + +#+name: meta_markup_source_raw_tuple_of_header_and_body +#+BEGIN_SRC d +auto markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) { + string[] file_insert_list = []; + string[] images_list = []; + char[][] hc = header0Content1(source_txt_str); + char[] header = hc[0]; + char[] source_txt = hc[1]; + auto source_line_arr = markupSourceLineArray(source_txt); + string header_type = ""; + if (header.match(rgx.yaml_config)) { + header_type = "yaml"; + } + auto t = tuple( + header, + source_line_arr, + header_type, + file_insert_list, + images_list + ); + return t; +} +#+END_SRC + +**** get insert source line array + +#+name: meta_markup_source_raw_get_insert_source_line_array +#+BEGIN_SRC d +final char[][] getInsertMarkupSourceContentRawLineArray( + in char[] fn_src_insert, + Regex!(char) rgx_file +) { + enforce( + fn_src_insert.match(rgx_file), + "not a dr markup filename: «" ~ + fn_src_insert ~ "»" + ); + auto source_txt_str = readInMarkupSource(fn_src_insert); + auto source_line_arr = markupSourceLineArray(source_txt_str); + return source_line_arr; +} +#+END_SRC + +** get markup source, master file & inserts :masterfile:inserts: +[[./spine.org][spine]] [[./][org/]] + +*** scan inserts (sub-document) source :scan_insert_src: +**** scan subdoc source + +#+name: meta_inserts_scan +#+BEGIN_SRC d +char[][] contents_insert; +int[string] type1 = flags_type_init; +auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); +auto markup_src_file_path = fn_pth_full.captures[1]; +#+END_SRC + +**** loop insert (sub-document) + +#+name: meta_inserts_scan_loop +#+BEGIN_SRC d +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 (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) { + writeln(line); + writeln(fn_src_insert); + writeln( + " length contents insert array: ", + markup_sourcesubfile_insert_content.length + ); + } + if (_opt_action.source || _opt_action.pod) { + _images ~= _extract_images(markup_sourcesubfile_insert_content); + } + auto ins = Inserts(); + /+ + - 1. load file + - 2. read lines + - 3. scan lines + - a. if filename insert, and insert filename + - repeat 1 + - b. else + - add line to new array; + - build image list, search for any image files to add to image list + +/ +} else { + type1["header_make"] = 0; + type1["header_meta"] = 0; + contents_insert ~= line; // images to extract for image list? + if (_opt_action.source || _opt_action.pod) { + auto _image_linelist = _extract_images(line); + if (_image_linelist.length > 0) { + _images ~= _image_linelist; + } + } +} +#+END_SRC + +**** post loop + +#+name: meta_inserts_scan_post +#+BEGIN_SRC d +auto t = tuple( + contents_insert, + _images +); +return t; +#+END_SRC + +*** scan document source :scan_src: +**** scan doc source + +#+name: meta_master_doc_scan_for_insert_filenames +#+BEGIN_SRC d +char[][] contents; +int[string] type = flags_type_init; +auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); +auto markup_src_file_path = fn_pth_full.captures[1]; +char[][] contents_insert; +string[] _images =[]; +string[] insert_file_list =[]; +#+END_SRC + +**** include inserts: _loop master_ scan for inserts (insert documents) + +#+name: meta_master_doc_scan_for_insert_filenames_loop +#+BEGIN_SRC d +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 ~= fn_src_insert.to!string; + auto raw = MarkupRawUnit(); + /+ TODO +/ + auto markup_sourcefile_insert_content + = raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); + debug(insert_file) { + writeln(line); + writeln(fn_src_insert); + writeln( + " length contents insert array: ", + markup_sourcefile_insert_content.length + ); + } + auto ins = Inserts(); + auto contents_insert_tu = ins.scan_subdoc_source( + _opt_action, + markup_sourcefile_insert_content, + fn_src_insert.to!string + ); + contents ~= contents_insert_tu[0]; // images to extract for image list? + if (_opt_action.source || _opt_action.pod) { + auto _image_linelist = _extract_images(contents_insert_tu[0]); + if (_image_linelist.length > 0) { + _images ~= _image_linelist; + } + } + /+ + - 1. load file + - 2. read lines + - 3. scan lines + - a. if filename insert, and insert filename + - repeat 1 + - b. else + - add line to new array; + - build image list, search for any image files to add to image list + +/ +} else { + contents ~= line; + if (_opt_action.source || _opt_action.pod) { + auto _image_linelist = _extract_images(line); + if (_image_linelist.length > 0) { + _images ~= _image_linelist; + } + } +} +#+END_SRC + +**** post loop + +#+name: meta_master_doc_scan_for_insert_filenames_post +#+BEGIN_SRC d +string[] images = []; +foreach(i; uniq(_images.sort())) { + images ~= i; +} +debug(insert_file) { + writeln(__LINE__); + writeln(contents.length); +} +auto t = tuple( + contents, + insert_file_list, + images +); +return t; +#+END_SRC + +* __END__ diff --git a/org/meta_abstraction.org b/org/meta_abstraction.org deleted file mode 100644 index e76e7b9..0000000 --- a/org/meta_abstraction.org +++ /dev/null @@ -1,7828 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) document abstraction -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:abstraction: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] - -* 1. Document Abstraction -Process markup document, create document abstraction. - -** _module template_ :module:metadoc_from_src: - -#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_from_src.d" -/++ - document abstraction: - abstraction of sisu markup for downstream processing - metadoc_from_src.d -+/ -module doc_reform.meta.metadoc_from_src; -template DocReformDocAbstraction() { - /+ ↓ abstraction imports +/ - <> - /+ ↓ abstraction mixins +/ - <> - /+ ↓ abstraction struct init +/ - <> - <> - /+ ↓ abstract marked up document +/ - auto DocReformDocAbstraction(CMM,Opt,Mf)( - char[][] markup_sourcefile_content, - CMM conf_make_meta, - Opt opt_action, - Mf manifested, - bool _new_doc - ) { - static auto rgx = Rgx(); - /+ ↓ abstraction init +/ - <> - /+ abstraction init ↑ +/ - <> - /+ ↓ ↻ loop markup document/text line by line +/ - srcDocLoop: - foreach (line; markup_sourcefile_content) { /+ ↓ markup document/text line by line +/ - // "line" variable can be empty but should never be null - <> - if (obj_type_status["code"] == TriState.on) { - <> - } 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 +/ - <> - } else { /+ not within a block group +/ - <> - if (line.matchFirst(rgx.block_open)) { - <> - } else if (!line.empty) { /+ line not empty +/ - /+ non blocks (headings, paragraphs) & closed blocks +/ - <> - } else if (obj_type_status["blocks"] == TriState.closing) { /+ line empty, with blocks flag +/ - <> - } else { /+ line.empty, post contents, empty variables: +/ - <> - } // close else for line empty - } // close else for not the above - } // close after non code, other blocks or regular text - <> - } /+ ← srcDocLoop closed: loop markup document/text line by line +/ - /+ ↓ post loop markup document/text +/ - <> - <> - <> - <> - /+ post loop markup document/text ↑ +/ - } /+ ← closed: abstract doc source +/ - /+ ↓ abstraction functions +/ - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - /+ abstraction functions ↑ +/ - /+ ↓ abstraction function emitters +/ - <> - /+ +/ - <> - <> - <> - <> - <> - <> - <> - /+ +/ - <> - <> - <> - <> - <> - <> - /+ +/ - <> - <> - <> - /+ +/ - <> - /+ +/ - <> - /+ +/ - <> - /+ abstraction functions emitters ↑ +/ - /+ ↓ abstraction functions assertions +/ - <> - /+ abstraction functions assertions ↑ +/ -} /+ ← closed: template DocReformDocAbstraction +/ -<> -#+END_SRC - -** 1. _pre loop processing_ :pre: -*** imports :imports: -[[./meta_defaults.org][meta_defaults]] - -#+name: abs_top_imports -#+BEGIN_SRC d -import doc_reform.meta; -import - std.algorithm, - std.container, - std.file, - std.json, - std.path; -import - doc_reform.meta.defaults, - doc_reform.meta.object_setter, - doc_reform.meta.rgx; -#+END_SRC - -*** mixins :mixins: - -#+name: abs_top_mixins -#+BEGIN_SRC d -mixin ObjectSetter; -mixin InternalMarkup; -mixin DocReformRgxInit; -#+END_SRC - -*** initialize :initialize: -**** initialize general - -#+name: abs_top_init_struct -#+BEGIN_SRC d -/+ initialize +/ -ObjGenericComposite[] 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 anchor_tag_; -string[string] tag_in_seg; -string lev_anchor_tag; -string[string][string] tag_assoc; -string[] lv0_to_3_tags; -/+ 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 -enum Status { off, on, } -enum OCNstatus { on, off, bkidx, closing, reset, } -enum OCN_off_block_status { off, on } -enum OCNtype { ocn, non, bkidx, } -/+ 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"; -static auto obj_im = ObjInlineMarkup(); -static auto obj_att = ObjAttributes(); -/+ ocn +/ -struct OCNset { - int digit; - int object_number; - bool off; - string identifier; - int bkidx; - int type; -} -OCNset obj_cite_digits; -int obj_cite_digit_, obj_cite_digit_off, obj_cite_digit_bkidx, obj_cite_digit_type; -auto object_citation_number = OCNemitter(); -int[] dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -int[] dom_structure_markedup_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -int[] dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -int[] dom_structure_collapsed_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -enum DomTags { none, open, close, close_and_open, open_still, } -#+END_SRC - -**** method heading ancestors - -#+name: abs_top_init_struct -#+BEGIN_SRC d -pure ObjGenericComposite obj_heading_ancestors()( - ObjGenericComposite obj, - string[] lv_ancestors_txt, -) { - switch (obj.metainfo.heading_lev_markup) { - case 0: - lv_ancestors_txt[0] = obj.text.to!string; - foreach(k; 1..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 1: - lv_ancestors_txt[1] = obj.text.to!string; - foreach(k; 2..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 2: - lv_ancestors_txt[2] = obj.text.to!string; - foreach(k; 3..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 3: - lv_ancestors_txt[3] = obj.text.to!string; - foreach(k; 4..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 4: - lv_ancestors_txt[4] = obj.text.to!string; - foreach(k; 5..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 5: - lv_ancestors_txt[5] = obj.text.to!string; - foreach(k; 6..8) { - lv_ancestors_txt[k] = ""; - } - goto default; - case 6: - lv_ancestors_txt[6] = obj.text.to!string; - lv_ancestors_txt[7] = ""; - goto default; - case 7: - lv_ancestors_txt[7] = obj.text.to!string; - goto default; - default: - obj.tags.heading_ancestors_text = lv_ancestors_txt.dup; - } - return obj; -} -#+END_SRC - -**** method dom markup tags - -#+name: abs_top_init_struct -#+BEGIN_SRC d -pure ObjGenericComposite obj_dom_structure_set_markup_tags()( - ObjGenericComposite obj, - 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); - } - obj.metainfo.dom_structure_markedup_tags_status = dom.dup; - return obj; -} -#+END_SRC - -**** method dom collapsed tags - -#+name: abs_top_init_struct -#+BEGIN_SRC d -pure ObjGenericComposite obj_dom_set_collapsed_tags()( - ObjGenericComposite obj, - 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); - } - obj.metainfo.dom_structure_collapsed_tags_status = dom.dup; - return obj; -} -#+END_SRC - -**** method ocn emit - -#+name: abs_top_init_struct -#+BEGIN_SRC d -static auto ocn_emit(int ocn_status_flag) { - return object_citation_number.ocn_emitter(ocn_status_flag); -} -static auto inline_markup_faces(L)(L line) { - static auto rgx = Rgx(); - static auto mkup = InlineMarkup(); - line = replaceAll!(m => mkup.quote_o ~ m[1] ~ mkup.quote_c)(line, rgx.within_quotes); - line = replaceAll!(m => mkup.mono ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); - line = replaceAll!(m => mkup.cite ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); - foreach (regx; [rgx.inline_mark_emphasis, rgx.inline_mark_bold, rgx.inline_mark_underscore, rgx.inline_mark_italics, rgx.inline_mark_superscript, rgx.inline_mark_subscript, rgx.inline_mark_strike, rgx.inline_mark_insert]) { - line = replaceAll!(m => m["mark"] ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ m["mark"])(line, regx); - } - return line; -} -static string links_and_images()(string obj_txt) { - static auto rgx = Rgx(); - static auto mkup = InlineMarkup(); - if (obj_txt.match(rgx.smid_inline_url_generic)) { - if ( - obj_txt.match(rgx.smid_inline_link_endnote_url_helper) - || obj_txt.match(rgx.smid_inline_link_endnote_url_helper_punctuated) - ) { - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s%s", - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_o, - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_c, - m[3] - ))(obj_txt, rgx.smid_inline_link_endnote_url_helper_punctuated); - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s", - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_o, - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c, - mkup.en_a_c - ))(obj_txt, rgx.smid_inline_link_endnote_url_helper); - } else { - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m["pre"], - mkup.lnk_o, m["content"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c - ))(obj_txt, rgx.smid_inline_link_markup_regular); - } - obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", - m["pre"], - mkup.lnk_o, m["link"].strip, mkup.lnk_c, - mkup.url_o, m["link"], mkup.url_c - ))(obj_txt, rgx.smid_inline_link_naked_url); // - } - return obj_txt; -} -/+ 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_tag, notes_reg, notes_star, links, image_no_dimensions } -#+END_SRC - -*** inline para tag associations - -#+name: abs_inline_para_tag_associations -#+BEGIN_SRC d -string[string][string] inline_para_link_anchor()( - string[string] an_object, - string[string] tag_in_seg, - string[string][string] tag_assoc -) { - static auto rgx = Rgx(); - if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) { - if (m.captures[1] !in tag_assoc) { - tag_assoc[(m.captures[1])]["seg_lv4"] = tag_in_seg["seg_lv4"]; - tag_assoc[(m.captures[1])]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; - } else { - writeln("a tag named already exists, check text line\n ", an_object["substantive"]); - } - } - return tag_assoc; -} -#+END_SRC - -*** scope - -#+name: abs_init_rest -#+BEGIN_SRC d -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; -} -#+END_SRC - -*** init rest - -#+name: abs_init_rest -#+BEGIN_SRC d -mixin DocReformRgxInitFlags; -mixin DocReformNode; -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, -]; -uint[string] dochas = [ - "inline_links" : 0, - "inline_notes" : 0, - "inline_notes_star" : 0, - "codeblock" : 0, - "table" : 0, - "block" : 0, - "group" : 0, - "poem" : 0, - "quote" : 0, - "images" : 0, -]; -auto obj_type_status = flags_type_init; -string[string] object_number_poem = [ - "start" : "", - "end" : "" -]; -string[] lv_ancestors_txt = [ "", "", "", "", "", "", "", "", ]; -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)" -]; -Regex!char[string] 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_.metainfo.is_of_part = "frontmatter"; -comp_obj_heading_.metainfo.is_of_section = "toc"; -comp_obj_heading_.metainfo.is_of_type = "para"; -comp_obj_heading_.metainfo.is_a = "heading"; -comp_obj_heading_.text = "Table of Contents"; -comp_obj_heading_.metainfo.ocn = 0; -comp_obj_heading_.metainfo.identifier = ""; -comp_obj_heading_.metainfo.dummy_heading = false; -comp_obj_heading_.metainfo.object_number_off = true; -comp_obj_heading_.metainfo.object_number_type = 0; -comp_obj_heading_.tags.segment_anchor_tag_epub = "toc"; -comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; -comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; -comp_obj_heading_.metainfo.heading_lev_markup = 4; -comp_obj_heading_.metainfo.heading_lev_collapsed = 1; -comp_obj_heading_.metainfo.parent_ocn = 1; -comp_obj_heading_.metainfo.parent_lev_markup = 0; -comp_obj_heading_.ptr.html_segnames = html_segnames_ptr; -comp_obj_heading_.tags.anchor_tags = ["toc"]; -comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; -comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; -tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; -tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; -auto toc_head = comp_obj_heading_; -html_segnames_ptr_cntr++; -the_table_of_contents_section = [toc_head]; -static auto mkup = InlineMarkup(); -static auto munge = ObjInlineMarkupMunge(); -auto note_section = NotesSection(); -auto bookindex_extract_hash = BookIndexNuggetHash(); -string[][string] lev4_subtoc; -string[][string] segnames = ["html": ["toc"], "epub": ["toc"]]; -int cnt1 = 1; int cnt2 = 1; int cnt3 = 1; -#+END_SRC - -*** make tests - -#+name: make_tests -#+BEGIN_SRC d -enum Substitute { match, markup, } -debug (substitutions) { - writeln(__LINE__, ":", __FILE__, ": DEBUG substitutions:"); - if (!(conf_make_meta.make.headings.empty)) { - writeln(conf_make_meta.make.headings); - } - if (conf_make_meta.make.substitute) { - foreach(substitution_pair; conf_make_meta.make.substitute) { - writeln("regex to match: ", substitution_pair[Substitute.match]); - writeln("substitution to make: ", substitution_pair[Substitute.markup]); - } - } - if (conf_make_meta.make.bold) { - writeln("regex to match: ", conf_make_meta.make.bold[Substitute.match]); - writeln("substitution to make: ", conf_make_meta.make.bold[Substitute.markup]); - } - if (conf_make_meta.make.emphasis) { - writeln("regex to match: ", conf_make_meta.make.emphasis[Substitute.match]); - writeln("substitution to make: ", conf_make_meta.make.emphasis[Substitute.markup]); - } - if (conf_make_meta.make.italics) { - writeln("regex to match: ", conf_make_meta.make.italics[Substitute.match]); - writeln("substitution to make: ", conf_make_meta.make.italics[Substitute.markup]); - } -} -#+END_SRC - -** 2. ↻ *LOOP* _loop: process document body_ [+6] :loop: -*** Loop scope :scope: - -#+name: abs_in_loop_body_00 -#+BEGIN_SRC d -/+ scope +/ -scope(exit) { -} -scope(failure) { - stderr.writefln( - "%s\n%s\n%s:%s failed here:\n line: %s", - __MODULE__, __FUNCTION__, - __FILE__, __LINE__, - line, - ); -} -debug(source) { - writeln(line); -} -debug(srclines) { - if (!line.empty) { - writefln( - "* %s", - line - ); - } -} -#+END_SRC - -*** check whether object_number is on or turned off :ocn: - -#+name: abs_in_loop_body_00 -#+BEGIN_SRC d -if (!line.empty) { - obj_type_status = line._check_ocn_status_(obj_type_status); -} -#+END_SRC - -*** separate _code blocks_ from _other markup text_ [+5] [#A] -**** _code blocks_ :block:code: - -#+name: abs_in_loop_body_00_code_block -#+BEGIN_SRC d -/+ block object: code +/ -line.flow_txt_block_code(an_object, obj_type_status); -continue; -#+END_SRC - -**** _non code objects_ (non-code blocks & regular text: by line) [+4] :non_code: -***** inline fontface markup - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -line = line.inline_markup_faces; // by text line (rather than by text object), linebreaks in para problematic -#+END_SRC - -***** in section (biblio, glossary, blurb) +(block group)+ [+1] :block:active: -****** in section: biblio :biblio: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -if ((line.matchFirst(rgx.heading_biblio) - && obj_type_status["para"] != State.on - && obj_type_status["group"] != State.on - && obj_type_status["block"] != State.on - && obj_type_status["poem"] != State.on - && obj_type_status["table"] != State.on - && obj_type_status["quote"] != State.on) -|| (obj_type_status["biblio_section"] == State.on -&& (!(line.matchFirst(rgx.heading_blurb_glossary))) -&& (!(line.matchFirst(rgx.heading))) -&& (!(line.matchFirst(rgx.comment))))) { - /+ within section (block object): biblio +/ - obj_type_status["glossary_section"] = State.off; - obj_type_status["biblio_section"] = State.on; - obj_type_status["blurb_section"] = State.off; - if (opt_action.backmatter && opt_action.section_biblio) { - line.flow_txt_block_biblio(obj_type_status, bib_entry, biblio_entry_str_json, biblio_arr_json); - debug(bibliobuild) { - writeln("- ", biblio_entry_str_json); - writeln("-> ", biblio_arr_json.length); - } - } - continue; -#+END_SRC - -****** in section: glossary :glossary: - -if there is a glossary section you need to: -- extract it -- create standard headings -- markup contents in standard way like regular paragraphs - - need indentation and regular paragraph inline markup -- reconstitute the document with the glossary section following the endnotes - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if ((line.matchFirst(rgx.heading_glossary) - && obj_type_status["para"] != State.on - && obj_type_status["group"] != State.on - && obj_type_status["block"] != State.on - && obj_type_status["poem"] != State.on - && obj_type_status["table"] != State.on - && obj_type_status["quote"] != State.on) -|| (obj_type_status["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); - } - obj_type_status["glossary_section"] = State.on; - obj_type_status["biblio_section"] = State.off; - obj_type_status["blurb_section"] = State.off; - if (opt_action.backmatter && opt_action.section_glossary) { - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - obj_type_status["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_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "glossary"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_glossary"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "glossary"; - comp_obj_heading_.tags.anchor_tags = ["section_glossary"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - the_glossary_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "glossary"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Glossary"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "glossary"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; - comp_obj_heading_.tags.anchor_tags = ["glossary"]; - the_glossary_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - } else { - an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "glossary"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "glossary"; - comp_obj_para.text = line.to!string.strip; - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.attrib.bullet = bullet; - the_glossary_section ~= comp_obj_para; - } - obj_type_status["ocn_status"] = OCNstatus.on; - } - continue; -#+END_SRC - -****** in section: blurb :blurb: - -if there is a blurb section you need to: -- extract it -- create standard headings (or use line provided in 1~ heading) -- markup contents in standard way like regular paragraphs - - need regular paragraph inline markup -- reconstitute the document with the blurb section at the very end of the doucment - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if ((line.matchFirst(rgx.heading_blurb) - && obj_type_status["para"] != State.on - && obj_type_status["group"] != State.on - && obj_type_status["block"] != State.on - && obj_type_status["poem"] != State.on - && obj_type_status["table"] != State.on - && obj_type_status["quote"] != State.on) -|| (obj_type_status["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); - } - obj_type_status["glossary_section"] = State.off; - obj_type_status["biblio_section"] = State.off; - obj_type_status["blurb_section"] = State.on; - if (opt_action.backmatter && opt_action.section_blurb) { - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - if (auto m = line.matchFirst(rgx.para_indent)) { - debug(paraindent) { - writeln(line); - } - indent["hang_position"] = (m["indent"]).to!int; - indent["base_position"] = (m["indent"]).to!int; - } else if (line.matchFirst(rgx.para_bullet)) { - debug(parabullet) { - writeln(line); - } - bullet = true; - } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { - debug(paraindenthang) { - writeln(line); - } - indent=[ - "hang_position" : (m["hang"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { - debug(parabulletindent) { - writeln(line); - } - indent=[ - "hang_position" : (m["indent"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - bullet = true; - } - obj_type_status["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_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "blurb"; - comp_obj_heading_.tags.anchor_tags = ["section_blurb"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; - the_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Blurb"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.tags.anchor_tags = ["blurb"]; - comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; - comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; - the_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - } else if (line.matchFirst(rgx.heading) - && (opt_action.backmatter && opt_action.section_blurb)) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "blurb"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = line.to!string; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv - comp_obj_heading_.metainfo.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_blurb_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } else { - an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "blurb"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "blurb"; - comp_obj_para.text = links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""); - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.has.inline_links = true; - comp_obj_para.attrib.bullet = bullet; - the_blurb_section ~= comp_obj_para; - } - obj_type_status["ocn_status"] = OCNstatus.on; - } - continue; -#+END_SRC - -***** in blocks [+1] :block:active: -****** in block: quote :quote: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if (obj_type_status["quote"] == TriState.on) { /+ within block object: quote +/ - line = line - ._doc_header_and_make_substitutions_(conf_make_meta) - ._doc_header_and_make_substitutions_fontface_(conf_make_meta); - an_object = line.flow_txt_block_quote(an_object, obj_type_status); - continue; -#+END_SRC - -****** in block: group :group: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -/+ within block object: group +/ -} else if (obj_type_status["group"] == TriState.on) { /+ within block object: group +/ - line = line - ._doc_header_and_make_substitutions_(conf_make_meta) - ._doc_header_and_make_substitutions_fontface_(conf_make_meta) - .replaceAll(rgx.para_delimiter, mkup.br_paragraph ~ "$1"); - an_object = line.flow_txt_block_group(an_object, obj_type_status); - continue; -#+END_SRC - -****** in block: block :block: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if (obj_type_status["block"] == TriState.on) { /+ within block object: block +/ - line = line - ._doc_header_and_make_substitutions_(conf_make_meta) - ._doc_header_and_make_substitutions_fontface_(conf_make_meta); - if (auto m = line.match(rgx.spaces_keep)) { - line = line - .replaceAll(rgx.spaces_keep, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); - } - an_object = line.flow_txt_block_block(an_object, obj_type_status); - continue; -#+END_SRC - -****** in block: poem :poem: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if (obj_type_status["poem"] == TriState.on) { /+ within block object: poem +/ - an_object = line.flow_txt_block_poem(an_object, obj_type_status, cntr, object_number_poem, conf_make_meta, tag_in_seg); - continue; -#+END_SRC - -****** in block: table :table: - -#+name: abs_in_loop_body_non_code_obj -#+BEGIN_SRC d -} else if (obj_type_status["table"] == TriState.on) { /+ within block object: table +/ - an_object = line.flow_txt_block_table(an_object, obj_type_status, conf_make_meta); - continue; -#+END_SRC - -***** not identified as being within block group (could still be, or not) [+3] -****** assert - -#+name: abs_in_loop_body_open_block_obj_assert -#+BEGIN_SRC d -assert( - (obj_type_status["blocks"] == TriState.off) - || (obj_type_status["blocks"] == TriState.closing), - "block status: none or closed" -); -assertions_flag_types_block_status_none_or_closed(obj_type_status); -#+END_SRC - -****** catch misc +block open+ - -#+name: abs_in_loop_body_open_block_obj -#+BEGIN_SRC d -if (line.matchFirst(rgx.block_poem_open)) { /+ poem to verse exceptions! +/ - object_reset(an_object); - processing.remove("verse"); - object_number_poem["start"] = obj_cite_digits.object_number.to!string; -} -line.flow_txt_block_start(obj_type_status, dochas, object_number_poem); -continue; -#+END_SRC - -****** line not empty [+2] -******* asserts :assert: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d -assert( - !line.empty, - "line tested, line not empty surely:\n \"" ~ line ~ "\"" -); -assert( - (obj_type_status["blocks"] == TriState.off) - || (obj_type_status["blocks"] == TriState.closing), - "code block status: none or closed" -); -if (obj_type_status["blocks"] == TriState.closing) { - debug(check) { - writeln(__LINE__); - writeln(line); - } - assert( - line.matchFirst(rgx.book_index) - || line.matchFirst(rgx.book_index_open) - || obj_type_status["book_index"] == State.on, - "\nblocks closed, unless followed by book index, non-matching line:\n \"" - ~ line ~ "\"" - ); -} -#+END_SRC - -******* book index :bookindex: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d -if (line.matchFirst(rgx.book_index) -|| line.matchFirst(rgx.book_index_open) -|| obj_type_status["book_index"] == State.on ) { /+ book_index +/ - an_object = line.flow_book_index_(an_object, book_idx_tmp, obj_type_status, opt_action); -#+END_SRC - -******* not book index [+1] - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d -} else { /+ not book_index +/ -#+END_SRC - -******** matched: comment :comment:match: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d - an_object_key="body_nugget"; - if (auto m = line.matchFirst(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.metainfo.is_of_part = "comment"; // breaks flow - comp_obj_comment.metainfo.is_of_section = "comment"; // breaks flow - comp_obj_comment.metainfo.is_of_type = "comment"; - comp_obj_comment.metainfo.is_a = "comment"; - comp_obj_comment.text = an_object[an_object_key].strip; - the_document_body_section ~= comp_obj_comment; - flow_common_reset_(line_occur, an_object, obj_type_status); - processing.remove("verse"); - ++cntr; -#+END_SRC - -******** flag !set & line !exist: heading or para :heading:paragraph: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d - } else if (((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((obj_type_status["para"] == State.off) - && (obj_type_status["heading"] == State.off))) { /+ heading or para but neither flag nor line exists +/ - if ((conf_make_meta.make.headings.length > 2) - && (obj_type_status["make_headings"] == State.off)) { /+ heading found +/ - heading_match_str = line.flow_heading_found_(heading_match_str, conf_make_meta.make.headings, heading_match_rgx, obj_type_status); - } - if ((obj_type_status["make_headings"] == State.on) - && ((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((obj_type_status["para"] == State.off) - && (obj_type_status["heading"] == State.off))) { /+ heading make set +/ - line = line.flow_heading_make_set_(line_occur, heading_match_rgx, obj_type_status); - } - /+ 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 +/ - line = line._doc_header_and_make_substitutions_(conf_make_meta); - an_object = line.flow_heading_matched_(an_object, line_occur, an_object_key, lv, collapsed_lev, obj_type_status, conf_make_meta); - } else if (line_occur["para"] == State.off) { /+ para match +/ - an_object_key="body_nugget"; - line = line - ._doc_header_and_make_substitutions_(conf_make_meta) - ._doc_header_and_make_substitutions_fontface_(conf_make_meta); - an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); - } -#+END_SRC - -******** line exist: heading :heading: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d - } else if (line_occur["heading"] > State.off) { /+ heading +/ - debug(heading) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; - ++line_occur["heading"]; -#+END_SRC - -******** line exist: para :para: - -#+name: abs_in_loop_body_not_block_obj -#+BEGIN_SRC d - } else if (line_occur["para"] > State.off) { /+ paragraph +/ - debug(para) { - writeln(an_object_key, "-> ", line); - } - line = line - ._doc_header_and_make_substitutions_(conf_make_meta) - ._doc_header_and_make_substitutions_fontface_(conf_make_meta); - an_object[an_object_key] ~= " " ~ line; - ++line_occur["para"]; - } -} -#+END_SRC - -****** line empty, with block flag - -#+name: abs_in_loop_body_not_block_obj_line_empty_blocks_flags -#+BEGIN_SRC d -an_object = line.flow_block_flag_line_empty_( - an_object, - bookindex_extract_hash, - the_document_body_section, - bookindex_unordered_hashes, - obj_cite_digits, - comp_obj_heading, - cntr, - obj_type_status, - object_number_poem, - conf_make_meta, - tag_in_seg, -); -#+END_SRC - -****** line empty [+1] -******* assert line empty :assert: - -#+name: abs_in_loop_body_not_block_obj_line_empty -#+BEGIN_SRC d -assert( - line.empty, - "\nline should be empty:\n \"" - ~ line ~ "\"" -); -assert( - (obj_type_status["blocks"] == State.off), - "code block status: none" -); -#+END_SRC - -******* heading object :heading:object: - -#+name: abs_in_loop_body_not_block_obj_line_empty -#+BEGIN_SRC d -if (_new_doc) { - tag_assoc = tag_assoc.init; - lv0_to_3_tags = lv0_to_3_tags.init; - tag_in_seg = tag_in_seg.init; -} -if ((obj_type_status["heading"] == State.on) -&& (line_occur["heading"] > State.off)) { /+ heading object (current line empty) +/ - obj_cite_digits = (an_object["lev_markup_number"].to!int == 0) - ? ocn_emit(OCNstatus.reset) - : ocn_emit(obj_type_status["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, conf_make_meta, ((_new_doc) ? Yes._new_doc : No._new_doc)); - an_object["substantive"] = substantive_object_and_anchor_tags_tuple[sObj.content]; - anchor_tag = substantive_object_and_anchor_tags_tuple[sObj.anchor_tag]; - if (_new_doc) { - cnt1 = 1; - cnt2 = 1; - cnt3 = 1; - _new_doc = false; - } - if ( - an_object["lev_markup_number"].to!int == 4 - && (!(anchor_tag.empty) - || (lv0_to_3_tags.length > 0)) - ) { - tag_in_seg["seg_lv4"] = anchor_tag; - tag_in_seg["seg_lv1_to_4"] = anchor_tag; - lev_anchor_tag = anchor_tag; - tag_assoc[anchor_tag]["seg_lv4"] = tag_in_seg["seg_lv4"]; - tag_assoc[anchor_tag]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; - if (lv0_to_3_tags.length > 0) { /+ names used for html markup segments 1 to 4 (rather than epub which has separate segments for A to D) +/ - foreach (lv0_to_lv3_html_tag; lv0_to_3_tags) { - tag_assoc[lv0_to_lv3_html_tag]["seg_lv4"] = anchor_tag; - } - } - anchor_tag_ = anchor_tag; - lv0_to_3_tags = lv0_to_3_tags.init; - } else if (an_object["lev_markup_number"].to!int > 4) { - tag_in_seg["seg_lv4"] = anchor_tag_; - tag_in_seg["seg_lv1_to_4"] = anchor_tag_; - lev_anchor_tag = anchor_tag; - tag_assoc[anchor_tag]["seg_lv4"] = tag_in_seg["seg_lv4"]; - tag_assoc[anchor_tag]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; - } else if (an_object["lev_markup_number"].to!int < 4) { - string segn; - switch (an_object["lev_markup_number"].to!int) { /+ names used for epub markup segments A to D +/ - 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: - lv0_to_3_tags ~= obj_cite_digits.object_number.to!string; - lv0_to_3_tags ~= segn; - tag_in_seg["seg_lv4"] = segn; // for html segname need following lv4 not yet known - tag_in_seg["seg_lv1_to_4"] = segn; - 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_digits, tag_in_seg); - /+ (incrementally build toc) table of contents here! +/ - _anchor_tag = obj_cite_digits.identifier; - the_table_of_contents_section = obj_im.flow_table_of_contents_gather_headings( - an_object, - conf_make_meta, - tag_in_seg, - _anchor_tag, - lev4_subtoc, - the_table_of_contents_section, - ); - if (an_object["lev_markup_number"] == "4") { - segnames["html"] ~= tag_in_seg["seg_lv4"]; - html_segnames_ptr = html_segnames_ptr_cntr; - html_segnames_ptr_cntr++; - } - if (an_object["lev_markup_number"].to!int <= 4) { - segnames["epub"] ~= tag_in_seg["seg_lv1_to_4"]; - } - auto comp_obj_heading - = node_construct.node_emitter_heading( - an_object["substantive"], - an_object["lev_markup_number"], - an_object["lev_collapsed_number"], - an_object["dummy_heading_status"], - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, // OCNset - cntr, // int - heading_ptr, // int - lv_ancestors_txt, // 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(tag_in_seg["seg_lv4"]); - writeln(tag_in_seg["seg_lv1_to_4"]); - } - the_document_body_section ~= comp_obj_heading; - debug(objectrelated1) { // check - writeln(line); - } - flow_common_reset_(line_occur, an_object, obj_type_status); - an_object.remove("lev"); - an_object.remove("lev_markup_number"); - processing.remove("verse"); - ++cntr; -#+END_SRC - -******* paragraph object :paragraph:object: - -#+name: abs_in_loop_body_not_block_obj_line_empty -#+BEGIN_SRC d -} else if ((obj_type_status["para"] == State.on) -&& (line_occur["para"] > State.off)) { - /+ paragraph object (current line empty) +/ - /+ repeated character paragraph separator +/ - if ((an_object[an_object_key].to!string).matchFirst(rgx.repeated_character_line_separator)) { - obj_type_status["ocn_status"] = OCNstatus.off; - } - obj_cite_digits = ocn_emit(obj_type_status["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_digits, tag_in_seg); - an_object["is"] = "para"; - auto comp_obj_heading - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "body"; - comp_obj_para.metainfo.is_of_section = "body"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "para"; - comp_obj_para.text = an_object["substantive"].to!string.strip; - comp_obj_para.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_para.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_para.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_para.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_para.metainfo.object_number_off = (obj_cite_digits.off==0) ? true : false; // TODO - comp_obj_para.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_para.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_para.attrib.indent_hang = indent["hang_position"]; - comp_obj_para.attrib.indent_base = indent["base_position"]; - comp_obj_para.attrib.bullet = bullet; - comp_obj_para.tags.anchor_tags = [anchor_tag]; - comp_obj_para.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_para.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_para.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - comp_obj_para.has.image_without_dimensions = substantive_obj_misc_tuple[sObj.image_no_dimensions]; - the_document_body_section ~= comp_obj_para; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - flow_common_reset_(line_occur, an_object, obj_type_status); - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - processing.remove("verse"); - ++cntr; -} else { - // could be useful to test line variable should be empty and never null -} -#+END_SRC - -*** regular _text objects_ identified :text:paragraph: - -#+name: abs_in_loop_body_01 -#+BEGIN_SRC d -/+ unless (the_document_body_section.length == 0) ? +/ -if (the_document_body_section.length > 0) { - if (((the_document_body_section[$-1].metainfo.is_a == "para") - || (the_document_body_section[$-1].metainfo.is_a == "heading") - || (the_document_body_section[$-1].metainfo.is_a == "quote") - || (the_document_body_section[$-1].metainfo.is_a == "group") - || (the_document_body_section[$-1].metainfo.is_a == "block") - || (the_document_body_section[$-1].metainfo.is_a == "verse")) - && (the_document_body_section.length > previous_length)) { - if ((the_document_body_section[$-1].metainfo.is_a == "heading") - && (the_document_body_section[$-1].metainfo.heading_lev_markup < 5)) { - obj_type_status["glossary_section"] = State.off; - obj_type_status["biblio_section"] = State.off; - obj_type_status["blurb_section"] = State.off; - } - if (the_document_body_section[$-1].metainfo.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].metainfo.is_a == "verse") { - if ((the_document_body_section[i].text).match( - rgx.inline_notes_al_all_note - )) { - note_section.gather_notes_for_endnote_section( - the_document_body_section, - tag_in_seg, - (i).to!int, - ); - } - } - } - } 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_al_all_note - )) { - previous_count=(the_document_body_section.length -1).to!int; - note_section.gather_notes_for_endnote_section( - the_document_body_section, - tag_in_seg, - (the_document_body_section.length-1).to!int, - ); - } - } - previous_length = the_document_body_section.length.to!int; - } -} -#+END_SRC - -** 3. _post main-loop processing_ :post: -*** misc - -/+ - Backmatter: - - endnotes - - glossary - - bibliography / references - - book index - - blurb -+/ - -*** tie up preparation of document sections -**** endnotes section (scroll & seg) :endnotes: - -#+name: abs_post -#+BEGIN_SRC d -auto en_tuple - = note_section.endnote_objects(obj_cite_digits, opt_action); -static assert(!isTypeTuple!(en_tuple)); -auto the_endnotes_section = en_tuple[0]; -obj_cite_digits = en_tuple[1]; -debug(endnotes) { - writefln( - "%s %s", - __LINE__, - the_endnotes_section.length - ); - foreach (o; the_endnotes_section) { - writeln(o); - } -} -#+END_SRC - -**** no glossary section? :glossary: - -#+name: abs_post -#+BEGIN_SRC d -if (an_object["glossary_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Glossary section"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_glossary_section ~= comp_obj_heading_; -} -debug(glossary) { - foreach (gloss; the_glossary_section) { - writeln(gloss.text); - } -} -#+END_SRC - -**** bibliography section (objects) :bibliography: - -#+name: abs_post -#+BEGIN_SRC d -auto biblio_unsorted_incomplete = biblio_arr_json.dup; -auto biblio = Bibliography(); -auto biblio_ordered - = biblio.flow_bibliography_(biblio_unsorted_incomplete, bib_arr_json); -#+END_SRC - -#+name: abs_post -#+BEGIN_SRC d -if (biblio_ordered.length > 0) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bibliography"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_bibliography"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "bibliography"; - comp_obj_heading_.tags.anchor_tags = ["section_bibliography"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_bibliography_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bibliography"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "bibliography"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.tags.anchor_tags = ["bibliography"]; - the_bibliography_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - } -} else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Bibliography"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_bibliography_section ~= comp_obj_heading_; -} -#+END_SRC - -***** format biblio string - -#+name: abs_post -#+BEGIN_SRC d -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) ? "" : ", " ~ mkup.italic ~ mkup.ff_o ~ entry["journal"].str ~ mkup.ff_c ~ mkup.italic), - ((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.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "bibliography"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "bibliography"; - comp_obj_para.text = out_.to!string.strip; - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.attrib.indent_hang = 0; - comp_obj_para.attrib.indent_base = 1; - comp_obj_para.attrib.bullet = bullet; - comp_obj_para.tags.anchor_tags = [anchor_tag]; - the_bibliography_section ~= comp_obj_para; -} -#+END_SRC - -#+name: abs_post -#+BEGIN_SRC d -debug(bibliosection) { - foreach (o; the_bibliography_section) { - writeln(o.text); - } -} -#+END_SRC - -***** bibliography components - -JSONValue biblio_entry_tags_jsonstr = `{ - "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 - -**** bookindex section (scroll & seg) :book:index: - -#+name: abs_post -#+BEGIN_SRC d -auto bi = BookIndexReportSection(); -auto bi_tuple - = bi.bookindex_build_abstraction_section( - bookindex_unordered_hashes, - obj_cite_digits, - opt_action, - ); -destroy(bookindex_unordered_hashes); -static assert(!isTypeTuple!(bi_tuple)); -auto the_bookindex_section = bi_tuple[0]; -obj_cite_digits = bi_tuple[1]; -debug(bookindex) { - foreach (bi_entry; the_bookindex_section) { - writeln(bi_entry); - } -} -#+END_SRC - -**** no blurb section? :blurb: - -#+name: abs_post -#+BEGIN_SRC d -if (an_object["blurb_nugget"].length == 0) { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there is no Blurb section"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = ""; - comp_obj_heading_.tags.anchor_tag_html = ""; - comp_obj_heading_.tags.in_segment_html = ""; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_blurb_section ~= comp_obj_heading_; -} -debug(blurb) { - foreach (blurb; the_blurb_section) { - writeln(blurb.text); - } -} -#+END_SRC - -**** toc backmatter, table of contents backmatter (scroll & seg) :contents: - -#+name: abs_post -#+BEGIN_SRC d -indent=[ - "hang_position" : 1, - "base_position" : 1, -]; -comp_obj_toc = comp_obj_toc.init; -comp_obj_toc.metainfo.is_of_part = "frontmatter"; -comp_obj_toc.metainfo.is_of_section = "toc"; -comp_obj_toc.metainfo.is_of_type = "para"; -comp_obj_toc.metainfo.is_a = "toc"; -comp_obj_toc.metainfo.ocn = 0; -comp_obj_toc.metainfo.identifier = ""; -comp_obj_toc.metainfo.object_number_off = true; -comp_obj_toc.metainfo.object_number_type = 0; -comp_obj_toc.attrib.indent_hang = indent["hang_position"]; -comp_obj_toc.attrib.indent_base = indent["base_position"]; -comp_obj_toc.attrib.bullet = false; -if (the_endnotes_section.length > 1) { - toc_txt_ = format( - mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - "Endnotes", - "endnotes", - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_table_of_contents_section ~= comp_obj_toc; -} -if (the_glossary_section.length > 1) { - toc_txt_ = format( - mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - "Glossary", - "glossary", - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_table_of_contents_section ~= comp_obj_toc; -} -if (the_bibliography_section.length > 1){ - toc_txt_ = format( - mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - "Bibliography", - "bibliography", - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_table_of_contents_section ~= comp_obj_toc; -} -if (the_bookindex_section.length > 1) { - toc_txt_ = format( - mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - "Book Index", - "bookindex", - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_table_of_contents_section ~= comp_obj_toc; -} -if (the_blurb_section.length > 1) { - toc_txt_ = format( - mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - "Blurb", - "blurb", - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc.has.inline_links = true; - comp_obj_toc.text = toc_txt_.to!string.strip; - the_table_of_contents_section ~= comp_obj_toc; -} -debug(toc) { - writefln( - "%s %s", - __LINE__, - ); - foreach (toc_linked_heading; the_table_of_contents_section) { - writeln(mkup.indent_by_spaces_provided(toc_linked_heading.attrib.indent_hang), toc_linked_heading.text); - } -} -#+END_SRC - -**** doc head (separate document head from body, make space for toc) - -#+name: abs_post -#+BEGIN_SRC d -the_document_head_section ~= the_document_body_section[0]; -the_document_body_section=the_document_body_section[1..$]; -#+END_SRC - -*** ↻ *LOOPs* _post main-loop loops_ :loop:post: -**** 1. ↻ _Loop as required_ (e.g. backmatter): loop up to lev4, extract html_segnames, set pointers - -this extra loop is used/needed to determine pre and (in particular) next segment -for html, that is then used in a subsequent loop - -NOTE there are issues attempting to do this on first pass as: - - backmatter is created out of sequence and - - it is not certain which are present - - - it is quite neat to have all in one place as we have here - - - could optimise a bit by - - skipping this loop unless the html seg or epub output is selected - -***** Methods -****** get ancestors markup - -#+name: abs_post -#+BEGIN_SRC d -int[] _get_ancestors_markup(O)(O obj, ref int[] _ancestors_markup) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.metainfo.heading_lev_markup == 1) { - _ancestors_markup = [ - _ancestors_markup[0], - 0,0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 2) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - 0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 3) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - 0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 4) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - 0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 5) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - 0,0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 6) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - 0,0 - ]; - } - if (obj.metainfo.heading_lev_markup == 7) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - _ancestors_markup[6], - 0 - ]; - } - if (obj.metainfo.heading_lev_markup == 8) { - _ancestors_markup = [ - _ancestors_markup[0], - _ancestors_markup[1], - _ancestors_markup[2], - _ancestors_markup[3], - _ancestors_markup[4], - _ancestors_markup[5], - _ancestors_markup[6], - _ancestors_markup[7] - ]; - } - _ancestors_markup[obj.metainfo.heading_lev_markup] = obj.metainfo.ocn; - } - debug(ancestor_markup) { - writeln("marked up: ", _ancestors_markup); - } - return _ancestors_markup; -} -#+END_SRC - -****** get ancestors collapsed - -#+name: abs_post -#+BEGIN_SRC d -int[] _get_ancestors_collapsed(O)(O obj, ref int[] _ancestors_collapsed) { - if (obj.metainfo.is_a == "heading") { - if (obj.metainfo.heading_lev_collapsed == 1) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - 0,0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 2) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - 0,0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 3) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - 0,0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 4) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - 0,0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 5) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - 0,0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 6) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - 0,0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 7) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - _ancestors_collapsed[6], - 0 - ]; - } - if (obj.metainfo.heading_lev_collapsed == 8) { - _ancestors_collapsed = [ - _ancestors_collapsed[0], - _ancestors_collapsed[1], - _ancestors_collapsed[2], - _ancestors_collapsed[3], - _ancestors_collapsed[4], - _ancestors_collapsed[5], - _ancestors_collapsed[6], - _ancestors_collapsed[7] - ]; - } - _ancestors_collapsed[obj.metainfo.heading_lev_collapsed] = obj.metainfo.ocn; - } - debug(ancestor_collapsed) { - writeln("collapsed: ", _ancestors_collapsed); - } - return _ancestors_collapsed; -} -#+END_SRC - -***** ↻ Loop section: document body [bd] - -- substantive object numbers already exist -- number un-numbered non-substantive text - -#+name: abs_post -#+BEGIN_SRC d -/+ multiple 1~ levels, loop through document body +/ -if (the_document_body_section.length > 1) { - int[] _ancestors_markup = [0,0,0,0,0,0,0,0]; - int[][] _ancestors_markup_; - _ancestors_markup = [1,0,0,0,0,0,0,0]; - _ancestors_markup_ ~= _ancestors_markup; - int[] _ancestors_collapsed = [0,0,0,0,0,0,0,0]; - int[][] _ancestors_collapsed_; - _ancestors_collapsed = [1,0,0,0,0,0,0,0]; - _ancestors_collapsed_ ~= _ancestors_collapsed; - foreach (ref obj; the_document_body_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.markedup_ancestors = _get_ancestors_markup(obj, _ancestors_markup); - obj.metainfo.collapsed_ancestors = _get_ancestors_collapsed(obj, _ancestors_collapsed); - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - } - debug(ancestors) { - writeln("ancestors markup o_n: ", obj.metainfo.markedup_ancestors); - writeln("ancestors collapsed o_n: ", obj.metainfo.markedup_ancestors); - } -} -#+END_SRC - -***** ↻ Loop section: endnotes [en] - -#+name: abs_post -#+BEGIN_SRC d -if (the_endnotes_section.length > 1) { - segnames["html"] ~= "endnotes"; - segnames["epub"] ~= "endnotes"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_endnotes_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -***** ↻ Loop section: glossary [gl] - -#+name: abs_post -#+BEGIN_SRC d -if (the_glossary_section.length > 1) { - segnames["html"] ~= "glossary"; - segnames["epub"] ~= "glossary"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_glossary_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -***** ↻ Loop section: bibliography [bb] - -#+name: abs_post -#+BEGIN_SRC d -if (the_bibliography_section.length > 1) { - segnames["html"] ~= "bibliography"; - segnames["epub"] ~= "bibliography"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_bibliography_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -***** ↻ Loop section: book index [bi] - -#+name: abs_post -#+BEGIN_SRC d -if (the_bookindex_section.length > 1) { - segnames["html"] ~= "bookindex"; - segnames["epub"] ~= "bookindex"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_bookindex_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -***** ↻ Loop section: blurb [bl] - -#+name: abs_post -#+BEGIN_SRC d -if (the_blurb_section.length > 1) { - segnames["html"] ~= "blurb"; - segnames["epub"] ~= "blurb"; - html_segnames_ptr = html_segnames_ptr_cntr; - foreach (ref obj; the_blurb_section) { - if (obj.metainfo.is_a == "heading") { - obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; - } - if (obj.metainfo.heading_lev_markup == 4) { - obj.ptr.html_segnames = html_segnames_ptr; - break; - } - } - html_segnames_ptr_cntr++; -} -#+END_SRC - -**** 2. ↻ _Loop all objects:_ encode _structural relationships_ (sections, segments, objects) - -needed for DOM structure, segnames & subtoc, backmatter pointers & unique image -list - -if used minimally only for DOM structure, segnames, subtoc, could optimise by -- skipping second and third pass unless the output html seg or epub is being - made! - -- this loop could conveniently be used more extensively for ancestors as well - (though this information can be extracted earlier) - -Build here: -- DOM structure - - ancestors & decendants - - ancestors could be determined earlier, but convenient to have here - - descendants could be in the form of: - - headings contained under current heading, and/or; - - the range of objects under the current heading -- numbering - - already given - - substantive object numbers - - endnote - - provide - - glossary - - bibliography - - book index - - blurb - - other non-substantive objects (prefix & other stuff) - - you could also decide on a sequential object list, containing all objects - (both substantive and non-substantive objects), in addition to ocn, which - are for substantive/ citable objects within the document - -(as needed) up to document heading 1~, lev4 html: - -- during this (the third) pass all previous and next segment names are known -- next are not yet known for backmatter during the second pas - -***** Methods -****** decendants - -#+name: abs_post -#+BEGIN_SRC d -auto get_decendants()(ObjGenericComposite[] document_sections) { - int[string] _heading_ocn_decendants; - string[] _ocn_open_key = ["","","","","","","",""]; - auto _doc_sect_length = document_sections.length - 1; - int _last_ocn; - foreach (_lg, ref obj; document_sections) { - if (obj.metainfo.is_a == "heading") { - foreach (_dts_lv, dom_tag_status; obj.metainfo.dom_structure_markedup_tags_status) { - switch (dom_tag_status) with (DomTags) { - case none: break; - case open: - _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; - break; - case close: - if (_ocn_open_key[_dts_lv].empty) { - _ocn_open_key[_dts_lv] = "0"; - } - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; - _ocn_open_key[_dts_lv] = (0).to!string; - break; - case close_and_open: - if (_ocn_open_key[_dts_lv].empty) { - _ocn_open_key[_dts_lv] = "0"; - } - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; - _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; - _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; - break; - case open_still: break; - default: break; - } - } - } - if (obj.metainfo.ocn > 0) { - _last_ocn = obj.metainfo.ocn; - } - if (_lg == _doc_sect_length) { - _heading_ocn_decendants["1"] = _last_ocn; // close existing o_n key - } - } - Tuple!(int, int)[] pairs; - foreach (pair; _heading_ocn_decendants.byPair) { - pairs ~= tuple(pair[0].to!int, pair[1]); - } - return pairs.sort; -} -#+END_SRC - -****** images: extract - -#+name: abs_post -#+BEGIN_SRC d -string[] _images; -string[] extract_images()(string content_block) { - string[] images_; - if (auto m = content_block.matchAll(rgx.image)) { - images_ ~= m.captures[1]; - } - return images_; -} -string[] segnames_0_to_4; -#+END_SRC - -****** images: dimensions - -#+name: abs_post -#+BEGIN_SRC d -auto _image_dimensions(O,M)(O obj, M manifested) { - if (obj.has.image_without_dimensions) { - import std.math; - import imageformats; - int w, h, chans; - real _w, _h; - int max_width = 640; - foreach (m; obj.text.matchAll(rgx.inline_image_without_dimensions)) { - debug(images) { - writeln(manifested.src.image_dir_path ~ "/" ~ m["img"]); - } - read_image_info(manifested.src.image_dir_path ~ "/" ~ m["img"], w, h, chans); - // calculate, decide max width and proportionally reduce to keep w & h within it - debug(images) { - writeln("width: ", w, ", height: ", h); - } - if (w > max_width) { - _w = max_width; - _h = round((max_width / w.to!real) * h.to!real); - } else { - _w = w; - _h = h; - } - obj.text = obj.text.replaceFirst( - rgx.inline_image_without_dimensions, - format(q"┃%s☼%s,w%sh%s %s┃", - "$1", - "$3", - _w.to!string, - _h.to!string, - "$6", - ) - ); - } - debug(images) { - writeln("image without dimensions: ", obj.text); - } - } - return obj; -} -#+END_SRC - -***** links: think about!!! -- move actual links to an array in object struct so they cannot be regex munged within text block - - you may wish to exclude certain types of internal document link - - object number links - - toc - - book index - - footnotes and footnote numbers - -#+name: abs_post -#+BEGIN_SRC d -auto _links(O)(O obj) { - if (auto m = obj.text.match(rgx.inline_link_stow_uri)) { - debug(links) { - writeln("number of link matches to stow: ", (obj.text.match(rgx.inline_link_stow_uri)).count); - writeln("links to stow: ", (obj.text.match(rgx.inline_link_stow_uri))); - } - int _n_matches = (obj.text.match(rgx.inline_link_stow_uri)).count.to!int; - for(int i=0; i < _n_matches; ++i) { - if (obj.text.match(rgx.inline_link_stow_uri)) { - obj.stow.link ~= obj.text.matchFirst(rgx.inline_link_stow_uri)[2]; - obj.text = obj.text.replaceFirst( - rgx.inline_link_stow_uri, - format(q"┃┥%s┝┤%s├┃", "$1", i) - ); - } - } - } - return obj; -} -#+END_SRC - -***** ↻ Loop section: head - -#+name: abs_post -#+BEGIN_SRC d -foreach (ref obj; the_document_head_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - } - if (obj.metainfo.heading_lev_markup == 0) { - /+ TODO second hit (of two) with same assertion failure, check, fix and reinstate - assert( obj.metainfo.ocn == 1, - "Title OCN should be 1 not: " ~ obj.metainfo.ocn.to!string); // bug introduced 0.18.1 - +/ - obj.metainfo.ocn = 1; - obj.metainfo.identifier = "1"; - obj.metainfo.object_number_type = OCNtype.ocn; - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } - obj = _links(obj); -} -#+END_SRC - -***** ↻ Loop section: toc [to] - -#+name: abs_post -#+BEGIN_SRC d -if (the_table_of_contents_section.length > 1) { - /+ scroll +/ - dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; - dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; - foreach (ref obj; the_table_of_contents_section) { - if (obj.metainfo.is_a == "heading") { - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } - obj = _links(obj); - } -} -#+END_SRC - -***** ↻ Loop section: document body [bd] - -#+name: abs_post -#+BEGIN_SRC d -/+ multiple 1~ levels, loop through document body +/ -if (the_document_body_section.length > 1) { - foreach (ref obj; the_document_body_section) { - if (!(obj.metainfo.identifier.empty)) { - if (!(((obj.metainfo.identifier) in tag_assoc) - && ("seg_lv4" in tag_assoc[(obj.metainfo.identifier)])) - ) { - tag_assoc[(obj.metainfo.identifier)]["seg_lv4"] - = obj.tags.html_segment_anchor_tag_is; - } - tag_assoc[(obj.metainfo.identifier)]["seg_lv1_to_4"] - = obj.tags.epub_segment_anchor_tag_is; - } - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.lev4_subtoc = lev4_subtoc[obj.tags.anchor_tag_html]; - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "para") { - _images ~= extract_images(obj.text); - obj = _image_dimensions(obj, manifested); - } - obj = _links(obj); - } -} -auto image_list = (_images.sort()).uniq; -#+END_SRC - -***** ↻ Loop section: endnotes [en] - -- endnotes have their own number, (also use in node) and they belong to calling object - -#+name: abs_post -#+BEGIN_SRC d -/+ optional only one 1~ level +/ -if (the_endnotes_section.length > 1) { - dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; - dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; - dom_structure_markedup_tags_status = dom_structure_markedup_tags_status_buffer.dup; - dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status_buffer.dup; - foreach (ref obj; the_endnotes_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } - obj = _links(obj); - } -} -#+END_SRC - -***** ↻ Loop section: glossary [gl] - -- add glossary numbering, (also use in node) no need to show in text - -#+name: abs_post -#+BEGIN_SRC d -/+ optional only one 1~ level +/ -if (the_glossary_section.length > 1) { - foreach (ref obj; the_glossary_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "glossary") { - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - } - obj = _links(obj); - } -} -#+END_SRC - -***** ↻ Loop section: bibliography [bb] - -- add bibliography numbering, (also use in node) no need to show in text - -#+name: abs_post -#+BEGIN_SRC d -/+ optional only one 1~ level +/ -if (the_bibliography_section.length > 1) { - foreach (ref obj; the_bibliography_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "bibliography") { - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - } - obj = _links(obj); - } -} -#+END_SRC - -***** ↻ Loop section: book index (scroll, seg) [bi] - -- add book index numbering?, (also use in node) no need to show in text - -#+name: abs_post -#+BEGIN_SRC d -/+ optional only one 1~ level +/ -int ocn_ = obj_cite_digits.object_number; -int ocn_bkidx_ = 0; -int ocn_bidx_; -if (the_bookindex_section.length > 1) { /+ scroll +/ - dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; - dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; - foreach (ref obj; the_bookindex_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - } - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - } - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - if (obj.metainfo.heading_lev_markup <= 4) { - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "bookindex") { - obj_cite_digits = ocn_emit(OCNstatus.bkidx); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - obj.metainfo.o_n_book_index = obj_cite_digits.bkidx; - obj.metainfo.object_number_type = OCNtype.bkidx; - } - obj = _links(obj); - } - /+ TODO assert failure, reinstate - assert(obj_cite_digit_bkidx == ocn_bidx_ - obj_cite_digit_bkidx ~ " == ocn_" ~ ocn_ ~ "?"); - +/ -} -#+END_SRC - -***** ↻ Loop section: blurb [bl] - -#+name: abs_post -#+BEGIN_SRC d -/+ optional only one 1~ level +/ -if (the_blurb_section.length > 1) { - foreach (ref obj; the_blurb_section) { - if (obj.metainfo.is_a == "heading") { - debug(dom) { - writeln(obj.text); - } - obj_cite_digits = ocn_emit(OCNstatus.on); - obj.metainfo.ocn = obj_cite_digits.object_number; - obj.metainfo.identifier = obj_cite_digits.identifier; - if (obj.metainfo.heading_lev_markup <= 4) { - segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; - if (obj.metainfo.heading_lev_markup == 4) { - obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; - if (segnames["html"].length > obj.ptr.html_segnames + 1) { - obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; - } - assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], - obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); - } - } - /+ dom structure (marked up & collapsed) +/ - if (opt_action.meta_processing_xml_dom) { - obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); - obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); - } - obj = obj.obj_heading_ancestors(lv_ancestors_txt); - } else if (obj.metainfo.is_a == "blurb") { - obj_cite_digits = ocn_emit(OCNstatus.off); - obj.metainfo.object_number_off = obj_cite_digits.off; - obj.metainfo.object_number_type = OCNtype.non; - } - obj = _links(obj); - } -} -#+END_SRC - -***** ↻ Loop sections: get decendants - -#+name: abs_post -#+BEGIN_SRC d -if (the_document_body_section.length > 1) { - auto pairs = get_decendants( - the_document_head_section ~ - the_document_body_section ~ - the_endnotes_section ~ - the_glossary_section ~ - the_bibliography_section ~ - the_bookindex_section ~ - the_blurb_section - ); - debug(decendants_tuple) { - pairs = pairs.sort(); - foreach (pair; pairs) { // (pair; pairs.sort()) - writeln(pair[0], "..", pair[1]); - } - } - foreach (ref obj; the_document_head_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - if (the_document_body_section.length > 1) { - foreach (ref obj; the_document_body_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } - if (the_endnotes_section.length > 1) { - foreach (ref obj; the_endnotes_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } - if (the_glossary_section.length > 1) { - foreach (ref obj; the_glossary_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } - if (the_bibliography_section.length > 1) { - foreach (ref obj; the_bibliography_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } - if (the_bookindex_section.length > 1) { - foreach (ref obj; the_bookindex_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } - if (the_blurb_section.length > 1) { - foreach (ref obj; the_blurb_section) { - if (obj.metainfo.is_a == "heading") { - foreach (pair; pairs) { - if (obj.metainfo.ocn == pair[0]) { - obj.metainfo.last_decendant_ocn = pair[1]; - } - } - } - } - } -} -#+END_SRC - -**** TODO update BUG? - -#+name: abs_post -#+BEGIN_SRC d - /+ TODO - - note create/insert heading object sole purpose eof close all open tags - sort out: - - obj.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status; - - obj.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status; - +/ -comp_obj_heading_ = comp_obj_heading_.init; -comp_obj_heading_.metainfo.is_of_part = "empty"; -comp_obj_heading_.metainfo.is_of_section = "empty"; -comp_obj_heading_.metainfo.is_of_type = "para"; -comp_obj_heading_.metainfo.is_a = "heading"; -comp_obj_heading_.metainfo.ocn = 0; -comp_obj_heading_.metainfo.identifier = ""; -comp_obj_heading_.metainfo.dummy_heading = true; -comp_obj_heading_.metainfo.object_number_off = true; -comp_obj_heading_.metainfo.object_number_type = 0; -comp_obj_heading_.tags.segment_anchor_tag_epub = ""; -comp_obj_heading_.tags.anchor_tag_html = ""; -comp_obj_heading_.tags.in_segment_html = ""; -comp_obj_heading_.tags.html_segment_anchor_tag_is = ""; -comp_obj_heading_.tags.epub_segment_anchor_tag_is = ""; -comp_obj_heading_.metainfo.heading_lev_markup = 9; -comp_obj_heading_.metainfo.heading_lev_collapsed = 9; -comp_obj_heading_.metainfo.parent_ocn = 0; -comp_obj_heading_.metainfo.parent_lev_markup = 0; -comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status.dup; -comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status.dup; -comp_obj_heading_ = comp_obj_heading_.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, 0); -comp_obj_heading_ = comp_obj_heading_.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, 0); -comp_obj_heading_ = comp_obj_heading_.obj_heading_ancestors(lv_ancestors_txt); -// the_dom_tail_section ~= comp_obj_heading_; // remove tail for now, decide on later -#+END_SRC - -** 4. _return document tuple_ :post: -*** _the document_ :document: - -#+name: abs_post -#+BEGIN_SRC d -ObjGenericComposite[][string] document_the = [ - "head": the_document_head_section, - "toc": the_table_of_contents_section, - /+ substantive/body: +/ - "body": the_document_body_section, - /+ backmatter: +/ - "endnotes": the_endnotes_section, - "glossary": the_glossary_section, - "bibliography": the_bibliography_section, - "bookindex": the_bookindex_section, - "blurb": the_blurb_section, - /+ dom tail only +/ - "tail": the_dom_tail_section, -]; -#+END_SRC - -*** document _section keys_ sequence - -#+name: abs_post -#+BEGIN_SRC d -string[][string] document_section_keys_sequenced = [ - "scroll": ["head", "toc", "body",], - "seg": ["head", "toc", "body",], - "sql": ["head", "body",], - "latex": ["head", "toc", "body",] -]; -if (document_the["endnotes"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "endnotes"; - document_section_keys_sequenced["seg"] ~= "endnotes"; - document_section_keys_sequenced["latex"] ~= "endnotes"; -} -if (document_the["glossary"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "glossary"; - document_section_keys_sequenced["seg"] ~= "glossary"; - document_section_keys_sequenced["sql"] ~= "glossary"; - document_section_keys_sequenced["latex"] ~= "glossary"; -} -if (document_the["bibliography"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "bibliography"; - document_section_keys_sequenced["seg"] ~= "bibliography"; - document_section_keys_sequenced["sql"] ~= "bibliography"; - document_section_keys_sequenced["latex"] ~= "bibliography"; -} -if (document_the["bookindex"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "bookindex"; - document_section_keys_sequenced["seg"] ~= "bookindex"; - document_section_keys_sequenced["sql"] ~= "bookindex"; - document_section_keys_sequenced["latex"] ~= "bookindex"; -} -if (document_the["blurb"].length > 1) { - document_section_keys_sequenced["scroll"] ~= "blurb"; - document_section_keys_sequenced["seg"] ~= "blurb"; - document_section_keys_sequenced["sql"] ~= "blurb"; - document_section_keys_sequenced["latex"] ~= "blurb"; -} -if ((opt_action.html) -|| (opt_action.html_scroll) -|| (opt_action.html_seg) -|| (opt_action.epub)) { - document_section_keys_sequenced["scroll"] ~= "tail"; - document_section_keys_sequenced["seg"] ~= "tail"; -} -#+END_SRC - -*** dup - -#+name: abs_post -#+BEGIN_SRC d -string[] segnames_4 = segnames["html"].dup; -string[] segnames_lv1_to_4 = segnames["epub"].dup; -debug(segnames) { - writeln("segnames_lv4: ", segnames_4); - writeln("segnames_lv1_to_4: ", segnames_lv1_to_4); -} -#+END_SRC - -*** clean out structure - -#+name: abs_post -#+BEGIN_SRC d -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(segnames); -destroy(bookindex_unordered_hashes); -destroy(an_object); -obj_cite_digits = ocn_emit(OCNstatus.reset); -biblio_arr_json = []; -obj_cite_digit_ = 0; -html_segnames_ptr = 0; -html_segnames_ptr_cntr = 0; -content_non_header = "8"; -dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -dom_structure_markedup_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -dom_structure_collapsed_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; -#+END_SRC - -*** doc_has struct - -#+name: abs_struct_doc_has -#+BEGIN_SRC d -auto doc_has() { - struct DocHas_ { - uint inline_links() { - return dochas["inline_links"]; - } - uint inline_notes_reg() { - return dochas["inline_notes"]; - } - uint inline_notes_star() { - return dochas["inline_notes_star"]; - } - uint codeblocks() { - return dochas["codeblock"]; - } - uint tables() { - return dochas["table"]; - } - uint blocks() { - return dochas["block"]; - } - uint groups() { - return dochas["group"]; - } - uint poems() { - return dochas["poem"]; - } - uint quotes() { - return dochas["quote"]; - } - ulong images() { // TODO not ideal rethink - return (image_list.to!string.strip("[","]").split(",").length); - } - auto imagelist() { - return image_list; - } - auto keys_seq() { - return docSectKeysSeq!()(document_section_keys_sequenced); - } - string[] segnames_lv4() { - return segnames_4; - } - string[] segnames_lv_0_to_4() { - return segnames_0_to_4; - } - string[string][string] tag_associations() { - return tag_assoc; - } - } - return DocHas_(); -} -#+END_SRC - -*** _return document tuple_ [#A] :return:tuple: - -#+name: abs_return_tuple -#+BEGIN_SRC d -auto t = tuple( - document_the, - doc_has, -); -return t; -#+END_SRC - -** 5. Functions :abstract:function: - -functions used in document abstraction - -*** set & resets :reset: -**** object reset: remove (clean) :object:remove: - -#+name: abs_functions_object_reset -#+BEGIN_SRC d -static string[string] object_reset()(string[string] an_object) { - an_object.remove("body_nugget"); - an_object.remove("substantive"); - an_object.remove("is"); - an_object.remove("attrib"); - an_object.remove("bookindex_nugget"); - return an_object; -} -#+END_SRC - -**** set, initialize or re-initialize :set: - -#+name: abs_functions_header_set_common -#+BEGIN_SRC d -void flow_common_reset_()( - return ref int[string] line_occur, - return ref string[string] an_object, - return ref int[string] obj_type_status, -) { - line_occur["heading"] = State.off; - line_occur["para"] = State.off; - obj_type_status["heading"] = State.off; - obj_type_status["para"] = State.off; - an_object = an_object.object_reset; -} -#+END_SRC - -*** check object_number status in document :ocn: - -#+name: abs_functions_ocn_status -#+BEGIN_SRC d -static int[string] _check_ocn_status_()( - char[] line, - int[string] obj_type_status, -) { - static auto rgx = Rgx(); - if (!(line.empty) - && (obj_type_status["ocn_status_off_for_multiple_objects"] == OCN_off_block_status.off) - ) { - /+ not multi-line object, check whether object_number is on or turned off +/ - if (line.matchFirst(rgx.object_number_block_marks)) { /+ switch off object_number +/ - if (line.matchFirst(rgx.object_number_off_block)) { - obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.on; - obj_type_status["ocn_status"] = OCNstatus.off; - debug(ocnoff) { - writeln(line); - } - } - if (line.matchFirst(rgx.object_number_off_block_dummy_heading)) { - obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.on; - obj_type_status["heading_off_for_multiple_objects"] = Status.on; - obj_type_status["ocn_status"] = OCNstatus.off; - debug(ocnoff) { - writeln(line); - } - } - } else { - if (obj_type_status["ocn_status_off_for_multiple_objects"] == OCN_off_block_status.off) { - obj_type_status["dummy_heading_status"] = Status.off; - if (obj_type_status["heading_off_for_multiple_objects"]) { - obj_type_status["dummy_heading_status"] = Status.on; - } - if (line.matchFirst(rgx.object_number_off)) { - obj_type_status["ocn_status"] = OCNstatus.off; - } else if (line.matchFirst(rgx.object_number_off_dummy_heading)) { - obj_type_status["ocn_status"] = OCNstatus.off; - obj_type_status["dummy_heading_status"] = Status.on; - } else { - obj_type_status["ocn_status"] = OCNstatus.on; - obj_type_status["dummy_heading_status"] = Status.off; - } - } else { - obj_type_status["ocn_status"] = obj_type_status["ocn_status_off_for_multiple_objects"]; - } - } - } else if ( - !(line.empty) - && (obj_type_status["ocn_status_off_for_multiple_objects"] > OCN_off_block_status.off) - ) { - if (line.matchFirst(rgx.object_number_off_block_close)) { - obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.off; - obj_type_status["ocn_status"] = OCNstatus.on; - obj_type_status["dummy_heading_status"] = Status.off; - debug(ocnoff) { - writeln(line); - } - } - } - return obj_type_status; -} -#+END_SRC - -*** make substitutions -**** project - -#+name: abs_functions_substitutions -#+BEGIN_SRC d -char[] _doc_header_and_make_substitutions_(CMM)( - char[] line, - CMM conf_make_meta, -) { - enum Substitute { match, markup, } - if (conf_make_meta.make.substitute) { - foreach(substitution_pair; conf_make_meta.make.substitute) { - line = line.replaceAll( - regex("\b" ~ substitution_pair[Substitute.match]), - substitution_pair[Substitute.markup] - ); - } - } - return line; -} -#+END_SRC - -**** fontface - -#+name: abs_functions_substitutions -#+BEGIN_SRC d -char[] _doc_header_and_make_substitutions_fontface_(CMM)( - char[] line, - CMM conf_make_meta, -) { - enum Substitute { match, markup, } - if ( conf_make_meta.make.bold) { - line = line.replaceAll( - regex("\b" ~ conf_make_meta.make.bold[Substitute.match]), - conf_make_meta.make.bold[Substitute.markup] - ); - } - if (conf_make_meta.make.emphasis) { - line = line.replaceAll( - regex("\b" ~ conf_make_meta.make.emphasis[Substitute.match]), - conf_make_meta.make.emphasis[Substitute.markup] - ); - } - if (conf_make_meta.make.italics) { - line = line.replaceAll( - regex("\b" ~ conf_make_meta.make.italics[Substitute.match]), - conf_make_meta.make.italics[Substitute.markup] - ); - } - return line; -} -#+END_SRC - -*** block :block: -**** block start (open) block :start: -***** { block starts function - -#+name: abs_functions_block -#+BEGIN_SRC d -void flow_txt_block_start()( - char[] line, - return ref int[string] obj_type_status, - return ref uint[string] dochas, - return ref string[string] object_number_poem -) { -#+END_SRC - -****** block (various) curly open :curly: - -#+name: abs_functions_block -#+BEGIN_SRC d - static auto rgx = Rgx(); -#+END_SRC - -******* code - -#+name: abs_functions_block -#+BEGIN_SRC d - if (auto m = line.matchFirst(rgx.block_curly_code_open)) { - dochas["codeblock"]++; - an_object["lang"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; - debug(codecurly) { // code (curly) open - writefln( - "* [code curly] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["code"] = TriState.on; - obj_type_status["curly_code"] = TriState.on; -#+END_SRC - -******* poem - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_poem_open)) { - dochas["poem"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(poem) { // poem (curly) open - writefln( - "* [poem curly] %s", - line - ); - } - object_number_poem["start"] = obj_cite_digits.object_number.to!string; - obj_type_status["blocks"] = TriState.on; - obj_type_status["verse_new"] = State.on; - obj_type_status["poem"] = TriState.on; - obj_type_status["curly_poem"] = TriState.on; -#+END_SRC - -******* group - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_group_open)) { - dochas["group"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(group) { // group (curly) open - writefln( - "* [group curly] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["group"] = TriState.on; - obj_type_status["curly_group"] = TriState.on; -#+END_SRC - -******* block - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_block_open)) { - dochas["block"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(block) { // block (curly) open - writefln( - "* [block curly] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["block"] = TriState.on; - obj_type_status["curly_block"] = TriState.on; -#+END_SRC - -******* quote - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_quote_open)) { - dochas["quote"]++; - an_object["syntax"] = ""; - an_object["attrib"] = m["attrib"].to!string; - an_object["lang"] = m["lang"].to!string; - debug(quote) { // quote (curly) open - writefln( - "* [quote curly] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["quote"] = TriState.on; - obj_type_status["curly_quote"] = TriState.on; -#+END_SRC - -******* table - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_table_open)) { /+ curly table open +/ - debug(table) { // table (curly) open - writefln( - "* [table curly] %s", - line - ); - } - dochas["table"] ++; - an_object["table_head"] = m["attrib"].to!string; - an_object["block_type"] = "curly"; - obj_type_status["blocks"] = TriState.on; - obj_type_status["table"] = TriState.on; - obj_type_status["curly_table"] = TriState.on; -#+END_SRC - -******* table special - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { /+ table: special table block markup syntax! +/ - dochas["table"]++; - an_object["table_head"] = m["attrib"].to!string; - an_object["block_type"] = "special"; - obj_type_status["blocks"] = TriState.on; - obj_type_status["table"] = TriState.on; - obj_type_status["curly_table_special_markup"] = TriState.on; -#+END_SRC - -****** block (various) tic open :tic: -******* code - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_code_open)) { - dochas["codeblock"]++; - an_object["lang"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; - debug(codetic) { // code (tic) open - writefln( - "* [code tic] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["code"] = TriState.on; - obj_type_status["tic_code"] = TriState.on; -#+END_SRC - -******* poem - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_poem_open)) { - dochas["poem"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(poem) { // poem (tic) open - writefln( - "* [poem tic] %s", - line - ); - } - object_number_poem["start"] = obj_cite_digits.object_number.to!string; - obj_type_status["blocks"] = TriState.on; - obj_type_status["verse_new"] = State.on; - obj_type_status["poem"] = TriState.on; - obj_type_status["tic_poem"] = TriState.on; -#+END_SRC - -******* group - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_group_open)) { - dochas["group"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(group) { // group (tic) open - writefln( - "* [group tic] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["group"] = TriState.on; - obj_type_status["tic_group"] = TriState.on; -#+END_SRC - -******* block - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_block_open)) { - dochas["block"]++; - an_object["syntax"] = ""; - an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; - an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; - debug(block) { // block (tic) open - writefln( - "* [block tic] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["block"] = TriState.on; - obj_type_status["tic_block"] = TriState.on; -#+END_SRC - -******* quote - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_quote_open)) { - dochas["quote"]++; - an_object["syntax"] = ""; - an_object["attrib"] = m["attrib"].to!string; - an_object["lang"] = m["lang"].to!string; - debug(quote) { // quote (tic) open - writefln( - "* [quote tic] %s", - line - ); - } - obj_type_status["blocks"] = TriState.on; - obj_type_status["quote"] = TriState.on; - obj_type_status["tic_quote"] = TriState.on; -#+END_SRC - -******* table - -#+name: abs_functions_block -#+BEGIN_SRC d - } else if (auto m = line.matchFirst(rgx.block_tic_table_open)) { /+ tic table open +/ - debug(table) { // table (tic) open - writefln( - "* [table tic] %s", - line - ); - } - dochas["table"] ++; - an_object["table_head"] = m["attrib"].to!string; - an_object["block_type"] = "tic"; - obj_type_status["blocks"] = TriState.on; - obj_type_status["table"] = TriState.on; - obj_type_status["tic_table"] = TriState.on; - } -#+END_SRC - -***** } - -#+name: abs_functions_block -#+BEGIN_SRC d -} -#+END_SRC - -**** block continue (an open block) :continue: -***** _code block_ (special status, deal with first) :code: - -#+name: abs_functions_block_code -#+BEGIN_SRC d -void flow_txt_block_code()( - char[] line, - return ref string[string] an_object, - return ref int[string] obj_type_status -) { - static auto rgx = Rgx(); - if (obj_type_status["curly_code"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_code_close)) { - debug(codecurly) { // code (curly) close - writeln(line); - } - an_object[an_object_key] = an_object[an_object_key] - .replaceFirst(rgx.newline_eol_delimiter_only, "") - .stripRight; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["code"] = TriState.closing; - obj_type_status["curly_code"] = TriState.off; - } else { - debug(codecurly) { // code (curly) line - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // code (curly) line - } - } else if (obj_type_status["tic_code"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - debug(codetic) { // code (tic) close - writeln(line); - } - an_object[an_object_key] = an_object[an_object_key] - .replaceFirst(rgx.newline_eol_delimiter_only, "") - .stripRight; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["code"] = TriState.closing; - obj_type_status["tic_code"] = TriState.off; - } else { - debug(codetic) { // code (tic) line - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // code (tic) line - } - } -} -#+END_SRC - -***** biblio block :biblio: -****** biblio tag map - -#+name: abs_functions_block_biblio -#+BEGIN_SRC d -final string biblio_tag_map()(string abr) { - 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]; -} -#+END_SRC - -******* +consider+ - -#+name: none -#+BEGIN_SRC d -final string biblio_tag_map_()(string abr) { - string name; - switch (abr) { - case "au" : name = "author_raw"; break; - case "ed" : name = "editor_raw"; break; - case "ti" : name = "fulltitle"; break; - case "lng" : name = "language"; break; - case "jo" : name = "journal"; break; - case "vol" : name = "volume"; break; - case "edn" : name = "edition"; break; - case "yr" : name = "year"; break; - case "pl" : name = "place"; break; - case "pb" : name = "publisher"; break; - case "pub" : name = "publisher"; break; - case "pg" : name = "pages"; break; - case "pgs" : name = "pages"; break; - case "sn" : name = "short_name"; break; - default : name = abr; break; - } - return name; -} -#+END_SRC - -****** biblio block - -#+name: abs_functions_block_biblio -#+BEGIN_SRC d -void flow_txt_block_biblio( - char[] line, - return ref int[string] obj_type_status, - return ref int bib_entry, - return ref string biblio_entry_str_json, - return ref string[] biblio_arr_json -) { - mixin DocReformBiblio; - auto jsn = BibJsnStr(); - static auto rgx = Rgx(); - if (line.matchFirst(rgx.heading_biblio) - && obj_type_status["para"] != State.on - && obj_type_status["group"] != State.on - && obj_type_status["block"] != State.on - && obj_type_status["poem"] != State.on - && obj_type_status["table"] != State.on - && obj_type_status["quote"] != State.on - ) { - obj_type_status["glossary_section"] = State.off; - obj_type_status["biblio_section"] = TriState.on; - obj_type_status["blurb_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=""; - } -} -#+END_SRC - -***** quote block :quote: - -#+name: abs_functions_block_quote -#+BEGIN_SRC d -string[string] flow_txt_block_quote()( - char[] line, - string[string] an_object, - return ref int[string] obj_type_status -) { - static auto rgx = Rgx(); - if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["quote"] = TriState.closing; - obj_type_status["curly_quote"] = TriState.off; - } else { - debug(quote) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) - } - } else if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["quote"] = TriState.closing; - obj_type_status["tic_quote"] = TriState.off; - } else { - debug(quote) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) - } - } - return an_object; -} -#+END_SRC - -***** group block :group: - -- apply inline markup -- discard leading and newline whitespace - -#+name: abs_functions_block_group -#+BEGIN_SRC d -string[string] flow_txt_block_group()( - char[] line, - string[string] an_object, - return ref int[string] obj_type_status -) { - static auto rgx = Rgx(); - if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["group"] = TriState.closing; - obj_type_status["curly_group"] = TriState.off; - } else { - debug(group) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) - } - } else if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["group"] = TriState.closing; - obj_type_status["tic_group"] = TriState.off; - } else { - debug(group) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) - } - } - return an_object; -} -#+END_SRC - -***** block block :block: - -- apply inline markup -- keep whitespace indentation -- keep newlines - -#+name: abs_functions_block_block -#+BEGIN_SRC d -string[string] flow_txt_block_block()( - char[] line, - string[string] an_object, - return ref int[string] obj_type_status -) { - static auto rgx = Rgx(); - if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["block"] = TriState.closing; - obj_type_status["curly_block"] = TriState.off; - } else { - debug(block) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) - } - } else if (obj_type_status["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; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["block"] = TriState.closing; - obj_type_status["tic_block"] = TriState.off; - } else { - debug(block) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) - } - } - return an_object; -} -#+END_SRC - -***** poem block, verse objects :poem:verse: - -why extra object stuff only in poem/verse? - -#+name: abs_functions_block_poem -#+BEGIN_SRC d -string[string] flow_txt_block_poem(CMM)( - char[] line, - string[string] an_object, - return ref int[string] obj_type_status, - return ref int cntr, - string[string] object_number_poem, - CMM conf_make_meta, - string[string] tag_in_seg, -) { - static auto rgx = Rgx(); - if (obj_type_status["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) { - writefln( - "* [poem curly] %s", - line - ); - } - if (processing.length > 0) { - an_object[an_object_key] = processing["verse"]; - } - debug(poem) { - writeln(__LINE__); - writefln( - "* %s %s", - obj_cite_digits.object_number, - line - ); - } - if (an_object.length > 0) { - debug(poem) { // poem (curly) close - writeln( - obj_cite_digits.object_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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - } - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - object_number_poem["end"] = obj_cite_digits.object_number.to!string; - obj_type_status["blocks"] = TriState.closing; - obj_type_status["poem"] = TriState.closing; - obj_type_status["curly_poem"] = TriState.off; - } else { - processing["verse"] ~= line ~= "\n"; - if (obj_type_status["verse_new"] == State.on) { - obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); - obj_type_status["verse_new"] = State.off; - } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { - processing["verse"] = processing["verse"].stripRight; - verse_line = TriState.off; - obj_type_status["verse_new"] = State.on; - } - if (obj_type_status["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_digits.object_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, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - } - } else if (obj_type_status["tic_poem"] == TriState.on) { - if (auto m = line.matchFirst(rgx.block_tic_close)) { // tic_poem_close - an_object[an_object_key]="verse"; - debug(poem) { - 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_digits.object_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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - object_number_poem["end"] = obj_cite_digits.object_number.to!string; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - obj_type_status["blocks"] = TriState.closing; - obj_type_status["poem"] = TriState.closing; - obj_type_status["tic_poem"] = TriState.off; - } else { - processing["verse"] ~= line ~= "\n"; - if (obj_type_status["verse_new"] == State.on) { - obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); - obj_type_status["verse_new"] = State.off; - } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { - processing["verse"] = processing["verse"].stripRight; - obj_type_status["verse_new"] = State.on; - verse_line = TriState.off; - } - if (obj_type_status["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_digits.object_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, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "verse"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } - } - } - return an_object; -} -#+END_SRC - -***** table block :table: - -there are 3 types of table markup that need to be nomalized (given a single representation) here - -- curly brace block -- tic block -- special notation block - -you need: -- identify the type for the munging to create uniform presentation - - curly, tick, special - - table heading row, bool -- present table header info in uniform way - - table_number_of_columns, int (count) - - table_column_widths, int[] column widths (as given or calculate average) - - show table walls, bool -- table content marked up in uniform way - -#+name: abs_functions_block_table -#+BEGIN_SRC d -string[string] flow_txt_block_table(CMM)( - char[] line, - string[string] an_object, - return ref int[string] obj_type_status, - return ref CMM conf_make_meta, -) { - static auto rgx = Rgx(); - if (obj_type_status["curly_table"] == TriState.on) { - if (line.matchFirst(rgx.block_curly_table_close)) { - debug(table) { // table (curly) close - writeln(line); - } - obj_type_status["blocks"] = TriState.closing; - obj_type_status["table"] = TriState.closing; - obj_type_status["curly_table"] = TriState.off; - } else { - debug(table) { // table - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) - } - } else if (obj_type_status["curly_table_special_markup"] == TriState.on) { - if (line.empty) { - obj_type_status["blocks"] = TriState.off; - obj_type_status["table"] = TriState.off; - obj_type_status["curly_table_special_markup"] = TriState.off; - line.flow_table_closed_make_special_notation_table_( - an_object, - the_document_body_section, - obj_cite_digits, - comp_obj_heading, - cntr, - obj_type_status, - conf_make_meta, - ); - } else { - debug(table) { - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; - } - } else if (obj_type_status["tic_table"] == TriState.on) { - if (line.matchFirst(rgx.block_tic_close)) { - debug(table) { // table (tic) close - writeln(line); - } - obj_type_status["blocks"] = TriState.closing; - obj_type_status["table"] = TriState.closing; - obj_type_status["tic_table"] = TriState.off; - } else { - debug(table) { // table - writeln(line); - } - an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) - } - } - return an_object; -} -#+END_SRC - -**** special table notation, make: table - -process and use an_object["table_head"] (then empty it) -- present table header info in uniform way - - table_number_of_columns, int (count) - - table_column_widths, int[] column widths (as given or calculate average) - - show table walls, bool - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d -void flow_table_closed_make_special_notation_table_(N,CMM)( - char[] line, - return ref string[string] an_object, - return ref ObjGenericComposite[] the_document_body_section, - return ref N obj_cite_digits, - return ref ObjGenericComposite _comp_obj_heading, - return ref int cntr, - return ref int[string] obj_type_status, - CMM conf_make_meta -) { - comp_obj_block = comp_obj_block.init; - obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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", conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); - comp_obj_block = comp_obj_block.flow_table_substantive_munge_special(an_object["substantive"]); - the_document_body_section ~= comp_obj_block; - object_reset(an_object); - processing.remove("verse"); - ++cntr; -} -#+END_SRC - -**** block end (close an open block): line empty, block flag _makes_ :close: - -***** { line empty, _make block_ - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d -string[string] flow_block_flag_line_empty_(B,N,CMM,Ts)( - char[] line, - string[string] an_object, - B bookindex_extract_hash, - return ref ObjGenericComposite[] the_document_body_section, - return ref string[][string][string] bookindex_unordered_hashes, - return ref N obj_cite_digits, - return ref ObjGenericComposite _comp_obj_heading, - return ref int cntr, - return ref int[string] obj_type_status, - string[string] object_number_poem, - CMM conf_make_meta, - Ts tag_in_seg, -) { - assert( - line.empty, - "\nline should be empty:\n \"" - ~ line ~ "\"" - ); - assert( - (obj_type_status["blocks"] == TriState.closing), - "code block status: closed" - ); - assertions_flag_types_block_status_none_or_closed(obj_type_status); - static auto rgx = Rgx(); -#+END_SRC - -****** make: quote block - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - if (obj_type_status["quote"] == TriState.closing) { - obj_cite_digits = ocn_emit(obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "quote"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "quote"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - obj_type_status["blocks"] = TriState.off; - obj_type_status["quote"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; -#+END_SRC - -****** make: group block - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - } else if (obj_type_status["group"] == TriState.closing) { - obj_cite_digits = ocn_emit(obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "group"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "group"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); - obj_type_status["blocks"] = TriState.off; - obj_type_status["group"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; -#+END_SRC - -****** make: block - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - } else if (obj_type_status["block"] == TriState.closing) { - obj_cite_digits = ocn_emit(obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "block"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - // anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.is_of_part = "body"; - comp_obj_block.metainfo.is_of_section = "body"; - comp_obj_block.metainfo.is_of_type = "block"; - comp_obj_block.metainfo.is_a = "block"; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; - comp_obj_block.metainfo.lang = an_object["lang"]; - comp_obj_block.metainfo.attrib = an_object["attrib"]; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.text = an_object["substantive"]; - comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_block; - obj_type_status["blocks"] = TriState.off; - obj_type_status["block"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; -#+END_SRC - -****** make: poem - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - } else if (obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "verse"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - cntr, - heading_ptr-1, - an_object["is"] - ); - comp_obj_poem_ocn = comp_obj_poem_ocn.init; - comp_obj_poem_ocn.metainfo.is_of_part = "body"; - comp_obj_poem_ocn.metainfo.is_of_section = "body"; - comp_obj_poem_ocn.metainfo.is_of_type = "block"; - comp_obj_poem_ocn.metainfo.is_a = "poem"; - comp_obj_poem_ocn.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_poem_ocn.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_poem_ocn.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_poem_ocn.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_poem_ocn.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_poem_ocn.text = ""; - the_document_body_section ~= comp_obj_poem_ocn; - obj_type_status["blocks"] = TriState.off; - obj_type_status["poem"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); -#+END_SRC - -****** make: code block - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - } else if (obj_type_status["code"] == TriState.closing) { - obj_cite_digits = ocn_emit(obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "code"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; - comp_obj_code = comp_obj_code.init; - comp_obj_code.metainfo.is_of_part = "body"; - comp_obj_code.metainfo.is_of_section = "body"; - comp_obj_code.metainfo.is_of_type = "block"; - comp_obj_code.metainfo.is_a = "code"; - comp_obj_code.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_code.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_code.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_code.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_code.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_code.metainfo.syntax = an_object["syntax"]; - comp_obj_code.metainfo.attrib = an_object["attrib"]; - comp_obj_code.code_block.linenumbers = (an_object["attrib"].match(rgx.code_numbering)) ? true : false; - comp_obj_code.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_code.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_code.text = an_object["substantive"]; - comp_obj_code.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; - comp_obj_code.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; - comp_obj_code.has.inline_links = substantive_obj_misc_tuple[sObj.links]; - the_document_body_section ~= comp_obj_code; - obj_type_status["blocks"] = TriState.off; - obj_type_status["code"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; -#+END_SRC - -****** make: table - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - } else if (obj_type_status["table"] == TriState.closing) { - comp_obj_block = comp_obj_block.init; - obj_cite_digits = ocn_emit(obj_type_status["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_digits, - tag_in_seg - ); - an_object["is"] = "table"; - auto comp_obj_location - = node_construct.node_location_emitter( - content_non_header, - tag_in_seg, - lev_anchor_tag, - tag_assoc, - obj_cite_digits, - 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, conf_make_meta, No._new_doc); - an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; - comp_obj_block = comp_obj_block.init; - comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; - comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; - comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; - comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); - comp_obj_block = comp_obj_block.flow_table_substantive_munge(an_object["substantive"]); - the_document_body_section ~= comp_obj_block; - obj_type_status["blocks"] = TriState.off; - obj_type_status["table"] = TriState.off; - object_reset(an_object); - processing.remove("verse"); - ++cntr; - } -#+END_SRC - -***** } - -#+name: abs_functions_block_line_status_empty -#+BEGIN_SRC d - return an_object; -} -#+END_SRC - -*** book index :bookindex: - -#+name: abs_functions_book_index -#+BEGIN_SRC d -string[string] flow_book_index_(B)( - char[] line, - string[string] an_object, - return ref string book_idx_tmp, - return ref int[string] obj_type_status, - B opt_action, -) { - static auto rgx = Rgx(); - if (auto m = line.match(rgx.book_index)) { /+ match book_index +/ - debug(bookindexmatch) { - writefln( - "* [bookindex] %s\n", - m["bookindex"].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 +/ - obj_type_status["book_index"] = State.on; - if (opt_action.backmatter && opt_action.section_bookindex) { - book_idx_tmp = m.captures[1].to!string; - debug(bookindexmatch) { - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); - } - } - } else if (obj_type_status["book_index"] == State.on ) { /+ book_index flag set +/ - if (auto m = line.match(rgx.book_index_close)) { - obj_type_status["book_index"] = State.off; - if (opt_action.backmatter - && opt_action.section_bookindex) { - an_object["bookindex_nugget"] = book_idx_tmp ~ m.captures[1].to!string; - debug(bookindexmatch) { - writefln( - "* [bookindex] %s\n", - book_idx_tmp, - ); - } - } - book_idx_tmp = ""; - } else { - if (opt_action.backmatter - && opt_action.section_bookindex) { - book_idx_tmp ~= line; - } - } - } - return an_object; -} -#+END_SRC - -*** heading or paragraph :heading:paragraph: -**** heading found :heading: - -#+name: abs_functions_heading -#+BEGIN_SRC d -string[string] flow_heading_found_()( - char[] line, - string[string] heading_match_str, - string[] _make_unmarked_headings, - return ref Regex!(char)[string] heading_match_rgx, - return ref int[string] obj_type_status -) { - static auto rgx = Rgx(); - if ((_make_unmarked_headings.length > 2) - && (obj_type_status["make_headings"] == State.off)) { /+ headings found +/ - debug(headingsfound) { - writeln(_make_unmarked_headings); - } - debug(headingsfound) { - writeln(_make_unmarked_headings.length); - writeln(_make_unmarked_headings); - } - switch (_make_unmarked_headings.length) { - case 7 : - if (!empty(_make_unmarked_headings[6])) { - heading_match_str["h_4"] - = "^(" ~ _make_unmarked_headings[6].to!string ~ ")"; - heading_match_rgx["h_4"] - = regex(heading_match_str["h_4"]); - } - goto case; - case 6 : - if (!empty(_make_unmarked_headings[5])) { - heading_match_str["h_3"] - = "^(" ~ _make_unmarked_headings[5].to!string ~ ")"; - heading_match_rgx["h_3"] - = regex(heading_match_str["h_3"]); - } - goto case; - case 5 : - if (!empty(_make_unmarked_headings[4])) { - heading_match_str["h_2"] - = "^(" ~ _make_unmarked_headings[4].to!string ~ ")"; - heading_match_rgx["h_2"] - = regex(heading_match_str["h_2"]); - } - goto case; - case 4 : - if (!empty(_make_unmarked_headings[3])) { - heading_match_str["h_1"] - = "^(" ~ _make_unmarked_headings[3].to!string ~ ")"; - heading_match_rgx["h_1"] - = regex(heading_match_str["h_1"]); - } - goto case; - case 3 : - if (!empty(_make_unmarked_headings[2])) { - heading_match_str["h_D"] - = "^(" ~ _make_unmarked_headings[2].to!string ~ ")"; - heading_match_rgx["h_D"] - = regex(heading_match_str["h_D"]); - } - goto case; - case 2 : - if (!empty(_make_unmarked_headings[1])) { - heading_match_str["h_C"] - = "^(" ~ _make_unmarked_headings[1].to!string ~ ")"; - heading_match_rgx["h_C"] - = regex(heading_match_str["h_C"]); - } - goto case; - case 1 : - if (!empty(_make_unmarked_headings[0])) { - heading_match_str["h_B"] - = "^(" ~ _make_unmarked_headings[0].to!string ~ ")"; - heading_match_rgx["h_B"] - = regex(heading_match_str["h_B"]); - } - break; - default: - break; - } - obj_type_status["make_headings"] = State.on; - } - return heading_match_str; -} -#+END_SRC - -**** heading make set :heading: - -#+name: abs_functions_heading -#+BEGIN_SRC d -char[] flow_heading_make_set_()( - char[] line, - int[string] line_occur, - return ref Regex!(char)[string] heading_match_rgx, - return ref int[string] obj_type_status -) { - if ((obj_type_status["make_headings"] == State.on) - && ((line_occur["para"] == State.off) - && (line_occur["heading"] == State.off)) - && ((obj_type_status["para"] == State.off) - && (obj_type_status["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; -} -#+END_SRC - -**** heading match :heading: - -#+name: abs_functions_heading -#+BEGIN_SRC d -string[string] flow_heading_matched_(CMM)( - char[] line, - string[string] an_object, - return ref int[string] line_occur, - return ref string an_object_key, - return ref int[string] lv, - return ref int[string] collapsed_lev, - return ref int[string] obj_type_status, - return ref CMM conf_make_meta, -) { - static auto rgx = Rgx(); - if (auto m = line.match(rgx.heading)) { /+ heading match +/ - ++line_occur["heading"]; - obj_type_status["heading"] = State.on; - obj_type_status["para"] = State.off; - if (line.match(rgx.heading_seg_and_above)) { - obj_type_status["glossary_section"] = State.off; - obj_type_status["biblio_section"] = State.off; - obj_type_status["blurb_section"] = State.off; - } - 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": // Title set - if (an_object[an_object_key].match(rgx.variable_doc_title) - && an_object[an_object_key].match(rgx.variable_doc_author)) { - an_object[an_object_key] = an_object[an_object_key] - .replaceFirst(rgx.variable_doc_title, - (conf_make_meta.meta.title_full ~ ", ")) - .replaceFirst(rgx.variable_doc_author, - conf_make_meta.meta.creator_author); - } else if (an_object[an_object_key].match(rgx.variable_doc_title)) { - an_object[an_object_key] = an_object[an_object_key] - .replaceFirst(rgx.variable_doc_title, - conf_make_meta.meta.title_full); - } - 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; - } - an_object["dummy_heading_status"] = (obj_type_status["dummy_heading_status"] == State.off) ? "f" : "t"; - debug(heading) { - writeln(line.strip); - } - } - return an_object; -} -#+END_SRC - -**** para match :para: - -#+name: abs_functions_para -#+BEGIN_SRC d -string[string] flow_para_match_()( - char[] line, - string[string] an_object, - return ref string an_object_key, - return ref int[string] indent, - return ref bool bullet, - return ref int[string] obj_type_status, - return ref int[string] line_occur, -) { - static auto rgx = Rgx(); - if (line_occur["para"] == State.off) { - line = font_faces_line(line); - /+ para matches +/ - obj_type_status["para"] = State.on; - an_object[an_object_key] ~= line; - indent=[ - "hang_position" : 0, - "base_position" : 0, - ]; - bullet = false; - if (auto m = line.matchFirst(rgx.para_indent)) { - debug(paraindent) { - writeln(line); - } - indent["hang_position"] = (m["indent"]).to!int; - indent["base_position"] = (m["indent"]).to!int; - } else if (line.matchFirst(rgx.para_bullet)) { - debug(parabullet) { - writeln(line); - } - bullet = true; - } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { - debug(paraindenthang) { - writeln(line); - } - indent = [ - "hang_position" : (m["hang"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { - debug(parabulletindent) { - writeln(line); - } - indent = [ - "hang_position" : (m["indent"]).to!int, - "base_position" : (m["indent"]).to!int, - ]; - bullet = true; - } - ++line_occur["para"]; - } - return an_object; -} -#+END_SRC - -**** text font face - -#+name: abs_functions_para -#+BEGIN_SRC d -char[] font_faces_line()( - char[] textline, -) { - static auto rgx = Rgx(); - static auto mkup = InlineMarkup(); - if (textline.match(rgx.inline_faces_line)) { - textline = textline - .replaceFirst(rgx.inline_emphasis_line, format(q"┃%s%s%s%s%s%s┃", mkup.emph, mkup.ff_o, "$1", mkup.ff_c, mkup.emph, "$2")) - .replaceFirst(rgx.inline_bold_line, format(q"┃%s%s%s%s%s%s┃", mkup.bold, mkup.ff_o, "$1", mkup.ff_c, mkup.bold, "$2")) - .replaceFirst(rgx.inline_underscore_line, format(q"┃%s%s%s%s%s%s┃", mkup.underscore, mkup.ff_o, "$1", mkup.ff_c, mkup.underscore, "$2")) - .replaceFirst(rgx.inline_italics_line, format(q"┃%s%s%s%s%s%s┃", mkup.italic, mkup.ff_o, "$1", mkup.ff_c, mkup.italic, "$2")); - } - return textline; -} -#+END_SRC - -**** tables - -- number of columns -- column widths (either as given or uniform, first often different from rest) -- column aligns (as given else default left for text, check whether can default right for digits) -- table heading (auto align left) -- table walls -- TODO need to be able to align columns left or right (digits) - -***** table instructions - -#+name: abs_functions_table -#+BEGIN_SRC d -ObjGenericComposite flow_table_instructions(H)( - return ref ObjGenericComposite table_object, - H table_head, -) { - static auto rgx = Rgx(); - table_object.metainfo.is_of_part = "body"; - table_object.metainfo.is_of_section = "body"; - table_object.metainfo.is_of_type = "block"; - table_object.metainfo.is_a = "table"; - table_object.has.inline_notes_reg = false; - table_object.has.inline_notes_star = false; - table_object.has.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; - 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; -} -#+END_SRC - -***** table array munge - -#+name: abs_functions_table -#+BEGIN_SRC d -ObjGenericComposite flow_table_array_munge(T)( - return ref ObjGenericComposite table_object, - return ref T table_array, -) { - static auto rgx = Rgx(); - static 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 (col.match(rgx.numeric_col) && idx_r == 1) { // conditions reversed to avoid: gdc compiled program run segfault - 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; -} -#+END_SRC - -***** table substantive munge - -#+name: abs_functions_table -#+BEGIN_SRC d -ObjGenericComposite flow_table_substantive_munge(T)( - return ref ObjGenericComposite table_object, - return ref T table_substantive, -) { - static auto rgx = Rgx(); - static 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_object.flow_table_array_munge(_table); - return table_object; -} -#+END_SRC - -***** table substantive munge special - -#+name: abs_functions_table -#+BEGIN_SRC d -ObjGenericComposite flow_table_substantive_munge_special(T)( - return ref ObjGenericComposite table_object, - return ref T table_substantive, -) { - static auto rgx = Rgx(); - static 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_object.flow_table_array_munge(_table); - return table_object; -} -#+END_SRC - -*** function emitters :emitters: -**** object :object: -***** ocn :ocn: - -#+name: meta_emitters_ocn -#+BEGIN_SRC d -pure struct OCNemitter { - int ocn_digit, ocn_object_number, ocn_on_, ocn_off_, ocn_bkidx, ocn_bkidx_; - string object_identifier; - bool ocn_is_off; - auto ocn_emitter(int ocn_status_flag) { - OCNset ocn; - assert(ocn_status_flag <= OCNstatus.reset); - ocn_object_number = ocn_bkidx = 0; - object_identifier = ""; - ocn_is_off = false; - switch(ocn_status_flag) with (OCNstatus) { - case reset: - ocn_digit = ocn_on_ = 1; - object_identifier = "1"; - ocn_is_off = false; - ocn_off_ = ocn_bkidx_ = 0; - break; - case on: - ocn_digit = ocn_object_number = ++ocn_on_; - object_identifier = ocn_digit.to!string; - ocn_is_off = false; - break; - case off: - ocn_digit = 0; - ocn_off_ = ++ocn_off_; - object_identifier = "a" ~ ocn_off_.to!string; - ocn_is_off = true; - break; - case bkidx: - ocn_bkidx = ++ocn_bkidx_; - break; - case closing: - break; - default: - ocn_digit = 0; - } - assert(ocn_digit >= 0); - ocn.digit = ocn_digit; - ocn.object_number = ocn_object_number; // difference between .object_number and .digit? - ocn.identifier = object_identifier; - ocn.off = ocn_is_off; - ocn.bkidx = ocn_bkidx; - ocn.type = ocn_status_flag; - return ocn; - } - invariant() { - } -} -#+END_SRC - -***** object inline markup munge :markup:inline: - -****** { struct, inline markup munge - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d -static struct ObjInlineMarkupMunge { - string[string] obj_txt; - int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; - string asterisks_, plus_; - string obj_txt_out, tail, note; - static auto rgx = Rgx(); - static 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; - } -#+END_SRC - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - static auto images()(string obj_txt_in) { - static auto mng = InlineMarkup(); - /+ url matched +/ - obj_txt_in = obj_txt_in.replaceAll(rgx.inline_notes_al_special, ""); // TODO reinstate when special footnotes are implemented - if (obj_txt_in.match(rgx.smid_image_generic)) { /+ images with and without links +/ - debug(images) { - writeln("Image: ", obj_txt_in); - } - if (obj_txt_in.match(rgx.smid_image_with_dimensions)) { - obj_txt_in = obj_txt_in - .replaceAll(rgx.smid_image_with_dimensions, ("$1" ~ mkup.img ~ "$2,w$3h$4 " ~ "$5")) - .replaceAll(rgx.smid_image_delimit, ("$1" - ~ mkup.lnk_o ~ "$2".strip ~ mkup.lnk_c - ~ mkup.url_o ~ mkup.url_c)); - debug(images) { - writeln("IMAGE with size: ", obj_txt_in); - } - } else if (obj_txt_in.match(rgx.smid_image)) { - obj_txt_in = obj_txt_in - .replaceAll(rgx.smid_image, ("$1" ~ mkup.img ~ "$2,w0h0" ~ "$3")) - .replaceAll(rgx.smid_image_delimit, ("$1" - ~ mkup.lnk_o ~ "$2".strip ~ mkup.lnk_c - ~ mkup.url_o ~ mkup.url_c)); - debug(images) { - writeln("IMAGE: ", obj_txt_in); // decide on representation - } - } - } - return obj_txt_in; - } -#+END_SRC - -******* footnotes endnotes markup - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto footnotes_endnotes_markup_and_number_or_stars()(string obj_txt_in, bool reset_note_numbers) { - /+ endnotes (regular) +/ - bool flg_notes_reg = false; - bool flg_notes_star = false; - bool flg_notes_plus = 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_symbol_plus)) { - flg_notes_plus = true; - ++n_foot_sp_plus; - plus_ = "*"; - n_foot=n_foot_sp_plus; - obj_txt_out ~= n.hit.to!string.replaceFirst( - rgx.inline_al_delimiter_open_symbol_plus, - (mkup.en_a_o ~ replicate(plus_, n_foot_sp_plus) ~ " ") - ) ~ "\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 ~ n_foot.to!string ~ " ") - ) ~ "\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, - flg_notes_plus, - ); - return t; - } -#+END_SRC - -******* object notes and links - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - private auto object_notes_and_links_()( - string obj_txt_in, - bool reset_note_numbers=false - ) { - obj_txt_out = ""; - bool urls = false; - bool images_without_dimensions = 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) - ); - /+ image matched +/ - if (obj_txt_in.match(rgx.smid_image_generic)) { - obj_txt_in = images(obj_txt_in); - if (obj_txt_in.match(rgx.smid_mod_image_without_dimensions)) { - images_without_dimensions = true; - } - } - /+ url matched +/ - if (obj_txt_in.match(rgx.smid_inline_url)) { - urls = true; - obj_txt_in = obj_txt_in.links_and_images; - } - if (auto m = obj_txt_in.match(rgx.para_inline_link_anchor)) { - obj_txt_in = obj_txt_in - .replaceAll(rgx.para_inline_link_anchor, "┃$1┃"); - } - 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[1]); - writeln(m.hit); - } - } - auto t = tuple( - obj_txt_out, - ftn[1], - ftn[2], - ftn[3], - urls, - images_without_dimensions, - ); - return t; - } - auto init() { - auto t = object_notes_and_links_(""); - return t; - } - invariant() { - } -#+END_SRC - -******* heading -- identified text by heading level marker followed by text until two new lines -- general markup - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto munge_heading()( - string obj_txt_in, - bool reset_note_numbers=false - ) { - obj_txt["munge"] = obj_txt_in - .replaceFirst(rgx.heading, "") - .replaceFirst(rgx.object_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() { - } -#+END_SRC - -******* para -- paragraph text without other identification until two new lines -- general markup - - paragraph attributes - - font faces (bold, italics, underscore etc.) - - footnotes/endnotes - - links - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto munge_para()(string obj_txt_in) { - obj_txt["munge"]=(obj_txt_in) - .replaceFirst(rgx.para_attribs, "") - .replaceFirst(rgx.object_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; - } -#+END_SRC - -******* quote - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - string munge_quote()(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } -#+END_SRC - -******* group -- group block identified by open an close tags -- general markup - - paragraph attributes - - font faces (bold, italics, underscore etc.) - - footnotes/endnotes - - links -- newlines detected and kept? - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto munge_group(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } -#+END_SRC - -******* block -- group block identified by open an close tags -- general markup - - paragraph attributes - - font faces (bold, italics, underscore etc.) - - footnotes/endnotes - - links -- newlines detected and kept? - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto munge_block()(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } -#+END_SRC - -******* verse (poem) -- sub part of poem block which is identified by open an close tags, separated from other verse by double newline -- newlines -- indentation -- what part of general markup? - - font faces (bold, italics, underscore etc.) - - footnotes/endnotes - - links? - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - auto munge_verse()(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - auto t = object_notes_and_links_(obj_txt["munge"]); - return t; - } - invariant() { - } -#+END_SRC - -******* code -- newlines -- indentation -- possibly identify syntax for coloring (obj attribute) -- numbered code blocks (markup/obj attribute?) -- no general markup -- one special character represented by mkup.nbsp ░ - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - string munge_code()(string obj_txt_in) { - obj_txt_in = obj_txt_in.replaceAll(rgx.space, mkup.nbsp); - obj_txt["munge"] = obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } -#+END_SRC - -******* table -- table block identified by open an close tags -- table markup - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - string munge_table()(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } -#+END_SRC - -******* comment - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d - string munge_comment()(string obj_txt_in) { - obj_txt["munge"]=obj_txt_in; - return obj_txt["munge"]; - } - invariant() { - } -#+END_SRC - -****** } - -#+name: meta_emitters_obj_inline_markup_munge -#+BEGIN_SRC d -} -#+END_SRC - -***** toc, tags, object inline markup :markup:inline: -****** { - -#+name: meta_emitters_obj_inline_markup -#+BEGIN_SRC d -static struct ObjInlineMarkup { - static auto rgx = Rgx(); - static auto munge = ObjInlineMarkupMunge(); - string[string] obj_txt; - static string anchor_tag = ""; -#+END_SRC - -******* object inline markup and anchor tags :markup:inline: - -#+name: meta_emitters_obj_inline_markup_and_anchor_tags_and_misc -#+BEGIN_SRC d - auto obj_inline_markup_and_anchor_tags_and_misc(CMM)( - string[string] obj_, - string obj_key_, - CMM conf_make_meta, - Flag!"_new_doc" _new_doc - ) { - obj_txt["munge"] = obj_[obj_key_].dup; - obj_txt["munge"] = (obj_["is"].match(ctRegex!(`verse|code`))) - ? obj_txt["munge"] - : obj_txt["munge"].strip; - if (_new_doc) { - anchor_tag = ""; - } - 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; - obj_notes_and_links["image_no_dimensions"] = false; - if ((obj_["is"] == "para") - || (obj_["is"] == "heading") - || (obj_["is"] == "quote") - || (obj_["is"] == "group") - || (obj_["is"] == "block") - || (obj_["is"] == "verse")) { - obj_txt["munge"] = (obj_txt["munge"]).inline_markup_faces; - obj_txt["munge"] = (obj_txt["munge"]).links_and_images; - } - switch (obj_["is"]) { - case "heading": - if (_new_doc) { - anchor_tag = ""; - } - obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, conf_make_meta, _new_doc); - obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"], _new_doc); - if (auto m = obj_txt["munge"].match(rgx.heading_anchor_tag)) { - anchor_tag = m.captures[1]; - } 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["notes_plus"] = x[3]; - obj_notes_and_links["links"] = x[4]; - obj_notes_and_links["image_no_dimensions"] = x[5]; - break; - } - auto t = tuple( - obj_txt["munge"], - anchor_tag, - obj_notes_and_links["notes_reg"], - obj_notes_and_links["notes_star"], - obj_notes_and_links["links"], - obj_notes_and_links["image_no_dimensions"], - ); - anchor_tag = ""; - return t; - } - invariant() { - } -#+END_SRC - -******* toc (table of contents), build, gather headings :markup:inline: - -#+name: meta_emitters_obj_inline_markup_table_of_contents -#+BEGIN_SRC d - auto _clean_heading_toc_()( - char[] heading_toc_, - ) { - auto m = (cast(char[]) heading_toc_).matchFirst(rgx.heading); - heading_toc_ = (m.post).replaceAll( - rgx.inline_notes_curly_gen, - ""); - return heading_toc_; - }; - ObjGenericComposite[] flow_table_of_contents_gather_headings(CMM)( - string[string] obj_, - CMM conf_make_meta, - string[string] tag_in_seg, - string _anchor_tag, - return ref string[][string] lev4_subtoc, - ObjGenericComposite[] the_table_of_contents_section, - ) { - ObjGenericComposite comp_obj_toc; - mixin InternalMarkup; - static 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( - mkup.lnk_o ~ "%s".strip ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - heading_toc_, - _anchor_tag, - ); - toc_txt_= toc_txt_.links_and_images; - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.metainfo.is_of_part = "frontmatter"; - comp_obj_toc.metainfo.is_of_section = "toc"; - comp_obj_toc.metainfo.is_of_type = "para"; - comp_obj_toc.metainfo.is_a = "toc"; - comp_obj_toc.metainfo.ocn = 0; - comp_obj_toc.metainfo.identifier = ""; - comp_obj_toc.metainfo.object_number_off = true; - comp_obj_toc.metainfo.object_number_type = 0; - comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; - comp_obj_toc.attrib.indent_hang = indent["hang_position"]; - comp_obj_toc.attrib.indent_base = indent["base_position"]; - comp_obj_toc.attrib.bullet = false; - comp_obj_toc.text = toc_txt_.to!string.strip; - comp_obj_toc.has.inline_links = true; - the_table_of_contents_section ~= comp_obj_toc; - } - comp_obj_toc = comp_obj_toc.init; - comp_obj_toc.metainfo.is_of_part = "frontmatter"; - comp_obj_toc.metainfo.is_of_section = "toc"; - comp_obj_toc.metainfo.is_of_type = "para"; - comp_obj_toc.metainfo.is_a = "toc"; - comp_obj_toc.metainfo.ocn = 0; - comp_obj_toc.metainfo.identifier = ""; - comp_obj_toc.metainfo.object_number_off = true; - comp_obj_toc.metainfo.object_number_type = 0; - comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; - comp_obj_toc.attrib.bullet = false; - comp_obj_toc.has.inline_links = true; - switch (obj_["lev_markup_number"].to!int) { - case 0: .. case 3: - break; - case 4: - lev4_subtoc[tag_in_seg["seg_lv4"]] = []; - break; - case 5: .. case 7: - subtoc_txt_ = format( - mkup.lnk_o ~ "%s".strip ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, - heading_toc_, - _anchor_tag, - ); - lev4_subtoc[tag_in_seg["seg_lv4"]] - ~= links_and_images(obj_["lev_markup_number"] - ~ "~ " ~ subtoc_txt_.to!string.strip - ); - break; - default: - break; - } - return the_table_of_contents_section; - } - invariant() { - } -#+END_SRC - -******* private: - -#+name: meta_emitters_obj_inline_markup_private -#+BEGIN_SRC d -private: -#+END_SRC - -******** make heading number & segment anchor tags if instructed :markup:inline:segment:anchor:tags: - -#+name: meta_emitters_obj_inline_markup_heading_numbering_segment_anchor_tags -#+BEGIN_SRC d - static int[] heading_num = [ 0, 0, 0, 0 ]; - static string heading_number_auto_composite = ""; - static string heading_number_auto_composite_segname = ""; - static bool[] auto_heading_numbering = [ true, true, true, true]; - static string _configured_auto_heading_numbering_and_segment_anchor_tags(CMM)( - string munge_, - string[string] obj_, - CMM conf_make_meta, - bool _new_doc, - ) { - if (_new_doc) { - heading_num = [ 0, 0, 0, 0 ]; - heading_number_auto_composite = ""; - auto_heading_numbering = [ true, true, true, true]; - } - if (conf_make_meta.make.auto_num_top_lv) { - if (obj_["lev_markup_number"].to!int == 0) { - heading_num[0] = 0; - heading_num[1] = 0; - heading_num[2] = 0; - heading_num[3] = 0; - heading_number_auto_composite = ""; - } - /+ auto_num_depth minimum 0 - (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ - if ( - conf_make_meta.make.auto_num_top_lv - > obj_["lev_markup_number"].to!uint - ) { - heading_num[1] = 0; - heading_num[2] = 0; - heading_num[3] = 0; - } else if ( - conf_make_meta.make.auto_num_top_lv - == obj_["lev_markup_number"].to!uint - ) { - auto_heading_numbering[0] = - (munge_.match(rgx.auto_heading_numbering_off_lv1)) ? false : true; - if (auto_heading_numbering[0]) { - heading_num[0] ++; - } - heading_num[1] = 0; - heading_num[2] = 0; - heading_num[3] = 0; - } else if ( - conf_make_meta.make.auto_num_top_lv - == (obj_["lev_markup_number"].to!uint - 1) - ) { - auto_heading_numbering[1] = - (munge_.match(rgx.auto_heading_numbering_off_lv2)) ? false : true; - if (auto_heading_numbering[0] - && auto_heading_numbering[1]) { - heading_num[1] ++; - } - heading_num[2] = 0; - heading_num[3] = 0; - } else if ( - conf_make_meta.make.auto_num_top_lv - == (obj_["lev_markup_number"].to!uint - 2) - ) { - auto_heading_numbering[2] = - (munge_.match(rgx.auto_heading_numbering_off_lv3)) ? false : true; - if (auto_heading_numbering[0] - && auto_heading_numbering[1] - && auto_heading_numbering[2]) { - heading_num[2] ++; - } - heading_num[3] = 0; - } else if ( - conf_make_meta.make.auto_num_top_lv - == (obj_["lev_markup_number"].to!uint - 3) - ) { - auto_heading_numbering[3] = - (munge_.match(rgx.auto_heading_numbering_off_lv4)) ? false : true; - if (auto_heading_numbering[0] - && auto_heading_numbering[1] - && auto_heading_numbering[2] - && auto_heading_numbering[3]) { - heading_num[3] ++; - } - } - if (auto_heading_numbering[0]) { - if (heading_num[3] > 0) { - heading_number_auto_composite - = (conf_make_meta.make.auto_num_depth.to!uint == 3 - && auto_heading_numbering[3]) - ? (format(q"┃%s.%s.%s.%s┃", - 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 - = ((conf_make_meta.make.auto_num_depth.to!uint >= 2) - && (conf_make_meta.make.auto_num_depth.to!uint <= 3) - && auto_heading_numbering[2]) - ? (format(q"┃%s.%s.%s┃", - 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 - = ((conf_make_meta.make.auto_num_depth.to!uint >= 1) - && (conf_make_meta.make.auto_num_depth.to!uint <= 3) - && auto_heading_numbering[1]) - ? (format(q"┃%s.%s┃", - heading_num[0].to!string, - heading_num[1].to!string - )) - : ""; - } else if (heading_num[0] > 0 - && munge_.match(rgx.auto_heading_numbering_lv1) - ) { - heading_number_auto_composite - = ((conf_make_meta.make.auto_num_depth.to!uint >= 0) - && (conf_make_meta.make.auto_num_depth.to!uint <= 3) - && auto_heading_numbering[0]) - ? (format(q"┃%s┃", - heading_num[0].to!string - )) - : ""; - } else { - heading_number_auto_composite = ""; - } - } - heading_number_auto_composite_segname = - (heading_number_auto_composite.empty) - ? "" - : "seg_" ~ heading_number_auto_composite; - debug(heading_number_auto) { - writeln(heading_number_auto_composite); - } - if ((!empty(heading_number_auto_composite)) - && (obj_["lev_markup_number"].to!uint >= conf_make_meta.make.auto_num_top_lv)) { - munge_ = munge_ - .replaceFirst(rgx.heading, - "$1~$2 " ~ heading_number_auto_composite ~ ". ") - .replaceFirst(rgx.heading_marker_missing_tag, - "$1~" ~ heading_number_auto_composite_segname ~ " "); - } - } - return munge_; - } -#+END_SRC - -******** make segment anchor tags if not provided :markup:inline:segment:anchor:tags: - -#+name: meta_emitters_obj_inline_markup_heading_numbering_segment_anchor_tags -#+BEGIN_SRC d - static int heading_num_lev1 = 0; - static string _make_segment_anchor_tags_if_none_provided()( - string munge_, - string lev_, - bool _new_doc - ) { - 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] ~ " "); - if (auto n = munge_.match(rgx.heading_anchor_tag_plus_colon)) { - auto tag_remunge_ = n.captures[2] - .replaceAll(rgx.heading_marker_tag_has_colon, ".."); - munge_ = munge_.replaceFirst(rgx.heading_anchor_tag_plus_colon, n.captures[1] ~ tag_remunge_ ~ " "); - } - } 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" - if (_new_doc) { - heading_num_lev1 = 0; - } - heading_num_lev1 ++; - munge_ = munge_.replaceFirst( - rgx.heading_marker_missing_tag, - "$1~" ~ "x" ~ heading_num_lev1.to!string ~ " "); - } - } - return munge_; - } -#+END_SRC - -****** } - -#+name: meta_emitters_obj_inline_markup_close -#+BEGIN_SRC d -} -#+END_SRC - -***** object attrib :attributes: -****** { attributes structure open, public - -#+name: meta_emitters_obj_attributes -#+BEGIN_SRC d -struct ObjAttributes { - string[string] _obj_attrib; -#+END_SRC - -******* emitter obj attributes, public - -#+name: meta_emitters_obj_attributes_public -#+BEGIN_SRC d - string obj_attributes()( - string obj_is_, - string obj_raw, - ObjGenericComposite _comp_obj_heading, - ) { - scope(exit) { - destroy(obj_is_); - destroy(obj_raw); - destroy(_comp_obj_heading); - } - _obj_attrib["json"] ="{"; - switch (obj_is_) { - case "heading": - _obj_attrib["json"] ~= txt_heading(obj_raw); - break; - case "para": - _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) - ~ txt_para(obj_raw); - break; - case "code": - _obj_attrib["json"] ~= txt_code(obj_raw); - break; - case "group": - _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) - ~ txt_group(obj_raw); - break; - case "block": - _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) - ~ txt_block(obj_raw); - break; - case "verse": - _obj_attrib["json"] ~= txt_verse(obj_raw); - break; - case "quote": - _obj_attrib["json"] ~= txt_quote(obj_raw); - break; - case "table": - _obj_attrib["json"] ~= txt_table(obj_raw); - break; - case "comment": - _obj_attrib["json"] ~= txt_comment(obj_raw); - break; - default: - _obj_attrib["json"] ~= txt_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(), - "; object_number: ", oa_j["object_number"].integer() - ); - } - } - return _obj_attrib["json"]; - } - invariant() { - } -#+END_SRC - -******* private - -#+name: meta_emitters_obj_attributes_private -#+BEGIN_SRC d - private: - string _obj_attributes; -#+END_SRC - -******** para & blocks - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_para_and_blocks()(string obj_txt_in) { - 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["indent"].to!string ~ "," - ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; - } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent_hang)) { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m["hang"].to!string ~ "," - ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; - } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent)) { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": " ~ m["indent"].to!string ~ "," - ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; - } else { - _obj_attributes =" \"bullet\": \"false\"," - ~ " \"indent_hang\": 0," - ~ " \"indent_base\": 0,"; - } - return _obj_attributes; - } -#+END_SRC - -******** heading - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_heading()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"heading\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** para - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_para()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"para\"," - ~ " \"is\": \"para\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** quote - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_quote()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"quote\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** group - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_group()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"group\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** block - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_block()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"block\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** verse - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_verse()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"verse\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** code - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_code()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"code\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** table - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_table()(string obj_txt_in) { - _obj_attributes = " \"use\": \"content\"," - ~ " \"of\": \"block\"," - ~ " \"is\": \"table\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** comment - -#+name: meta_emitters_obj_attributes_private_an_attribute -#+BEGIN_SRC d - string txt_comment()(string obj_txt_in) { - _obj_attributes = " \"use\": \"comment\"," - ~ " \"of\": \"comment\"," - ~ " \"is\": \"comment\""; - return _obj_attributes; - } - invariant() { - } -#+END_SRC - -******** set additional attribute values, parse as json - -#+name: meta_emitters_obj_attributes_private_json -#+BEGIN_SRC d - string _set_additional_values_parse_as_json()( - string _obj_attrib, - string obj_is_, - ObjGenericComposite _comp_obj_heading, - ) { - JSONValue oa_j = parseJSON(_obj_attrib); - assert( - (oa_j.type == JSON_TYPE.OBJECT) - ); - if (obj_is_ == "heading") { - oa_j.object["object_number"] = _comp_obj_heading.metainfo.ocn; - oa_j.object["lev_markup_number"] = _comp_obj_heading.metainfo.heading_lev_markup; - oa_j.object["lev_collapsed_number"] = _comp_obj_heading.metainfo.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_object_number"] = _comp_obj_heading.metainfo.parent_ocn; - oa_j.object["parent_lev_markup_number"] = _comp_obj_heading.metainfo.parent_lev_markup; - _obj_attrib = oa_j.toString(); - return _obj_attrib; - } -#+END_SRC - -****** } - -#+name: meta_emitters_obj_attributes_private_close -#+BEGIN_SRC d -} -#+END_SRC - -**** book index :book:index: -***** book index nugget hash :hash:nugget: - -#+name: meta_emitters_book_index_nugget -#+BEGIN_SRC d -struct BookIndexNuggetHash { - string main_term, sub_term, sub_term_bits; - int object_number_offset, object_number_endpoint; - string[] object_numbers; - string[][string][string] bi_hash_nugget; - string[] bi_main_terms_split_arr; - string[][string][string] bookindex_nugget_hash(N,S)( - string bookindex_section, - N obj_cite_digits, - S tag_in_seg, - ) { - debug(asserts) { - static assert(is(typeof(obj_cite_digits.object_number) == int)); - } - debug(bookindexraw) { - if (!bookindex_section.empty) { - writeln( - "* [bookindex] ", - "[", obj_cite_digits.object_number.to!string, ": ", tag_in_seg["seg_lv4"], "] ", bookindex_section, - " - - - ", - "[", obj_cite_digits.object_number.to!string, "] ", bookindex_section - ); - } - } - static 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_object_numbers_match) - ) { - main_term = m.captures[1].strip; - object_number_offset = m.captures[2].to!int; - object_number_endpoint=(obj_cite_digits.object_number + object_number_offset); - object_numbers ~= (obj_cite_digits.object_number.to!string - ~ "-" ~ object_number_endpoint.to!string); - } else { - main_term = bi_main_term_and_rest[0].strip; - object_numbers ~= obj_cite_digits.object_number.to!string; - } - bi_hash_nugget[main_term]["_a"] ~= object_numbers; - object_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_object_number_offset_split - ); - foreach (sub_terms_bits; bi_sub_terms_split_arr) { - if (auto m = sub_terms_bits.match(rgx.bi_term_and_object_numbers_match)) { - sub_term = m.captures[1].strip; - object_number_offset = m.captures[2].to!int; - object_number_endpoint=(obj_cite_digits.object_number + object_number_offset); - object_numbers ~= (obj_cite_digits.object_number.to!string - ~ " - " ~ object_number_endpoint.to!string); - } else { - sub_term = sub_terms_bits.strip; - object_numbers ~= obj_cite_digits.object_number.to!string; - } - if (!empty(sub_term)) { - bi_hash_nugget[main_term][sub_term] ~= object_numbers; - } - object_numbers=null; - } - } - } - } - return bi_hash_nugget; - } - invariant() { - } -} -#+END_SRC - -***** book index (sort &) report indented :report:indented: - -#+name: meta_emitters_book_index_report_indented -#+BEGIN_SRC d -struct BookIndexReportIndent { - int mkn, skn; - void bookindex_report_indented()( - string[][string][string] bookindex_unordered_hashes - ) { - 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; - } - } -} -#+END_SRC - -***** book index (sort &) report section :report:section: -****** { book index struct open - -#+name: meta_emitters_book_index_report_section -#+BEGIN_SRC d -struct BookIndexReportSection { - int mkn, skn; - static auto rgx = Rgx(); - static auto munge = ObjInlineMarkupMunge(); -#+END_SRC - -******* bookindex write section - -#+name: meta_emitters_book_index_report_section -#+BEGIN_SRC d - void bookindex_write_section()( - string[][string][string] bookindex_unordered_hashes - ) { - auto mainkeys = - bookindex_unordered_hashes.byKey.array - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable).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!("toUpper(a) < toUpper(b)", SwapStrategy.stable).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; - } - } -#+END_SRC - -******* book index (sort &) build section :report:section: - -#+name: meta_emitters_book_index_report_section -#+BEGIN_SRC d - auto bookindex_build_abstraction_section(N,B)( - string[][string][string] bookindex_unordered_hashes, - N obj_cite_digits, - B opt_action, - ) { - debug(asserts) { - static assert(is(typeof(obj_cite_digits.object_number) == int)); - } - mixin DocReformNode; - mixin InternalMarkup; - static 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!("toUpper(a) < toUpper(b)", SwapStrategy.stable).release; - ObjGenericComposite[] 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.backmatter - && opt_action.section_bookindex)) { - string bi_tmp; - string[] bi_tmp_tags; - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bookindex"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Book Index"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_book_index"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "bookindex"; - comp_obj_heading_.tags.anchor_tags = ["section_bookindex"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading.has.inline_links = true; - bookindex_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "bookindex"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Index"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "bookindex"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading.has.inline_links = false; - comp_obj_heading_.tags.anchor_tags = ["bookindex"]; - bookindex_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; - } - import std.array : appender; - auto buffer = appender!(char[])(); - string[dchar] transTable = [' ' : "_"]; - foreach (mainkey; mainkeys) { - bi_tmp_tags = [""]; - bi_tmp = mkup.bold ~ mkup.ff_o ~ mainkey ~ mkup.ff_c ~ mkup.bold ~ " "; - buffer.clear(); - bi_tmp_tags ~= translate(mainkey, transTable); - auto bkidx_lnk(string locs) { - string markup = ""; - if (auto m = locs.matchFirst(rgx.book_index_go)) { - markup - = links_and_images("{ " ~ m["link"] ~ " }" - ~ "#" ~ m["ocn"] ~ ", "); - } else { - writeln(__LINE__, ": ", locs); - } - return markup; - } - foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { - bi_tmp ~= bkidx_lnk(ref_); - } - bi_tmp ~= " \\\\\n "; - bookindex_unordered_hashes[mainkey].remove("_a"); - auto subkeys = - bookindex_unordered_hashes[mainkey].byKey.array - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable).release; - foreach (subkey; subkeys) { - bi_tmp ~= subkey ~ ", "; - buffer.clear(); - bi_tmp_tags ~= translate(subkey, transTable); - foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { - bi_tmp ~= bkidx_lnk(ref_); - } - bi_tmp ~= " \\\\\n "; - ++skn; - } - bi_tmp = bi_tmp.replaceFirst(rgx.trailing_linebreak, ""); - comp_obj_para = comp_obj_para.init; - comp_obj_para.metainfo.is_of_part = "backmatter"; - comp_obj_para.metainfo.is_of_section = "bookindex"; - comp_obj_para.metainfo.is_of_type = "para"; - comp_obj_para.metainfo.is_a = "bookindex"; - comp_obj_para.text = bi_tmp.to!string.strip; - comp_obj_para.metainfo.ocn = 0; - comp_obj_para.metainfo.identifier = ""; - comp_obj_para.metainfo.object_number_off = true; - comp_obj_para.metainfo.object_number_type = 0; - comp_obj_para.tags.anchor_tags = bi_tmp_tags; - comp_obj_para.attrib.indent_hang = 0; - comp_obj_para.attrib.indent_base = 1; - comp_obj_para.attrib.bullet = false; - comp_obj_para.has.inline_links = true; - comp_obj_para.text = bi_tmp.to!string.strip; - bookindex_section ~= comp_obj_para; - ++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_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - bookindex_section ~= comp_obj_heading_; - } - auto t = tuple( - bookindex_section, - obj_cite_digits - ); - return t; - } -#+END_SRC - -****** } - -#+name: meta_emitters_book_index_report_section -#+BEGIN_SRC d -} -#+END_SRC - -**** (end)notes section :endnotes:section: - -#+name: meta_emitters_endnotes -#+BEGIN_SRC d -struct NotesSection { - string[string] object_notes; - int previous_count; - int mkn; - static auto rgx = Rgx(); -#+END_SRC - -***** { gather notes for endnote section struct open - -#+name: meta_emitters_endnotes -#+BEGIN_SRC d - private auto gather_notes_for_endnote_section( - ObjGenericComposite[] contents_am, - string[string] tag_in_seg, - int cntr, - ) { - assert((contents_am[cntr].metainfo.is_a == "para") - || (contents_am[cntr].metainfo.is_a == "heading") - || (contents_am[cntr].metainfo.is_a == "quote") - || (contents_am[cntr].metainfo.is_a == "group") - || (contents_am[cntr].metainfo.is_a == "block") - || (contents_am[cntr].metainfo.is_a == "verse")); - assert(cntr >= previous_count); - assert( - (contents_am[cntr].text).match( - rgx.inline_notes_al_all_note) - ); - mixin InternalMarkup; - previous_count=cntr; - static auto mkup = InlineMarkup(); - static auto munge = ObjInlineMarkupMunge(); - foreach(m; - (contents_am[cntr].text).matchAll( - rgx.inline_notes_al_special_char_note) - ) { - debug(endnotes_build) { - writeln( - "{^", mkup.ff_o, m["char"], ".", mkup.ff_c, "^}" - ~ mkup.mark_internal_site_lnk, - tag_in_seg["seg_lv4"], - ".fnSuffix#noteref_\n ", m["char"], " ", - m["note"]); // sometimes need segment name (segmented html & epub) - } - // you need anchor for segments at this point -> - object_notes["anchor"] ~= "note_" ~ m["char"] ~ "』"; - object_notes["notes"] ~= (tag_in_seg["seg_lv4"].empty) - ? (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m["char"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" - ~ m["char"]) ~ " " - ~ m["note"] ~ "』" - ) - : (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m["char"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" - ~ mkup.mark_internal_site_lnk - ~ tag_in_seg["seg_lv4"] - ~ ".fnSuffix#noteref_" - ~ m["char"]) ~ " " - ~ m["note"] ~ "』" - ); - } - foreach(m; - (contents_am[cntr].text).matchAll( - rgx.inline_notes_al_regular_number_note) - ) { - debug(endnotes_build) { - writeln( - "{^", mkup.ff_o, m["num"], ".", mkup.ff_c, "^}" - ~ mkup.mark_internal_site_lnk, - tag_in_seg["seg_lv4"], - ".fnSuffix#noteref_\n ", m["num"], " ", - m["note"]); // sometimes need segment name (segmented html & epub) - } - // you need anchor for segments at this point -> - object_notes["anchor"] ~= "note_" ~ m["num"] ~ "』"; - object_notes["notes"] ~= (tag_in_seg["seg_lv4"].empty) - ? (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" - ~ m["num"]) ~ " " - ~ m["note"] ~ "』" - ) - : (links_and_images( - "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" - ~ mkup.mark_internal_site_lnk - ~ tag_in_seg["seg_lv4"] - ~ ".fnSuffix#noteref_" - ~ m["num"]) ~ " " - ~ m["note"] ~ "』" - ); - } - return object_notes; - } -#+END_SRC - -****** gathered notes - -#+name: meta_emitters_endnotes -#+BEGIN_SRC d - private auto gathered_notes() { - 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_; - } -#+END_SRC - -****** endnote objects - -#+name: meta_emitters_endnotes -#+BEGIN_SRC d - private auto endnote_objects(N,O)( - N obj_cite_digits, - O opt_action, - ) { - mixin DocReformNode; - 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.backmatter && opt_action.section_endnotes)) { - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "endnotes"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_endnotes"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = "endnotes"; - comp_obj_heading_.tags.anchor_tags = ["section_endnotes"]; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_endnotes_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; - } - { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "backmatter"; - comp_obj_heading_.metainfo.is_of_section = "endnotes"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.tags.segment_anchor_tag_epub = "endnotes"; - comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; - comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; - comp_obj_heading_.metainfo.heading_lev_markup = 4; - comp_obj_heading_.metainfo.heading_lev_collapsed = 2; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - comp_obj_heading_.tags.anchor_tags = ["endnotes"]; - the_endnotes_section ~= comp_obj_heading_; - tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; - tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; - ++mkn; - } - } else { - comp_obj_heading_ = comp_obj_heading_.init; - comp_obj_heading_.metainfo.is_of_part = "empty"; - comp_obj_heading_.metainfo.is_of_section = "empty"; - comp_obj_heading_.metainfo.is_of_type = "para"; - comp_obj_heading_.metainfo.is_a = "heading"; - comp_obj_heading_.text = "(skip) there are no Endnotes"; - comp_obj_heading_.metainfo.ocn = 0; - comp_obj_heading_.metainfo.identifier = ""; - comp_obj_heading_.metainfo.dummy_heading = true; - comp_obj_heading_.metainfo.object_number_off = true; - comp_obj_heading_.metainfo.object_number_type = 0; - comp_obj_heading_.metainfo.heading_lev_markup = 1; - comp_obj_heading_.metainfo.heading_lev_collapsed = 1; - comp_obj_heading_.metainfo.parent_ocn = 1; - comp_obj_heading_.metainfo.parent_lev_markup = 0; - the_endnotes_section ~= comp_obj_heading_; - } - if (opt_action.backmatter && opt_action.section_endnotes) { - ObjGenericComposite comp_obj_endnote_; - comp_obj_endnote_ = comp_obj_endnote_.init; - comp_obj_endnote_.metainfo.is_of_part = "backmatter"; - comp_obj_endnote_.metainfo.is_of_section = "endnote"; - comp_obj_endnote_.metainfo.is_of_type = "para"; - comp_obj_endnote_.metainfo.is_a = "endnote"; - comp_obj_endnote_.metainfo.ocn = 0; - comp_obj_endnote_.metainfo.identifier = ""; - // comp_obj_heading_.metainfo.dummy_heading = false; - comp_obj_heading_.metainfo.object_number_off = true; // check - comp_obj_heading_.metainfo.object_number_type = 0; // check - comp_obj_endnote_.attrib.indent_hang = 0; - comp_obj_endnote_.attrib.indent_base = 0; - comp_obj_endnote_.attrib.bullet = false; - foreach (i, endnote; endnotes_["notes"]) { - auto m = endnote.matchFirst(rgx.note_ref); - string notenumber = m["ref"].to!string; - string anchor_tag = "note_" ~ notenumber; - comp_obj_endnote_.tags.anchor_tags = [ endnotes_["anchor"][i] ]; - comp_obj_endnote_.has.inline_links = true; - comp_obj_endnote_.text = endnote.inline_markup_faces.strip; - the_endnotes_section ~= comp_obj_endnote_; - } - } - auto t = tuple(the_endnotes_section, obj_cite_digits); - return t; - } -#+END_SRC - -***** } - -#+name: meta_emitters_endnotes -#+BEGIN_SRC d -} -#+END_SRC - -**** bibliography :bibliography: -***** { biblio struct - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d -struct Bibliography { -#+END_SRC - -****** biblio - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d - public JSONValue[] flow_bibliography_()( - return ref string[] biblio_unsorted_incomplete, - return ref JSONValue[] bib_arr_json - ) { - JSONValue[] biblio_unsorted - = biblio_make_unsorted_array_of_json_objects(biblio_unsorted_incomplete, bib_arr_json); // TODO lookat returns - biblio_arr_json = []; - biblio_unsorted_incomplete = []; - JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); - debug(biblio0) { - biblio_debug(biblio_sorted__); - 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__; - } -#+END_SRC - -****** biblio unsorted complete - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d - final private JSONValue[] biblio_make_unsorted_array_of_json_objects()( - string[] biblio_unordered, - JSONValue[] bib_arr_json - ) { - 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; - } - return bib_arr_json.dup; - } -#+END_SRC - -****** biblio sort - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d - final private JSONValue[] biblio_sort()(JSONValue[] biblio_unordered) { - 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_; - } -#+END_SRC - -****** biblio debug - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d - void biblio_debug()(JSONValue[] biblio_sorted) { - debug(biblio0) { - foreach (j; biblio_sorted) { - if (!empty(j["fulltitle"].str)) { - writeln(j["sortby_deemed_author_year_title"]); - } - } - } - } -#+END_SRC - -***** } - -#+name: meta_emitters_bibliography -#+BEGIN_SRC d -} -#+END_SRC - -**** node structure metadata :structure:metadata:node: -***** { metadata node struct - -#+name: meta_emitters_metadata -#+BEGIN_SRC d -struct NodeStructureMetadata { - int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; - int obj_cite_digit; - int[string] p_; // p_ parent_ - static auto rgx = Rgx(); -#+END_SRC - -****** node metadata emitter - -#+name: meta_emitters_metadata -#+BEGIN_SRC d - ObjGenericComposite node_location_emitter(La,Ta,N)( - string lev_markup_number, - string[string] tag_in_seg, - La lev_anchor_tag, - Ta tag_assoc, - N obj_cite_digits, - int cntr_, - int ptr_, - string is_ - ) { - debug(asserts) { - static assert(is(typeof(obj_cite_digits.object_number) == int)); - } - assert(is_ != "heading"); - assert(obj_cite_digits.object_number.to!int >= 0); - assert(is_ != "heading"); // should not be necessary - assert(obj_cite_digits.object_number.to!int >= 0); // should not be necessary - if (lv7 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_4; - p_["object_number"] = lv7; - } else if (lv6 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_3; - p_["object_number"] = lv6; - } else if (lv5 > State.off) { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_2; - p_["object_number"] = lv5; - } else { - p_["lev_markup_number"] = DocStructMarkupHeading.h_text_1; - p_["object_number"] = lv4; - } - ObjGenericComposite comp_obj_location; - comp_obj_location = comp_obj_location.init; - comp_obj_location.metainfo.is_a = is_; - comp_obj_location.metainfo.ocn = obj_cite_digits.object_number; - comp_obj_location.metainfo.identifier = obj_cite_digits.identifier; - comp_obj_location.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; - comp_obj_location.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1_to_4"]; - comp_obj_location.tags.heading_lev_anchor_tag = lev_anchor_tag; - comp_obj_location.metainfo.parent_ocn = p_["object_number"]; - comp_obj_location.metainfo.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.metainfo.parent_lev_markup >= 4); - assert(comp_obj_location.metainfo.parent_lev_markup <= 7); - assert(comp_obj_location.metainfo.parent_ocn >= 0); - return comp_obj_location; - } - invariant() { - } -#+END_SRC - -****** node metadata emitter heading, (including most segnames & their pointers) - -#+name: meta_emitters_metadata -#+BEGIN_SRC d - ObjGenericComposite node_emitter_heading(Hd,TaL,TA,N,fNr,fNs,fL)( - string _text, - string lev_markup_number, - string lev_collapsed_number, - Hd dummy_heading_status, - string[string] tag_in_seg, - TaL lev_anchor_tag, - TA tag_assoc, - N obj_cite_digits, - int cntr_, - int ptr_, - string[] lv_ancestors_txt, - string is_, - int html_segnames_ptr, - fNr flag_notes_reg, - fNs flag_notes_star, - fL flag_links, - ) { - debug(asserts) { - static assert(is(typeof(lev) == string)); - static assert(is(typeof(obj_cite_digits.object_number) == int)); - } - assert(is_ == "heading"); - assert((obj_cite_digits.object_number).to!int >= 0); - assert( - lev_markup_number.match(rgx.levels_numbered), - ("not a valid heading level: " ~ lev_markup_number ~ " at " ~ obj_cite_digits.object_number.to!string) - ); - if (lev_markup_number.match(rgx.levels_numbered)) { - if (lev_markup_number.to!int == 0) { - /+ TODO first hit (of two) with this assertion failure, check, fix & reinstate - assert(obj_cite_digits.object_number.to!int == 1, - "ERROR header lev markup number is: " ~ - lev_markup_number.to!string ~ - " obj_cite_digits.object_number.to!int should == 1 but is: " ~ - obj_cite_digits.object_number.to!string ~ - "\n" ~ _text); - +/ - } - } - switch (lev_markup_number.to!int) { - case 0: - lv = DocStructMarkupHeading.h_sect_A; - lv0 = obj_cite_digit; - lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] = 0; - p_["object_number"] = 0; - break; - case 1: - lv = DocStructMarkupHeading.h_sect_B; - lv1 = obj_cite_digit; - lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_A; - p_["object_number"] = lv0; - break; - case 2: - lv = DocStructMarkupHeading.h_sect_C; - lv2 = obj_cite_digit; - lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_B; - p_["object_number"] = lv1; - break; - case 3: - lv = DocStructMarkupHeading.h_sect_D; - lv3=obj_cite_digit; - lv4=0; lv5=0; lv6=0; lv7=0; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_C; - p_["object_number"] = lv2; - break; - case 4: - lv = DocStructMarkupHeading.h_text_1; - lv4 = obj_cite_digit; - lv5=0; lv6=0; lv7=0; - if (lv3 > State.off) { - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_D; - p_["object_number"] = lv3; - } else if (lv2 > State.off) { - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_C; - p_["object_number"] = lv2; - } else if (lv1 > State.off) { - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_B; - p_["object_number"] = lv1; - } else { - p_["lev_markup_number"] - = DocStructMarkupHeading.h_sect_A; - p_["object_number"] = lv0; - } - break; - case 5: - lv = DocStructMarkupHeading.h_text_2; - lv5 = obj_cite_digit; - lv6=0; lv7=0; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_text_1; - p_["object_number"] = lv4; - break; - case 6: - lv = DocStructMarkupHeading.h_text_3; - lv6 = obj_cite_digit; - lv7=0; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_text_2; - p_["object_number"] = lv5; - break; - case 7: - lv = DocStructMarkupHeading.h_text_4; - lv7 = obj_cite_digit; - p_["lev_markup_number"] - = DocStructMarkupHeading.h_text_3; - p_["object_number"] = lv6; - break; - default: - break; - } - ObjGenericComposite _comp_obj_heading_; - _comp_obj_heading_ = _comp_obj_heading_.init; - _comp_obj_heading_.metainfo.is_of_part = "body"; - _comp_obj_heading_.metainfo.is_of_section = "body"; - _comp_obj_heading_.metainfo.is_of_type = "para"; - _comp_obj_heading_.metainfo.is_a = "heading"; - _comp_obj_heading_.text = _text.to!string.strip; - _comp_obj_heading_.metainfo.ocn = obj_cite_digits.object_number; - _comp_obj_heading_.metainfo.identifier = obj_cite_digits.identifier; - _comp_obj_heading_.metainfo.dummy_heading = (dummy_heading_status == "t") ? true: false; - _comp_obj_heading_.metainfo.object_number_off = obj_cite_digits.off; - // _comp_obj_heading_.metainfo.o_n_book_index = obj_cite_digits.bkidx; - _comp_obj_heading_.metainfo.object_number_type = obj_cite_digits.type; - _comp_obj_heading_.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1_to_4"]; - _comp_obj_heading_.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; - _comp_obj_heading_.tags.in_segment_html = _comp_obj_heading_.tags.anchor_tag_html; - _comp_obj_heading_.tags.heading_lev_anchor_tag = lev_anchor_tag; - _comp_obj_heading_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; - _comp_obj_heading_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; - _comp_obj_heading_.metainfo.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); - _comp_obj_heading_.metainfo.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); - _comp_obj_heading_.metainfo.parent_ocn = p_["object_number"]; - _comp_obj_heading_.metainfo.parent_lev_markup = p_["lev_markup_number"]; - _comp_obj_heading_.tags.heading_ancestors_text = lv_ancestors_txt; - _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_.has.inline_notes_reg = flag_notes_reg; - _comp_obj_heading_.has.inline_notes_star = flag_notes_star; - _comp_obj_heading_.has.inline_links = flag_links; - tag_assoc[_comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = _comp_obj_heading_.tags.in_segment_html; - tag_assoc[_comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = _comp_obj_heading_.tags.segment_anchor_tag_epub; - 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_.metainfo.parent_lev_markup <= 7); - assert(_comp_obj_heading_.metainfo.parent_ocn >= 0); - if (lev_markup_number.match(rgx.levels_numbered_headings)) { - assert(_comp_obj_heading_.metainfo.heading_lev_markup <= 7); - assert(_comp_obj_heading_.metainfo.ocn >= 0); - if (_comp_obj_heading_.metainfo.parent_lev_markup > 0) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup < _comp_obj_heading_.metainfo.heading_lev_markup); - if (_comp_obj_heading_.metainfo.ocn != 0) { - assert(_comp_obj_heading_.metainfo.parent_ocn < _comp_obj_heading_.metainfo.ocn); - } - } - if (_comp_obj_heading_.metainfo.heading_lev_markup == 0) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_B); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_C); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_1) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_2) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_1); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_3) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_2); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_4) { - assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_3); - } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_5) { - } - } - return _comp_obj_heading_; - } - invariant() { - } -#+END_SRC - -***** } - -#+name: meta_emitters_metadata -#+BEGIN_SRC d -} -#+END_SRC - -*** function assertions :assertions: -**** assertions on markup document structure :doc_structure: - -#+name: abs_functions_assertions -#+BEGIN_SRC d -pure void assertions_doc_structure()( - string[string] an_object, - int[string] lv -) { - 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; - } -} -#+END_SRC - -**** assertions on blocks :blocks: - -#+name: abs_functions_assertions -#+BEGIN_SRC d -pure void assertions_flag_types_block_status_none_or_closed()(int[string] obj_type_status) { - assert( - (obj_type_status["code"] == TriState.off) - || (obj_type_status["code"] == TriState.closing), - "code block status: off or closing"); - assert( - (obj_type_status["poem"] == TriState.off) - || (obj_type_status["poem"] == TriState.closing), - "poem status: off or closing"); - assert( - (obj_type_status["table"] == TriState.off) - || (obj_type_status["table"] == TriState.closing), - "table status: off or closing"); - assert( - (obj_type_status["group"] == TriState.off) - || (obj_type_status["group"] == TriState.closing), - "group block status: off or closing"); - assert( - (obj_type_status["block"] == TriState.off) - || (obj_type_status["block"] == TriState.closing), - "block status: off or closing"); -} -#+END_SRC - -*** doc sect keys seq - -#+name: template_doc_sect_keys_seq -#+BEGIN_SRC d -template docSectKeysSeq() { - auto docSectKeysSeq(string[][string] document_section_keys_sequenced) { - struct doc_sect_keys_seq { - string[] scroll() { - return document_section_keys_sequenced["scroll"]; - } - string[] seg() { - return document_section_keys_sequenced["seg"]; - } - string[] sql() { - return document_section_keys_sequenced["sql"]; - } - string[] latex() { - return document_section_keys_sequenced["latex"]; - } - } - return doc_sect_keys_seq(); - } -} -#+END_SRC - -* 2. Object Setter (Set Abstract Object) :module:spine:meta_object_setter: - -set abstracted objects for downstream processing - -** _module template_ - -#+BEGIN_SRC d :tangle "../src/doc_reform/meta/object_setter.d" -/++ - object setter: - setting of sisu objects for downstream processing - meta_object_setter.d -+/ -module doc_reform.meta.object_setter; -template ObjectSetter() { - /+ structs +/ - <> -} -#+END_SRC - -** 1. initialize structs :struct: -*** heading attribute - -#+BEGIN_SRC d -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; -} -#+END_SRC - -*** _composite object_ [#A] - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_MetaInfo_ { - string is_of_part = ""; // frontmatter, body, backmatter - string is_of_section = ""; // toc, body, glossary, biography, book index, blurb - string is_of_type = ""; // para, block ? - string is_a = ""; // heading, para, table, code block, group, verse/poem ... - alias of_part = is_of_part; - alias of_section = is_of_section; - alias is_of = is_of_type; - string attrib = ""; - string lang = ""; // blocks: group, block, quote; not codeblock; - string syntax = ""; // codeblock only - /+ o_n +/ - int o_n_substantive = 0; - int o_n_non_substantive = 0; - int o_n_glossary = 0; - int o_n_bibliography = 0; - int o_n_book_index = 0; - int o_n_blurb = 0; - string object_number_substantive() const @property { - return (o_n_substantive==0) ? "" : o_n_substantive.to!string; - } - string object_number_non_substantive() const @property { - return (o_n_non_substantive==0) ? "" : o_n_non_substantive.to!string; - } - string object_number_glossary() const @property { - return (o_n_glossary==0) ? "" : o_n_glossary.to!string; - } - string object_number_bibliography() const @property { - return (o_n_bibliography==0) ? "" : o_n_bibliography.to!string; - } - string object_number_book_index() const @property { - return (o_n_book_index==0) ? "" : o_n_book_index.to!string; - } - string object_number_blurb() const @property { - return (o_n_blurb==0) ? "" : o_n_blurb.to!string; - } - bool object_number_off = false; - bool visible_object_number = false; - int object_number_type = 0; // { ocn, non, bkidx } - /+ node +/ - string[string][string] node; - int ocn = 0; - string identifier = ""; - string object_number() const @property { - return (ocn==0) ? "" : ocn.to!string; - } - int o_n_type = 0; - int heading_lev_markup = 9; - int heading_lev_collapsed = 9; - string marked_up_level() const @property { - string _out; - switch (heading_lev_markup) { - case 0 : _out = "A"; break; - case 1 : _out = "B"; break; - case 2 : _out = "C"; break; - case 3 : _out = "D"; break; - case 4 : _out = "1"; break; - case 5 : _out = "2"; break; - case 6 : _out = "3"; break; - case 7 : _out = "4"; break; - default : _out = ""; break; // "9"; - } - return _out; - } - bool dummy_heading = false; - int[] markedup_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] collapsed_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - int[] dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0,]; - int parent_lev_markup = 0; - int parent_ocn = 0; - int last_decendant_ocn = 0; -} -#+END_SRC - -**** object text attributes - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_TxtAttrib_ { - int indent_base = 0; - int indent_hang = 0; - bool bullet = false; - string language = ""; -} -#+END_SRC - -**** object has within it - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_Has_ { - bool inline_links = false; - bool inline_notes_reg = false; - bool inline_notes_star = false; - bool images = false; - bool image_without_dimensions = false; -} -#+END_SRC - -**** table attributes - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_Table_ { - int number_of_columns = 0; - double[] column_widths = []; - string[] column_aligns = []; - bool heading = false; - bool walls = false; -} -#+END_SRC - -**** code attributes - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_CodeBlock_ { - string syntax = ""; - bool linenumbers = false; -} -#+END_SRC - -**** stow (things to be protected from regular text transformations, so far links) - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_Stow_ { - string[] link = []; -} -#+END_SRC - -**** pointers - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_Pointer_ { - int doc_object = 0; - int html_segnames = 0; - int heading = 0; -} -#+END_SRC - -**** tags - -#+name: meta_structs_init -#+BEGIN_SRC d -struct DocObj_Tags_ { - string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ]; - string anchor_tag_html = ""; - string in_segment_html = ""; - string segment_anchor_tag_epub = ""; - string html_segment_anchor_tag_is = ""; - string epub_segment_anchor_tag_is = ""; - string heading_lev_anchor_tag = ""; - string segname_prev = ""; - string segname_next = ""; - string[] lev4_subtoc = []; - string[] anchor_tags = []; -} -#+END_SRC - -**** composite object the parts - -#+name: meta_structs_init -#+BEGIN_SRC d -struct ObjGenericComposite { - string text = ""; - DocObj_MetaInfo_ metainfo; - DocObj_TxtAttrib_ attrib; - DocObj_Tags_ tags; - DocObj_Has_ has; - DocObj_Table_ table; - DocObj_CodeBlock_ code_block; - DocObj_Stow_ stow; - DocObj_Pointer_ ptr; -} -#+END_SRC - -*** The Objects: generic composite object array - -#+name: meta_structs_init -#+BEGIN_SRC d -struct TheObjects { - ObjGenericComposite[] oca; -} -#+END_SRC - -* __END__ diff --git a/org/metaverse.org b/org/metaverse.org new file mode 100644 index 0000000..e76e7b9 --- /dev/null +++ b/org/metaverse.org @@ -0,0 +1,7828 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) document abstraction +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:abstraction: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] + +* 1. Document Abstraction +Process markup document, create document abstraction. + +** _module template_ :module:metadoc_from_src: + +#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_from_src.d" +/++ + document abstraction: + abstraction of sisu markup for downstream processing + metadoc_from_src.d ++/ +module doc_reform.meta.metadoc_from_src; +template DocReformDocAbstraction() { + /+ ↓ abstraction imports +/ + <> + /+ ↓ abstraction mixins +/ + <> + /+ ↓ abstraction struct init +/ + <> + <> + /+ ↓ abstract marked up document +/ + auto DocReformDocAbstraction(CMM,Opt,Mf)( + char[][] markup_sourcefile_content, + CMM conf_make_meta, + Opt opt_action, + Mf manifested, + bool _new_doc + ) { + static auto rgx = Rgx(); + /+ ↓ abstraction init +/ + <> + /+ abstraction init ↑ +/ + <> + /+ ↓ ↻ loop markup document/text line by line +/ + srcDocLoop: + foreach (line; markup_sourcefile_content) { /+ ↓ markup document/text line by line +/ + // "line" variable can be empty but should never be null + <> + if (obj_type_status["code"] == TriState.on) { + <> + } 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 +/ + <> + } else { /+ not within a block group +/ + <> + if (line.matchFirst(rgx.block_open)) { + <> + } else if (!line.empty) { /+ line not empty +/ + /+ non blocks (headings, paragraphs) & closed blocks +/ + <> + } else if (obj_type_status["blocks"] == TriState.closing) { /+ line empty, with blocks flag +/ + <> + } else { /+ line.empty, post contents, empty variables: +/ + <> + } // close else for line empty + } // close else for not the above + } // close after non code, other blocks or regular text + <> + } /+ ← srcDocLoop closed: loop markup document/text line by line +/ + /+ ↓ post loop markup document/text +/ + <> + <> + <> + <> + /+ post loop markup document/text ↑ +/ + } /+ ← closed: abstract doc source +/ + /+ ↓ abstraction functions +/ + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + /+ abstraction functions ↑ +/ + /+ ↓ abstraction function emitters +/ + <> + /+ +/ + <> + <> + <> + <> + <> + <> + <> + /+ +/ + <> + <> + <> + <> + <> + <> + /+ +/ + <> + <> + <> + /+ +/ + <> + /+ +/ + <> + /+ +/ + <> + /+ abstraction functions emitters ↑ +/ + /+ ↓ abstraction functions assertions +/ + <> + /+ abstraction functions assertions ↑ +/ +} /+ ← closed: template DocReformDocAbstraction +/ +<> +#+END_SRC + +** 1. _pre loop processing_ :pre: +*** imports :imports: +[[./meta_defaults.org][meta_defaults]] + +#+name: abs_top_imports +#+BEGIN_SRC d +import doc_reform.meta; +import + std.algorithm, + std.container, + std.file, + std.json, + std.path; +import + doc_reform.meta.defaults, + doc_reform.meta.object_setter, + doc_reform.meta.rgx; +#+END_SRC + +*** mixins :mixins: + +#+name: abs_top_mixins +#+BEGIN_SRC d +mixin ObjectSetter; +mixin InternalMarkup; +mixin DocReformRgxInit; +#+END_SRC + +*** initialize :initialize: +**** initialize general + +#+name: abs_top_init_struct +#+BEGIN_SRC d +/+ initialize +/ +ObjGenericComposite[] 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 anchor_tag_; +string[string] tag_in_seg; +string lev_anchor_tag; +string[string][string] tag_assoc; +string[] lv0_to_3_tags; +/+ 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 +enum Status { off, on, } +enum OCNstatus { on, off, bkidx, closing, reset, } +enum OCN_off_block_status { off, on } +enum OCNtype { ocn, non, bkidx, } +/+ 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"; +static auto obj_im = ObjInlineMarkup(); +static auto obj_att = ObjAttributes(); +/+ ocn +/ +struct OCNset { + int digit; + int object_number; + bool off; + string identifier; + int bkidx; + int type; +} +OCNset obj_cite_digits; +int obj_cite_digit_, obj_cite_digit_off, obj_cite_digit_bkidx, obj_cite_digit_type; +auto object_citation_number = OCNemitter(); +int[] dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +int[] dom_structure_markedup_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +int[] dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +int[] dom_structure_collapsed_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +enum DomTags { none, open, close, close_and_open, open_still, } +#+END_SRC + +**** method heading ancestors + +#+name: abs_top_init_struct +#+BEGIN_SRC d +pure ObjGenericComposite obj_heading_ancestors()( + ObjGenericComposite obj, + string[] lv_ancestors_txt, +) { + switch (obj.metainfo.heading_lev_markup) { + case 0: + lv_ancestors_txt[0] = obj.text.to!string; + foreach(k; 1..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 1: + lv_ancestors_txt[1] = obj.text.to!string; + foreach(k; 2..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 2: + lv_ancestors_txt[2] = obj.text.to!string; + foreach(k; 3..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 3: + lv_ancestors_txt[3] = obj.text.to!string; + foreach(k; 4..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 4: + lv_ancestors_txt[4] = obj.text.to!string; + foreach(k; 5..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 5: + lv_ancestors_txt[5] = obj.text.to!string; + foreach(k; 6..8) { + lv_ancestors_txt[k] = ""; + } + goto default; + case 6: + lv_ancestors_txt[6] = obj.text.to!string; + lv_ancestors_txt[7] = ""; + goto default; + case 7: + lv_ancestors_txt[7] = obj.text.to!string; + goto default; + default: + obj.tags.heading_ancestors_text = lv_ancestors_txt.dup; + } + return obj; +} +#+END_SRC + +**** method dom markup tags + +#+name: abs_top_init_struct +#+BEGIN_SRC d +pure ObjGenericComposite obj_dom_structure_set_markup_tags()( + ObjGenericComposite obj, + 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); + } + obj.metainfo.dom_structure_markedup_tags_status = dom.dup; + return obj; +} +#+END_SRC + +**** method dom collapsed tags + +#+name: abs_top_init_struct +#+BEGIN_SRC d +pure ObjGenericComposite obj_dom_set_collapsed_tags()( + ObjGenericComposite obj, + 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); + } + obj.metainfo.dom_structure_collapsed_tags_status = dom.dup; + return obj; +} +#+END_SRC + +**** method ocn emit + +#+name: abs_top_init_struct +#+BEGIN_SRC d +static auto ocn_emit(int ocn_status_flag) { + return object_citation_number.ocn_emitter(ocn_status_flag); +} +static auto inline_markup_faces(L)(L line) { + static auto rgx = Rgx(); + static auto mkup = InlineMarkup(); + line = replaceAll!(m => mkup.quote_o ~ m[1] ~ mkup.quote_c)(line, rgx.within_quotes); + line = replaceAll!(m => mkup.mono ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.mono)(line, rgx.inline_mark_mono); + line = replaceAll!(m => mkup.cite ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ mkup.cite)(line, rgx.inline_mark_cite); + foreach (regx; [rgx.inline_mark_emphasis, rgx.inline_mark_bold, rgx.inline_mark_underscore, rgx.inline_mark_italics, rgx.inline_mark_superscript, rgx.inline_mark_subscript, rgx.inline_mark_strike, rgx.inline_mark_insert]) { + line = replaceAll!(m => m["mark"] ~ mkup.ff_o ~ m["text"] ~ mkup.ff_c ~ m["mark"])(line, regx); + } + return line; +} +static string links_and_images()(string obj_txt) { + static auto rgx = Rgx(); + static auto mkup = InlineMarkup(); + if (obj_txt.match(rgx.smid_inline_url_generic)) { + if ( + obj_txt.match(rgx.smid_inline_link_endnote_url_helper) + || obj_txt.match(rgx.smid_inline_link_endnote_url_helper_punctuated) + ) { + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s%s", + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_o, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_c, + m[3] + ))(obj_txt, rgx.smid_inline_link_endnote_url_helper_punctuated); + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s %s%s%s%s%s%s %s", + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_o, + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c, + mkup.en_a_c + ))(obj_txt, rgx.smid_inline_link_endnote_url_helper); + } else { + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", + m["pre"], + mkup.lnk_o, m["content"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c + ))(obj_txt, rgx.smid_inline_link_markup_regular); + } + obj_txt = replaceAll!(m => format("%s%s%s%s%s%s%s", + m["pre"], + mkup.lnk_o, m["link"].strip, mkup.lnk_c, + mkup.url_o, m["link"], mkup.url_c + ))(obj_txt, rgx.smid_inline_link_naked_url); // + } + return obj_txt; +} +/+ 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_tag, notes_reg, notes_star, links, image_no_dimensions } +#+END_SRC + +*** inline para tag associations + +#+name: abs_inline_para_tag_associations +#+BEGIN_SRC d +string[string][string] inline_para_link_anchor()( + string[string] an_object, + string[string] tag_in_seg, + string[string][string] tag_assoc +) { + static auto rgx = Rgx(); + if (auto m = an_object["substantive"].match(rgx.inline_link_anchor)) { + if (m.captures[1] !in tag_assoc) { + tag_assoc[(m.captures[1])]["seg_lv4"] = tag_in_seg["seg_lv4"]; + tag_assoc[(m.captures[1])]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; + } else { + writeln("a tag named already exists, check text line\n ", an_object["substantive"]); + } + } + return tag_assoc; +} +#+END_SRC + +*** scope + +#+name: abs_init_rest +#+BEGIN_SRC d +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; +} +#+END_SRC + +*** init rest + +#+name: abs_init_rest +#+BEGIN_SRC d +mixin DocReformRgxInitFlags; +mixin DocReformNode; +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, +]; +uint[string] dochas = [ + "inline_links" : 0, + "inline_notes" : 0, + "inline_notes_star" : 0, + "codeblock" : 0, + "table" : 0, + "block" : 0, + "group" : 0, + "poem" : 0, + "quote" : 0, + "images" : 0, +]; +auto obj_type_status = flags_type_init; +string[string] object_number_poem = [ + "start" : "", + "end" : "" +]; +string[] lv_ancestors_txt = [ "", "", "", "", "", "", "", "", ]; +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)" +]; +Regex!char[string] 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_.metainfo.is_of_part = "frontmatter"; +comp_obj_heading_.metainfo.is_of_section = "toc"; +comp_obj_heading_.metainfo.is_of_type = "para"; +comp_obj_heading_.metainfo.is_a = "heading"; +comp_obj_heading_.text = "Table of Contents"; +comp_obj_heading_.metainfo.ocn = 0; +comp_obj_heading_.metainfo.identifier = ""; +comp_obj_heading_.metainfo.dummy_heading = false; +comp_obj_heading_.metainfo.object_number_off = true; +comp_obj_heading_.metainfo.object_number_type = 0; +comp_obj_heading_.tags.segment_anchor_tag_epub = "toc"; +comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; +comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; +comp_obj_heading_.metainfo.heading_lev_markup = 4; +comp_obj_heading_.metainfo.heading_lev_collapsed = 1; +comp_obj_heading_.metainfo.parent_ocn = 1; +comp_obj_heading_.metainfo.parent_lev_markup = 0; +comp_obj_heading_.ptr.html_segnames = html_segnames_ptr; +comp_obj_heading_.tags.anchor_tags = ["toc"]; +comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; +comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; +tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; +tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; +auto toc_head = comp_obj_heading_; +html_segnames_ptr_cntr++; +the_table_of_contents_section = [toc_head]; +static auto mkup = InlineMarkup(); +static auto munge = ObjInlineMarkupMunge(); +auto note_section = NotesSection(); +auto bookindex_extract_hash = BookIndexNuggetHash(); +string[][string] lev4_subtoc; +string[][string] segnames = ["html": ["toc"], "epub": ["toc"]]; +int cnt1 = 1; int cnt2 = 1; int cnt3 = 1; +#+END_SRC + +*** make tests + +#+name: make_tests +#+BEGIN_SRC d +enum Substitute { match, markup, } +debug (substitutions) { + writeln(__LINE__, ":", __FILE__, ": DEBUG substitutions:"); + if (!(conf_make_meta.make.headings.empty)) { + writeln(conf_make_meta.make.headings); + } + if (conf_make_meta.make.substitute) { + foreach(substitution_pair; conf_make_meta.make.substitute) { + writeln("regex to match: ", substitution_pair[Substitute.match]); + writeln("substitution to make: ", substitution_pair[Substitute.markup]); + } + } + if (conf_make_meta.make.bold) { + writeln("regex to match: ", conf_make_meta.make.bold[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.bold[Substitute.markup]); + } + if (conf_make_meta.make.emphasis) { + writeln("regex to match: ", conf_make_meta.make.emphasis[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.emphasis[Substitute.markup]); + } + if (conf_make_meta.make.italics) { + writeln("regex to match: ", conf_make_meta.make.italics[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.italics[Substitute.markup]); + } +} +#+END_SRC + +** 2. ↻ *LOOP* _loop: process document body_ [+6] :loop: +*** Loop scope :scope: + +#+name: abs_in_loop_body_00 +#+BEGIN_SRC d +/+ scope +/ +scope(exit) { +} +scope(failure) { + stderr.writefln( + "%s\n%s\n%s:%s failed here:\n line: %s", + __MODULE__, __FUNCTION__, + __FILE__, __LINE__, + line, + ); +} +debug(source) { + writeln(line); +} +debug(srclines) { + if (!line.empty) { + writefln( + "* %s", + line + ); + } +} +#+END_SRC + +*** check whether object_number is on or turned off :ocn: + +#+name: abs_in_loop_body_00 +#+BEGIN_SRC d +if (!line.empty) { + obj_type_status = line._check_ocn_status_(obj_type_status); +} +#+END_SRC + +*** separate _code blocks_ from _other markup text_ [+5] [#A] +**** _code blocks_ :block:code: + +#+name: abs_in_loop_body_00_code_block +#+BEGIN_SRC d +/+ block object: code +/ +line.flow_txt_block_code(an_object, obj_type_status); +continue; +#+END_SRC + +**** _non code objects_ (non-code blocks & regular text: by line) [+4] :non_code: +***** inline fontface markup + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +line = line.inline_markup_faces; // by text line (rather than by text object), linebreaks in para problematic +#+END_SRC + +***** in section (biblio, glossary, blurb) +(block group)+ [+1] :block:active: +****** in section: biblio :biblio: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +if ((line.matchFirst(rgx.heading_biblio) + && obj_type_status["para"] != State.on + && obj_type_status["group"] != State.on + && obj_type_status["block"] != State.on + && obj_type_status["poem"] != State.on + && obj_type_status["table"] != State.on + && obj_type_status["quote"] != State.on) +|| (obj_type_status["biblio_section"] == State.on +&& (!(line.matchFirst(rgx.heading_blurb_glossary))) +&& (!(line.matchFirst(rgx.heading))) +&& (!(line.matchFirst(rgx.comment))))) { + /+ within section (block object): biblio +/ + obj_type_status["glossary_section"] = State.off; + obj_type_status["biblio_section"] = State.on; + obj_type_status["blurb_section"] = State.off; + if (opt_action.backmatter && opt_action.section_biblio) { + line.flow_txt_block_biblio(obj_type_status, bib_entry, biblio_entry_str_json, biblio_arr_json); + debug(bibliobuild) { + writeln("- ", biblio_entry_str_json); + writeln("-> ", biblio_arr_json.length); + } + } + continue; +#+END_SRC + +****** in section: glossary :glossary: + +if there is a glossary section you need to: +- extract it +- create standard headings +- markup contents in standard way like regular paragraphs + - need indentation and regular paragraph inline markup +- reconstitute the document with the glossary section following the endnotes + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if ((line.matchFirst(rgx.heading_glossary) + && obj_type_status["para"] != State.on + && obj_type_status["group"] != State.on + && obj_type_status["block"] != State.on + && obj_type_status["poem"] != State.on + && obj_type_status["table"] != State.on + && obj_type_status["quote"] != State.on) +|| (obj_type_status["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); + } + obj_type_status["glossary_section"] = State.on; + obj_type_status["biblio_section"] = State.off; + obj_type_status["blurb_section"] = State.off; + if (opt_action.backmatter && opt_action.section_glossary) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + obj_type_status["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_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "glossary"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Glossary"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_glossary"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = "glossary"; + comp_obj_heading_.tags.anchor_tags = ["section_glossary"]; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + the_glossary_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "glossary"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Glossary"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "glossary"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = 4; + comp_obj_heading_.metainfo.heading_lev_collapsed = 2; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; + comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; + comp_obj_heading_.tags.anchor_tags = ["glossary"]; + the_glossary_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } + } else { + an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); + comp_obj_para = comp_obj_para.init; + comp_obj_para.metainfo.is_of_part = "backmatter"; + comp_obj_para.metainfo.is_of_section = "glossary"; + comp_obj_para.metainfo.is_of_type = "para"; + comp_obj_para.metainfo.is_a = "glossary"; + comp_obj_para.text = line.to!string.strip; + comp_obj_para.metainfo.ocn = 0; + comp_obj_para.metainfo.identifier = ""; + comp_obj_para.metainfo.object_number_off = true; + comp_obj_para.metainfo.object_number_type = 0; + comp_obj_para.attrib.indent_hang = indent["hang_position"]; + comp_obj_para.attrib.indent_base = indent["base_position"]; + comp_obj_para.attrib.bullet = bullet; + the_glossary_section ~= comp_obj_para; + } + obj_type_status["ocn_status"] = OCNstatus.on; + } + continue; +#+END_SRC + +****** in section: blurb :blurb: + +if there is a blurb section you need to: +- extract it +- create standard headings (or use line provided in 1~ heading) +- markup contents in standard way like regular paragraphs + - need regular paragraph inline markup +- reconstitute the document with the blurb section at the very end of the doucment + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if ((line.matchFirst(rgx.heading_blurb) + && obj_type_status["para"] != State.on + && obj_type_status["group"] != State.on + && obj_type_status["block"] != State.on + && obj_type_status["poem"] != State.on + && obj_type_status["table"] != State.on + && obj_type_status["quote"] != State.on) +|| (obj_type_status["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); + } + obj_type_status["glossary_section"] = State.off; + obj_type_status["biblio_section"] = State.off; + obj_type_status["blurb_section"] = State.on; + if (opt_action.backmatter && opt_action.section_blurb) { + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + if (auto m = line.matchFirst(rgx.para_indent)) { + debug(paraindent) { + writeln(line); + } + indent["hang_position"] = (m["indent"]).to!int; + indent["base_position"] = (m["indent"]).to!int; + } else if (line.matchFirst(rgx.para_bullet)) { + debug(parabullet) { + writeln(line); + } + bullet = true; + } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { + debug(paraindenthang) { + writeln(line); + } + indent=[ + "hang_position" : (m["hang"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { + debug(parabulletindent) { + writeln(line); + } + indent=[ + "hang_position" : (m["indent"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + bullet = true; + } + obj_type_status["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_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "blurb"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Blurb"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_blurb"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = "blurb"; + comp_obj_heading_.tags.anchor_tags = ["section_blurb"]; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 0, 0, 0, 0, 0, 0]; + the_blurb_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "blurb"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Blurb"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = 4; + comp_obj_heading_.metainfo.heading_lev_collapsed = 2; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.tags.anchor_tags = ["blurb"]; + comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = [ 1, 1, 0, 0, 1, 0, 0, 0]; + comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = [ 1, 1, 1, 0, 0, 0, 0, 0]; + the_blurb_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } + } else if (line.matchFirst(rgx.heading) + && (opt_action.backmatter && opt_action.section_blurb)) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "blurb"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = line.to!string; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "blurb"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = an_object["lev_markup_number"].to!int; // make int, remove need to conv + comp_obj_heading_.metainfo.heading_lev_collapsed = an_object["lev_collapsed_number"].to!int; // make int, remove need to conv + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_blurb_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } else { + an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); + comp_obj_para = comp_obj_para.init; + comp_obj_para.metainfo.is_of_part = "backmatter"; + comp_obj_para.metainfo.is_of_section = "blurb"; + comp_obj_para.metainfo.is_of_type = "para"; + comp_obj_para.metainfo.is_a = "blurb"; + comp_obj_para.text = links_and_images(line.to!string.strip).replaceFirst(rgx.para_attribs, ""); + comp_obj_para.metainfo.ocn = 0; + comp_obj_para.metainfo.identifier = ""; + comp_obj_para.metainfo.object_number_off = true; + comp_obj_para.metainfo.object_number_type = 0; + comp_obj_para.attrib.indent_hang = indent["hang_position"]; + comp_obj_para.attrib.indent_base = indent["base_position"]; + comp_obj_para.has.inline_links = true; + comp_obj_para.attrib.bullet = bullet; + the_blurb_section ~= comp_obj_para; + } + obj_type_status["ocn_status"] = OCNstatus.on; + } + continue; +#+END_SRC + +***** in blocks [+1] :block:active: +****** in block: quote :quote: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if (obj_type_status["quote"] == TriState.on) { /+ within block object: quote +/ + line = line + ._doc_header_and_make_substitutions_(conf_make_meta) + ._doc_header_and_make_substitutions_fontface_(conf_make_meta); + an_object = line.flow_txt_block_quote(an_object, obj_type_status); + continue; +#+END_SRC + +****** in block: group :group: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +/+ within block object: group +/ +} else if (obj_type_status["group"] == TriState.on) { /+ within block object: group +/ + line = line + ._doc_header_and_make_substitutions_(conf_make_meta) + ._doc_header_and_make_substitutions_fontface_(conf_make_meta) + .replaceAll(rgx.para_delimiter, mkup.br_paragraph ~ "$1"); + an_object = line.flow_txt_block_group(an_object, obj_type_status); + continue; +#+END_SRC + +****** in block: block :block: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if (obj_type_status["block"] == TriState.on) { /+ within block object: block +/ + line = line + ._doc_header_and_make_substitutions_(conf_make_meta) + ._doc_header_and_make_substitutions_fontface_(conf_make_meta); + if (auto m = line.match(rgx.spaces_keep)) { + line = line + .replaceAll(rgx.spaces_keep, (m.captures[1]).translate([ ' ' : mkup.nbsp ])); + } + an_object = line.flow_txt_block_block(an_object, obj_type_status); + continue; +#+END_SRC + +****** in block: poem :poem: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if (obj_type_status["poem"] == TriState.on) { /+ within block object: poem +/ + an_object = line.flow_txt_block_poem(an_object, obj_type_status, cntr, object_number_poem, conf_make_meta, tag_in_seg); + continue; +#+END_SRC + +****** in block: table :table: + +#+name: abs_in_loop_body_non_code_obj +#+BEGIN_SRC d +} else if (obj_type_status["table"] == TriState.on) { /+ within block object: table +/ + an_object = line.flow_txt_block_table(an_object, obj_type_status, conf_make_meta); + continue; +#+END_SRC + +***** not identified as being within block group (could still be, or not) [+3] +****** assert + +#+name: abs_in_loop_body_open_block_obj_assert +#+BEGIN_SRC d +assert( + (obj_type_status["blocks"] == TriState.off) + || (obj_type_status["blocks"] == TriState.closing), + "block status: none or closed" +); +assertions_flag_types_block_status_none_or_closed(obj_type_status); +#+END_SRC + +****** catch misc +block open+ + +#+name: abs_in_loop_body_open_block_obj +#+BEGIN_SRC d +if (line.matchFirst(rgx.block_poem_open)) { /+ poem to verse exceptions! +/ + object_reset(an_object); + processing.remove("verse"); + object_number_poem["start"] = obj_cite_digits.object_number.to!string; +} +line.flow_txt_block_start(obj_type_status, dochas, object_number_poem); +continue; +#+END_SRC + +****** line not empty [+2] +******* asserts :assert: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d +assert( + !line.empty, + "line tested, line not empty surely:\n \"" ~ line ~ "\"" +); +assert( + (obj_type_status["blocks"] == TriState.off) + || (obj_type_status["blocks"] == TriState.closing), + "code block status: none or closed" +); +if (obj_type_status["blocks"] == TriState.closing) { + debug(check) { + writeln(__LINE__); + writeln(line); + } + assert( + line.matchFirst(rgx.book_index) + || line.matchFirst(rgx.book_index_open) + || obj_type_status["book_index"] == State.on, + "\nblocks closed, unless followed by book index, non-matching line:\n \"" + ~ line ~ "\"" + ); +} +#+END_SRC + +******* book index :bookindex: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d +if (line.matchFirst(rgx.book_index) +|| line.matchFirst(rgx.book_index_open) +|| obj_type_status["book_index"] == State.on ) { /+ book_index +/ + an_object = line.flow_book_index_(an_object, book_idx_tmp, obj_type_status, opt_action); +#+END_SRC + +******* not book index [+1] + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d +} else { /+ not book_index +/ +#+END_SRC + +******** matched: comment :comment:match: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d + an_object_key="body_nugget"; + if (auto m = line.matchFirst(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.metainfo.is_of_part = "comment"; // breaks flow + comp_obj_comment.metainfo.is_of_section = "comment"; // breaks flow + comp_obj_comment.metainfo.is_of_type = "comment"; + comp_obj_comment.metainfo.is_a = "comment"; + comp_obj_comment.text = an_object[an_object_key].strip; + the_document_body_section ~= comp_obj_comment; + flow_common_reset_(line_occur, an_object, obj_type_status); + processing.remove("verse"); + ++cntr; +#+END_SRC + +******** flag !set & line !exist: heading or para :heading:paragraph: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d + } else if (((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((obj_type_status["para"] == State.off) + && (obj_type_status["heading"] == State.off))) { /+ heading or para but neither flag nor line exists +/ + if ((conf_make_meta.make.headings.length > 2) + && (obj_type_status["make_headings"] == State.off)) { /+ heading found +/ + heading_match_str = line.flow_heading_found_(heading_match_str, conf_make_meta.make.headings, heading_match_rgx, obj_type_status); + } + if ((obj_type_status["make_headings"] == State.on) + && ((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((obj_type_status["para"] == State.off) + && (obj_type_status["heading"] == State.off))) { /+ heading make set +/ + line = line.flow_heading_make_set_(line_occur, heading_match_rgx, obj_type_status); + } + /+ 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 +/ + line = line._doc_header_and_make_substitutions_(conf_make_meta); + an_object = line.flow_heading_matched_(an_object, line_occur, an_object_key, lv, collapsed_lev, obj_type_status, conf_make_meta); + } else if (line_occur["para"] == State.off) { /+ para match +/ + an_object_key="body_nugget"; + line = line + ._doc_header_and_make_substitutions_(conf_make_meta) + ._doc_header_and_make_substitutions_fontface_(conf_make_meta); + an_object = line.flow_para_match_(an_object, an_object_key, indent, bullet, obj_type_status, line_occur); + } +#+END_SRC + +******** line exist: heading :heading: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d + } else if (line_occur["heading"] > State.off) { /+ heading +/ + debug(heading) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + ++line_occur["heading"]; +#+END_SRC + +******** line exist: para :para: + +#+name: abs_in_loop_body_not_block_obj +#+BEGIN_SRC d + } else if (line_occur["para"] > State.off) { /+ paragraph +/ + debug(para) { + writeln(an_object_key, "-> ", line); + } + line = line + ._doc_header_and_make_substitutions_(conf_make_meta) + ._doc_header_and_make_substitutions_fontface_(conf_make_meta); + an_object[an_object_key] ~= " " ~ line; + ++line_occur["para"]; + } +} +#+END_SRC + +****** line empty, with block flag + +#+name: abs_in_loop_body_not_block_obj_line_empty_blocks_flags +#+BEGIN_SRC d +an_object = line.flow_block_flag_line_empty_( + an_object, + bookindex_extract_hash, + the_document_body_section, + bookindex_unordered_hashes, + obj_cite_digits, + comp_obj_heading, + cntr, + obj_type_status, + object_number_poem, + conf_make_meta, + tag_in_seg, +); +#+END_SRC + +****** line empty [+1] +******* assert line empty :assert: + +#+name: abs_in_loop_body_not_block_obj_line_empty +#+BEGIN_SRC d +assert( + line.empty, + "\nline should be empty:\n \"" + ~ line ~ "\"" +); +assert( + (obj_type_status["blocks"] == State.off), + "code block status: none" +); +#+END_SRC + +******* heading object :heading:object: + +#+name: abs_in_loop_body_not_block_obj_line_empty +#+BEGIN_SRC d +if (_new_doc) { + tag_assoc = tag_assoc.init; + lv0_to_3_tags = lv0_to_3_tags.init; + tag_in_seg = tag_in_seg.init; +} +if ((obj_type_status["heading"] == State.on) +&& (line_occur["heading"] > State.off)) { /+ heading object (current line empty) +/ + obj_cite_digits = (an_object["lev_markup_number"].to!int == 0) + ? ocn_emit(OCNstatus.reset) + : ocn_emit(obj_type_status["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, conf_make_meta, ((_new_doc) ? Yes._new_doc : No._new_doc)); + an_object["substantive"] = substantive_object_and_anchor_tags_tuple[sObj.content]; + anchor_tag = substantive_object_and_anchor_tags_tuple[sObj.anchor_tag]; + if (_new_doc) { + cnt1 = 1; + cnt2 = 1; + cnt3 = 1; + _new_doc = false; + } + if ( + an_object["lev_markup_number"].to!int == 4 + && (!(anchor_tag.empty) + || (lv0_to_3_tags.length > 0)) + ) { + tag_in_seg["seg_lv4"] = anchor_tag; + tag_in_seg["seg_lv1_to_4"] = anchor_tag; + lev_anchor_tag = anchor_tag; + tag_assoc[anchor_tag]["seg_lv4"] = tag_in_seg["seg_lv4"]; + tag_assoc[anchor_tag]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; + if (lv0_to_3_tags.length > 0) { /+ names used for html markup segments 1 to 4 (rather than epub which has separate segments for A to D) +/ + foreach (lv0_to_lv3_html_tag; lv0_to_3_tags) { + tag_assoc[lv0_to_lv3_html_tag]["seg_lv4"] = anchor_tag; + } + } + anchor_tag_ = anchor_tag; + lv0_to_3_tags = lv0_to_3_tags.init; + } else if (an_object["lev_markup_number"].to!int > 4) { + tag_in_seg["seg_lv4"] = anchor_tag_; + tag_in_seg["seg_lv1_to_4"] = anchor_tag_; + lev_anchor_tag = anchor_tag; + tag_assoc[anchor_tag]["seg_lv4"] = tag_in_seg["seg_lv4"]; + tag_assoc[anchor_tag]["seg_lv1_to_4"] = tag_in_seg["seg_lv1_to_4"]; + } else if (an_object["lev_markup_number"].to!int < 4) { + string segn; + switch (an_object["lev_markup_number"].to!int) { /+ names used for epub markup segments A to D +/ + 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: + lv0_to_3_tags ~= obj_cite_digits.object_number.to!string; + lv0_to_3_tags ~= segn; + tag_in_seg["seg_lv4"] = segn; // for html segname need following lv4 not yet known + tag_in_seg["seg_lv1_to_4"] = segn; + 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_digits, tag_in_seg); + /+ (incrementally build toc) table of contents here! +/ + _anchor_tag = obj_cite_digits.identifier; + the_table_of_contents_section = obj_im.flow_table_of_contents_gather_headings( + an_object, + conf_make_meta, + tag_in_seg, + _anchor_tag, + lev4_subtoc, + the_table_of_contents_section, + ); + if (an_object["lev_markup_number"] == "4") { + segnames["html"] ~= tag_in_seg["seg_lv4"]; + html_segnames_ptr = html_segnames_ptr_cntr; + html_segnames_ptr_cntr++; + } + if (an_object["lev_markup_number"].to!int <= 4) { + segnames["epub"] ~= tag_in_seg["seg_lv1_to_4"]; + } + auto comp_obj_heading + = node_construct.node_emitter_heading( + an_object["substantive"], + an_object["lev_markup_number"], + an_object["lev_collapsed_number"], + an_object["dummy_heading_status"], + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, // OCNset + cntr, // int + heading_ptr, // int + lv_ancestors_txt, // 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(tag_in_seg["seg_lv4"]); + writeln(tag_in_seg["seg_lv1_to_4"]); + } + the_document_body_section ~= comp_obj_heading; + debug(objectrelated1) { // check + writeln(line); + } + flow_common_reset_(line_occur, an_object, obj_type_status); + an_object.remove("lev"); + an_object.remove("lev_markup_number"); + processing.remove("verse"); + ++cntr; +#+END_SRC + +******* paragraph object :paragraph:object: + +#+name: abs_in_loop_body_not_block_obj_line_empty +#+BEGIN_SRC d +} else if ((obj_type_status["para"] == State.on) +&& (line_occur["para"] > State.off)) { + /+ paragraph object (current line empty) +/ + /+ repeated character paragraph separator +/ + if ((an_object[an_object_key].to!string).matchFirst(rgx.repeated_character_line_separator)) { + obj_type_status["ocn_status"] = OCNstatus.off; + } + obj_cite_digits = ocn_emit(obj_type_status["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_digits, tag_in_seg); + an_object["is"] = "para"; + auto comp_obj_heading + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_para = comp_obj_para.init; + comp_obj_para.metainfo.is_of_part = "body"; + comp_obj_para.metainfo.is_of_section = "body"; + comp_obj_para.metainfo.is_of_type = "para"; + comp_obj_para.metainfo.is_a = "para"; + comp_obj_para.text = an_object["substantive"].to!string.strip; + comp_obj_para.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_para.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_para.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_para.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_para.metainfo.object_number_off = (obj_cite_digits.off==0) ? true : false; // TODO + comp_obj_para.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_para.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_para.attrib.indent_hang = indent["hang_position"]; + comp_obj_para.attrib.indent_base = indent["base_position"]; + comp_obj_para.attrib.bullet = bullet; + comp_obj_para.tags.anchor_tags = [anchor_tag]; + comp_obj_para.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_para.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_para.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + comp_obj_para.has.image_without_dimensions = substantive_obj_misc_tuple[sObj.image_no_dimensions]; + the_document_body_section ~= comp_obj_para; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + flow_common_reset_(line_occur, an_object, obj_type_status); + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + processing.remove("verse"); + ++cntr; +} else { + // could be useful to test line variable should be empty and never null +} +#+END_SRC + +*** regular _text objects_ identified :text:paragraph: + +#+name: abs_in_loop_body_01 +#+BEGIN_SRC d +/+ unless (the_document_body_section.length == 0) ? +/ +if (the_document_body_section.length > 0) { + if (((the_document_body_section[$-1].metainfo.is_a == "para") + || (the_document_body_section[$-1].metainfo.is_a == "heading") + || (the_document_body_section[$-1].metainfo.is_a == "quote") + || (the_document_body_section[$-1].metainfo.is_a == "group") + || (the_document_body_section[$-1].metainfo.is_a == "block") + || (the_document_body_section[$-1].metainfo.is_a == "verse")) + && (the_document_body_section.length > previous_length)) { + if ((the_document_body_section[$-1].metainfo.is_a == "heading") + && (the_document_body_section[$-1].metainfo.heading_lev_markup < 5)) { + obj_type_status["glossary_section"] = State.off; + obj_type_status["biblio_section"] = State.off; + obj_type_status["blurb_section"] = State.off; + } + if (the_document_body_section[$-1].metainfo.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].metainfo.is_a == "verse") { + if ((the_document_body_section[i].text).match( + rgx.inline_notes_al_all_note + )) { + note_section.gather_notes_for_endnote_section( + the_document_body_section, + tag_in_seg, + (i).to!int, + ); + } + } + } + } 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_al_all_note + )) { + previous_count=(the_document_body_section.length -1).to!int; + note_section.gather_notes_for_endnote_section( + the_document_body_section, + tag_in_seg, + (the_document_body_section.length-1).to!int, + ); + } + } + previous_length = the_document_body_section.length.to!int; + } +} +#+END_SRC + +** 3. _post main-loop processing_ :post: +*** misc + +/+ + Backmatter: + - endnotes + - glossary + - bibliography / references + - book index + - blurb ++/ + +*** tie up preparation of document sections +**** endnotes section (scroll & seg) :endnotes: + +#+name: abs_post +#+BEGIN_SRC d +auto en_tuple + = note_section.endnote_objects(obj_cite_digits, opt_action); +static assert(!isTypeTuple!(en_tuple)); +auto the_endnotes_section = en_tuple[0]; +obj_cite_digits = en_tuple[1]; +debug(endnotes) { + writefln( + "%s %s", + __LINE__, + the_endnotes_section.length + ); + foreach (o; the_endnotes_section) { + writeln(o); + } +} +#+END_SRC + +**** no glossary section? :glossary: + +#+name: abs_post +#+BEGIN_SRC d +if (an_object["glossary_nugget"].length == 0) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "empty"; + comp_obj_heading_.metainfo.is_of_section = "empty"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Glossary section"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_glossary_section ~= comp_obj_heading_; +} +debug(glossary) { + foreach (gloss; the_glossary_section) { + writeln(gloss.text); + } +} +#+END_SRC + +**** bibliography section (objects) :bibliography: + +#+name: abs_post +#+BEGIN_SRC d +auto biblio_unsorted_incomplete = biblio_arr_json.dup; +auto biblio = Bibliography(); +auto biblio_ordered + = biblio.flow_bibliography_(biblio_unsorted_incomplete, bib_arr_json); +#+END_SRC + +#+name: abs_post +#+BEGIN_SRC d +if (biblio_ordered.length > 0) { + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "bibliography"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Bibliography"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_bibliography"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = "bibliography"; + comp_obj_heading_.tags.anchor_tags = ["section_bibliography"]; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_bibliography_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "bibliography"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Bibliography"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "bibliography"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = 4; + comp_obj_heading_.metainfo.heading_lev_collapsed = 2; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.tags.anchor_tags = ["bibliography"]; + the_bibliography_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + } +} else { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "empty"; + comp_obj_heading_.metainfo.is_of_section = "empty"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Bibliography"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_bibliography_section ~= comp_obj_heading_; +} +#+END_SRC + +***** format biblio string + +#+name: abs_post +#+BEGIN_SRC d +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) ? "" : ", " ~ mkup.italic ~ mkup.ff_o ~ entry["journal"].str ~ mkup.ff_c ~ mkup.italic), + ((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.metainfo.is_of_part = "backmatter"; + comp_obj_para.metainfo.is_of_section = "bibliography"; + comp_obj_para.metainfo.is_of_type = "para"; + comp_obj_para.metainfo.is_a = "bibliography"; + comp_obj_para.text = out_.to!string.strip; + comp_obj_para.metainfo.ocn = 0; + comp_obj_para.metainfo.identifier = ""; + comp_obj_para.metainfo.object_number_off = true; + comp_obj_para.metainfo.object_number_type = 0; + comp_obj_para.attrib.indent_hang = 0; + comp_obj_para.attrib.indent_base = 1; + comp_obj_para.attrib.bullet = bullet; + comp_obj_para.tags.anchor_tags = [anchor_tag]; + the_bibliography_section ~= comp_obj_para; +} +#+END_SRC + +#+name: abs_post +#+BEGIN_SRC d +debug(bibliosection) { + foreach (o; the_bibliography_section) { + writeln(o.text); + } +} +#+END_SRC + +***** bibliography components + +JSONValue biblio_entry_tags_jsonstr = `{ + "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 + +**** bookindex section (scroll & seg) :book:index: + +#+name: abs_post +#+BEGIN_SRC d +auto bi = BookIndexReportSection(); +auto bi_tuple + = bi.bookindex_build_abstraction_section( + bookindex_unordered_hashes, + obj_cite_digits, + opt_action, + ); +destroy(bookindex_unordered_hashes); +static assert(!isTypeTuple!(bi_tuple)); +auto the_bookindex_section = bi_tuple[0]; +obj_cite_digits = bi_tuple[1]; +debug(bookindex) { + foreach (bi_entry; the_bookindex_section) { + writeln(bi_entry); + } +} +#+END_SRC + +**** no blurb section? :blurb: + +#+name: abs_post +#+BEGIN_SRC d +if (an_object["blurb_nugget"].length == 0) { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "empty"; + comp_obj_heading_.metainfo.is_of_section = "empty"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "(skip) there is no Blurb section"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_para.metainfo.object_number_off = true; + comp_obj_para.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = ""; + comp_obj_heading_.tags.anchor_tag_html = ""; + comp_obj_heading_.tags.in_segment_html = ""; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_blurb_section ~= comp_obj_heading_; +} +debug(blurb) { + foreach (blurb; the_blurb_section) { + writeln(blurb.text); + } +} +#+END_SRC + +**** toc backmatter, table of contents backmatter (scroll & seg) :contents: + +#+name: abs_post +#+BEGIN_SRC d +indent=[ + "hang_position" : 1, + "base_position" : 1, +]; +comp_obj_toc = comp_obj_toc.init; +comp_obj_toc.metainfo.is_of_part = "frontmatter"; +comp_obj_toc.metainfo.is_of_section = "toc"; +comp_obj_toc.metainfo.is_of_type = "para"; +comp_obj_toc.metainfo.is_a = "toc"; +comp_obj_toc.metainfo.ocn = 0; +comp_obj_toc.metainfo.identifier = ""; +comp_obj_toc.metainfo.object_number_off = true; +comp_obj_toc.metainfo.object_number_type = 0; +comp_obj_toc.attrib.indent_hang = indent["hang_position"]; +comp_obj_toc.attrib.indent_base = indent["base_position"]; +comp_obj_toc.attrib.bullet = false; +if (the_endnotes_section.length > 1) { + toc_txt_ = format( + mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + "Endnotes", + "endnotes", + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.has.inline_links = true; + the_table_of_contents_section ~= comp_obj_toc; +} +if (the_glossary_section.length > 1) { + toc_txt_ = format( + mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + "Glossary", + "glossary", + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.has.inline_links = true; + the_table_of_contents_section ~= comp_obj_toc; +} +if (the_bibliography_section.length > 1){ + toc_txt_ = format( + mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + "Bibliography", + "bibliography", + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.has.inline_links = true; + the_table_of_contents_section ~= comp_obj_toc; +} +if (the_bookindex_section.length > 1) { + toc_txt_ = format( + mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + "Book Index", + "bookindex", + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.has.inline_links = true; + the_table_of_contents_section ~= comp_obj_toc; +} +if (the_blurb_section.length > 1) { + toc_txt_ = format( + mkup.lnk_o ~ "%s" ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + "Blurb", + "blurb", + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc.has.inline_links = true; + comp_obj_toc.text = toc_txt_.to!string.strip; + the_table_of_contents_section ~= comp_obj_toc; +} +debug(toc) { + writefln( + "%s %s", + __LINE__, + ); + foreach (toc_linked_heading; the_table_of_contents_section) { + writeln(mkup.indent_by_spaces_provided(toc_linked_heading.attrib.indent_hang), toc_linked_heading.text); + } +} +#+END_SRC + +**** doc head (separate document head from body, make space for toc) + +#+name: abs_post +#+BEGIN_SRC d +the_document_head_section ~= the_document_body_section[0]; +the_document_body_section=the_document_body_section[1..$]; +#+END_SRC + +*** ↻ *LOOPs* _post main-loop loops_ :loop:post: +**** 1. ↻ _Loop as required_ (e.g. backmatter): loop up to lev4, extract html_segnames, set pointers + +this extra loop is used/needed to determine pre and (in particular) next segment +for html, that is then used in a subsequent loop + +NOTE there are issues attempting to do this on first pass as: + - backmatter is created out of sequence and + - it is not certain which are present + + - it is quite neat to have all in one place as we have here + + - could optimise a bit by + - skipping this loop unless the html seg or epub output is selected + +***** Methods +****** get ancestors markup + +#+name: abs_post +#+BEGIN_SRC d +int[] _get_ancestors_markup(O)(O obj, ref int[] _ancestors_markup) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.metainfo.heading_lev_markup == 1) { + _ancestors_markup = [ + _ancestors_markup[0], + 0,0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 2) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + 0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 3) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + 0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 4) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + 0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 5) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + 0,0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 6) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + 0,0 + ]; + } + if (obj.metainfo.heading_lev_markup == 7) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + _ancestors_markup[6], + 0 + ]; + } + if (obj.metainfo.heading_lev_markup == 8) { + _ancestors_markup = [ + _ancestors_markup[0], + _ancestors_markup[1], + _ancestors_markup[2], + _ancestors_markup[3], + _ancestors_markup[4], + _ancestors_markup[5], + _ancestors_markup[6], + _ancestors_markup[7] + ]; + } + _ancestors_markup[obj.metainfo.heading_lev_markup] = obj.metainfo.ocn; + } + debug(ancestor_markup) { + writeln("marked up: ", _ancestors_markup); + } + return _ancestors_markup; +} +#+END_SRC + +****** get ancestors collapsed + +#+name: abs_post +#+BEGIN_SRC d +int[] _get_ancestors_collapsed(O)(O obj, ref int[] _ancestors_collapsed) { + if (obj.metainfo.is_a == "heading") { + if (obj.metainfo.heading_lev_collapsed == 1) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + 0,0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 2) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + 0,0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 3) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + 0,0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 4) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + 0,0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 5) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + 0,0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 6) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + 0,0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 7) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + _ancestors_collapsed[6], + 0 + ]; + } + if (obj.metainfo.heading_lev_collapsed == 8) { + _ancestors_collapsed = [ + _ancestors_collapsed[0], + _ancestors_collapsed[1], + _ancestors_collapsed[2], + _ancestors_collapsed[3], + _ancestors_collapsed[4], + _ancestors_collapsed[5], + _ancestors_collapsed[6], + _ancestors_collapsed[7] + ]; + } + _ancestors_collapsed[obj.metainfo.heading_lev_collapsed] = obj.metainfo.ocn; + } + debug(ancestor_collapsed) { + writeln("collapsed: ", _ancestors_collapsed); + } + return _ancestors_collapsed; +} +#+END_SRC + +***** ↻ Loop section: document body [bd] + +- substantive object numbers already exist +- number un-numbered non-substantive text + +#+name: abs_post +#+BEGIN_SRC d +/+ multiple 1~ levels, loop through document body +/ +if (the_document_body_section.length > 1) { + int[] _ancestors_markup = [0,0,0,0,0,0,0,0]; + int[][] _ancestors_markup_; + _ancestors_markup = [1,0,0,0,0,0,0,0]; + _ancestors_markup_ ~= _ancestors_markup; + int[] _ancestors_collapsed = [0,0,0,0,0,0,0,0]; + int[][] _ancestors_collapsed_; + _ancestors_collapsed = [1,0,0,0,0,0,0,0]; + _ancestors_collapsed_ ~= _ancestors_collapsed; + foreach (ref obj; the_document_body_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.markedup_ancestors = _get_ancestors_markup(obj, _ancestors_markup); + obj.metainfo.collapsed_ancestors = _get_ancestors_collapsed(obj, _ancestors_collapsed); + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + } + debug(ancestors) { + writeln("ancestors markup o_n: ", obj.metainfo.markedup_ancestors); + writeln("ancestors collapsed o_n: ", obj.metainfo.markedup_ancestors); + } +} +#+END_SRC + +***** ↻ Loop section: endnotes [en] + +#+name: abs_post +#+BEGIN_SRC d +if (the_endnotes_section.length > 1) { + segnames["html"] ~= "endnotes"; + segnames["epub"] ~= "endnotes"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_endnotes_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; +} +#+END_SRC + +***** ↻ Loop section: glossary [gl] + +#+name: abs_post +#+BEGIN_SRC d +if (the_glossary_section.length > 1) { + segnames["html"] ~= "glossary"; + segnames["epub"] ~= "glossary"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_glossary_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; +} +#+END_SRC + +***** ↻ Loop section: bibliography [bb] + +#+name: abs_post +#+BEGIN_SRC d +if (the_bibliography_section.length > 1) { + segnames["html"] ~= "bibliography"; + segnames["epub"] ~= "bibliography"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_bibliography_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; +} +#+END_SRC + +***** ↻ Loop section: book index [bi] + +#+name: abs_post +#+BEGIN_SRC d +if (the_bookindex_section.length > 1) { + segnames["html"] ~= "bookindex"; + segnames["epub"] ~= "bookindex"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_bookindex_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; +} +#+END_SRC + +***** ↻ Loop section: blurb [bl] + +#+name: abs_post +#+BEGIN_SRC d +if (the_blurb_section.length > 1) { + segnames["html"] ~= "blurb"; + segnames["epub"] ~= "blurb"; + html_segnames_ptr = html_segnames_ptr_cntr; + foreach (ref obj; the_blurb_section) { + if (obj.metainfo.is_a == "heading") { + obj.metainfo.parent_ocn = obj.metainfo.markedup_ancestors[obj.metainfo.parent_lev_markup]; + } + if (obj.metainfo.heading_lev_markup == 4) { + obj.ptr.html_segnames = html_segnames_ptr; + break; + } + } + html_segnames_ptr_cntr++; +} +#+END_SRC + +**** 2. ↻ _Loop all objects:_ encode _structural relationships_ (sections, segments, objects) + +needed for DOM structure, segnames & subtoc, backmatter pointers & unique image +list + +if used minimally only for DOM structure, segnames, subtoc, could optimise by +- skipping second and third pass unless the output html seg or epub is being + made! + +- this loop could conveniently be used more extensively for ancestors as well + (though this information can be extracted earlier) + +Build here: +- DOM structure + - ancestors & decendants + - ancestors could be determined earlier, but convenient to have here + - descendants could be in the form of: + - headings contained under current heading, and/or; + - the range of objects under the current heading +- numbering + - already given + - substantive object numbers + - endnote + - provide + - glossary + - bibliography + - book index + - blurb + - other non-substantive objects (prefix & other stuff) + - you could also decide on a sequential object list, containing all objects + (both substantive and non-substantive objects), in addition to ocn, which + are for substantive/ citable objects within the document + +(as needed) up to document heading 1~, lev4 html: + +- during this (the third) pass all previous and next segment names are known +- next are not yet known for backmatter during the second pas + +***** Methods +****** decendants + +#+name: abs_post +#+BEGIN_SRC d +auto get_decendants()(ObjGenericComposite[] document_sections) { + int[string] _heading_ocn_decendants; + string[] _ocn_open_key = ["","","","","","","",""]; + auto _doc_sect_length = document_sections.length - 1; + int _last_ocn; + foreach (_lg, ref obj; document_sections) { + if (obj.metainfo.is_a == "heading") { + foreach (_dts_lv, dom_tag_status; obj.metainfo.dom_structure_markedup_tags_status) { + switch (dom_tag_status) with (DomTags) { + case none: break; + case open: + _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; + break; + case close: + if (_ocn_open_key[_dts_lv].empty) { + _ocn_open_key[_dts_lv] = "0"; + } + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; + _ocn_open_key[_dts_lv] = (0).to!string; + break; + case close_and_open: + if (_ocn_open_key[_dts_lv].empty) { + _ocn_open_key[_dts_lv] = "0"; + } + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn - 1; + _ocn_open_key[_dts_lv] = (obj.metainfo.ocn).to!string; + _heading_ocn_decendants[_ocn_open_key[_dts_lv]] = obj.metainfo.ocn; + break; + case open_still: break; + default: break; + } + } + } + if (obj.metainfo.ocn > 0) { + _last_ocn = obj.metainfo.ocn; + } + if (_lg == _doc_sect_length) { + _heading_ocn_decendants["1"] = _last_ocn; // close existing o_n key + } + } + Tuple!(int, int)[] pairs; + foreach (pair; _heading_ocn_decendants.byPair) { + pairs ~= tuple(pair[0].to!int, pair[1]); + } + return pairs.sort; +} +#+END_SRC + +****** images: extract + +#+name: abs_post +#+BEGIN_SRC d +string[] _images; +string[] extract_images()(string content_block) { + string[] images_; + if (auto m = content_block.matchAll(rgx.image)) { + images_ ~= m.captures[1]; + } + return images_; +} +string[] segnames_0_to_4; +#+END_SRC + +****** images: dimensions + +#+name: abs_post +#+BEGIN_SRC d +auto _image_dimensions(O,M)(O obj, M manifested) { + if (obj.has.image_without_dimensions) { + import std.math; + import imageformats; + int w, h, chans; + real _w, _h; + int max_width = 640; + foreach (m; obj.text.matchAll(rgx.inline_image_without_dimensions)) { + debug(images) { + writeln(manifested.src.image_dir_path ~ "/" ~ m["img"]); + } + read_image_info(manifested.src.image_dir_path ~ "/" ~ m["img"], w, h, chans); + // calculate, decide max width and proportionally reduce to keep w & h within it + debug(images) { + writeln("width: ", w, ", height: ", h); + } + if (w > max_width) { + _w = max_width; + _h = round((max_width / w.to!real) * h.to!real); + } else { + _w = w; + _h = h; + } + obj.text = obj.text.replaceFirst( + rgx.inline_image_without_dimensions, + format(q"┃%s☼%s,w%sh%s %s┃", + "$1", + "$3", + _w.to!string, + _h.to!string, + "$6", + ) + ); + } + debug(images) { + writeln("image without dimensions: ", obj.text); + } + } + return obj; +} +#+END_SRC + +***** links: think about!!! +- move actual links to an array in object struct so they cannot be regex munged within text block + - you may wish to exclude certain types of internal document link + - object number links + - toc + - book index + - footnotes and footnote numbers + +#+name: abs_post +#+BEGIN_SRC d +auto _links(O)(O obj) { + if (auto m = obj.text.match(rgx.inline_link_stow_uri)) { + debug(links) { + writeln("number of link matches to stow: ", (obj.text.match(rgx.inline_link_stow_uri)).count); + writeln("links to stow: ", (obj.text.match(rgx.inline_link_stow_uri))); + } + int _n_matches = (obj.text.match(rgx.inline_link_stow_uri)).count.to!int; + for(int i=0; i < _n_matches; ++i) { + if (obj.text.match(rgx.inline_link_stow_uri)) { + obj.stow.link ~= obj.text.matchFirst(rgx.inline_link_stow_uri)[2]; + obj.text = obj.text.replaceFirst( + rgx.inline_link_stow_uri, + format(q"┃┥%s┝┤%s├┃", "$1", i) + ); + } + } + } + return obj; +} +#+END_SRC + +***** ↻ Loop section: head + +#+name: abs_post +#+BEGIN_SRC d +foreach (ref obj; the_document_head_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + } + if (obj.metainfo.heading_lev_markup == 0) { + /+ TODO second hit (of two) with same assertion failure, check, fix and reinstate + assert( obj.metainfo.ocn == 1, + "Title OCN should be 1 not: " ~ obj.metainfo.ocn.to!string); // bug introduced 0.18.1 + +/ + obj.metainfo.ocn = 1; + obj.metainfo.identifier = "1"; + obj.metainfo.object_number_type = OCNtype.ocn; + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } + obj = _links(obj); +} +#+END_SRC + +***** ↻ Loop section: toc [to] + +#+name: abs_post +#+BEGIN_SRC d +if (the_table_of_contents_section.length > 1) { + /+ scroll +/ + dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; + dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; + foreach (ref obj; the_table_of_contents_section) { + if (obj.metainfo.is_a == "heading") { + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } + obj = _links(obj); + } +} +#+END_SRC + +***** ↻ Loop section: document body [bd] + +#+name: abs_post +#+BEGIN_SRC d +/+ multiple 1~ levels, loop through document body +/ +if (the_document_body_section.length > 1) { + foreach (ref obj; the_document_body_section) { + if (!(obj.metainfo.identifier.empty)) { + if (!(((obj.metainfo.identifier) in tag_assoc) + && ("seg_lv4" in tag_assoc[(obj.metainfo.identifier)])) + ) { + tag_assoc[(obj.metainfo.identifier)]["seg_lv4"] + = obj.tags.html_segment_anchor_tag_is; + } + tag_assoc[(obj.metainfo.identifier)]["seg_lv1_to_4"] + = obj.tags.epub_segment_anchor_tag_is; + } + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.lev4_subtoc = lev4_subtoc[obj.tags.anchor_tag_html]; + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "para") { + _images ~= extract_images(obj.text); + obj = _image_dimensions(obj, manifested); + } + obj = _links(obj); + } +} +auto image_list = (_images.sort()).uniq; +#+END_SRC + +***** ↻ Loop section: endnotes [en] + +- endnotes have their own number, (also use in node) and they belong to calling object + +#+name: abs_post +#+BEGIN_SRC d +/+ optional only one 1~ level +/ +if (the_endnotes_section.length > 1) { + dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; + dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; + dom_structure_markedup_tags_status = dom_structure_markedup_tags_status_buffer.dup; + dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status_buffer.dup; + foreach (ref obj; the_endnotes_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } + obj = _links(obj); + } +} +#+END_SRC + +***** ↻ Loop section: glossary [gl] + +- add glossary numbering, (also use in node) no need to show in text + +#+name: abs_post +#+BEGIN_SRC d +/+ optional only one 1~ level +/ +if (the_glossary_section.length > 1) { + foreach (ref obj; the_glossary_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "glossary") { + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + } + obj = _links(obj); + } +} +#+END_SRC + +***** ↻ Loop section: bibliography [bb] + +- add bibliography numbering, (also use in node) no need to show in text + +#+name: abs_post +#+BEGIN_SRC d +/+ optional only one 1~ level +/ +if (the_bibliography_section.length > 1) { + foreach (ref obj; the_bibliography_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "bibliography") { + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + } + obj = _links(obj); + } +} +#+END_SRC + +***** ↻ Loop section: book index (scroll, seg) [bi] + +- add book index numbering?, (also use in node) no need to show in text + +#+name: abs_post +#+BEGIN_SRC d +/+ optional only one 1~ level +/ +int ocn_ = obj_cite_digits.object_number; +int ocn_bkidx_ = 0; +int ocn_bidx_; +if (the_bookindex_section.length > 1) { /+ scroll +/ + dom_structure_markedup_tags_status_buffer = dom_structure_markedup_tags_status.dup; + dom_structure_collapsed_tags_status_buffer = dom_structure_collapsed_tags_status.dup; + foreach (ref obj; the_bookindex_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + } + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + } + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + if (obj.metainfo.heading_lev_markup <= 4) { + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "bookindex") { + obj_cite_digits = ocn_emit(OCNstatus.bkidx); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + obj.metainfo.o_n_book_index = obj_cite_digits.bkidx; + obj.metainfo.object_number_type = OCNtype.bkidx; + } + obj = _links(obj); + } + /+ TODO assert failure, reinstate + assert(obj_cite_digit_bkidx == ocn_bidx_ + obj_cite_digit_bkidx ~ " == ocn_" ~ ocn_ ~ "?"); + +/ +} +#+END_SRC + +***** ↻ Loop section: blurb [bl] + +#+name: abs_post +#+BEGIN_SRC d +/+ optional only one 1~ level +/ +if (the_blurb_section.length > 1) { + foreach (ref obj; the_blurb_section) { + if (obj.metainfo.is_a == "heading") { + debug(dom) { + writeln(obj.text); + } + obj_cite_digits = ocn_emit(OCNstatus.on); + obj.metainfo.ocn = obj_cite_digits.object_number; + obj.metainfo.identifier = obj_cite_digits.identifier; + if (obj.metainfo.heading_lev_markup <= 4) { + segnames_0_to_4 ~= obj.tags.segment_anchor_tag_epub; + if (obj.metainfo.heading_lev_markup == 4) { + obj.tags.segname_prev = segnames["html"][obj.ptr.html_segnames - 1]; + if (segnames["html"].length > obj.ptr.html_segnames + 1) { + obj.tags.segname_next = segnames["html"][obj.ptr.html_segnames + 1]; + } + assert(obj.tags.anchor_tag_html == segnames["html"][obj.ptr.html_segnames], + obj.tags.anchor_tag_html ~ "!=" ~ segnames["html"][obj.ptr.html_segnames]); + } + } + /+ dom structure (marked up & collapsed) +/ + if (opt_action.meta_processing_xml_dom) { + obj = obj.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, obj.metainfo.heading_lev_markup); + obj = obj.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, obj.metainfo.heading_lev_collapsed); + } + obj = obj.obj_heading_ancestors(lv_ancestors_txt); + } else if (obj.metainfo.is_a == "blurb") { + obj_cite_digits = ocn_emit(OCNstatus.off); + obj.metainfo.object_number_off = obj_cite_digits.off; + obj.metainfo.object_number_type = OCNtype.non; + } + obj = _links(obj); + } +} +#+END_SRC + +***** ↻ Loop sections: get decendants + +#+name: abs_post +#+BEGIN_SRC d +if (the_document_body_section.length > 1) { + auto pairs = get_decendants( + the_document_head_section ~ + the_document_body_section ~ + the_endnotes_section ~ + the_glossary_section ~ + the_bibliography_section ~ + the_bookindex_section ~ + the_blurb_section + ); + debug(decendants_tuple) { + pairs = pairs.sort(); + foreach (pair; pairs) { // (pair; pairs.sort()) + writeln(pair[0], "..", pair[1]); + } + } + foreach (ref obj; the_document_head_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + if (the_document_body_section.length > 1) { + foreach (ref obj; the_document_body_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } + if (the_endnotes_section.length > 1) { + foreach (ref obj; the_endnotes_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } + if (the_glossary_section.length > 1) { + foreach (ref obj; the_glossary_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } + if (the_bibliography_section.length > 1) { + foreach (ref obj; the_bibliography_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } + if (the_bookindex_section.length > 1) { + foreach (ref obj; the_bookindex_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } + if (the_blurb_section.length > 1) { + foreach (ref obj; the_blurb_section) { + if (obj.metainfo.is_a == "heading") { + foreach (pair; pairs) { + if (obj.metainfo.ocn == pair[0]) { + obj.metainfo.last_decendant_ocn = pair[1]; + } + } + } + } + } +} +#+END_SRC + +**** TODO update BUG? + +#+name: abs_post +#+BEGIN_SRC d + /+ TODO + - note create/insert heading object sole purpose eof close all open tags + sort out: + - obj.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status; + - obj.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status; + +/ +comp_obj_heading_ = comp_obj_heading_.init; +comp_obj_heading_.metainfo.is_of_part = "empty"; +comp_obj_heading_.metainfo.is_of_section = "empty"; +comp_obj_heading_.metainfo.is_of_type = "para"; +comp_obj_heading_.metainfo.is_a = "heading"; +comp_obj_heading_.metainfo.ocn = 0; +comp_obj_heading_.metainfo.identifier = ""; +comp_obj_heading_.metainfo.dummy_heading = true; +comp_obj_heading_.metainfo.object_number_off = true; +comp_obj_heading_.metainfo.object_number_type = 0; +comp_obj_heading_.tags.segment_anchor_tag_epub = ""; +comp_obj_heading_.tags.anchor_tag_html = ""; +comp_obj_heading_.tags.in_segment_html = ""; +comp_obj_heading_.tags.html_segment_anchor_tag_is = ""; +comp_obj_heading_.tags.epub_segment_anchor_tag_is = ""; +comp_obj_heading_.metainfo.heading_lev_markup = 9; +comp_obj_heading_.metainfo.heading_lev_collapsed = 9; +comp_obj_heading_.metainfo.parent_ocn = 0; +comp_obj_heading_.metainfo.parent_lev_markup = 0; +comp_obj_heading_.metainfo.dom_structure_markedup_tags_status = dom_structure_markedup_tags_status.dup; +comp_obj_heading_.metainfo.dom_structure_collapsed_tags_status = dom_structure_collapsed_tags_status.dup; +comp_obj_heading_ = comp_obj_heading_.obj_dom_structure_set_markup_tags(dom_structure_markedup_tags_status, 0); +comp_obj_heading_ = comp_obj_heading_.obj_dom_set_collapsed_tags(dom_structure_collapsed_tags_status, 0); +comp_obj_heading_ = comp_obj_heading_.obj_heading_ancestors(lv_ancestors_txt); +// the_dom_tail_section ~= comp_obj_heading_; // remove tail for now, decide on later +#+END_SRC + +** 4. _return document tuple_ :post: +*** _the document_ :document: + +#+name: abs_post +#+BEGIN_SRC d +ObjGenericComposite[][string] document_the = [ + "head": the_document_head_section, + "toc": the_table_of_contents_section, + /+ substantive/body: +/ + "body": the_document_body_section, + /+ backmatter: +/ + "endnotes": the_endnotes_section, + "glossary": the_glossary_section, + "bibliography": the_bibliography_section, + "bookindex": the_bookindex_section, + "blurb": the_blurb_section, + /+ dom tail only +/ + "tail": the_dom_tail_section, +]; +#+END_SRC + +*** document _section keys_ sequence + +#+name: abs_post +#+BEGIN_SRC d +string[][string] document_section_keys_sequenced = [ + "scroll": ["head", "toc", "body",], + "seg": ["head", "toc", "body",], + "sql": ["head", "body",], + "latex": ["head", "toc", "body",] +]; +if (document_the["endnotes"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "endnotes"; + document_section_keys_sequenced["seg"] ~= "endnotes"; + document_section_keys_sequenced["latex"] ~= "endnotes"; +} +if (document_the["glossary"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "glossary"; + document_section_keys_sequenced["seg"] ~= "glossary"; + document_section_keys_sequenced["sql"] ~= "glossary"; + document_section_keys_sequenced["latex"] ~= "glossary"; +} +if (document_the["bibliography"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "bibliography"; + document_section_keys_sequenced["seg"] ~= "bibliography"; + document_section_keys_sequenced["sql"] ~= "bibliography"; + document_section_keys_sequenced["latex"] ~= "bibliography"; +} +if (document_the["bookindex"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "bookindex"; + document_section_keys_sequenced["seg"] ~= "bookindex"; + document_section_keys_sequenced["sql"] ~= "bookindex"; + document_section_keys_sequenced["latex"] ~= "bookindex"; +} +if (document_the["blurb"].length > 1) { + document_section_keys_sequenced["scroll"] ~= "blurb"; + document_section_keys_sequenced["seg"] ~= "blurb"; + document_section_keys_sequenced["sql"] ~= "blurb"; + document_section_keys_sequenced["latex"] ~= "blurb"; +} +if ((opt_action.html) +|| (opt_action.html_scroll) +|| (opt_action.html_seg) +|| (opt_action.epub)) { + document_section_keys_sequenced["scroll"] ~= "tail"; + document_section_keys_sequenced["seg"] ~= "tail"; +} +#+END_SRC + +*** dup + +#+name: abs_post +#+BEGIN_SRC d +string[] segnames_4 = segnames["html"].dup; +string[] segnames_lv1_to_4 = segnames["epub"].dup; +debug(segnames) { + writeln("segnames_lv4: ", segnames_4); + writeln("segnames_lv1_to_4: ", segnames_lv1_to_4); +} +#+END_SRC + +*** clean out structure + +#+name: abs_post +#+BEGIN_SRC d +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(segnames); +destroy(bookindex_unordered_hashes); +destroy(an_object); +obj_cite_digits = ocn_emit(OCNstatus.reset); +biblio_arr_json = []; +obj_cite_digit_ = 0; +html_segnames_ptr = 0; +html_segnames_ptr_cntr = 0; +content_non_header = "8"; +dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +dom_structure_markedup_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +dom_structure_collapsed_tags_status_buffer = [ 0, 0, 0, 0, 0, 0, 0, 0, 0,]; +#+END_SRC + +*** doc_has struct + +#+name: abs_struct_doc_has +#+BEGIN_SRC d +auto doc_has() { + struct DocHas_ { + uint inline_links() { + return dochas["inline_links"]; + } + uint inline_notes_reg() { + return dochas["inline_notes"]; + } + uint inline_notes_star() { + return dochas["inline_notes_star"]; + } + uint codeblocks() { + return dochas["codeblock"]; + } + uint tables() { + return dochas["table"]; + } + uint blocks() { + return dochas["block"]; + } + uint groups() { + return dochas["group"]; + } + uint poems() { + return dochas["poem"]; + } + uint quotes() { + return dochas["quote"]; + } + ulong images() { // TODO not ideal rethink + return (image_list.to!string.strip("[","]").split(",").length); + } + auto imagelist() { + return image_list; + } + auto keys_seq() { + return docSectKeysSeq!()(document_section_keys_sequenced); + } + string[] segnames_lv4() { + return segnames_4; + } + string[] segnames_lv_0_to_4() { + return segnames_0_to_4; + } + string[string][string] tag_associations() { + return tag_assoc; + } + } + return DocHas_(); +} +#+END_SRC + +*** _return document tuple_ [#A] :return:tuple: + +#+name: abs_return_tuple +#+BEGIN_SRC d +auto t = tuple( + document_the, + doc_has, +); +return t; +#+END_SRC + +** 5. Functions :abstract:function: + +functions used in document abstraction + +*** set & resets :reset: +**** object reset: remove (clean) :object:remove: + +#+name: abs_functions_object_reset +#+BEGIN_SRC d +static string[string] object_reset()(string[string] an_object) { + an_object.remove("body_nugget"); + an_object.remove("substantive"); + an_object.remove("is"); + an_object.remove("attrib"); + an_object.remove("bookindex_nugget"); + return an_object; +} +#+END_SRC + +**** set, initialize or re-initialize :set: + +#+name: abs_functions_header_set_common +#+BEGIN_SRC d +void flow_common_reset_()( + return ref int[string] line_occur, + return ref string[string] an_object, + return ref int[string] obj_type_status, +) { + line_occur["heading"] = State.off; + line_occur["para"] = State.off; + obj_type_status["heading"] = State.off; + obj_type_status["para"] = State.off; + an_object = an_object.object_reset; +} +#+END_SRC + +*** check object_number status in document :ocn: + +#+name: abs_functions_ocn_status +#+BEGIN_SRC d +static int[string] _check_ocn_status_()( + char[] line, + int[string] obj_type_status, +) { + static auto rgx = Rgx(); + if (!(line.empty) + && (obj_type_status["ocn_status_off_for_multiple_objects"] == OCN_off_block_status.off) + ) { + /+ not multi-line object, check whether object_number is on or turned off +/ + if (line.matchFirst(rgx.object_number_block_marks)) { /+ switch off object_number +/ + if (line.matchFirst(rgx.object_number_off_block)) { + obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.on; + obj_type_status["ocn_status"] = OCNstatus.off; + debug(ocnoff) { + writeln(line); + } + } + if (line.matchFirst(rgx.object_number_off_block_dummy_heading)) { + obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.on; + obj_type_status["heading_off_for_multiple_objects"] = Status.on; + obj_type_status["ocn_status"] = OCNstatus.off; + debug(ocnoff) { + writeln(line); + } + } + } else { + if (obj_type_status["ocn_status_off_for_multiple_objects"] == OCN_off_block_status.off) { + obj_type_status["dummy_heading_status"] = Status.off; + if (obj_type_status["heading_off_for_multiple_objects"]) { + obj_type_status["dummy_heading_status"] = Status.on; + } + if (line.matchFirst(rgx.object_number_off)) { + obj_type_status["ocn_status"] = OCNstatus.off; + } else if (line.matchFirst(rgx.object_number_off_dummy_heading)) { + obj_type_status["ocn_status"] = OCNstatus.off; + obj_type_status["dummy_heading_status"] = Status.on; + } else { + obj_type_status["ocn_status"] = OCNstatus.on; + obj_type_status["dummy_heading_status"] = Status.off; + } + } else { + obj_type_status["ocn_status"] = obj_type_status["ocn_status_off_for_multiple_objects"]; + } + } + } else if ( + !(line.empty) + && (obj_type_status["ocn_status_off_for_multiple_objects"] > OCN_off_block_status.off) + ) { + if (line.matchFirst(rgx.object_number_off_block_close)) { + obj_type_status["ocn_status_off_for_multiple_objects"] = OCN_off_block_status.off; + obj_type_status["ocn_status"] = OCNstatus.on; + obj_type_status["dummy_heading_status"] = Status.off; + debug(ocnoff) { + writeln(line); + } + } + } + return obj_type_status; +} +#+END_SRC + +*** make substitutions +**** project + +#+name: abs_functions_substitutions +#+BEGIN_SRC d +char[] _doc_header_and_make_substitutions_(CMM)( + char[] line, + CMM conf_make_meta, +) { + enum Substitute { match, markup, } + if (conf_make_meta.make.substitute) { + foreach(substitution_pair; conf_make_meta.make.substitute) { + line = line.replaceAll( + regex("\b" ~ substitution_pair[Substitute.match]), + substitution_pair[Substitute.markup] + ); + } + } + return line; +} +#+END_SRC + +**** fontface + +#+name: abs_functions_substitutions +#+BEGIN_SRC d +char[] _doc_header_and_make_substitutions_fontface_(CMM)( + char[] line, + CMM conf_make_meta, +) { + enum Substitute { match, markup, } + if ( conf_make_meta.make.bold) { + line = line.replaceAll( + regex("\b" ~ conf_make_meta.make.bold[Substitute.match]), + conf_make_meta.make.bold[Substitute.markup] + ); + } + if (conf_make_meta.make.emphasis) { + line = line.replaceAll( + regex("\b" ~ conf_make_meta.make.emphasis[Substitute.match]), + conf_make_meta.make.emphasis[Substitute.markup] + ); + } + if (conf_make_meta.make.italics) { + line = line.replaceAll( + regex("\b" ~ conf_make_meta.make.italics[Substitute.match]), + conf_make_meta.make.italics[Substitute.markup] + ); + } + return line; +} +#+END_SRC + +*** block :block: +**** block start (open) block :start: +***** { block starts function + +#+name: abs_functions_block +#+BEGIN_SRC d +void flow_txt_block_start()( + char[] line, + return ref int[string] obj_type_status, + return ref uint[string] dochas, + return ref string[string] object_number_poem +) { +#+END_SRC + +****** block (various) curly open :curly: + +#+name: abs_functions_block +#+BEGIN_SRC d + static auto rgx = Rgx(); +#+END_SRC + +******* code + +#+name: abs_functions_block +#+BEGIN_SRC d + if (auto m = line.matchFirst(rgx.block_curly_code_open)) { + dochas["codeblock"]++; + an_object["lang"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; + debug(codecurly) { // code (curly) open + writefln( + "* [code curly] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["code"] = TriState.on; + obj_type_status["curly_code"] = TriState.on; +#+END_SRC + +******* poem + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_poem_open)) { + dochas["poem"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(poem) { // poem (curly) open + writefln( + "* [poem curly] %s", + line + ); + } + object_number_poem["start"] = obj_cite_digits.object_number.to!string; + obj_type_status["blocks"] = TriState.on; + obj_type_status["verse_new"] = State.on; + obj_type_status["poem"] = TriState.on; + obj_type_status["curly_poem"] = TriState.on; +#+END_SRC + +******* group + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_group_open)) { + dochas["group"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(group) { // group (curly) open + writefln( + "* [group curly] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["group"] = TriState.on; + obj_type_status["curly_group"] = TriState.on; +#+END_SRC + +******* block + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_block_open)) { + dochas["block"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(block) { // block (curly) open + writefln( + "* [block curly] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["block"] = TriState.on; + obj_type_status["curly_block"] = TriState.on; +#+END_SRC + +******* quote + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_quote_open)) { + dochas["quote"]++; + an_object["syntax"] = ""; + an_object["attrib"] = m["attrib"].to!string; + an_object["lang"] = m["lang"].to!string; + debug(quote) { // quote (curly) open + writefln( + "* [quote curly] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["quote"] = TriState.on; + obj_type_status["curly_quote"] = TriState.on; +#+END_SRC + +******* table + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_table_open)) { /+ curly table open +/ + debug(table) { // table (curly) open + writefln( + "* [table curly] %s", + line + ); + } + dochas["table"] ++; + an_object["table_head"] = m["attrib"].to!string; + an_object["block_type"] = "curly"; + obj_type_status["blocks"] = TriState.on; + obj_type_status["table"] = TriState.on; + obj_type_status["curly_table"] = TriState.on; +#+END_SRC + +******* table special + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_curly_table_special_markup)) { /+ table: special table block markup syntax! +/ + dochas["table"]++; + an_object["table_head"] = m["attrib"].to!string; + an_object["block_type"] = "special"; + obj_type_status["blocks"] = TriState.on; + obj_type_status["table"] = TriState.on; + obj_type_status["curly_table_special_markup"] = TriState.on; +#+END_SRC + +****** block (various) tic open :tic: +******* code + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_code_open)) { + dochas["codeblock"]++; + an_object["lang"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["syntax"] = (m["syntax"]) ? m["syntax"].to!string : ""; + debug(codetic) { // code (tic) open + writefln( + "* [code tic] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["code"] = TriState.on; + obj_type_status["tic_code"] = TriState.on; +#+END_SRC + +******* poem + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_poem_open)) { + dochas["poem"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(poem) { // poem (tic) open + writefln( + "* [poem tic] %s", + line + ); + } + object_number_poem["start"] = obj_cite_digits.object_number.to!string; + obj_type_status["blocks"] = TriState.on; + obj_type_status["verse_new"] = State.on; + obj_type_status["poem"] = TriState.on; + obj_type_status["tic_poem"] = TriState.on; +#+END_SRC + +******* group + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_group_open)) { + dochas["group"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(group) { // group (tic) open + writefln( + "* [group tic] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["group"] = TriState.on; + obj_type_status["tic_group"] = TriState.on; +#+END_SRC + +******* block + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_block_open)) { + dochas["block"]++; + an_object["syntax"] = ""; + an_object["attrib"] = (m["attrib"]) ? m["attrib"].to!string : ""; + an_object["lang"] = (m["lang"]) ? m["lang"].to!string : ""; + debug(block) { // block (tic) open + writefln( + "* [block tic] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["block"] = TriState.on; + obj_type_status["tic_block"] = TriState.on; +#+END_SRC + +******* quote + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_quote_open)) { + dochas["quote"]++; + an_object["syntax"] = ""; + an_object["attrib"] = m["attrib"].to!string; + an_object["lang"] = m["lang"].to!string; + debug(quote) { // quote (tic) open + writefln( + "* [quote tic] %s", + line + ); + } + obj_type_status["blocks"] = TriState.on; + obj_type_status["quote"] = TriState.on; + obj_type_status["tic_quote"] = TriState.on; +#+END_SRC + +******* table + +#+name: abs_functions_block +#+BEGIN_SRC d + } else if (auto m = line.matchFirst(rgx.block_tic_table_open)) { /+ tic table open +/ + debug(table) { // table (tic) open + writefln( + "* [table tic] %s", + line + ); + } + dochas["table"] ++; + an_object["table_head"] = m["attrib"].to!string; + an_object["block_type"] = "tic"; + obj_type_status["blocks"] = TriState.on; + obj_type_status["table"] = TriState.on; + obj_type_status["tic_table"] = TriState.on; + } +#+END_SRC + +***** } + +#+name: abs_functions_block +#+BEGIN_SRC d +} +#+END_SRC + +**** block continue (an open block) :continue: +***** _code block_ (special status, deal with first) :code: + +#+name: abs_functions_block_code +#+BEGIN_SRC d +void flow_txt_block_code()( + char[] line, + return ref string[string] an_object, + return ref int[string] obj_type_status +) { + static auto rgx = Rgx(); + if (obj_type_status["curly_code"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_code_close)) { + debug(codecurly) { // code (curly) close + writeln(line); + } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["code"] = TriState.closing; + obj_type_status["curly_code"] = TriState.off; + } else { + debug(codecurly) { // code (curly) line + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // code (curly) line + } + } else if (obj_type_status["tic_code"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + debug(codetic) { // code (tic) close + writeln(line); + } + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.newline_eol_delimiter_only, "") + .stripRight; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["code"] = TriState.closing; + obj_type_status["tic_code"] = TriState.off; + } else { + debug(codetic) { // code (tic) line + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // code (tic) line + } + } +} +#+END_SRC + +***** biblio block :biblio: +****** biblio tag map + +#+name: abs_functions_block_biblio +#+BEGIN_SRC d +final string biblio_tag_map()(string abr) { + 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]; +} +#+END_SRC + +******* +consider+ + +#+name: none +#+BEGIN_SRC d +final string biblio_tag_map_()(string abr) { + string name; + switch (abr) { + case "au" : name = "author_raw"; break; + case "ed" : name = "editor_raw"; break; + case "ti" : name = "fulltitle"; break; + case "lng" : name = "language"; break; + case "jo" : name = "journal"; break; + case "vol" : name = "volume"; break; + case "edn" : name = "edition"; break; + case "yr" : name = "year"; break; + case "pl" : name = "place"; break; + case "pb" : name = "publisher"; break; + case "pub" : name = "publisher"; break; + case "pg" : name = "pages"; break; + case "pgs" : name = "pages"; break; + case "sn" : name = "short_name"; break; + default : name = abr; break; + } + return name; +} +#+END_SRC + +****** biblio block + +#+name: abs_functions_block_biblio +#+BEGIN_SRC d +void flow_txt_block_biblio( + char[] line, + return ref int[string] obj_type_status, + return ref int bib_entry, + return ref string biblio_entry_str_json, + return ref string[] biblio_arr_json +) { + mixin DocReformBiblio; + auto jsn = BibJsnStr(); + static auto rgx = Rgx(); + if (line.matchFirst(rgx.heading_biblio) + && obj_type_status["para"] != State.on + && obj_type_status["group"] != State.on + && obj_type_status["block"] != State.on + && obj_type_status["poem"] != State.on + && obj_type_status["table"] != State.on + && obj_type_status["quote"] != State.on + ) { + obj_type_status["glossary_section"] = State.off; + obj_type_status["biblio_section"] = TriState.on; + obj_type_status["blurb_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=""; + } +} +#+END_SRC + +***** quote block :quote: + +#+name: abs_functions_block_quote +#+BEGIN_SRC d +string[string] flow_txt_block_quote()( + char[] line, + string[string] an_object, + return ref int[string] obj_type_status +) { + static auto rgx = Rgx(); + if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["quote"] = TriState.closing; + obj_type_status["curly_quote"] = TriState.off; + } else { + debug(quote) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + } + } else if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["quote"] = TriState.closing; + obj_type_status["tic_quote"] = TriState.off; + } else { + debug(quote) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build quote array (or string) + } + } + return an_object; +} +#+END_SRC + +***** group block :group: + +- apply inline markup +- discard leading and newline whitespace + +#+name: abs_functions_block_group +#+BEGIN_SRC d +string[string] flow_txt_block_group()( + char[] line, + string[string] an_object, + return ref int[string] obj_type_status +) { + static auto rgx = Rgx(); + if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["group"] = TriState.closing; + obj_type_status["curly_group"] = TriState.off; + } else { + debug(group) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) + } + } else if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["group"] = TriState.closing; + obj_type_status["tic_group"] = TriState.off; + } else { + debug(group) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build group array (or string) + } + } + return an_object; +} +#+END_SRC + +***** block block :block: + +- apply inline markup +- keep whitespace indentation +- keep newlines + +#+name: abs_functions_block_block +#+BEGIN_SRC d +string[string] flow_txt_block_block()( + char[] line, + string[string] an_object, + return ref int[string] obj_type_status +) { + static auto rgx = Rgx(); + if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["block"] = TriState.closing; + obj_type_status["curly_block"] = TriState.off; + } else { + debug(block) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) + } + } else if (obj_type_status["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; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["block"] = TriState.closing; + obj_type_status["tic_block"] = TriState.off; + } else { + debug(block) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build block array (or string) + } + } + return an_object; +} +#+END_SRC + +***** poem block, verse objects :poem:verse: + +why extra object stuff only in poem/verse? + +#+name: abs_functions_block_poem +#+BEGIN_SRC d +string[string] flow_txt_block_poem(CMM)( + char[] line, + string[string] an_object, + return ref int[string] obj_type_status, + return ref int cntr, + string[string] object_number_poem, + CMM conf_make_meta, + string[string] tag_in_seg, +) { + static auto rgx = Rgx(); + if (obj_type_status["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) { + writefln( + "* [poem curly] %s", + line + ); + } + if (processing.length > 0) { + an_object[an_object_key] = processing["verse"]; + } + debug(poem) { + writeln(__LINE__); + writefln( + "* %s %s", + obj_cite_digits.object_number, + line + ); + } + if (an_object.length > 0) { + debug(poem) { // poem (curly) close + writeln( + obj_cite_digits.object_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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "verse"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + } + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + object_number_poem["end"] = obj_cite_digits.object_number.to!string; + obj_type_status["blocks"] = TriState.closing; + obj_type_status["poem"] = TriState.closing; + obj_type_status["curly_poem"] = TriState.off; + } else { + processing["verse"] ~= line ~= "\n"; + if (obj_type_status["verse_new"] == State.on) { + obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); + obj_type_status["verse_new"] = State.off; + } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; + verse_line = TriState.off; + obj_type_status["verse_new"] = State.on; + } + if (obj_type_status["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_digits.object_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, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "verse"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + } + } else if (obj_type_status["tic_poem"] == TriState.on) { + if (auto m = line.matchFirst(rgx.block_tic_close)) { // tic_poem_close + an_object[an_object_key]="verse"; + debug(poem) { + 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_digits.object_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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "verse"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + object_number_poem["end"] = obj_cite_digits.object_number.to!string; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + obj_type_status["blocks"] = TriState.closing; + obj_type_status["poem"] = TriState.closing; + obj_type_status["tic_poem"] = TriState.off; + } else { + processing["verse"] ~= line ~= "\n"; + if (obj_type_status["verse_new"] == State.on) { + obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); + obj_type_status["verse_new"] = State.off; + } else if (line.matchFirst(rgx.newline_eol_delimiter_only)) { + processing["verse"] = processing["verse"].stripRight; + obj_type_status["verse_new"] = State.on; + verse_line = TriState.off; + } + if (obj_type_status["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_digits.object_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, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "verse"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } + } + } + return an_object; +} +#+END_SRC + +***** table block :table: + +there are 3 types of table markup that need to be nomalized (given a single representation) here + +- curly brace block +- tic block +- special notation block + +you need: +- identify the type for the munging to create uniform presentation + - curly, tick, special + - table heading row, bool +- present table header info in uniform way + - table_number_of_columns, int (count) + - table_column_widths, int[] column widths (as given or calculate average) + - show table walls, bool +- table content marked up in uniform way + +#+name: abs_functions_block_table +#+BEGIN_SRC d +string[string] flow_txt_block_table(CMM)( + char[] line, + string[string] an_object, + return ref int[string] obj_type_status, + return ref CMM conf_make_meta, +) { + static auto rgx = Rgx(); + if (obj_type_status["curly_table"] == TriState.on) { + if (line.matchFirst(rgx.block_curly_table_close)) { + debug(table) { // table (curly) close + writeln(line); + } + obj_type_status["blocks"] = TriState.closing; + obj_type_status["table"] = TriState.closing; + obj_type_status["curly_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } else if (obj_type_status["curly_table_special_markup"] == TriState.on) { + if (line.empty) { + obj_type_status["blocks"] = TriState.off; + obj_type_status["table"] = TriState.off; + obj_type_status["curly_table_special_markup"] = TriState.off; + line.flow_table_closed_make_special_notation_table_( + an_object, + the_document_body_section, + obj_cite_digits, + comp_obj_heading, + cntr, + obj_type_status, + conf_make_meta, + ); + } else { + debug(table) { + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; + } + } else if (obj_type_status["tic_table"] == TriState.on) { + if (line.matchFirst(rgx.block_tic_close)) { + debug(table) { // table (tic) close + writeln(line); + } + obj_type_status["blocks"] = TriState.closing; + obj_type_status["table"] = TriState.closing; + obj_type_status["tic_table"] = TriState.off; + } else { + debug(table) { // table + writeln(line); + } + an_object[an_object_key] ~= line ~= "\n"; // build table array (or string) + } + } + return an_object; +} +#+END_SRC + +**** special table notation, make: table + +process and use an_object["table_head"] (then empty it) +- present table header info in uniform way + - table_number_of_columns, int (count) + - table_column_widths, int[] column widths (as given or calculate average) + - show table walls, bool + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d +void flow_table_closed_make_special_notation_table_(N,CMM)( + char[] line, + return ref string[string] an_object, + return ref ObjGenericComposite[] the_document_body_section, + return ref N obj_cite_digits, + return ref ObjGenericComposite _comp_obj_heading, + return ref int cntr, + return ref int[string] obj_type_status, + CMM conf_make_meta +) { + comp_obj_block = comp_obj_block.init; + obj_cite_digits = ocn_emit(obj_type_status["ocn_status"]); + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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", conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); + comp_obj_block = comp_obj_block.flow_table_substantive_munge_special(an_object["substantive"]); + the_document_body_section ~= comp_obj_block; + object_reset(an_object); + processing.remove("verse"); + ++cntr; +} +#+END_SRC + +**** block end (close an open block): line empty, block flag _makes_ :close: + +***** { line empty, _make block_ + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d +string[string] flow_block_flag_line_empty_(B,N,CMM,Ts)( + char[] line, + string[string] an_object, + B bookindex_extract_hash, + return ref ObjGenericComposite[] the_document_body_section, + return ref string[][string][string] bookindex_unordered_hashes, + return ref N obj_cite_digits, + return ref ObjGenericComposite _comp_obj_heading, + return ref int cntr, + return ref int[string] obj_type_status, + string[string] object_number_poem, + CMM conf_make_meta, + Ts tag_in_seg, +) { + assert( + line.empty, + "\nline should be empty:\n \"" + ~ line ~ "\"" + ); + assert( + (obj_type_status["blocks"] == TriState.closing), + "code block status: closed" + ); + assertions_flag_types_block_status_none_or_closed(obj_type_status); + static auto rgx = Rgx(); +#+END_SRC + +****** make: quote block + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + if (obj_type_status["quote"] == TriState.closing) { + obj_cite_digits = ocn_emit(obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "quote"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "quote"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; + comp_obj_block.metainfo.lang = an_object["lang"]; + comp_obj_block.metainfo.attrib = an_object["attrib"]; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + obj_type_status["blocks"] = TriState.off; + obj_type_status["quote"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; +#+END_SRC + +****** make: group block + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + } else if (obj_type_status["group"] == TriState.closing) { + obj_cite_digits = ocn_emit(obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "group"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "group"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block.metainfo.lang = an_object["lang"]; + comp_obj_block.metainfo.attrib = an_object["attrib"]; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + tag_assoc = an_object.inline_para_link_anchor(tag_in_seg, tag_assoc); + obj_type_status["blocks"] = TriState.off; + obj_type_status["group"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; +#+END_SRC + +****** make: block + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + } else if (obj_type_status["block"] == TriState.closing) { + obj_cite_digits = ocn_emit(obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "block"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + // anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.is_of_part = "body"; + comp_obj_block.metainfo.is_of_section = "body"; + comp_obj_block.metainfo.is_of_type = "block"; + comp_obj_block.metainfo.is_a = "block"; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digit_type; + comp_obj_block.metainfo.lang = an_object["lang"]; + comp_obj_block.metainfo.attrib = an_object["attrib"]; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.text = an_object["substantive"]; + comp_obj_block.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_block.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_block.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_block; + obj_type_status["blocks"] = TriState.off; + obj_type_status["block"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; +#+END_SRC + +****** make: poem + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + } else if (obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "verse"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + cntr, + heading_ptr-1, + an_object["is"] + ); + comp_obj_poem_ocn = comp_obj_poem_ocn.init; + comp_obj_poem_ocn.metainfo.is_of_part = "body"; + comp_obj_poem_ocn.metainfo.is_of_section = "body"; + comp_obj_poem_ocn.metainfo.is_of_type = "block"; + comp_obj_poem_ocn.metainfo.is_a = "poem"; + comp_obj_poem_ocn.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_poem_ocn.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_poem_ocn.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_poem_ocn.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_poem_ocn.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_poem_ocn.text = ""; + the_document_body_section ~= comp_obj_poem_ocn; + obj_type_status["blocks"] = TriState.off; + obj_type_status["poem"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); +#+END_SRC + +****** make: code block + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + } else if (obj_type_status["code"] == TriState.closing) { + obj_cite_digits = ocn_emit(obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "code"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + anchor_tag = substantive_obj_misc_tuple[sObj.anchor_tag]; + comp_obj_code = comp_obj_code.init; + comp_obj_code.metainfo.is_of_part = "body"; + comp_obj_code.metainfo.is_of_section = "body"; + comp_obj_code.metainfo.is_of_type = "block"; + comp_obj_code.metainfo.is_a = "code"; + comp_obj_code.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_code.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_code.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_code.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_code.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_code.metainfo.syntax = an_object["syntax"]; + comp_obj_code.metainfo.attrib = an_object["attrib"]; + comp_obj_code.code_block.linenumbers = (an_object["attrib"].match(rgx.code_numbering)) ? true : false; + comp_obj_code.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_code.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_code.text = an_object["substantive"]; + comp_obj_code.has.inline_notes_reg = substantive_obj_misc_tuple[sObj.notes_reg]; + comp_obj_code.has.inline_notes_star = substantive_obj_misc_tuple[sObj.notes_star]; + comp_obj_code.has.inline_links = substantive_obj_misc_tuple[sObj.links]; + the_document_body_section ~= comp_obj_code; + obj_type_status["blocks"] = TriState.off; + obj_type_status["code"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; +#+END_SRC + +****** make: table + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + } else if (obj_type_status["table"] == TriState.closing) { + comp_obj_block = comp_obj_block.init; + obj_cite_digits = ocn_emit(obj_type_status["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_digits, + tag_in_seg + ); + an_object["is"] = "table"; + auto comp_obj_location + = node_construct.node_location_emitter( + content_non_header, + tag_in_seg, + lev_anchor_tag, + tag_assoc, + obj_cite_digits, + 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, conf_make_meta, No._new_doc); + an_object["substantive"] = substantive_obj_misc_tuple[sObj.content]; + comp_obj_block = comp_obj_block.init; + comp_obj_block.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_block.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_block.metainfo.object_number_off = obj_cite_digits.off; + comp_obj_block.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + comp_obj_block.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + comp_obj_block.metainfo.o_n_book_index = obj_cite_digits.bkidx; + comp_obj_block.metainfo.object_number_type = obj_cite_digits.type; + comp_obj_block = comp_obj_block.flow_table_instructions(an_object["table_head"]); + comp_obj_block = comp_obj_block.flow_table_substantive_munge(an_object["substantive"]); + the_document_body_section ~= comp_obj_block; + obj_type_status["blocks"] = TriState.off; + obj_type_status["table"] = TriState.off; + object_reset(an_object); + processing.remove("verse"); + ++cntr; + } +#+END_SRC + +***** } + +#+name: abs_functions_block_line_status_empty +#+BEGIN_SRC d + return an_object; +} +#+END_SRC + +*** book index :bookindex: + +#+name: abs_functions_book_index +#+BEGIN_SRC d +string[string] flow_book_index_(B)( + char[] line, + string[string] an_object, + return ref string book_idx_tmp, + return ref int[string] obj_type_status, + B opt_action, +) { + static auto rgx = Rgx(); + if (auto m = line.match(rgx.book_index)) { /+ match book_index +/ + debug(bookindexmatch) { + writefln( + "* [bookindex] %s\n", + m["bookindex"].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 +/ + obj_type_status["book_index"] = State.on; + if (opt_action.backmatter && opt_action.section_bookindex) { + book_idx_tmp = m.captures[1].to!string; + debug(bookindexmatch) { + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } + } + } else if (obj_type_status["book_index"] == State.on ) { /+ book_index flag set +/ + if (auto m = line.match(rgx.book_index_close)) { + obj_type_status["book_index"] = State.off; + if (opt_action.backmatter + && opt_action.section_bookindex) { + an_object["bookindex_nugget"] = book_idx_tmp ~ m.captures[1].to!string; + debug(bookindexmatch) { + writefln( + "* [bookindex] %s\n", + book_idx_tmp, + ); + } + } + book_idx_tmp = ""; + } else { + if (opt_action.backmatter + && opt_action.section_bookindex) { + book_idx_tmp ~= line; + } + } + } + return an_object; +} +#+END_SRC + +*** heading or paragraph :heading:paragraph: +**** heading found :heading: + +#+name: abs_functions_heading +#+BEGIN_SRC d +string[string] flow_heading_found_()( + char[] line, + string[string] heading_match_str, + string[] _make_unmarked_headings, + return ref Regex!(char)[string] heading_match_rgx, + return ref int[string] obj_type_status +) { + static auto rgx = Rgx(); + if ((_make_unmarked_headings.length > 2) + && (obj_type_status["make_headings"] == State.off)) { /+ headings found +/ + debug(headingsfound) { + writeln(_make_unmarked_headings); + } + debug(headingsfound) { + writeln(_make_unmarked_headings.length); + writeln(_make_unmarked_headings); + } + switch (_make_unmarked_headings.length) { + case 7 : + if (!empty(_make_unmarked_headings[6])) { + heading_match_str["h_4"] + = "^(" ~ _make_unmarked_headings[6].to!string ~ ")"; + heading_match_rgx["h_4"] + = regex(heading_match_str["h_4"]); + } + goto case; + case 6 : + if (!empty(_make_unmarked_headings[5])) { + heading_match_str["h_3"] + = "^(" ~ _make_unmarked_headings[5].to!string ~ ")"; + heading_match_rgx["h_3"] + = regex(heading_match_str["h_3"]); + } + goto case; + case 5 : + if (!empty(_make_unmarked_headings[4])) { + heading_match_str["h_2"] + = "^(" ~ _make_unmarked_headings[4].to!string ~ ")"; + heading_match_rgx["h_2"] + = regex(heading_match_str["h_2"]); + } + goto case; + case 4 : + if (!empty(_make_unmarked_headings[3])) { + heading_match_str["h_1"] + = "^(" ~ _make_unmarked_headings[3].to!string ~ ")"; + heading_match_rgx["h_1"] + = regex(heading_match_str["h_1"]); + } + goto case; + case 3 : + if (!empty(_make_unmarked_headings[2])) { + heading_match_str["h_D"] + = "^(" ~ _make_unmarked_headings[2].to!string ~ ")"; + heading_match_rgx["h_D"] + = regex(heading_match_str["h_D"]); + } + goto case; + case 2 : + if (!empty(_make_unmarked_headings[1])) { + heading_match_str["h_C"] + = "^(" ~ _make_unmarked_headings[1].to!string ~ ")"; + heading_match_rgx["h_C"] + = regex(heading_match_str["h_C"]); + } + goto case; + case 1 : + if (!empty(_make_unmarked_headings[0])) { + heading_match_str["h_B"] + = "^(" ~ _make_unmarked_headings[0].to!string ~ ")"; + heading_match_rgx["h_B"] + = regex(heading_match_str["h_B"]); + } + break; + default: + break; + } + obj_type_status["make_headings"] = State.on; + } + return heading_match_str; +} +#+END_SRC + +**** heading make set :heading: + +#+name: abs_functions_heading +#+BEGIN_SRC d +char[] flow_heading_make_set_()( + char[] line, + int[string] line_occur, + return ref Regex!(char)[string] heading_match_rgx, + return ref int[string] obj_type_status +) { + if ((obj_type_status["make_headings"] == State.on) + && ((line_occur["para"] == State.off) + && (line_occur["heading"] == State.off)) + && ((obj_type_status["para"] == State.off) + && (obj_type_status["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; +} +#+END_SRC + +**** heading match :heading: + +#+name: abs_functions_heading +#+BEGIN_SRC d +string[string] flow_heading_matched_(CMM)( + char[] line, + string[string] an_object, + return ref int[string] line_occur, + return ref string an_object_key, + return ref int[string] lv, + return ref int[string] collapsed_lev, + return ref int[string] obj_type_status, + return ref CMM conf_make_meta, +) { + static auto rgx = Rgx(); + if (auto m = line.match(rgx.heading)) { /+ heading match +/ + ++line_occur["heading"]; + obj_type_status["heading"] = State.on; + obj_type_status["para"] = State.off; + if (line.match(rgx.heading_seg_and_above)) { + obj_type_status["glossary_section"] = State.off; + obj_type_status["biblio_section"] = State.off; + obj_type_status["blurb_section"] = State.off; + } + 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": // Title set + if (an_object[an_object_key].match(rgx.variable_doc_title) + && an_object[an_object_key].match(rgx.variable_doc_author)) { + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.variable_doc_title, + (conf_make_meta.meta.title_full ~ ", ")) + .replaceFirst(rgx.variable_doc_author, + conf_make_meta.meta.creator_author); + } else if (an_object[an_object_key].match(rgx.variable_doc_title)) { + an_object[an_object_key] = an_object[an_object_key] + .replaceFirst(rgx.variable_doc_title, + conf_make_meta.meta.title_full); + } + 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; + } + an_object["dummy_heading_status"] = (obj_type_status["dummy_heading_status"] == State.off) ? "f" : "t"; + debug(heading) { + writeln(line.strip); + } + } + return an_object; +} +#+END_SRC + +**** para match :para: + +#+name: abs_functions_para +#+BEGIN_SRC d +string[string] flow_para_match_()( + char[] line, + string[string] an_object, + return ref string an_object_key, + return ref int[string] indent, + return ref bool bullet, + return ref int[string] obj_type_status, + return ref int[string] line_occur, +) { + static auto rgx = Rgx(); + if (line_occur["para"] == State.off) { + line = font_faces_line(line); + /+ para matches +/ + obj_type_status["para"] = State.on; + an_object[an_object_key] ~= line; + indent=[ + "hang_position" : 0, + "base_position" : 0, + ]; + bullet = false; + if (auto m = line.matchFirst(rgx.para_indent)) { + debug(paraindent) { + writeln(line); + } + indent["hang_position"] = (m["indent"]).to!int; + indent["base_position"] = (m["indent"]).to!int; + } else if (line.matchFirst(rgx.para_bullet)) { + debug(parabullet) { + writeln(line); + } + bullet = true; + } else if (auto m = line.matchFirst(rgx.para_indent_hang)) { + debug(paraindenthang) { + writeln(line); + } + indent = [ + "hang_position" : (m["hang"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + } else if (auto m = line.matchFirst(rgx.para_bullet_indent)) { + debug(parabulletindent) { + writeln(line); + } + indent = [ + "hang_position" : (m["indent"]).to!int, + "base_position" : (m["indent"]).to!int, + ]; + bullet = true; + } + ++line_occur["para"]; + } + return an_object; +} +#+END_SRC + +**** text font face + +#+name: abs_functions_para +#+BEGIN_SRC d +char[] font_faces_line()( + char[] textline, +) { + static auto rgx = Rgx(); + static auto mkup = InlineMarkup(); + if (textline.match(rgx.inline_faces_line)) { + textline = textline + .replaceFirst(rgx.inline_emphasis_line, format(q"┃%s%s%s%s%s%s┃", mkup.emph, mkup.ff_o, "$1", mkup.ff_c, mkup.emph, "$2")) + .replaceFirst(rgx.inline_bold_line, format(q"┃%s%s%s%s%s%s┃", mkup.bold, mkup.ff_o, "$1", mkup.ff_c, mkup.bold, "$2")) + .replaceFirst(rgx.inline_underscore_line, format(q"┃%s%s%s%s%s%s┃", mkup.underscore, mkup.ff_o, "$1", mkup.ff_c, mkup.underscore, "$2")) + .replaceFirst(rgx.inline_italics_line, format(q"┃%s%s%s%s%s%s┃", mkup.italic, mkup.ff_o, "$1", mkup.ff_c, mkup.italic, "$2")); + } + return textline; +} +#+END_SRC + +**** tables + +- number of columns +- column widths (either as given or uniform, first often different from rest) +- column aligns (as given else default left for text, check whether can default right for digits) +- table heading (auto align left) +- table walls +- TODO need to be able to align columns left or right (digits) + +***** table instructions + +#+name: abs_functions_table +#+BEGIN_SRC d +ObjGenericComposite flow_table_instructions(H)( + return ref ObjGenericComposite table_object, + H table_head, +) { + static auto rgx = Rgx(); + table_object.metainfo.is_of_part = "body"; + table_object.metainfo.is_of_section = "body"; + table_object.metainfo.is_of_type = "block"; + table_object.metainfo.is_a = "table"; + table_object.has.inline_notes_reg = false; + table_object.has.inline_notes_star = false; + table_object.has.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; + 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; +} +#+END_SRC + +***** table array munge + +#+name: abs_functions_table +#+BEGIN_SRC d +ObjGenericComposite flow_table_array_munge(T)( + return ref ObjGenericComposite table_object, + return ref T table_array, +) { + static auto rgx = Rgx(); + static 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 (col.match(rgx.numeric_col) && idx_r == 1) { // conditions reversed to avoid: gdc compiled program run segfault + 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; +} +#+END_SRC + +***** table substantive munge + +#+name: abs_functions_table +#+BEGIN_SRC d +ObjGenericComposite flow_table_substantive_munge(T)( + return ref ObjGenericComposite table_object, + return ref T table_substantive, +) { + static auto rgx = Rgx(); + static 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_object.flow_table_array_munge(_table); + return table_object; +} +#+END_SRC + +***** table substantive munge special + +#+name: abs_functions_table +#+BEGIN_SRC d +ObjGenericComposite flow_table_substantive_munge_special(T)( + return ref ObjGenericComposite table_object, + return ref T table_substantive, +) { + static auto rgx = Rgx(); + static 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_object.flow_table_array_munge(_table); + return table_object; +} +#+END_SRC + +*** function emitters :emitters: +**** object :object: +***** ocn :ocn: + +#+name: meta_emitters_ocn +#+BEGIN_SRC d +pure struct OCNemitter { + int ocn_digit, ocn_object_number, ocn_on_, ocn_off_, ocn_bkidx, ocn_bkidx_; + string object_identifier; + bool ocn_is_off; + auto ocn_emitter(int ocn_status_flag) { + OCNset ocn; + assert(ocn_status_flag <= OCNstatus.reset); + ocn_object_number = ocn_bkidx = 0; + object_identifier = ""; + ocn_is_off = false; + switch(ocn_status_flag) with (OCNstatus) { + case reset: + ocn_digit = ocn_on_ = 1; + object_identifier = "1"; + ocn_is_off = false; + ocn_off_ = ocn_bkidx_ = 0; + break; + case on: + ocn_digit = ocn_object_number = ++ocn_on_; + object_identifier = ocn_digit.to!string; + ocn_is_off = false; + break; + case off: + ocn_digit = 0; + ocn_off_ = ++ocn_off_; + object_identifier = "a" ~ ocn_off_.to!string; + ocn_is_off = true; + break; + case bkidx: + ocn_bkidx = ++ocn_bkidx_; + break; + case closing: + break; + default: + ocn_digit = 0; + } + assert(ocn_digit >= 0); + ocn.digit = ocn_digit; + ocn.object_number = ocn_object_number; // difference between .object_number and .digit? + ocn.identifier = object_identifier; + ocn.off = ocn_is_off; + ocn.bkidx = ocn_bkidx; + ocn.type = ocn_status_flag; + return ocn; + } + invariant() { + } +} +#+END_SRC + +***** object inline markup munge :markup:inline: + +****** { struct, inline markup munge + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d +static struct ObjInlineMarkupMunge { + string[string] obj_txt; + int n_foot, n_foot_reg, n_foot_sp_asterisk, n_foot_sp_plus; + string asterisks_, plus_; + string obj_txt_out, tail, note; + static auto rgx = Rgx(); + static 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; + } +#+END_SRC + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + static auto images()(string obj_txt_in) { + static auto mng = InlineMarkup(); + /+ url matched +/ + obj_txt_in = obj_txt_in.replaceAll(rgx.inline_notes_al_special, ""); // TODO reinstate when special footnotes are implemented + if (obj_txt_in.match(rgx.smid_image_generic)) { /+ images with and without links +/ + debug(images) { + writeln("Image: ", obj_txt_in); + } + if (obj_txt_in.match(rgx.smid_image_with_dimensions)) { + obj_txt_in = obj_txt_in + .replaceAll(rgx.smid_image_with_dimensions, ("$1" ~ mkup.img ~ "$2,w$3h$4 " ~ "$5")) + .replaceAll(rgx.smid_image_delimit, ("$1" + ~ mkup.lnk_o ~ "$2".strip ~ mkup.lnk_c + ~ mkup.url_o ~ mkup.url_c)); + debug(images) { + writeln("IMAGE with size: ", obj_txt_in); + } + } else if (obj_txt_in.match(rgx.smid_image)) { + obj_txt_in = obj_txt_in + .replaceAll(rgx.smid_image, ("$1" ~ mkup.img ~ "$2,w0h0" ~ "$3")) + .replaceAll(rgx.smid_image_delimit, ("$1" + ~ mkup.lnk_o ~ "$2".strip ~ mkup.lnk_c + ~ mkup.url_o ~ mkup.url_c)); + debug(images) { + writeln("IMAGE: ", obj_txt_in); // decide on representation + } + } + } + return obj_txt_in; + } +#+END_SRC + +******* footnotes endnotes markup + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto footnotes_endnotes_markup_and_number_or_stars()(string obj_txt_in, bool reset_note_numbers) { + /+ endnotes (regular) +/ + bool flg_notes_reg = false; + bool flg_notes_star = false; + bool flg_notes_plus = 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_symbol_plus)) { + flg_notes_plus = true; + ++n_foot_sp_plus; + plus_ = "*"; + n_foot=n_foot_sp_plus; + obj_txt_out ~= n.hit.to!string.replaceFirst( + rgx.inline_al_delimiter_open_symbol_plus, + (mkup.en_a_o ~ replicate(plus_, n_foot_sp_plus) ~ " ") + ) ~ "\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 ~ n_foot.to!string ~ " ") + ) ~ "\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, + flg_notes_plus, + ); + return t; + } +#+END_SRC + +******* object notes and links + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + private auto object_notes_and_links_()( + string obj_txt_in, + bool reset_note_numbers=false + ) { + obj_txt_out = ""; + bool urls = false; + bool images_without_dimensions = 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) + ); + /+ image matched +/ + if (obj_txt_in.match(rgx.smid_image_generic)) { + obj_txt_in = images(obj_txt_in); + if (obj_txt_in.match(rgx.smid_mod_image_without_dimensions)) { + images_without_dimensions = true; + } + } + /+ url matched +/ + if (obj_txt_in.match(rgx.smid_inline_url)) { + urls = true; + obj_txt_in = obj_txt_in.links_and_images; + } + if (auto m = obj_txt_in.match(rgx.para_inline_link_anchor)) { + obj_txt_in = obj_txt_in + .replaceAll(rgx.para_inline_link_anchor, "┃$1┃"); + } + 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[1]); + writeln(m.hit); + } + } + auto t = tuple( + obj_txt_out, + ftn[1], + ftn[2], + ftn[3], + urls, + images_without_dimensions, + ); + return t; + } + auto init() { + auto t = object_notes_and_links_(""); + return t; + } + invariant() { + } +#+END_SRC + +******* heading +- identified text by heading level marker followed by text until two new lines +- general markup + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto munge_heading()( + string obj_txt_in, + bool reset_note_numbers=false + ) { + obj_txt["munge"] = obj_txt_in + .replaceFirst(rgx.heading, "") + .replaceFirst(rgx.object_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() { + } +#+END_SRC + +******* para +- paragraph text without other identification until two new lines +- general markup + - paragraph attributes + - font faces (bold, italics, underscore etc.) + - footnotes/endnotes + - links + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto munge_para()(string obj_txt_in) { + obj_txt["munge"]=(obj_txt_in) + .replaceFirst(rgx.para_attribs, "") + .replaceFirst(rgx.object_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; + } +#+END_SRC + +******* quote + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + string munge_quote()(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } +#+END_SRC + +******* group +- group block identified by open an close tags +- general markup + - paragraph attributes + - font faces (bold, italics, underscore etc.) + - footnotes/endnotes + - links +- newlines detected and kept? + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto munge_group(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } +#+END_SRC + +******* block +- group block identified by open an close tags +- general markup + - paragraph attributes + - font faces (bold, italics, underscore etc.) + - footnotes/endnotes + - links +- newlines detected and kept? + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto munge_block()(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } +#+END_SRC + +******* verse (poem) +- sub part of poem block which is identified by open an close tags, separated from other verse by double newline +- newlines +- indentation +- what part of general markup? + - font faces (bold, italics, underscore etc.) + - footnotes/endnotes + - links? + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + auto munge_verse()(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + auto t = object_notes_and_links_(obj_txt["munge"]); + return t; + } + invariant() { + } +#+END_SRC + +******* code +- newlines +- indentation +- possibly identify syntax for coloring (obj attribute) +- numbered code blocks (markup/obj attribute?) +- no general markup +- one special character represented by mkup.nbsp ░ + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + string munge_code()(string obj_txt_in) { + obj_txt_in = obj_txt_in.replaceAll(rgx.space, mkup.nbsp); + obj_txt["munge"] = obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } +#+END_SRC + +******* table +- table block identified by open an close tags +- table markup + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + string munge_table()(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } +#+END_SRC + +******* comment + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d + string munge_comment()(string obj_txt_in) { + obj_txt["munge"]=obj_txt_in; + return obj_txt["munge"]; + } + invariant() { + } +#+END_SRC + +****** } + +#+name: meta_emitters_obj_inline_markup_munge +#+BEGIN_SRC d +} +#+END_SRC + +***** toc, tags, object inline markup :markup:inline: +****** { + +#+name: meta_emitters_obj_inline_markup +#+BEGIN_SRC d +static struct ObjInlineMarkup { + static auto rgx = Rgx(); + static auto munge = ObjInlineMarkupMunge(); + string[string] obj_txt; + static string anchor_tag = ""; +#+END_SRC + +******* object inline markup and anchor tags :markup:inline: + +#+name: meta_emitters_obj_inline_markup_and_anchor_tags_and_misc +#+BEGIN_SRC d + auto obj_inline_markup_and_anchor_tags_and_misc(CMM)( + string[string] obj_, + string obj_key_, + CMM conf_make_meta, + Flag!"_new_doc" _new_doc + ) { + obj_txt["munge"] = obj_[obj_key_].dup; + obj_txt["munge"] = (obj_["is"].match(ctRegex!(`verse|code`))) + ? obj_txt["munge"] + : obj_txt["munge"].strip; + if (_new_doc) { + anchor_tag = ""; + } + 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; + obj_notes_and_links["image_no_dimensions"] = false; + if ((obj_["is"] == "para") + || (obj_["is"] == "heading") + || (obj_["is"] == "quote") + || (obj_["is"] == "group") + || (obj_["is"] == "block") + || (obj_["is"] == "verse")) { + obj_txt["munge"] = (obj_txt["munge"]).inline_markup_faces; + obj_txt["munge"] = (obj_txt["munge"]).links_and_images; + } + switch (obj_["is"]) { + case "heading": + if (_new_doc) { + anchor_tag = ""; + } + obj_txt["munge"]=_configured_auto_heading_numbering_and_segment_anchor_tags(obj_txt["munge"], obj_, conf_make_meta, _new_doc); + obj_txt["munge"]=_make_segment_anchor_tags_if_none_provided(obj_txt["munge"], obj_["lev"], _new_doc); + if (auto m = obj_txt["munge"].match(rgx.heading_anchor_tag)) { + anchor_tag = m.captures[1]; + } 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["notes_plus"] = x[3]; + obj_notes_and_links["links"] = x[4]; + obj_notes_and_links["image_no_dimensions"] = x[5]; + break; + } + auto t = tuple( + obj_txt["munge"], + anchor_tag, + obj_notes_and_links["notes_reg"], + obj_notes_and_links["notes_star"], + obj_notes_and_links["links"], + obj_notes_and_links["image_no_dimensions"], + ); + anchor_tag = ""; + return t; + } + invariant() { + } +#+END_SRC + +******* toc (table of contents), build, gather headings :markup:inline: + +#+name: meta_emitters_obj_inline_markup_table_of_contents +#+BEGIN_SRC d + auto _clean_heading_toc_()( + char[] heading_toc_, + ) { + auto m = (cast(char[]) heading_toc_).matchFirst(rgx.heading); + heading_toc_ = (m.post).replaceAll( + rgx.inline_notes_curly_gen, + ""); + return heading_toc_; + }; + ObjGenericComposite[] flow_table_of_contents_gather_headings(CMM)( + string[string] obj_, + CMM conf_make_meta, + string[string] tag_in_seg, + string _anchor_tag, + return ref string[][string] lev4_subtoc, + ObjGenericComposite[] the_table_of_contents_section, + ) { + ObjGenericComposite comp_obj_toc; + mixin InternalMarkup; + static 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( + mkup.lnk_o ~ "%s".strip ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + heading_toc_, + _anchor_tag, + ); + toc_txt_= toc_txt_.links_and_images; + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.metainfo.is_of_part = "frontmatter"; + comp_obj_toc.metainfo.is_of_section = "toc"; + comp_obj_toc.metainfo.is_of_type = "para"; + comp_obj_toc.metainfo.is_a = "toc"; + comp_obj_toc.metainfo.ocn = 0; + comp_obj_toc.metainfo.identifier = ""; + comp_obj_toc.metainfo.object_number_off = true; + comp_obj_toc.metainfo.object_number_type = 0; + comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; + comp_obj_toc.attrib.indent_hang = indent["hang_position"]; + comp_obj_toc.attrib.indent_base = indent["base_position"]; + comp_obj_toc.attrib.bullet = false; + comp_obj_toc.text = toc_txt_.to!string.strip; + comp_obj_toc.has.inline_links = true; + the_table_of_contents_section ~= comp_obj_toc; + } + comp_obj_toc = comp_obj_toc.init; + comp_obj_toc.metainfo.is_of_part = "frontmatter"; + comp_obj_toc.metainfo.is_of_section = "toc"; + comp_obj_toc.metainfo.is_of_type = "para"; + comp_obj_toc.metainfo.is_a = "toc"; + comp_obj_toc.metainfo.ocn = 0; + comp_obj_toc.metainfo.identifier = ""; + comp_obj_toc.metainfo.object_number_off = true; + comp_obj_toc.metainfo.object_number_type = 0; + comp_obj_toc.metainfo.dummy_heading = (an_object["dummy_heading_status"] == "t") ? true: false; + comp_obj_toc.attrib.bullet = false; + comp_obj_toc.has.inline_links = true; + switch (obj_["lev_markup_number"].to!int) { + case 0: .. case 3: + break; + case 4: + lev4_subtoc[tag_in_seg["seg_lv4"]] = []; + break; + case 5: .. case 7: + subtoc_txt_ = format( + mkup.lnk_o ~ "%s".strip ~ mkup.lnk_c ~ mkup.url_o ~ "#%s"~ mkup.url_c, + heading_toc_, + _anchor_tag, + ); + lev4_subtoc[tag_in_seg["seg_lv4"]] + ~= links_and_images(obj_["lev_markup_number"] + ~ "~ " ~ subtoc_txt_.to!string.strip + ); + break; + default: + break; + } + return the_table_of_contents_section; + } + invariant() { + } +#+END_SRC + +******* private: + +#+name: meta_emitters_obj_inline_markup_private +#+BEGIN_SRC d +private: +#+END_SRC + +******** make heading number & segment anchor tags if instructed :markup:inline:segment:anchor:tags: + +#+name: meta_emitters_obj_inline_markup_heading_numbering_segment_anchor_tags +#+BEGIN_SRC d + static int[] heading_num = [ 0, 0, 0, 0 ]; + static string heading_number_auto_composite = ""; + static string heading_number_auto_composite_segname = ""; + static bool[] auto_heading_numbering = [ true, true, true, true]; + static string _configured_auto_heading_numbering_and_segment_anchor_tags(CMM)( + string munge_, + string[string] obj_, + CMM conf_make_meta, + bool _new_doc, + ) { + if (_new_doc) { + heading_num = [ 0, 0, 0, 0 ]; + heading_number_auto_composite = ""; + auto_heading_numbering = [ true, true, true, true]; + } + if (conf_make_meta.make.auto_num_top_lv) { + if (obj_["lev_markup_number"].to!int == 0) { + heading_num[0] = 0; + heading_num[1] = 0; + heading_num[2] = 0; + heading_num[3] = 0; + heading_number_auto_composite = ""; + } + /+ auto_num_depth minimum 0 + (1.) default 2 (1.1.1) max 3 (1.1.1.1) implement +/ + if ( + conf_make_meta.make.auto_num_top_lv + > obj_["lev_markup_number"].to!uint + ) { + heading_num[1] = 0; + heading_num[2] = 0; + heading_num[3] = 0; + } else if ( + conf_make_meta.make.auto_num_top_lv + == obj_["lev_markup_number"].to!uint + ) { + auto_heading_numbering[0] = + (munge_.match(rgx.auto_heading_numbering_off_lv1)) ? false : true; + if (auto_heading_numbering[0]) { + heading_num[0] ++; + } + heading_num[1] = 0; + heading_num[2] = 0; + heading_num[3] = 0; + } else if ( + conf_make_meta.make.auto_num_top_lv + == (obj_["lev_markup_number"].to!uint - 1) + ) { + auto_heading_numbering[1] = + (munge_.match(rgx.auto_heading_numbering_off_lv2)) ? false : true; + if (auto_heading_numbering[0] + && auto_heading_numbering[1]) { + heading_num[1] ++; + } + heading_num[2] = 0; + heading_num[3] = 0; + } else if ( + conf_make_meta.make.auto_num_top_lv + == (obj_["lev_markup_number"].to!uint - 2) + ) { + auto_heading_numbering[2] = + (munge_.match(rgx.auto_heading_numbering_off_lv3)) ? false : true; + if (auto_heading_numbering[0] + && auto_heading_numbering[1] + && auto_heading_numbering[2]) { + heading_num[2] ++; + } + heading_num[3] = 0; + } else if ( + conf_make_meta.make.auto_num_top_lv + == (obj_["lev_markup_number"].to!uint - 3) + ) { + auto_heading_numbering[3] = + (munge_.match(rgx.auto_heading_numbering_off_lv4)) ? false : true; + if (auto_heading_numbering[0] + && auto_heading_numbering[1] + && auto_heading_numbering[2] + && auto_heading_numbering[3]) { + heading_num[3] ++; + } + } + if (auto_heading_numbering[0]) { + if (heading_num[3] > 0) { + heading_number_auto_composite + = (conf_make_meta.make.auto_num_depth.to!uint == 3 + && auto_heading_numbering[3]) + ? (format(q"┃%s.%s.%s.%s┃", + 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 + = ((conf_make_meta.make.auto_num_depth.to!uint >= 2) + && (conf_make_meta.make.auto_num_depth.to!uint <= 3) + && auto_heading_numbering[2]) + ? (format(q"┃%s.%s.%s┃", + 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 + = ((conf_make_meta.make.auto_num_depth.to!uint >= 1) + && (conf_make_meta.make.auto_num_depth.to!uint <= 3) + && auto_heading_numbering[1]) + ? (format(q"┃%s.%s┃", + heading_num[0].to!string, + heading_num[1].to!string + )) + : ""; + } else if (heading_num[0] > 0 + && munge_.match(rgx.auto_heading_numbering_lv1) + ) { + heading_number_auto_composite + = ((conf_make_meta.make.auto_num_depth.to!uint >= 0) + && (conf_make_meta.make.auto_num_depth.to!uint <= 3) + && auto_heading_numbering[0]) + ? (format(q"┃%s┃", + heading_num[0].to!string + )) + : ""; + } else { + heading_number_auto_composite = ""; + } + } + heading_number_auto_composite_segname = + (heading_number_auto_composite.empty) + ? "" + : "seg_" ~ heading_number_auto_composite; + debug(heading_number_auto) { + writeln(heading_number_auto_composite); + } + if ((!empty(heading_number_auto_composite)) + && (obj_["lev_markup_number"].to!uint >= conf_make_meta.make.auto_num_top_lv)) { + munge_ = munge_ + .replaceFirst(rgx.heading, + "$1~$2 " ~ heading_number_auto_composite ~ ". ") + .replaceFirst(rgx.heading_marker_missing_tag, + "$1~" ~ heading_number_auto_composite_segname ~ " "); + } + } + return munge_; + } +#+END_SRC + +******** make segment anchor tags if not provided :markup:inline:segment:anchor:tags: + +#+name: meta_emitters_obj_inline_markup_heading_numbering_segment_anchor_tags +#+BEGIN_SRC d + static int heading_num_lev1 = 0; + static string _make_segment_anchor_tags_if_none_provided()( + string munge_, + string lev_, + bool _new_doc + ) { + 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] ~ " "); + if (auto n = munge_.match(rgx.heading_anchor_tag_plus_colon)) { + auto tag_remunge_ = n.captures[2] + .replaceAll(rgx.heading_marker_tag_has_colon, ".."); + munge_ = munge_.replaceFirst(rgx.heading_anchor_tag_plus_colon, n.captures[1] ~ tag_remunge_ ~ " "); + } + } 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" + if (_new_doc) { + heading_num_lev1 = 0; + } + heading_num_lev1 ++; + munge_ = munge_.replaceFirst( + rgx.heading_marker_missing_tag, + "$1~" ~ "x" ~ heading_num_lev1.to!string ~ " "); + } + } + return munge_; + } +#+END_SRC + +****** } + +#+name: meta_emitters_obj_inline_markup_close +#+BEGIN_SRC d +} +#+END_SRC + +***** object attrib :attributes: +****** { attributes structure open, public + +#+name: meta_emitters_obj_attributes +#+BEGIN_SRC d +struct ObjAttributes { + string[string] _obj_attrib; +#+END_SRC + +******* emitter obj attributes, public + +#+name: meta_emitters_obj_attributes_public +#+BEGIN_SRC d + string obj_attributes()( + string obj_is_, + string obj_raw, + ObjGenericComposite _comp_obj_heading, + ) { + scope(exit) { + destroy(obj_is_); + destroy(obj_raw); + destroy(_comp_obj_heading); + } + _obj_attrib["json"] ="{"; + switch (obj_is_) { + case "heading": + _obj_attrib["json"] ~= txt_heading(obj_raw); + break; + case "para": + _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) + ~ txt_para(obj_raw); + break; + case "code": + _obj_attrib["json"] ~= txt_code(obj_raw); + break; + case "group": + _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) + ~ txt_group(obj_raw); + break; + case "block": + _obj_attrib["json"] ~= txt_para_and_blocks(obj_raw) + ~ txt_block(obj_raw); + break; + case "verse": + _obj_attrib["json"] ~= txt_verse(obj_raw); + break; + case "quote": + _obj_attrib["json"] ~= txt_quote(obj_raw); + break; + case "table": + _obj_attrib["json"] ~= txt_table(obj_raw); + break; + case "comment": + _obj_attrib["json"] ~= txt_comment(obj_raw); + break; + default: + _obj_attrib["json"] ~= txt_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(), + "; object_number: ", oa_j["object_number"].integer() + ); + } + } + return _obj_attrib["json"]; + } + invariant() { + } +#+END_SRC + +******* private + +#+name: meta_emitters_obj_attributes_private +#+BEGIN_SRC d + private: + string _obj_attributes; +#+END_SRC + +******** para & blocks + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_para_and_blocks()(string obj_txt_in) { + 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["indent"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; + } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent_hang)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": " ~ m["hang"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; + } else if (auto m = obj_txt_in.matchFirst(rgx.para_indent)) { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": " ~ m["indent"].to!string ~ "," + ~ " \"indent_base\": " ~ m["indent"].to!string ~ ","; + } else { + _obj_attributes =" \"bullet\": \"false\"," + ~ " \"indent_hang\": 0," + ~ " \"indent_base\": 0,"; + } + return _obj_attributes; + } +#+END_SRC + +******** heading + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_heading()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"heading\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** para + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_para()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"para\"," + ~ " \"is\": \"para\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** quote + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_quote()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"quote\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** group + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_group()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"group\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** block + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_block()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"block\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** verse + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_verse()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"verse\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** code + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_code()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"code\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** table + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_table()(string obj_txt_in) { + _obj_attributes = " \"use\": \"content\"," + ~ " \"of\": \"block\"," + ~ " \"is\": \"table\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** comment + +#+name: meta_emitters_obj_attributes_private_an_attribute +#+BEGIN_SRC d + string txt_comment()(string obj_txt_in) { + _obj_attributes = " \"use\": \"comment\"," + ~ " \"of\": \"comment\"," + ~ " \"is\": \"comment\""; + return _obj_attributes; + } + invariant() { + } +#+END_SRC + +******** set additional attribute values, parse as json + +#+name: meta_emitters_obj_attributes_private_json +#+BEGIN_SRC d + string _set_additional_values_parse_as_json()( + string _obj_attrib, + string obj_is_, + ObjGenericComposite _comp_obj_heading, + ) { + JSONValue oa_j = parseJSON(_obj_attrib); + assert( + (oa_j.type == JSON_TYPE.OBJECT) + ); + if (obj_is_ == "heading") { + oa_j.object["object_number"] = _comp_obj_heading.metainfo.ocn; + oa_j.object["lev_markup_number"] = _comp_obj_heading.metainfo.heading_lev_markup; + oa_j.object["lev_collapsed_number"] = _comp_obj_heading.metainfo.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_object_number"] = _comp_obj_heading.metainfo.parent_ocn; + oa_j.object["parent_lev_markup_number"] = _comp_obj_heading.metainfo.parent_lev_markup; + _obj_attrib = oa_j.toString(); + return _obj_attrib; + } +#+END_SRC + +****** } + +#+name: meta_emitters_obj_attributes_private_close +#+BEGIN_SRC d +} +#+END_SRC + +**** book index :book:index: +***** book index nugget hash :hash:nugget: + +#+name: meta_emitters_book_index_nugget +#+BEGIN_SRC d +struct BookIndexNuggetHash { + string main_term, sub_term, sub_term_bits; + int object_number_offset, object_number_endpoint; + string[] object_numbers; + string[][string][string] bi_hash_nugget; + string[] bi_main_terms_split_arr; + string[][string][string] bookindex_nugget_hash(N,S)( + string bookindex_section, + N obj_cite_digits, + S tag_in_seg, + ) { + debug(asserts) { + static assert(is(typeof(obj_cite_digits.object_number) == int)); + } + debug(bookindexraw) { + if (!bookindex_section.empty) { + writeln( + "* [bookindex] ", + "[", obj_cite_digits.object_number.to!string, ": ", tag_in_seg["seg_lv4"], "] ", bookindex_section, + " - - - ", + "[", obj_cite_digits.object_number.to!string, "] ", bookindex_section + ); + } + } + static 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_object_numbers_match) + ) { + main_term = m.captures[1].strip; + object_number_offset = m.captures[2].to!int; + object_number_endpoint=(obj_cite_digits.object_number + object_number_offset); + object_numbers ~= (obj_cite_digits.object_number.to!string + ~ "-" ~ object_number_endpoint.to!string); + } else { + main_term = bi_main_term_and_rest[0].strip; + object_numbers ~= obj_cite_digits.object_number.to!string; + } + bi_hash_nugget[main_term]["_a"] ~= object_numbers; + object_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_object_number_offset_split + ); + foreach (sub_terms_bits; bi_sub_terms_split_arr) { + if (auto m = sub_terms_bits.match(rgx.bi_term_and_object_numbers_match)) { + sub_term = m.captures[1].strip; + object_number_offset = m.captures[2].to!int; + object_number_endpoint=(obj_cite_digits.object_number + object_number_offset); + object_numbers ~= (obj_cite_digits.object_number.to!string + ~ " - " ~ object_number_endpoint.to!string); + } else { + sub_term = sub_terms_bits.strip; + object_numbers ~= obj_cite_digits.object_number.to!string; + } + if (!empty(sub_term)) { + bi_hash_nugget[main_term][sub_term] ~= object_numbers; + } + object_numbers=null; + } + } + } + } + return bi_hash_nugget; + } + invariant() { + } +} +#+END_SRC + +***** book index (sort &) report indented :report:indented: + +#+name: meta_emitters_book_index_report_indented +#+BEGIN_SRC d +struct BookIndexReportIndent { + int mkn, skn; + void bookindex_report_indented()( + string[][string][string] bookindex_unordered_hashes + ) { + 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; + } + } +} +#+END_SRC + +***** book index (sort &) report section :report:section: +****** { book index struct open + +#+name: meta_emitters_book_index_report_section +#+BEGIN_SRC d +struct BookIndexReportSection { + int mkn, skn; + static auto rgx = Rgx(); + static auto munge = ObjInlineMarkupMunge(); +#+END_SRC + +******* bookindex write section + +#+name: meta_emitters_book_index_report_section +#+BEGIN_SRC d + void bookindex_write_section()( + string[][string][string] bookindex_unordered_hashes + ) { + auto mainkeys = + bookindex_unordered_hashes.byKey.array + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable).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!("toUpper(a) < toUpper(b)", SwapStrategy.stable).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; + } + } +#+END_SRC + +******* book index (sort &) build section :report:section: + +#+name: meta_emitters_book_index_report_section +#+BEGIN_SRC d + auto bookindex_build_abstraction_section(N,B)( + string[][string][string] bookindex_unordered_hashes, + N obj_cite_digits, + B opt_action, + ) { + debug(asserts) { + static assert(is(typeof(obj_cite_digits.object_number) == int)); + } + mixin DocReformNode; + mixin InternalMarkup; + static 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!("toUpper(a) < toUpper(b)", SwapStrategy.stable).release; + ObjGenericComposite[] 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.backmatter + && opt_action.section_bookindex)) { + string bi_tmp; + string[] bi_tmp_tags; + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "bookindex"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Book Index"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_book_index"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = "bookindex"; + comp_obj_heading_.tags.anchor_tags = ["section_bookindex"]; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading.has.inline_links = true; + bookindex_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + ++mkn; + } + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "bookindex"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Index"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "bookindex"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = 4; + comp_obj_heading_.metainfo.heading_lev_collapsed = 2; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading.has.inline_links = false; + comp_obj_heading_.tags.anchor_tags = ["bookindex"]; + bookindex_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + ++mkn; + } + import std.array : appender; + auto buffer = appender!(char[])(); + string[dchar] transTable = [' ' : "_"]; + foreach (mainkey; mainkeys) { + bi_tmp_tags = [""]; + bi_tmp = mkup.bold ~ mkup.ff_o ~ mainkey ~ mkup.ff_c ~ mkup.bold ~ " "; + buffer.clear(); + bi_tmp_tags ~= translate(mainkey, transTable); + auto bkidx_lnk(string locs) { + string markup = ""; + if (auto m = locs.matchFirst(rgx.book_index_go)) { + markup + = links_and_images("{ " ~ m["link"] ~ " }" + ~ "#" ~ m["ocn"] ~ ", "); + } else { + writeln(__LINE__, ": ", locs); + } + return markup; + } + foreach (ref_; bookindex_unordered_hashes[mainkey]["_a"]) { + bi_tmp ~= bkidx_lnk(ref_); + } + bi_tmp ~= " \\\\\n "; + bookindex_unordered_hashes[mainkey].remove("_a"); + auto subkeys = + bookindex_unordered_hashes[mainkey].byKey.array + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable).release; + foreach (subkey; subkeys) { + bi_tmp ~= subkey ~ ", "; + buffer.clear(); + bi_tmp_tags ~= translate(subkey, transTable); + foreach (ref_; bookindex_unordered_hashes[mainkey][subkey]) { + bi_tmp ~= bkidx_lnk(ref_); + } + bi_tmp ~= " \\\\\n "; + ++skn; + } + bi_tmp = bi_tmp.replaceFirst(rgx.trailing_linebreak, ""); + comp_obj_para = comp_obj_para.init; + comp_obj_para.metainfo.is_of_part = "backmatter"; + comp_obj_para.metainfo.is_of_section = "bookindex"; + comp_obj_para.metainfo.is_of_type = "para"; + comp_obj_para.metainfo.is_a = "bookindex"; + comp_obj_para.text = bi_tmp.to!string.strip; + comp_obj_para.metainfo.ocn = 0; + comp_obj_para.metainfo.identifier = ""; + comp_obj_para.metainfo.object_number_off = true; + comp_obj_para.metainfo.object_number_type = 0; + comp_obj_para.tags.anchor_tags = bi_tmp_tags; + comp_obj_para.attrib.indent_hang = 0; + comp_obj_para.attrib.indent_base = 1; + comp_obj_para.attrib.bullet = false; + comp_obj_para.has.inline_links = true; + comp_obj_para.text = bi_tmp.to!string.strip; + bookindex_section ~= comp_obj_para; + ++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_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + bookindex_section ~= comp_obj_heading_; + } + auto t = tuple( + bookindex_section, + obj_cite_digits + ); + return t; + } +#+END_SRC + +****** } + +#+name: meta_emitters_book_index_report_section +#+BEGIN_SRC d +} +#+END_SRC + +**** (end)notes section :endnotes:section: + +#+name: meta_emitters_endnotes +#+BEGIN_SRC d +struct NotesSection { + string[string] object_notes; + int previous_count; + int mkn; + static auto rgx = Rgx(); +#+END_SRC + +***** { gather notes for endnote section struct open + +#+name: meta_emitters_endnotes +#+BEGIN_SRC d + private auto gather_notes_for_endnote_section( + ObjGenericComposite[] contents_am, + string[string] tag_in_seg, + int cntr, + ) { + assert((contents_am[cntr].metainfo.is_a == "para") + || (contents_am[cntr].metainfo.is_a == "heading") + || (contents_am[cntr].metainfo.is_a == "quote") + || (contents_am[cntr].metainfo.is_a == "group") + || (contents_am[cntr].metainfo.is_a == "block") + || (contents_am[cntr].metainfo.is_a == "verse")); + assert(cntr >= previous_count); + assert( + (contents_am[cntr].text).match( + rgx.inline_notes_al_all_note) + ); + mixin InternalMarkup; + previous_count=cntr; + static auto mkup = InlineMarkup(); + static auto munge = ObjInlineMarkupMunge(); + foreach(m; + (contents_am[cntr].text).matchAll( + rgx.inline_notes_al_special_char_note) + ) { + debug(endnotes_build) { + writeln( + "{^", mkup.ff_o, m["char"], ".", mkup.ff_c, "^}" + ~ mkup.mark_internal_site_lnk, + tag_in_seg["seg_lv4"], + ".fnSuffix#noteref_\n ", m["char"], " ", + m["note"]); // sometimes need segment name (segmented html & epub) + } + // you need anchor for segments at this point -> + object_notes["anchor"] ~= "note_" ~ m["char"] ~ "』"; + object_notes["notes"] ~= (tag_in_seg["seg_lv4"].empty) + ? (links_and_images( + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["char"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" + ~ m["char"]) ~ " " + ~ m["note"] ~ "』" + ) + : (links_and_images( + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["char"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" + ~ mkup.mark_internal_site_lnk + ~ tag_in_seg["seg_lv4"] + ~ ".fnSuffix#noteref_" + ~ m["char"]) ~ " " + ~ m["note"] ~ "』" + ); + } + foreach(m; + (contents_am[cntr].text).matchAll( + rgx.inline_notes_al_regular_number_note) + ) { + debug(endnotes_build) { + writeln( + "{^", mkup.ff_o, m["num"], ".", mkup.ff_c, "^}" + ~ mkup.mark_internal_site_lnk, + tag_in_seg["seg_lv4"], + ".fnSuffix#noteref_\n ", m["num"], " ", + m["note"]); // sometimes need segment name (segmented html & epub) + } + // you need anchor for segments at this point -> + object_notes["anchor"] ~= "note_" ~ m["num"] ~ "』"; + object_notes["notes"] ~= (tag_in_seg["seg_lv4"].empty) + ? (links_and_images( + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}#noteref_" + ~ m["num"]) ~ " " + ~ m["note"] ~ "』" + ) + : (links_and_images( + "{" ~ mkup.superscript ~ mkup.ff_o ~ m["num"] ~ "." ~ mkup.ff_c ~ mkup.superscript ~ "}" + ~ mkup.mark_internal_site_lnk + ~ tag_in_seg["seg_lv4"] + ~ ".fnSuffix#noteref_" + ~ m["num"]) ~ " " + ~ m["note"] ~ "』" + ); + } + return object_notes; + } +#+END_SRC + +****** gathered notes + +#+name: meta_emitters_endnotes +#+BEGIN_SRC d + private auto gathered_notes() { + 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_; + } +#+END_SRC + +****** endnote objects + +#+name: meta_emitters_endnotes +#+BEGIN_SRC d + private auto endnote_objects(N,O)( + N obj_cite_digits, + O opt_action, + ) { + mixin DocReformNode; + 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.backmatter && opt_action.section_endnotes)) { + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "endnotes"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Endnotes"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "_part_endnotes"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = "endnotes"; + comp_obj_heading_.tags.anchor_tags = ["section_endnotes"]; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_endnotes_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + ++mkn; + } + { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "backmatter"; + comp_obj_heading_.metainfo.is_of_section = "endnotes"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "Endnotes"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.tags.segment_anchor_tag_epub = "endnotes"; + comp_obj_heading_.tags.anchor_tag_html = comp_obj_heading_.tags.segment_anchor_tag_epub; + comp_obj_heading_.tags.in_segment_html = comp_obj_heading_.tags.anchor_tag_html; + comp_obj_heading_.metainfo.heading_lev_markup = 4; + comp_obj_heading_.metainfo.heading_lev_collapsed = 2; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + comp_obj_heading_.tags.anchor_tags = ["endnotes"]; + the_endnotes_section ~= comp_obj_heading_; + tag_assoc[comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = comp_obj_heading_.tags.in_segment_html; + tag_assoc[comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = comp_obj_heading_.tags.segment_anchor_tag_epub; + ++mkn; + } + } else { + comp_obj_heading_ = comp_obj_heading_.init; + comp_obj_heading_.metainfo.is_of_part = "empty"; + comp_obj_heading_.metainfo.is_of_section = "empty"; + comp_obj_heading_.metainfo.is_of_type = "para"; + comp_obj_heading_.metainfo.is_a = "heading"; + comp_obj_heading_.text = "(skip) there are no Endnotes"; + comp_obj_heading_.metainfo.ocn = 0; + comp_obj_heading_.metainfo.identifier = ""; + comp_obj_heading_.metainfo.dummy_heading = true; + comp_obj_heading_.metainfo.object_number_off = true; + comp_obj_heading_.metainfo.object_number_type = 0; + comp_obj_heading_.metainfo.heading_lev_markup = 1; + comp_obj_heading_.metainfo.heading_lev_collapsed = 1; + comp_obj_heading_.metainfo.parent_ocn = 1; + comp_obj_heading_.metainfo.parent_lev_markup = 0; + the_endnotes_section ~= comp_obj_heading_; + } + if (opt_action.backmatter && opt_action.section_endnotes) { + ObjGenericComposite comp_obj_endnote_; + comp_obj_endnote_ = comp_obj_endnote_.init; + comp_obj_endnote_.metainfo.is_of_part = "backmatter"; + comp_obj_endnote_.metainfo.is_of_section = "endnote"; + comp_obj_endnote_.metainfo.is_of_type = "para"; + comp_obj_endnote_.metainfo.is_a = "endnote"; + comp_obj_endnote_.metainfo.ocn = 0; + comp_obj_endnote_.metainfo.identifier = ""; + // comp_obj_heading_.metainfo.dummy_heading = false; + comp_obj_heading_.metainfo.object_number_off = true; // check + comp_obj_heading_.metainfo.object_number_type = 0; // check + comp_obj_endnote_.attrib.indent_hang = 0; + comp_obj_endnote_.attrib.indent_base = 0; + comp_obj_endnote_.attrib.bullet = false; + foreach (i, endnote; endnotes_["notes"]) { + auto m = endnote.matchFirst(rgx.note_ref); + string notenumber = m["ref"].to!string; + string anchor_tag = "note_" ~ notenumber; + comp_obj_endnote_.tags.anchor_tags = [ endnotes_["anchor"][i] ]; + comp_obj_endnote_.has.inline_links = true; + comp_obj_endnote_.text = endnote.inline_markup_faces.strip; + the_endnotes_section ~= comp_obj_endnote_; + } + } + auto t = tuple(the_endnotes_section, obj_cite_digits); + return t; + } +#+END_SRC + +***** } + +#+name: meta_emitters_endnotes +#+BEGIN_SRC d +} +#+END_SRC + +**** bibliography :bibliography: +***** { biblio struct + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d +struct Bibliography { +#+END_SRC + +****** biblio + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d + public JSONValue[] flow_bibliography_()( + return ref string[] biblio_unsorted_incomplete, + return ref JSONValue[] bib_arr_json + ) { + JSONValue[] biblio_unsorted + = biblio_make_unsorted_array_of_json_objects(biblio_unsorted_incomplete, bib_arr_json); // TODO lookat returns + biblio_arr_json = []; + biblio_unsorted_incomplete = []; + JSONValue[] biblio_sorted__ = biblio_sort(biblio_unsorted); + debug(biblio0) { + biblio_debug(biblio_sorted__); + 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__; + } +#+END_SRC + +****** biblio unsorted complete + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d + final private JSONValue[] biblio_make_unsorted_array_of_json_objects()( + string[] biblio_unordered, + JSONValue[] bib_arr_json + ) { + 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; + } + return bib_arr_json.dup; + } +#+END_SRC + +****** biblio sort + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d + final private JSONValue[] biblio_sort()(JSONValue[] biblio_unordered) { + 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_; + } +#+END_SRC + +****** biblio debug + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d + void biblio_debug()(JSONValue[] biblio_sorted) { + debug(biblio0) { + foreach (j; biblio_sorted) { + if (!empty(j["fulltitle"].str)) { + writeln(j["sortby_deemed_author_year_title"]); + } + } + } + } +#+END_SRC + +***** } + +#+name: meta_emitters_bibliography +#+BEGIN_SRC d +} +#+END_SRC + +**** node structure metadata :structure:metadata:node: +***** { metadata node struct + +#+name: meta_emitters_metadata +#+BEGIN_SRC d +struct NodeStructureMetadata { + int lv, lv0, lv1, lv2, lv3, lv4, lv5, lv6, lv7; + int obj_cite_digit; + int[string] p_; // p_ parent_ + static auto rgx = Rgx(); +#+END_SRC + +****** node metadata emitter + +#+name: meta_emitters_metadata +#+BEGIN_SRC d + ObjGenericComposite node_location_emitter(La,Ta,N)( + string lev_markup_number, + string[string] tag_in_seg, + La lev_anchor_tag, + Ta tag_assoc, + N obj_cite_digits, + int cntr_, + int ptr_, + string is_ + ) { + debug(asserts) { + static assert(is(typeof(obj_cite_digits.object_number) == int)); + } + assert(is_ != "heading"); + assert(obj_cite_digits.object_number.to!int >= 0); + assert(is_ != "heading"); // should not be necessary + assert(obj_cite_digits.object_number.to!int >= 0); // should not be necessary + if (lv7 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_4; + p_["object_number"] = lv7; + } else if (lv6 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_3; + p_["object_number"] = lv6; + } else if (lv5 > State.off) { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_2; + p_["object_number"] = lv5; + } else { + p_["lev_markup_number"] = DocStructMarkupHeading.h_text_1; + p_["object_number"] = lv4; + } + ObjGenericComposite comp_obj_location; + comp_obj_location = comp_obj_location.init; + comp_obj_location.metainfo.is_a = is_; + comp_obj_location.metainfo.ocn = obj_cite_digits.object_number; + comp_obj_location.metainfo.identifier = obj_cite_digits.identifier; + comp_obj_location.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; + comp_obj_location.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1_to_4"]; + comp_obj_location.tags.heading_lev_anchor_tag = lev_anchor_tag; + comp_obj_location.metainfo.parent_ocn = p_["object_number"]; + comp_obj_location.metainfo.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.metainfo.parent_lev_markup >= 4); + assert(comp_obj_location.metainfo.parent_lev_markup <= 7); + assert(comp_obj_location.metainfo.parent_ocn >= 0); + return comp_obj_location; + } + invariant() { + } +#+END_SRC + +****** node metadata emitter heading, (including most segnames & their pointers) + +#+name: meta_emitters_metadata +#+BEGIN_SRC d + ObjGenericComposite node_emitter_heading(Hd,TaL,TA,N,fNr,fNs,fL)( + string _text, + string lev_markup_number, + string lev_collapsed_number, + Hd dummy_heading_status, + string[string] tag_in_seg, + TaL lev_anchor_tag, + TA tag_assoc, + N obj_cite_digits, + int cntr_, + int ptr_, + string[] lv_ancestors_txt, + string is_, + int html_segnames_ptr, + fNr flag_notes_reg, + fNs flag_notes_star, + fL flag_links, + ) { + debug(asserts) { + static assert(is(typeof(lev) == string)); + static assert(is(typeof(obj_cite_digits.object_number) == int)); + } + assert(is_ == "heading"); + assert((obj_cite_digits.object_number).to!int >= 0); + assert( + lev_markup_number.match(rgx.levels_numbered), + ("not a valid heading level: " ~ lev_markup_number ~ " at " ~ obj_cite_digits.object_number.to!string) + ); + if (lev_markup_number.match(rgx.levels_numbered)) { + if (lev_markup_number.to!int == 0) { + /+ TODO first hit (of two) with this assertion failure, check, fix & reinstate + assert(obj_cite_digits.object_number.to!int == 1, + "ERROR header lev markup number is: " ~ + lev_markup_number.to!string ~ + " obj_cite_digits.object_number.to!int should == 1 but is: " ~ + obj_cite_digits.object_number.to!string ~ + "\n" ~ _text); + +/ + } + } + switch (lev_markup_number.to!int) { + case 0: + lv = DocStructMarkupHeading.h_sect_A; + lv0 = obj_cite_digit; + lv1=0; lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] = 0; + p_["object_number"] = 0; + break; + case 1: + lv = DocStructMarkupHeading.h_sect_B; + lv1 = obj_cite_digit; + lv2=0; lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_A; + p_["object_number"] = lv0; + break; + case 2: + lv = DocStructMarkupHeading.h_sect_C; + lv2 = obj_cite_digit; + lv3=0; lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_B; + p_["object_number"] = lv1; + break; + case 3: + lv = DocStructMarkupHeading.h_sect_D; + lv3=obj_cite_digit; + lv4=0; lv5=0; lv6=0; lv7=0; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_C; + p_["object_number"] = lv2; + break; + case 4: + lv = DocStructMarkupHeading.h_text_1; + lv4 = obj_cite_digit; + lv5=0; lv6=0; lv7=0; + if (lv3 > State.off) { + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_D; + p_["object_number"] = lv3; + } else if (lv2 > State.off) { + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_C; + p_["object_number"] = lv2; + } else if (lv1 > State.off) { + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_B; + p_["object_number"] = lv1; + } else { + p_["lev_markup_number"] + = DocStructMarkupHeading.h_sect_A; + p_["object_number"] = lv0; + } + break; + case 5: + lv = DocStructMarkupHeading.h_text_2; + lv5 = obj_cite_digit; + lv6=0; lv7=0; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_text_1; + p_["object_number"] = lv4; + break; + case 6: + lv = DocStructMarkupHeading.h_text_3; + lv6 = obj_cite_digit; + lv7=0; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_text_2; + p_["object_number"] = lv5; + break; + case 7: + lv = DocStructMarkupHeading.h_text_4; + lv7 = obj_cite_digit; + p_["lev_markup_number"] + = DocStructMarkupHeading.h_text_3; + p_["object_number"] = lv6; + break; + default: + break; + } + ObjGenericComposite _comp_obj_heading_; + _comp_obj_heading_ = _comp_obj_heading_.init; + _comp_obj_heading_.metainfo.is_of_part = "body"; + _comp_obj_heading_.metainfo.is_of_section = "body"; + _comp_obj_heading_.metainfo.is_of_type = "para"; + _comp_obj_heading_.metainfo.is_a = "heading"; + _comp_obj_heading_.text = _text.to!string.strip; + _comp_obj_heading_.metainfo.ocn = obj_cite_digits.object_number; + _comp_obj_heading_.metainfo.identifier = obj_cite_digits.identifier; + _comp_obj_heading_.metainfo.dummy_heading = (dummy_heading_status == "t") ? true: false; + _comp_obj_heading_.metainfo.object_number_off = obj_cite_digits.off; + // _comp_obj_heading_.metainfo.o_n_book_index = obj_cite_digits.bkidx; + _comp_obj_heading_.metainfo.object_number_type = obj_cite_digits.type; + _comp_obj_heading_.tags.segment_anchor_tag_epub = tag_in_seg["seg_lv1_to_4"]; + _comp_obj_heading_.tags.anchor_tag_html = tag_in_seg["seg_lv4"]; + _comp_obj_heading_.tags.in_segment_html = _comp_obj_heading_.tags.anchor_tag_html; + _comp_obj_heading_.tags.heading_lev_anchor_tag = lev_anchor_tag; + _comp_obj_heading_.tags.html_segment_anchor_tag_is = tag_in_seg["seg_lv4"]; + _comp_obj_heading_.tags.epub_segment_anchor_tag_is = tag_in_seg["seg_lv1_to_4"]; + _comp_obj_heading_.metainfo.heading_lev_markup = (!(lev_markup_number.empty) ? lev_markup_number.to!int : 0); + _comp_obj_heading_.metainfo.heading_lev_collapsed = (!(lev_collapsed_number.empty) ? lev_collapsed_number.to!int : 0); + _comp_obj_heading_.metainfo.parent_ocn = p_["object_number"]; + _comp_obj_heading_.metainfo.parent_lev_markup = p_["lev_markup_number"]; + _comp_obj_heading_.tags.heading_ancestors_text = lv_ancestors_txt; + _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_.has.inline_notes_reg = flag_notes_reg; + _comp_obj_heading_.has.inline_notes_star = flag_notes_star; + _comp_obj_heading_.has.inline_links = flag_links; + tag_assoc[_comp_obj_heading_.tags.anchor_tag_html]["seg_lv4"] = _comp_obj_heading_.tags.in_segment_html; + tag_assoc[_comp_obj_heading_.tags.segment_anchor_tag_epub]["seg_lv1_to_4"] = _comp_obj_heading_.tags.segment_anchor_tag_epub; + 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_.metainfo.parent_lev_markup <= 7); + assert(_comp_obj_heading_.metainfo.parent_ocn >= 0); + if (lev_markup_number.match(rgx.levels_numbered_headings)) { + assert(_comp_obj_heading_.metainfo.heading_lev_markup <= 7); + assert(_comp_obj_heading_.metainfo.ocn >= 0); + if (_comp_obj_heading_.metainfo.parent_lev_markup > 0) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup < _comp_obj_heading_.metainfo.heading_lev_markup); + if (_comp_obj_heading_.metainfo.ocn != 0) { + assert(_comp_obj_heading_.metainfo.parent_ocn < _comp_obj_heading_.metainfo.ocn); + } + } + if (_comp_obj_heading_.metainfo.heading_lev_markup == 0) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_B) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_A); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_C) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_B); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_sect_D) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_sect_C); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_1) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup <= DocStructMarkupHeading.h_sect_D); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_2) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_1); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_3) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_2); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_4) { + assert(_comp_obj_heading_.metainfo.parent_lev_markup == DocStructMarkupHeading.h_text_3); + } else if (_comp_obj_heading_.metainfo.heading_lev_markup == DocStructMarkupHeading.h_text_5) { + } + } + return _comp_obj_heading_; + } + invariant() { + } +#+END_SRC + +***** } + +#+name: meta_emitters_metadata +#+BEGIN_SRC d +} +#+END_SRC + +*** function assertions :assertions: +**** assertions on markup document structure :doc_structure: + +#+name: abs_functions_assertions +#+BEGIN_SRC d +pure void assertions_doc_structure()( + string[string] an_object, + int[string] lv +) { + 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; + } +} +#+END_SRC + +**** assertions on blocks :blocks: + +#+name: abs_functions_assertions +#+BEGIN_SRC d +pure void assertions_flag_types_block_status_none_or_closed()(int[string] obj_type_status) { + assert( + (obj_type_status["code"] == TriState.off) + || (obj_type_status["code"] == TriState.closing), + "code block status: off or closing"); + assert( + (obj_type_status["poem"] == TriState.off) + || (obj_type_status["poem"] == TriState.closing), + "poem status: off or closing"); + assert( + (obj_type_status["table"] == TriState.off) + || (obj_type_status["table"] == TriState.closing), + "table status: off or closing"); + assert( + (obj_type_status["group"] == TriState.off) + || (obj_type_status["group"] == TriState.closing), + "group block status: off or closing"); + assert( + (obj_type_status["block"] == TriState.off) + || (obj_type_status["block"] == TriState.closing), + "block status: off or closing"); +} +#+END_SRC + +*** doc sect keys seq + +#+name: template_doc_sect_keys_seq +#+BEGIN_SRC d +template docSectKeysSeq() { + auto docSectKeysSeq(string[][string] document_section_keys_sequenced) { + struct doc_sect_keys_seq { + string[] scroll() { + return document_section_keys_sequenced["scroll"]; + } + string[] seg() { + return document_section_keys_sequenced["seg"]; + } + string[] sql() { + return document_section_keys_sequenced["sql"]; + } + string[] latex() { + return document_section_keys_sequenced["latex"]; + } + } + return doc_sect_keys_seq(); + } +} +#+END_SRC + +* 2. Object Setter (Set Abstract Object) :module:spine:meta_object_setter: + +set abstracted objects for downstream processing + +** _module template_ + +#+BEGIN_SRC d :tangle "../src/doc_reform/meta/object_setter.d" +/++ + object setter: + setting of sisu objects for downstream processing + meta_object_setter.d ++/ +module doc_reform.meta.object_setter; +template ObjectSetter() { + /+ structs +/ + <> +} +#+END_SRC + +** 1. initialize structs :struct: +*** heading attribute + +#+BEGIN_SRC d +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; +} +#+END_SRC + +*** _composite object_ [#A] + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_MetaInfo_ { + string is_of_part = ""; // frontmatter, body, backmatter + string is_of_section = ""; // toc, body, glossary, biography, book index, blurb + string is_of_type = ""; // para, block ? + string is_a = ""; // heading, para, table, code block, group, verse/poem ... + alias of_part = is_of_part; + alias of_section = is_of_section; + alias is_of = is_of_type; + string attrib = ""; + string lang = ""; // blocks: group, block, quote; not codeblock; + string syntax = ""; // codeblock only + /+ o_n +/ + int o_n_substantive = 0; + int o_n_non_substantive = 0; + int o_n_glossary = 0; + int o_n_bibliography = 0; + int o_n_book_index = 0; + int o_n_blurb = 0; + string object_number_substantive() const @property { + return (o_n_substantive==0) ? "" : o_n_substantive.to!string; + } + string object_number_non_substantive() const @property { + return (o_n_non_substantive==0) ? "" : o_n_non_substantive.to!string; + } + string object_number_glossary() const @property { + return (o_n_glossary==0) ? "" : o_n_glossary.to!string; + } + string object_number_bibliography() const @property { + return (o_n_bibliography==0) ? "" : o_n_bibliography.to!string; + } + string object_number_book_index() const @property { + return (o_n_book_index==0) ? "" : o_n_book_index.to!string; + } + string object_number_blurb() const @property { + return (o_n_blurb==0) ? "" : o_n_blurb.to!string; + } + bool object_number_off = false; + bool visible_object_number = false; + int object_number_type = 0; // { ocn, non, bkidx } + /+ node +/ + string[string][string] node; + int ocn = 0; + string identifier = ""; + string object_number() const @property { + return (ocn==0) ? "" : ocn.to!string; + } + int o_n_type = 0; + int heading_lev_markup = 9; + int heading_lev_collapsed = 9; + string marked_up_level() const @property { + string _out; + switch (heading_lev_markup) { + case 0 : _out = "A"; break; + case 1 : _out = "B"; break; + case 2 : _out = "C"; break; + case 3 : _out = "D"; break; + case 4 : _out = "1"; break; + case 5 : _out = "2"; break; + case 6 : _out = "3"; break; + case 7 : _out = "4"; break; + default : _out = ""; break; // "9"; + } + return _out; + } + bool dummy_heading = false; + int[] markedup_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] collapsed_ancestors = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_structure_markedup_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + int[] dom_structure_collapsed_tags_status = [ 0, 0, 0, 0, 0, 0, 0, 0,]; + int parent_lev_markup = 0; + int parent_ocn = 0; + int last_decendant_ocn = 0; +} +#+END_SRC + +**** object text attributes + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_TxtAttrib_ { + int indent_base = 0; + int indent_hang = 0; + bool bullet = false; + string language = ""; +} +#+END_SRC + +**** object has within it + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_Has_ { + bool inline_links = false; + bool inline_notes_reg = false; + bool inline_notes_star = false; + bool images = false; + bool image_without_dimensions = false; +} +#+END_SRC + +**** table attributes + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_Table_ { + int number_of_columns = 0; + double[] column_widths = []; + string[] column_aligns = []; + bool heading = false; + bool walls = false; +} +#+END_SRC + +**** code attributes + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_CodeBlock_ { + string syntax = ""; + bool linenumbers = false; +} +#+END_SRC + +**** stow (things to be protected from regular text transformations, so far links) + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_Stow_ { + string[] link = []; +} +#+END_SRC + +**** pointers + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_Pointer_ { + int doc_object = 0; + int html_segnames = 0; + int heading = 0; +} +#+END_SRC + +**** tags + +#+name: meta_structs_init +#+BEGIN_SRC d +struct DocObj_Tags_ { + string[] heading_ancestors_text = [ "", "", "", "", "", "", "", "", ]; + string anchor_tag_html = ""; + string in_segment_html = ""; + string segment_anchor_tag_epub = ""; + string html_segment_anchor_tag_is = ""; + string epub_segment_anchor_tag_is = ""; + string heading_lev_anchor_tag = ""; + string segname_prev = ""; + string segname_next = ""; + string[] lev4_subtoc = []; + string[] anchor_tags = []; +} +#+END_SRC + +**** composite object the parts + +#+name: meta_structs_init +#+BEGIN_SRC d +struct ObjGenericComposite { + string text = ""; + DocObj_MetaInfo_ metainfo; + DocObj_TxtAttrib_ attrib; + DocObj_Tags_ tags; + DocObj_Has_ has; + DocObj_Table_ table; + DocObj_CodeBlock_ code_block; + DocObj_Stow_ stow; + DocObj_Pointer_ ptr; +} +#+END_SRC + +*** The Objects: generic composite object array + +#+name: meta_structs_init +#+BEGIN_SRC d +struct TheObjects { + ObjGenericComposite[] oca; +} +#+END_SRC + +* __END__ diff --git a/org/out_harvest_metadata.org b/org/out_harvest_metadata.org new file mode 100644 index 0000000..b2c7b1a --- /dev/null +++ b/org/out_harvest_metadata.org @@ -0,0 +1,862 @@ +-*- mode: org -*- +#+TITLE: spine (doc_manifest) metadata (multidocument) harvests +#+DESCRIPTION: documents - structuring, various output representations & search +#+FILETAGS: :spine:hub: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +* document harvest _summary_ :module:spine:metadoc_show_summary: + +** _module template_ metadoc harvest + +#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvest.d" +module doc_reform.meta.metadoc_harvest; +template DocReformMetaDocHarvest() { + auto DocReformMetaDocHarvest(T,H)( + T doc_matters, + H hvst, + ) { + <> + mixin InternalMarkup; + <> + <> + } +} +#+END_SRC + +** init +*** imports + +#+name: metadoc_harvest_imports +#+BEGIN_SRC d +import + doc_reform.meta.defaults, + doc_reform.meta.rgx; +import + std.array, + std.exception, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.uni, + std.utf, + std.conv : to; +#+END_SRC + +*** initialize :report: + +#+name: metadoc_harvest_initialize +#+BEGIN_SRC d +auto markup = InlineMarkup(); +#+END_SRC + +** harvest summary + +#+name: meta_metadoc_harvest_summary +#+BEGIN_SRC d +auto min_repeat_number = 66; +auto char_repeat_number = (doc_matters.conf_make_meta.meta.title_full.length + + doc_matters.conf_make_meta.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", + markup.repeat_character_by_number_provided("-", char_repeat_number), + doc_matters.conf_make_meta.meta.title_full, + doc_matters.conf_make_meta.meta.creator_author, + doc_matters.src.filename, + doc_matters.conf_make_meta.meta.classify_topic_register_arr, + markup.repeat_character_by_number_provided("-", char_repeat_number), +); +#+END_SRC + +** return harvest + +#+name: meta_metadoc_harvest +#+BEGIN_SRC d +import doc_reform.output.paths_output; +auto pth_html_abs = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); +auto pth_html_rel = DocReformDocRootTreeHTML!()(doc_matters.src.language); +hvst.harvest.title = doc_matters.conf_make_meta.meta.title_full; +hvst.harvest.author = doc_matters.conf_make_meta.meta.creator_author; +hvst.harvest.author_surname = doc_matters.conf_make_meta.meta.creator_author_surname; +hvst.harvest.author_surname_fn = doc_matters.conf_make_meta.meta.creator_author_surname_fn; +hvst.harvest.author_arr = doc_matters.conf_make_meta.meta.creator_author_arr; +hvst.harvest.language_original = doc_matters.conf_make_meta.meta.original_language; +hvst.harvest.language = doc_matters.src.language; +hvst.harvest.uid = doc_matters.src.doc_uid; +hvst.harvest.date_published = doc_matters.conf_make_meta.meta.date_published; +hvst.harvest.topic_register_arr = doc_matters.conf_make_meta.meta.classify_topic_register_arr; +hvst.harvest.path_html_scroll = pth_html_rel.fn_scroll(doc_matters.src.filename); +hvst.harvest.path_html_segtoc = pth_html_rel.fn_seg(doc_matters.src.filename, "toc"); +hvst.harvest.path_abs_html_scroll = pth_html_abs.fn_scroll(doc_matters.src.filename); +hvst.harvest.path_abs_html_segtoc = pth_html_abs.fn_seg(doc_matters.src.filename, "toc"); +return hvst.harvest; +#+END_SRC + +** _module template_ metadoc harvest topics +*** _module template_ metadoc harvest topics template + +#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvests_topics.d" +module doc_reform.meta.metadoc_harvests_topics; + import + std.algorithm, + std.array, + std.exception, + std.regex, + std.stdio, + std.string, + std.conv : to; + import + doc_reform.meta.defaults, + doc_reform.meta.rgx; + mixin DocReformHarvest; + mixin InternalMarkup; + mixin DocReformRgxInit; +template DocReformMetaDocHarvestsTopics() { + auto mkup = InlineMarkup(); + void DocReformMetaDocHarvestsTopics(H,M,O)( + H hvst, + M _make_and_meta_struct, + O _opt_action, + ) { + <> +<> +<> +<> +<> +<> + <> + topics +<> + <> + } +} +#+END_SRC + +*** order topic register + +#+NAME: harvested_topics +#+BEGIN_SRC d +auto min_repeat_number = 42; +string[] _document_topic_register; +string[] _topic_register; +string[] _sub_topic_register; +string[] topics = []; +string _auth = ""; +foreach(k, doc_harvest; hvst.harvests) { + _topic_register = []; + foreach(topic; doc_harvest.topic_register_arr.sort) { + _sub_topic_register = []; + string _spaces; + string[] subject_tree = topic.split(mkup.sep); + switch (subject_tree.length) { + case 1: + hvst.subject_trees[subject_tree[0]]["_a"]["_a"]["_a"] ~= doc_harvest; + break; + case 2: + hvst.subject_trees[subject_tree[0]][subject_tree[1]]["_a"]["_a"] ~= doc_harvest; + break; + case 3: + hvst.subject_trees[subject_tree[0]][subject_tree[1]][subject_tree[2]]["_a"] ~= doc_harvest; + break; + case 4: + hvst.subject_trees[subject_tree[0]][subject_tree[1]][subject_tree[2]][subject_tree[3]] ~= doc_harvest; + break; + default: + break; + } + _topic_register ~= _sub_topic_register.join("\n"); + } + auto char_repeat_number = (doc_harvest.title.length + + doc_harvest.author.length + 16); + char_repeat_number = (char_repeat_number > min_repeat_number) + ? char_repeat_number + : min_repeat_number; + _document_topic_register ~= format( + "\"%s\", %s%s\n%s", + doc_harvest.title, + doc_harvest.author, + (doc_harvest.date_published.length > 0) ? " (" ~ doc_harvest.date_published ~ ")" : "", + _topic_register.sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable).release.join("\n"), + ); +} +#+END_SRC + +*** harvested topics html head + +#+NAME: harvested_topics_html_head_1 +#+BEGIN_SRC d + topics ~= format(q"┃ + + + +Metadata Harvest - Topics +#+END_SRC + +*** harvested topics html head + +#+NAME: harvested_topics_html_head_2 +#+BEGIN_SRC d + + + + + +

Metadata Harvest - Topics (output organised by language & filetype)

+

[ HOME ] also see Metadata Harvest - Authors

+

ABCDEFGHIJKLMNOPQRSTUVWXYZ,  +

+
+

English   

+
+#+END_SRC + +*** harvested topics html head theme insert + +#+NAME: harvested_topics_html_head_theme +#+BEGIN_SRC d +┃", + _opt_action.css_theme_default ? theme_light_0 : theme_dark_0, + _opt_action.css_theme_default ? theme_light_1 : theme_dark_1, +) ~ "\n"; +#+END_SRC + +*** harvested topics html + +#+NAME: harvested_topics_html +#+BEGIN_SRC d +char _prev_k = "_".to!char; +int _kn; +foreach(k0; + hvst.subject_trees.keys + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) +) { + if (k0.toUpper.to!(char[])[0] != _prev_k) { + topics ~= format(q"┃

%s

┃", + k0.toUpper.to!(char[])[0], + k0.toUpper.to!(char[])[0], + ); + _prev_k = k0.toUpper.to!(char[])[0]; + } + if (k0 != "_a") { + topics ~= format(q"┃

%s

┃", + k0.translate([' ' : "_"]), k0,) ~ "\n"; + if (_opt_action.very_verbose) { + writeln("", k0); + } + if ("_a" in hvst.subject_trees[k0]) { + foreach (t_a_; + hvst.subject_trees[k0]["_a"]["_a"]["_a"] + .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) + ) { + _auth = []; + if (t_a_.author_arr.length < 2) { + _auth = format(q"┃ %s┃", + t_a_.author_surname.translate([' ' : "_"]), + t_a_.author, + ); + } else { + foreach (a; t_a_.author_arr) { + _auth ~= format(q"┃ %s,┃", + t_a_.author_surname.translate([' ' : "_"]), + a, + ); + } + } + topics ~= format(q"┃

"%s" -%s┃", + t_a_.path_html_segtoc, + t_a_.title, + _auth, + ) ~ "\n"; + if (_opt_action.very_verbose) { + writeln("- ", t_a_.title, " - ", t_a_.author); + } + } + } + foreach(k1; + hvst.subject_trees[k0].keys + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) + ) { + if (k1 != "_a") { + topics ~= format(q"┃

%s

┃", + k1.translate([' ' : "_"]), k1,) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" ", k1); + } + if ("_a" in hvst.subject_trees[k0][k1]) { + foreach (t_a_; + hvst.subject_trees[k0][k1]["_a"]["_a"] + .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) + ) { + _auth = []; + if (t_a_.author_arr.length < 2) { + _auth = format(q"┃ %s┃", + t_a_.author_surname.translate([' ' : "_"]), + t_a_.author, + ); + } else { + foreach (a; t_a_.author_arr) { + _auth ~= format(q"┃ %s,┃", + t_a_.author_surname.translate([' ' : "_"]), + a, + ); + } + } + topics ~= format(q"┃

%s -%s┃", + t_a_.path_html_segtoc, + t_a_.title, + _auth, + ) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" - ", t_a_.title, " - ", t_a_.author); + } + } + } + } + foreach(k2; + hvst.subject_trees[k0][k1].keys + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) + ) { + if (k2 != "_a") { + topics ~= format(q"┃

%s

┃", + k2.translate([' ' : "_"]), k2,) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" ", k2); + } + if ("_a" in hvst.subject_trees[k0][k1][k2]) { + foreach (t_a_; + hvst.subject_trees[k0][k1][k2]["_a"] + .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) + ) { + _auth = []; + if (t_a_.author_arr.length < 2) { + _auth = format(q"┃ %s┃", + t_a_.author_surname.translate([' ' : "_"]), + t_a_.author, + ); + } else { + foreach (a; t_a_.author_arr) { + _auth ~= format(q"┃ %s,┃", + t_a_.author_surname.translate([' ' : "_"]), + a, + ); + } + } + topics ~= format(q"┃

%s -%s┃", + t_a_.path_html_segtoc, + t_a_.title, + _auth, + ) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" - ", t_a_.title, " - ", t_a_.author); + } + } + } + } + foreach(k3; + hvst.subject_trees[k0][k1][k2].keys + .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) + ) { + if (k3 != "_a") { + topics ~= format(q"┃

%s

┃", + k3.translate([' ' : "_"]), k3,) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" ", k3); + } + { + foreach (t_a_; + hvst.subject_trees[k0][k1][k2][k3] + .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) + ) { + _auth = []; + if (t_a_.author_arr.length < 2) { + _auth = format(q"┃%s┃", + t_a_.author_surname.translate([' ' : "_"]), + t_a_.author, + ); + } else { + foreach (a; t_a_.author_arr) { + _auth ~= format(q"┃ %s,┃", + t_a_.author_surname.translate([' ' : "_"]), + a, + ); + } + } + topics ~= format(q"┃

%s -%s┃", + t_a_.path_html_segtoc, + t_a_.title, + _auth, + ) ~ "\n"; + if (_opt_action.very_verbose) { + writeln(" - ", t_a_.title, " - ", t_a_.author); + } + } + } + } + } + } + } + } +} +#+END_SRC + +*** harvested topics write + +#+NAME: harvested_topics_html_write +#+BEGIN_SRC d +import doc_reform.output.paths_output; +auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); +try { + auto f = File(out_pth.harvest("topics.html"), "w"); + foreach (o; topics) { + f.writeln(o); + } +} catch (ErrnoException ex) { + // Handle error +} +#+END_SRC + +** _module template_ metadoc harvests authors +*** _module template_ metadoc harvest authors + +#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvests_authors.d" +module doc_reform.meta.metadoc_harvests_authors; + import + std.algorithm, + std.array, + std.exception, + std.regex, + std.stdio, + std.string, + std.conv : to; + import + doc_reform.meta.defaults, + doc_reform.meta.rgx; + mixin DocReformHarvest; + mixin InternalMarkup; + mixin DocReformRgxInit; +template DocReformMetaDocHarvestsAuthors() { + auto mkup = InlineMarkup(); + void DocReformMetaDocHarvestsAuthors(H,M,O)( + H harvests, + M _make_and_meta_struct, + O _opt_action, + ) { +<> +<> +<> +<> +<> + authors +<> + <> + } +} +#+END_SRC + +*** harvested authors html head + +#+NAME: harvested_authors_html_head_1 +#+BEGIN_SRC d + string[] authors = []; + authors ~= format(q"┃ + + + + +Metadata Harvest - Authors +#+END_SRC + +*** harvested authors html head + +#+NAME: harvested_authors_html_head_2 +#+BEGIN_SRC d + + + + + +

Metadata Harvest - Authors (output organised by language & filetype)

+

[ HOME ] also see Metadata Harvest - Topics

+

+
+

English   

+
+

ABCDEFGHIJKLMNOPQRSTUVWXYZ,  +#+END_SRC + +*** harvested authors html theme inserts + +#+NAME: harvested_authors_html_head_theme +#+BEGIN_SRC d +┃", + _opt_action.css_theme_default ? theme_light_0 : theme_dark_0, + _opt_action.css_theme_default ? theme_light_1 : theme_dark_1, +) ~ "\n"; + string[string] _au; + string[] _auth_date_title; + string[] _author_date_title; + string _prev_auth = ""; + char _prev_k = "_".to!char; + foreach(doc_harvest; + harvests + .multiSort!( + "toUpper(a.author_surname_fn) < toUpper(b.author_surname_fn)", + "a.date_published < b.date_published", + "a.title < b.title", + SwapStrategy.unstable + ) + ) { + if (doc_harvest.author_surname_fn != _prev_auth) { + _au[doc_harvest.author_surname_fn] + = format(q"┃

%s

%s "%s" [%s]

┃", + doc_harvest.author_surname.translate([' ' : "_"]), + doc_harvest.author_surname_fn, + (doc_harvest.date_published.length > 0) + ? doc_harvest.date_published : "", + doc_harvest.path_html_segtoc, + doc_harvest.title, + doc_harvest.language, + ); + _prev_auth = doc_harvest.author_surname_fn; + } else { + _au[doc_harvest.author_surname_fn] + ~= format(q"┃

%s "%s" [%s]

┃", + (doc_harvest.date_published.length > 0) + ? doc_harvest.date_published : "", + doc_harvest.path_html_segtoc, + doc_harvest.title, + doc_harvest.language, + ); + } + _author_date_title ~= format(q"┃%s %s "%s" [%s]%s┃", + doc_harvest.author_surname_fn, + (doc_harvest.date_published.length > 0) + ? "(" ~ doc_harvest.date_published ~ ")" : "", + doc_harvest.title, + doc_harvest.language, + (_opt_action.very_verbose) ? "\n " ~ doc_harvest.path_abs_html_scroll : "", + ); + } + foreach (k; _au.keys.sort) { + if (k.toUpper.to!(char[])[0] != _prev_k) { + authors ~= format(q"┃

%s

┃", + k.toUpper.to!(char[])[0], + k.toUpper.to!(char[])[0], + ); + _prev_k = k.toUpper.to!(char[])[0]; + } + authors ~= _au[k]; + } +#+END_SRC + +*** harvested authors write + +#+NAME: harvested_authors_html_write +#+BEGIN_SRC d +import doc_reform.output.paths_output; +auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); +try { + auto f = File(out_pth.harvest("authors.html"), "w"); + foreach (o; authors) { + f.writeln(o); + } +} catch (ErrnoException ex) { + // Handle error +} +if (_opt_action.verbose + || _opt_action.very_verbose +) { + foreach(_adt; _author_date_title.sort) { + writeln(_adt); + } +} +#+END_SRC + +** harvested authors & topics shared html +*** themes +**** head + +#+NAME: harvested_html_themes +#+BEGIN_SRC d +string theme_dark_0 = format(q"┃ + body { + color : #CCCCCC; + background : #000000; + background-color : #000000; + } + a:link { + color : #FFFFFF; + text-decoration : none; + } + a:visited { + color : #999999; + text-decoration : none; + } + a:hover { + color : #000000; + background-color : #555555; + } + a:hover img { + background-color : #000000; + } + a:active { + color : #888888; + text-decoration : underline; + } + a.lev0:hover { + color : #FFFFFF; + background-color : #000000; + } + a.lev1:hover { + color : #FFFFFF; + background : #333333; + } + a.lev2:hover { + color : #FFFFFF; + background : #555555; + } + a.lev3:hover { + color : #FFFFFF; + background : #777777; + } +┃"); +string theme_light_0 = format(q"┃ + body { + color : #000000; + 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:hover img { + background-color : #FFFFFF; + } + a:active { + color : #003399; + text-decoration : underline; + } + a.lev0:hover { + color : #000000; + background-color : #FFFFFF; + } + a.lev1:hover { + color : #FFFFFF; + background : #444444; + } + a.lev2:hover { + background : #888888; + } + a.lev3:hover { + background : #BBBBBB; + } +┃"); +#+END_SRC + +**** levels + +#+NAME: harvested_html_themes +#+BEGIN_SRC d +string theme_dark_1 = format(q"┃ + h1 { + color : #FFFFFF; + background : #000000; + } + p.letter { + color : #FFFFFF; + background : #333333; + } + p.lev0 { + color : #FFFFFF; + background : #000000; + } + p.lev1 { + color : #FFFFFF; + background : #333333; + } + p.lev2 { + background : #555555; + } + p.lev3 { + background : #777777; + } + p.lev4 { + background : #AAAAAA; + } + p.lev5 { + } +┃"); +string theme_light_1 = format(q"┃ + h1 { + color : #FFFFFF; + background : #000088; + } + p.letter { + color : #FFFFFF; + background : #880000; + } + p.lev0 { + color : #FFFFFF; + background : #000000; + } + p.lev1 { + color : #FFFFFF; + background : #444444; + } + p.lev2 { + background : #888888; + } + p.lev3 { + background : #BBBBBB; + } + p.lev4 { + background : #EEEEEE; + } + p.lev5 { + } +┃"); +#+END_SRC + +*** harvested html head + +#+NAME: harvested_html_head +#+BEGIN_SRC d + + + + + + + + +#+END_SRC + +*** harvested html bottom + +#+NAME: harvested_html_bottom +#+BEGIN_SRC d + ~= format(q"┃ +
+ + + + + + + + +┃") ~ "\n"; +#+END_SRC diff --git a/org/out_latex.org b/org/out_latex.org new file mode 100644 index 0000000..f9c6d55 --- /dev/null +++ b/org/out_latex.org @@ -0,0 +1,1879 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) output latex +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:latex:pdf: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* latex +** _module template_ :latex:pdf:module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/latex.d" :noweb yes +module doc_reform.output.latex; +template outputLaTeX() { + <> + mixin InternalMarkup; // watch + mixin DocReformOutputRgxInit; + auto rgx = Rgx(); + mixin DocReformLanguageCodes; + auto lang = Lang(); + <> +<> + <> + <> +<> + <> + <> +<> + <> + <> + <> + <> +<> + <> + <> +} +#+END_SRC + +** write latex output :latex:out: + +#+name: output_latex +#+BEGIN_SRC d +void writeOutputLaTeX(T,M)( + const T latex_content, + M doc_matters, +) { + auto pth_latex = DocReformPathsLaTeX(doc_matters); + try { + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(latex_content.head); + writeln(latex_content.content); + writeln(latex_content.tail); + } + } + if (!exists(pth_latex.latex_path_stuff)) { + (pth_latex.latex_path_stuff).mkdirRecurse; + } + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_latex.latex_file_with_path); + } + auto f = File(pth_latex.latex_file_with_path, "w"); + f.writeln(latex_content.head); + f.writeln(latex_content.content); + f.writeln(latex_content.tail); + foreach (image; doc_matters.srcs.image_list) { + auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_src_out_file = pth_latex.latex_path_stuff ~ "/" ~ image; + if (exists(fn_src_in)) { + fn_src_in.copy(fn_src_out_file); + } + } + } catch (ErrnoException ex) { + // handle error + } +} +#+END_SRC + +** latex output hub [#A] :latex:pdf:out: + +#+name: output_latex +#+BEGIN_SRC d +void outputLaTeX(D,M)( + const D doc_abstraction, + M doc_matters, +) { + struct LaTeX { + string head; + string content; + string tail; + } + auto latex = LaTeX(); + latex.head = latex_head(doc_matters); + latex.content = latex_body(doc_abstraction, doc_matters); + latex.tail = latex_tail(doc_matters); + latex.writeOutputLaTeX(doc_matters); +} +#+END_SRC + +* stuff +** output imports + +#+name: output_latex_imports +#+BEGIN_SRC d +import doc_reform.output; +import + std.digest.sha, + std.file, + std.outbuffer, + std.uri, + std.conv : to; +#+END_SRC + +** shared +*** paper dimensions (struct) + +#+name: output_latex_shared +#+BEGIN_SRC d + auto paper() { + struct PaperType { + auto a4() { + struct A4 { + auto portrait() { + struct V { + uint w = 160; + uint h = 228; + uint img_px = 450; + } + return V(); + } + auto landscape() { + struct H { + uint w = 238; + uint h = 160; + uint img_px = 300; + } + return H(); + } + } + return A4(); + } + auto a5() { + struct A5 { + auto portrait() { + struct V { + uint w = 112; + uint h = 162; + uint img_px = 280; + } + return V(); + } + auto landscape() { + struct H { + uint w = 152; + uint h = 100; + uint img_px = 190; + } + return H(); + } + } + return A5(); + } + auto b4() { + struct B4 { + auto portrait() { + struct V { + uint w = 140; + uint h = 204; + uint img_px = 356; + } + return V(); + } + auto landscape() { + struct H { + uint w = 200; + uint h = 130; + uint img_px = 260; + } + return H(); + } + } + return B4(); + } + auto letter() { + struct Letter { + auto portrait() { + struct V { + uint w = 166; + uint h = 212; + uint img_px = 468; + } + return V(); + } + auto landscape() { + struct H { + uint w = 226; + uint h = 166; + uint img_px = 290; + } + return H(); + } + } + return Letter(); + } + auto legal() { + struct Legal { + auto portrait() { + struct V { + uint w = 168; + uint h = 286; + uint img_px = 474; + } + return V(); + } + auto landscape() { + struct H { + uint w = 296; + uint h = 166; + uint img_px = 420; + } + return H(); + } + } + return Legal(); + } + } + return PaperType(); + } +#+END_SRC + +*** latex \escape special characters +**** general + +#+name: output_latex_shared +#+BEGIN_SRC d +string sp_char_esc(O)( + string _txt, + const O obj, +) { + string _unescape_sp_char_esc()(string _txt) { + _txt = _txt + .replaceAll(rgx.latex_special_char_escaped, + format(q"┃%s┃", "$1")) + .replaceAll(rgx.latex_special_char_escaped_braced, + format(q"┃%s┃", "$1")); + return _txt; + } + string _unescape_fontface_esc()(string _txt) { + _txt = _txt.replaceAll(rgx.latex_identify_inline_fontface, + format(q"┃%s%s┃", "$1", "$2")); + return _txt; + } + if (obj.metainfo.is_a != "code") { + _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char_for_escape); + _txt = replaceAll!(m => "{\\" ~ m[1] ~ "}")(_txt, rgx.latex_special_char_for_escape_and_braces); + _txt = replaceAll!(m => _unescape_sp_char_esc(m[0]))(_txt, rgx.latex_identify_inline_link); + _txt = replaceAll!(m => _unescape_fontface_esc(m[0]))(_txt, rgx.latex_identify_inline_fontface); + } + return _txt; +} +#+END_SRC + +#+name: output_latex_shared +#+BEGIN_SRC d +string sp_char_esc_txt()( + string _txt, +) { + string _unescape_sp_char_esc()(string _txt) { + _txt = _txt + .replaceAll(rgx.latex_special_char_escaped, + format(q"┃%s┃", "$1")) + .replaceAll(rgx.latex_special_char_escaped_braced, + format(q"┃%s┃", "$1")); + return _txt; + } + string _unescape_fontface_esc()(string _txt) { + _txt = _txt.replaceAll(rgx.latex_identify_inline_fontface, + format(q"┃%s%s┃", "$1", "$2")); + return _txt; + } + _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char_for_escape); + _txt = replaceAll!(m => "{\\" ~ m[1] ~ "}")(_txt, rgx.latex_special_char_for_escape_and_braces); + _txt = replaceAll!(m => _unescape_sp_char_esc(m[0]))(_txt, rgx.latex_identify_inline_link); + _txt = replaceAll!(m => _unescape_fontface_esc(m[0]))(_txt, rgx.latex_identify_inline_fontface); + return _txt; +} +#+END_SRC + +*** not used latex \escape special characters + +#+BEGIN_SRC d +string sp_char_esc()( + string _txt, +) { + _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char); + return _txt; +} +#+END_SRC + +*** inline markup +**** fontface + +- bold, italics, underscore, strikethrough + +#+name: output_latex_shared +#+BEGIN_SRC d +string fontface()( + string _txt, +) { +_txt = _txt + .replaceAll(rgx.inline_emphasis, format(q"┃\begin{bfseries}%s\end{bfseries}┃", "$1")) + .replaceAll(rgx.inline_bold, format(q"┃\begin{bfseries}%s\end{bfseries}┃", "$1")) + .replaceAll(rgx.inline_italics, format(q"┃\emph{%s}┃", "$1")) + .replaceAll(rgx.inline_italics, format(q"┃\uline{%s}┃", "$1")) + .replaceAll(rgx.inline_superscript, format(q"┃$$^{\textrm{%s}}$$┃", "$1")) + .replaceAll(rgx.inline_subscript, format(q"┃$$_{\textrm{%s}}$$┃", "$1")) + .replaceAll(rgx.inline_strike, format(q"┃\sout{%s}┃", "$1")) + .replaceAll(rgx.inline_insert, format(q"┃\uline{%s}┃", "$1")) + .replaceAll(rgx.inline_mono, format(q"┃\begin{monosp}%s\end{monosp}┃", "$1")) + .replaceAll(rgx.inline_italics, format(q"┃``%s''┃", "$1")); + return _txt; +} +#+END_SRC + +**** spaces +***** leading hardspace + +#+name: output_latex_shared +#+BEGIN_SRC d +string leading_hardspaces()( + string _txt, +) { + string hardspaces(string _spaces) { + _spaces = _spaces + .replaceAll(rgx.space, "\\hardspace "); + return _spaces; + } + _txt = replaceAll!(m => hardspaces(m[0]))(_txt, rgx.spaces_line_start); + return _txt; +} +#+END_SRC + +***** nbsp character + +#+name: output_latex_shared +#+BEGIN_SRC d +string nbsp_char()(string _txt) { + if (_txt.match(rgx.nbsp_char)) { + _txt = _txt.replaceAll(rgx.nbsp_char, "\\hardspace "); + } + return _txt; +} +#+END_SRC + +***** remove nbsp character + +#+name: output_latex_shared +#+BEGIN_SRC d +string nbsp_char_to_space()(string _txt) { + if (_txt.match(rgx.nbsp_char)) { + _txt = _txt.replaceAll(rgx.nbsp_char, " "); + } + return _txt; +} +#+END_SRC + +**** links and images +***** links / urls + +#+name: output_latex_shared +#+BEGIN_SRC d +string links_and_images(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + if (obj.has.inline_links) { // TODO some images do not have inline links ... image without link + string _width_adjust(string _width) { + if (_width.to!int > 300) { _width = "300"; } // will need to vary max with papersize & orientation + return _width; + } + string _latex_image_path(string _image_path) { + auto pth_latex = DocReformPathsLaTeX(doc_matters); + _image_path = pth_latex.latex_path_stuff ~ "/" ~ _image_path; + return _image_path; + } + string _if_images(string _linked_content) { + if (_linked_content.match(rgx.inline_image_info)) { + _linked_content = replaceAll!(m => + format(q"┃\includegraphics*[width=%spt]{%s}%s┃", + _width_adjust(m[2]), _latex_image_path(m[1]), " \\\\\n") + )(_linked_content, rgx.inline_image_info); + } + return _linked_content; + } + string _check_link(string _link) { + _link = _link + .replaceFirst(rgx.latex_clean_internal_link, "") + .replaceAll(rgx.latex_special_char_for_escape_url, "\\$1"); + return _link; + } + if (obj.metainfo.is_a != "code") { + _txt = replaceAll!(m => + m[1] ~ "┤" ~ to!string((obj.stow.link[m[2].to!ulong])).encode ~ "├" + )(_txt, rgx.inline_link_number_only); + _txt = replaceAll!(m => + ((m[1] == m[2]) && (m[2].match(rgx.uri))) + ? format(q"┃\begin{scriptsize}\lefthalfcap\url{%s}\righthalfcup\end{scriptsize}┃", _check_link(m[1])) + : (m[2].match(rgx.uri)) // ERROR + ? format(q"┃%s\href{%s}%s{%s}┃", "\\\\\n", _check_link(m[2]), "\n", _if_images(m[1])) + : format(q"┃\hyperlink{%s}{%s}┃", _check_link(m[2]), _if_images(m[1])) + )(_txt, rgx.inline_link); + } + } + return _txt; +} +#+END_SRC + +*** footnotes +**** footnotes + +#+name: output_latex_shared +#+BEGIN_SRC d +string footnotes()( + string _txt, +) { + if (_txt.match(rgx.inline_notes_al_gen)) { + string _tex_note = q"┃\hypertarget{noteref_%s}{}\footnote[%s]{%% +\label{note_%s}%s}┃"; + _txt = _txt.replaceAll(rgx.inline_notes_al_regular_number_note, + format(_tex_note, + "$1", "$1", "$1", + "$2".strip + ).strip + ); + } + return _txt; +} +#+END_SRC + +**** footnote remove + +#+name: output_latex_shared +#+BEGIN_SRC d +string remove_footnotes()( + string _txt, +) { + if (_txt.match(rgx.inline_notes_al_gen)) { + _txt = replaceAll!(m => "")(_txt, rgx.inline_notes_al_gen); + } + return _txt; +} +#+END_SRC + +*** para +**** para + +#+name: output_latex_shared +#+BEGIN_SRC d +string para(O)( + string _txt, + O obj, +) { + if (obj.metainfo.is_of_type == "para") { + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s┃"; + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.footnotes + ).strip; + } + return _txt; +} +#+END_SRC + +**** bookindex para + +#+name: output_latex_shared +#+BEGIN_SRC d +string bookindex(O)( + string _txt, + O obj, +) { + if (obj.metainfo.is_of_type == "para" + && obj.metainfo.is_a == "bookindex" + ) { + string _tex_para; + _tex_para = q"┃%s┃"; + _txt = format(_tex_para, + _txt.replaceAll(rgx.latex_clean_bookindex_linebreak, "\n") ~ "\n\\\\\n" + ); + } + return _txt; +} +#+END_SRC + +*** bullets & indentation + +#+name: output_latex_head +#+BEGIN_SRC d +string bullets_and_indentation(O)( + string _txt, + O obj, +) { + string _tex_para; + string _hang; string _indent; + int _paper_margin = -10; + int _indent_increment = 8; // 5; 10; + if (obj.attrib.bullet) { + int _bullet_space = 5; + _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin + _bullet_space).to!string; + _txt = format(q"┃\begin{Bullet}{%smm}$\txtbullet$\hspace{\enspace}%s\end{Bullet}┃", + _indent, + _txt.footnotes + ).strip; + } else if ( + obj.attrib.indent_base != 0 + && obj.attrib.indent_base == obj.attrib.indent_hang + ) { + _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin).to!string; + _tex_para = q"┃\begin{ParagraphIndent}{%smm}%s \end{ParagraphIndent}┃"; + _txt = format(_tex_para, + _indent, + _txt.footnotes + ).strip; + } else if ( + obj.attrib.indent_base != 0 + || obj.attrib.indent_hang != 0 + ) { + _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin).to!string; + _hang = (((obj.attrib.indent_hang - obj.attrib.indent_base) * _indent_increment)).to!string; + _tex_para = q"┃\begin{ParagraphHang}{%smm}{%smm}%s \end{ParagraphHang}┃"; + _txt = format(_tex_para, + _indent, _hang, + _txt.footnotes + ).strip; + } + return _txt; +} +#+END_SRC + +*** heading + +#+name: output_latex_shared_0 +#+BEGIN_SRC d + string heading(O,M)( + string _txt, + O obj, + M doc_matters, + string _part = "" + ) { + if (obj.metainfo.is_a == "heading") { + string _tex_para; + string _pg_break; + string _sect; + string _post; + string _title_add; + string _columns = ""; + switch (obj.metainfo.heading_lev_markup) { + case 0: // A == TITLE + _pg_break = "\\begin{document}\n"; + goto default; + case 1: // B == part: section heading level + _pg_break = "\\clearpage\n"; + goto default; + case 2: // C == part: section heading level + _pg_break = "\\clearpage\n"; + goto default; + case 3: // D == part: section heading level + _pg_break = "\\clearpage\n"; + goto default; + case 4: // 1 == section + _columns = (_part != "bookindex") + ? "" : "\n\\\\\n\\begin{multicols}{2}"; + _pg_break = "\\clearpage\n"; + _sect = "section"; + _post = ""; + _title_add = format(q"┃ +\markboth{%s}{%s}┃", + doc_matters.conf_make_meta.meta.title_full, + doc_matters.conf_make_meta.meta.title_full, + ); + goto default; + case 5: // 2 == subsection + _pg_break = ""; + // _pg_break = "newpage"; // doubt this is necessary + _sect = "subsection"; + _post = " \\\n"; + _title_add = ""; + goto default; + case 6: // 3 == subsubsection + _pg_break = ""; + // _pg_break = "newpage"; // doubt this is necessary + _sect = "subsubsection"; + _post = " \\\n"; + _title_add = ""; + goto default; + default: + if (obj.metainfo.heading_lev_markup == 0) { + _tex_para = q"┃\begin{document} +\title{%s} +\author{ \textnormal{%s}} +\date{\begin{tiny}%s\end{tiny}} +\pagenumbering{roman}\maketitle +\pagestyle{fancy} +\newpage +\markboth{%s}{%s} +\\\\[3]\ \linebreak Copyright {\begin{small}{\copyright\end{small}} %s \\ +%s +\pagestyle{fancy} +\clearpage┃"; + _txt = format(_tex_para, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.creator_author).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.date_published).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.rights_copyright).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.rights_license).sp_char_esc_txt, + ); + } else if (obj.metainfo.heading_lev_markup < 4) { + _tex_para = q"┃%s\part*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} +\addcontentsline{toc}{part}{%s} +\markboth{%s}┃"; + _txt = format(_tex_para, + _pg_break, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.strip.footnotes, + _txt.strip.remove_footnotes, + (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, + ); + } else if (obj.metainfo.heading_lev_markup > 3) { + if (obj.metainfo.heading_lev_markup == 4 + && _txt.match(regex(r"^Table of Contents$"))) { + _tex_para = q"┃ +\pagenumbering{none} +\setcounter{page}{1} +\setlength{\parskip}{1ex plus0.5ex minus0.2ex} +\part*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{1}{1}\end{tiny}}}%s \newline %s} + +\clearpage +\markboth{%s}{%s} +\pagenumbering{gobble} +\renewcommand{\contentsname}{} +\tableofcontents +\markboth{%s}{%s} + +\clearpage +\pagenumbering{arabic} +\setcounter{page}{1} +\markboth{%s}{%s} +%% \null +\clearpage +\setcounter{page}{1}┃"; + _txt = format(_tex_para, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.creator_author).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, + ); + } else if (obj.metainfo.heading_lev_markup == 4 + && _part == "bookindex" + && _txt.match(regex(r"^Index$")) + ) { + _tex_para = q"┃%s\%s*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} +\addcontentsline{toc}{%s}{%s%s}%s%s┃"; + _txt = format(_tex_para, + _pg_break, + _sect.strip, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.footnotes.strip, + _sect, + _txt.remove_footnotes.strip, + _post, + _title_add, + _columns, + ); + } else if (obj.metainfo.dummy_heading + && obj.metainfo.heading_lev_markup == 4 + ) { /+ dummy headings completely omitted +/ + _txt = ""; + } else { + _tex_para = q"┃%s\%s*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} +\addcontentsline{toc}{%s}{%s%s}%s┃"; + _txt = format(_tex_para, + _pg_break, + _sect.strip, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.footnotes.strip, + _sect, + _txt.remove_footnotes.strip, + _post, + _title_add, + ); + } + } + break; + } + } + return _txt.strip; + } +#+END_SRC + +*** grouped text +**** group + +- (hardspace not honored) clear hardspace marker + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +string group(O,M)( + string _txt, + O obj, + M doc_matters, +) { + if (obj.metainfo.is_a == "group") { + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex} +\begin{footnotesize} +%s +\end{footnotesize} +┃"; + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.footnotes.strip + ).strip; + } + return _txt; +} +#+END_SRC + +**** block + +- (hardspace honored) \hardspace + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +string block(O,M)( + string _txt, + O obj, + M doc_matters, +) { + if (obj.metainfo.is_a == "block") { + // _txt = _txt.nbsp_char; + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex} +\begin{footnotesize} +%s +\end{footnotesize} +\setlength{\parskip}{1ex plus0.5ex minus0.2ex} +┃"; // \hardspace + /+ try both: +/ + _txt = _txt.split(rgx.br_newlines_linebreaks).join("\n\n"); // _txt = _txt.split(rgx.br_newlines_linebreaks).join(" \\\n"); + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.nbsp_char.footnotes.strip + ).strip; + } + return _txt; +} +#+END_SRC + +**** verse + +- (hardspace honored) \hardspace + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +string verse(O,M)( + string _txt, + O obj, + M doc_matters, +) { + if (obj.metainfo.is_a == "verse") { + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex} +\begin{footnotesize} + +%s + +\end{footnotesize} +\setlength{\parskip}{1ex plus0.5ex minus0.2ex} +\linebreak +┃"; // \hardspace + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.nbsp_char.footnotes.split("\n").join("\n\n").strip + ).strip; + } + return _txt; +} +#+END_SRC + +**** codeblock + +- (hardspace honored) \begin{lstlisting} clear hardspace marker + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +string codeblock(O,M)( + string _txt, + O obj, + M doc_matters, +) { + if (obj.metainfo.is_a == "code") { + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}\begin{Codeblock} +\begin{lstlisting} +%s +\end{lstlisting} +\end{Codeblock} +\setlength{\parskip}{1ex plus0.5ex minus0.2ex} +┃"; + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _txt.nbsp_char_to_space + ).strip; + } + return _txt; +} +#+END_SRC + +**** table + +- own set of rules + +***** tablarize + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +auto tablarize(O)( + string _txt, + const O obj, +) { + string[] _table_rows = (_txt).split(rgx.table_delimiter_row); + string[] _table_cols; + string _table; + string _tablenote; + foreach(row_idx, row; _table_rows) { + _table_cols = row.split(rgx.table_delimiter_col); + _table ~= ""; + foreach(col_idx, cell; _table_cols) { + if ((_table_cols.length == 1) + && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) + _tablenote ~= cell; + } else { + // // _table ~= "\\bfseries "; + // _table ~= cell; + // _table ~= (_table_cols.length > (col_idx + 1)) ? "&" : ""; + _table ~= format(q"┃%s%s┃", + cell, + (_table_cols.length > (col_idx + 1)) ? "&" : "" + ); + } + } + _table ~= "\\\\"; + } + auto t = tuple( + _table, + _tablenote, + ); + return t; +} +#+END_SRC + +***** table + +#+name: output_latex_shared_0 +#+BEGIN_SRC d +string table(O,M)( + string _txt, + O obj, + M doc_matters, +) { + if (obj.metainfo.is_a == "table") { + auto _t = _txt.tablarize(obj); + string _table = _t[0]; + string _t_n = _t[1]; + string papertype = "a4"; + uint pw = 0; + switch (papertype) { + case "a4": pw = (paper.a4.portrait.w - 20); break; + case "a5": pw = (paper.a5.portrait.w - 20); break; + case "b4": pw = (paper.b4.portrait.w - 20); break; + case "letter": pw = (paper.letter.portrait.w - 20); break; + case "legal": pw = (paper.legal.portrait.w - 20); break; + default: pw = 0; break; + } + // auto textwidth = (pw - 24); + string _colw = ""; + foreach (w; obj.table.column_widths) { + _colw ~= format(q"┃p{%.0fmm}┃", + (w * pw / 100) + // (w * (pw - 24)/ 100) + // (w * textwidth / 100) + ); + } + string _tex_para; + _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}} +\setlength{\LTleft}{0pt} +\setlength{\LTright}{\fill} +\begin{tiny} +\begin{longtable}{%s} +%s +\end{longtable} +\end{tiny} +┃"; + _txt = format(_tex_para, + obj.metainfo.object_number, + obj.metainfo.object_number, + _colw, + _table, + ).strip; + } + return _txt; +} +#+END_SRC + +** latex parts +*** latex head :head: +**** latex head function + +#+name: output_latex_head +#+BEGIN_SRC d +string latex_head(M)( + M doc_matters, +) { +#+END_SRC + +**** latex head options +***** paper type dimensions +****** struct + +#+name: output_latex_head +#+BEGIN_SRC d + struct paperType { + string a4_portrait; + string a4_landscape; + string us_letter_portrait; + string us_letter_landscape; + } + auto paper = paperType(); +#+END_SRC + +****** footer + +#+name: output_latex_head +#+BEGIN_SRC d + string _footer(M)(M doc_matters) { + string _ft = "\\lfoot[\\textrm{\\thepage}]"; + string _ft_1 = format(q"┃{\tiny \href{%s}{%s}}┃", "http://sisudoc.org", "SiSU",); + string _ft_2 = format(q"┃ +\cfoot{\href{%s}{%s}}┃", "http://git.sisudoc.org", "git",); + if (doc_matters.conf_make_meta.make.footer.length > 0) { + if (doc_matters.conf_make_meta.make.footer.length > 0) { + if (doc_matters.conf_make_meta.make.footer[0].matchAll(rgx.inline_link)) { + _ft ~= doc_matters.conf_make_meta.make.footer[0] + .replace(rgx.inline_link, "{\\tiny \\href{$2}{$1}}"); + } else { + _ft ~= _ft_1; + } + } + if (doc_matters.conf_make_meta.make.footer.length > 1) { + if (doc_matters.conf_make_meta.make.footer[1].matchAll(rgx.inline_link)) { + _ft ~= doc_matters.conf_make_meta.make.footer[1] + .replace(rgx.inline_link, "\n\\cfoot{\\href{$2}{$1}}"); + } else { + _ft ~= _ft_2; + } + } + } else { + _ft ~= _ft_1; + _ft ~= _ft_2; + } + return _ft; + } +#+END_SRC + +****** a4, portrait + +#+name: output_latex_head_1_format_string +#+BEGIN_SRC d + paper.a4_portrait = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\documentclass[12pt,a4paper,titlepage]{scrartcl} +\setlength{\textheight}{228mm} \setlength{\textwidth}{160mm} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** a4, landscape + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + paper.a4_landscape = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\documentclass[11pt,a4paper,landscape,titlepage,twocolumn]{scrartcl} +\setlength{\textheight}{160mm} \setlength{\textwidth}{238mm} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** us letter, portrait + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + paper.us_letter_portrait = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\documentclass[12pt,letterpaper,titlepage]{scrartcl} +\setlength{\textheight}{212mm} \setlength{\textwidth}{166mm} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** us letter, landscape + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + paper.us_letter_landscape = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\documentclass[11pt,letterpaper,landscape,titlepage,twocolumn]{scrartcl} +\setlength{\textheight}{166mm} \setlength{\textwidth}{226mm} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +***** paper margins +****** struct + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + struct paperMargins { + string portrait; + string landscape; + } + auto margins = paperMargins(); +#+END_SRC + +****** portrait + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + margins.portrait = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\setlength{\oddsidemargin}{0mm} \setlength{\evensidemargin}{0mm} +\setlength{\topmargin}{-12pt} \setlength{\headheight}{12pt} +\setlength{\headsep}{35pt} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** landscape + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + margins.landscape = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\setlength{\oddsidemargin}{6mm} \setlength{\evensidemargin}{6mm} +\setlength{\topmargin}{-12mm} \setlength{\headheight}{12pt} +\setlength{\headsep}{20pt} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +***** multicol +****** struct + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + struct columnsMulti { + string portrait; + string landscape; + } + auto multicol = columnsMulti(); +#+END_SRC + +****** portrait + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + multicol.portrait = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\usepackage{multicol} +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** landscape + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + multicol.landscape = ""; +#+END_SRC + +***** color links +****** struct + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + struct colorLinks { + string mono; + string color; + } + auto links = colorLinks(); +#+END_SRC + +****** mono + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + links.mono = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\usepackage[xetex, + colorlinks=true, + urlcolor=myblack, + filecolor=myblack, + linkcolor=myblack, +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +****** color + +#+name: output_latex_head_1_tex +#+BEGIN_SRC d + links.color = format(q"┃ +#+END_SRC + +#+name: output_latex_head_1_tex +#+BEGIN_SRC latex +\usepackage[xetex, + colorlinks=true, + urlcolor=myblue, %% \href{...}{...} external url + filecolor=mygreen, %% \href{...} local file + linkcolor=myred, %% \href{...} and \pageref{...} +#+END_SRC + +#+name: output_latex_head_1_format_string_variables +#+BEGIN_SRC d +┃", + ); +#+END_SRC + +**** latex head starts + +#+name: output_latex_head_0_format_string +#+BEGIN_SRC d + string _latex_head = format(q"┃%%%% DocReform LaTeX output +#+END_SRC + +***** description comment + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +%%%% Generated by: %s +%%%% D version: %s +%%%% LaTeX output last Generated on: %s +%%%% %s %s + +#+END_SRC + +***** paper type (a4, letter, ...; ( portrait | landscape )) + +- paper.a4_portrait +- paper.a4_landscape +- paper.us_letter_portrait +- paper.us_letter_landscape + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +%s +#+END_SRC + +***** paper margins (portrait | landscape) + +- margins.portrait +- margins.landscape + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +%s +#+END_SRC + +***** margin shared + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\setlength{\marginparsep}{4mm} +\setlength{\marginparwidth}{8mm} +#+END_SRC + +***** multicol (portrait | landscape) + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +%s +#+END_SRC + +***** language & font + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage{polyglossia, ucs, fontspec, xltxtra, xunicode} +\setmainlanguage{%s} +\setotherlanguage{%s} +\setmainfont{Liberation Sans} +\setmonofont[Scale=0.85]{Liberation Mono} +#+END_SRC + +%% \setsansfont{Liberation Sans} +%% \setromanfont{Liberation Serif} + +***** latex head + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage{alltt} +\usepackage{thumbpdf} +#+END_SRC + +***** color links: no = mono | yes = color + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +%s +#+END_SRC + +***** metadata + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex + pdftitle={%s}, + pdfauthor={%s}, + pdfsubject={%s}, + pdfkeywords={}, + pageanchor=true, + plainpages=true, + pdfpagelabels=true, + pagebackref, + bookmarks=true, + bookmarksopen=true, + pdfmenubar=true, + pdfpagemode=UseOutline, + pdffitwindow=true, + pdfwindowui=true, + plainpages=false, + pdfstartview=FitH +] +{hyperref} +#+END_SRC + +%% pdfusetitle=true, +%% pdfpagelayout=SinglePage, +%% pdfpagelayout=TwoColumnRight, +%% pdfpagelayout=TwoColumnLeft, +%% pdfstartpage=3, + +%%%% trace lost characters +%% \tracinglostchars = 1 +%% \tracingonline = 1 + +***** define colors + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage[usenames]{color} +\definecolor{myblack}{rgb}{0,0,0} +\definecolor{myred}{rgb}{0.75,0,0} +\definecolor{mygreen}{rgb}{0,0.5,0} +\definecolor{myblue}{rgb}{0,0,0.5} +\definecolor{mywhite}{rgb}{1,1,1} +#+END_SRC + +***** latex head + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage{url} +\urlstyle{sf} +#+END_SRC + +%%\usepackage{breakurl} + +***** latex head + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage{textcomp} +\usepackage[parfill]{parskip} +\usepackage[normalem]{ulem} +\usepackage{soul} +\usepackage{longtable} +\usepackage[tc]{titlepic} +\usepackage{graphicx} +\makeatletter +\parindent0pt +\usepackage{amssymb} +\usepackage{listings} +\usepackage{color} +\usepackage{textcomp} +\setcounter{secnumdepth}{2} +\setcounter{tocdepth}{4} +\makeatletter +#+END_SRC + +***** indent, bullet, list + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage[multiple,ragged]{footmisc} +\setlength\footnotemargin{12pt} +\usepackage[para]{manyfoot} +\DeclareNewFootnote{A} +\newenvironment{ParagraphIndent}[1]%% +{ +\begin{list}{}{%% +\setlength\topsep{0pt}%% +\addtolength{\leftmargin}{#1} +\setlength\parsep{0pt plus 1pt}%% +} +\item[] +} +{\end{list}} +\newenvironment{ParagraphHang}[2]%% +{ +\begin{list}{}{%% +\setlength\topsep{0pt}%% +\addtolength{\leftmargin}{#1} +\itemindent=#2 +\setlength\parsep{0pt plus 1pt}%% +} +\item[] +} +{\end{list}} +\newenvironment{Bullet}[1]%% +{ +\begin{list}{}{%% +\setlength\topsep{0pt}%% +\addtolength{\leftmargin}{#1} +\itemindent=-1em +\setlength\parsep{0pt plus 1pt}%% +} +\item[] +} +{\end{list}} +#+END_SRC + +%%\DeclareNewFootnote[para]{A} + +***** part, section, subsection, paragraph, subparagraph + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\usepackage{fancyhdr} +\lhead{} +\renewcommand{\part}{\@startsection + {part}{1}{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\bfseries\large\upshape\raggedright}} +\renewcommand{\section}{\@startsection + {section}{2}{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\bfseries\large\upshape\raggedright}} +\renewcommand{\subsection}{\@startsection + {subsection}{3}{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\bfseries\large\upshape\raggedright}} +\renewcommand{\subsubsection}{\@startsection + {subsubsection}{4}{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\normalfont\normalsize\bfseries\raggedright}} +\renewcommand{\paragraph}{\@startsection + {paragraph}{5}{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\normalfont\normalsize\itshape\raggedright}} +\renewcommand{\subparagraph}{\@startsection + {subparagraph}%%{6}%%{-2mm}%% + {-\baselineskip}{0.5\baselineskip}%% + {\normalfont\normalsize\itshape\raggedright}} +#+END_SRC + +%% \makeatother + +***** latex head misc. including defined commands + +#+name: output_latex_head_0_tex +#+BEGIN_SRC latex +\selectlanguage{%s} +\lhead[ ]{ } +\chead[ \fancyplain{} \bfseries \footnotesize \leftmark ]{ \fancyplain{} \bfseries \footnotesize \rightmark } +\rhead[ ]{ } +%s +\rfoot[\tiny \href{}{}]{\textrm{\thepage}} +\tolerance=300 +\clubpenalty=300 +\widowpenalty=300 +\makeatother +\makeatother +\chardef\txtbullet="2022 +\chardef\tilde="7E +\def\asterisk{{\rm \char42} } +\definecolor{Light}{gray}{.92} +\newcommand{\Codeblock}[1]{\normaltext\raggedright\small\ttfamily\texbackslash#1} +\newcommand{\monosp}[1]{\normaltext\ttfamily\texbackslash#1} +\newcommand{\parasep}{\\ \begin{center}*\hspace{2em}*\hspace{2em}*\end{center} \\} +\newcommand{\hardspace}{{~}} +\newcommand{\caret}{{\^{~}}} +\newcommand{\pipe}{{\textbar}} +\newcommand{\curlyopen}{{} +\newcommand{\curlyclose}{}} +\newcommand{\lt}{{UseTextSymbol{OML}{<}}} +\newcommand{\gt}{{UseTextSymbol{OML}{>}}} +\newcommand{\slash}{{/}} +\newcommand{\underscore}{\_} +\newcommand{\exclaim}{\Verbatim{!}} +\definecolor{listinggray}{gray}{0.9} +\definecolor{lbcolor}{rgb}{0.9,0.9,0.9} +\lstset{ + backgroundcolor=\color{lbcolor}, + tabsize=4, + rulecolor=, + language=, + basicstyle=\scriptsize, + upquote=true, + aboveskip={1.5\baselineskip}, + columns=fixed, + showstringspaces=false, + extendedchars=true, + breaklines=true, + prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, + frame=single, + showtabs=false, + showspaces=false, + showstringspaces=false, + identifierstyle=\ttfamily, + keywordstyle=\color[rgb]{0,0,1}, + commentstyle=\color[rgb]{0.133,0.545,0.133}, + stringstyle=\color[rgb]{0.627,0.126,0.941}, +} +#+END_SRC + +%%\chardef\asterisk="2A +%%\newcommand{\hardspace}{\hspace{.5em}} + +**** latex head format inclusions + +#+name: output_latex_head_0_format_string_variables +#+BEGIN_SRC d +┃", + doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.name_and_version.strip, + doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.compiler.strip, + doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.stime.strip, + doc_matters.generator_program.project_name.strip, + doc_matters.generator_program.url_home.strip, + paper.a4_portrait.strip, + margins.portrait.strip, + multicol.portrait.strip, + lang.codes[doc_matters.src.language]["xlp"], + "english", + links.mono.strip, // links.color.strip, + doc_matters.conf_make_meta.meta.title_full.strip, + doc_matters.conf_make_meta.meta.creator_author.strip, + doc_matters.conf_make_meta.meta.classify_subject.strip, + lang.codes[doc_matters.src.language]["xlp"], + _footer(doc_matters), +); +#+END_SRC + +**** latex head return + +#+name: output_latex_head_close +#+BEGIN_SRC d + return _latex_head.strip; +} +#+END_SRC + +*** ↻ latex body :content:body: +**** latex body function + +#+name: output_latex_body +#+BEGIN_SRC d +string latex_body(D,M)( + const D doc_abstraction, + M doc_matters, +) { + string _latex_body = ""; + bool _multicolumns = false; + string _txt; +#+END_SRC + +**** ↻ loop open + +#+name: output_latex_body +#+BEGIN_SRC d + foreach (part; doc_matters.has.keys_seq.latex) { + foreach (obj; doc_abstraction[part]) { + switch (obj.metainfo.is_of_part) { +#+END_SRC + +**** ↻ within loop +***** frontmatter + +#+name: output_latex_body +#+BEGIN_SRC d + case "frontmatter": assert(part == "head" || "toc"); + _txt = obj.text + .sp_char_esc(obj) + .fontface; + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + _txt = _txt.heading(obj, doc_matters); + goto default; + case "toc": + break; + default: + _latex_body ~= _txt ~ "\n\n"; + _txt = ""; + break; + } + break; + default: break; + } + break; +#+END_SRC + +***** body + +#+name: output_latex_body +#+BEGIN_SRC d + case "body": assert(part == "body" || "head"); // surprise + _txt = obj.text + .sp_char_esc(obj) + .fontface; + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + _txt = _txt.heading(obj, doc_matters); + goto default; + case "para": + _txt = _txt.para(obj) + .bullets_and_indentation(obj) + .links_and_images(obj, doc_matters); + goto default; + default: + _latex_body ~= _txt ~ "\n\n"; + _txt = ""; + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + goto default; // TODO + case "group": + /+ (hardspaces not honored) [remove any hardspace marker] +/ + _txt = _txt.group(obj, doc_matters) + .links_and_images(obj, doc_matters); + goto default; + case "block": + /+ (hardspace honored) \hardspace +/ + _txt = _txt.block(obj, doc_matters) + .links_and_images(obj, doc_matters); + goto default; + case "verse": + /+ (hardspace honored) \hardspace +/ + _txt = _txt.verse(obj, doc_matters) + .links_and_images(obj, doc_matters); + goto default; + case "code": + /+ (hardspace honored) \begin{lstlisting} clear hardspace marker +/ + _txt = _txt.codeblock(obj, doc_matters); + goto default; + case "table": + _txt = _txt.table(obj, doc_matters); + goto default; // TODO + default: + _latex_body ~= _txt ~ "\n\n"; + _txt = ""; + break; + } + break; + default: break; + } + break; +#+END_SRC + +***** backmatter + +#+name: output_latex_body +#+BEGIN_SRC d + case "backmatter": + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + _txt = obj.text + .sp_char_esc(obj) + .fontface; + switch (obj.metainfo.is_of_type) { + case "para": + if (part != "bookindex" && _multicolumns) { + _multicolumns = false; + _latex_body ~= "\n\\end{multicols}\n"; + } + switch (obj.metainfo.is_a) { + case "heading": + if (part == "bookindex") { + _multicolumns = true; + } + _txt = _txt.heading(obj, doc_matters, part); + goto default; + case "endnote": assert(part == "endnotes"); + _txt = _txt.para(obj) + .bullets_and_indentation(obj) + .links_and_images(obj, doc_matters); + goto default; + case "glossary": assert(part == "glossary"); + _txt = _txt.para(obj) + .bullets_and_indentation(obj) + .links_and_images(obj, doc_matters); + goto default; + case "bibliography": assert(part == "bibliography"); + _txt = _txt.para(obj) + .bullets_and_indentation(obj); + goto default; + case "bookindex": assert(part == "bookindex"); + /+ two column, special section +/ + _txt = _txt.bookindex(obj) + .links_and_images(obj, doc_matters); + goto default; + case "blurb": assert(part == "blurb"); + _txt = _txt.para(obj) + .bullets_and_indentation(obj) + .links_and_images(obj, doc_matters); + goto default; + default: + _latex_body ~= (part == "bookindex" && obj.metainfo.is_a != "heading") + ? _txt : (_txt ~ "\n\n"); + _txt = ""; + break; + } + break; + default: break; + } + break; +#+END_SRC + +***** after + +#+name: output_latex_body +#+BEGIN_SRC d + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + } + break; + } + } + } + if (_multicolumns) { + _multicolumns = false; + _latex_body ~= "\n\\end{multicols}\n"; + } +#+END_SRC + +**** latex body return + +#+name: output_latex_body +#+BEGIN_SRC d + return _latex_body; +} +#+END_SRC + +*** latex tail :tail: +**** latex tail function + +#+name: output_latex_tail +#+BEGIN_SRC d +string latex_tail(M)( + M doc_matters, +) { +#+END_SRC + +**** latex tail starts + +#+name: output_latex_tail +#+BEGIN_SRC d + string _latex_tail = format(q"┃ +#+END_SRC + +***** latex tail format inclusions + + +***** latex document end + +#+name: output_latex_tail_tex +#+BEGIN_SRC latex + +\end{document} +#+END_SRC + +**** latex tail format inclusions + +#+name: output_latex_tail_close +#+BEGIN_SRC d +┃", + // doc_matters.conf_make_meta.meta.title_full, + // doc_matters.conf_make_meta.meta.creator_author, +); +#+END_SRC + +**** latex tail return + +#+name: output_latex_tail_close +#+BEGIN_SRC d + return _latex_tail; +} +#+END_SRC + +* latex system command helper script +** latex command, ruby script + +#+BEGIN_SRC ruby :tangle "../util/dr_tex.rb" :tangle-mode (identity #o755) :shebang #!/usr/bin/env ruby +require 'fileutils' +pwd = Dir.pwd +argv,texfiles_with_path,flags=[],[],[] +lngs = %{(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)} +Regexp.new(lngs, Regexp::IGNORECASE) +argv=$* +argv.sort.each{|y| (y =~/^--\S+$/i) ? (flags << y) : (texfiles_with_path << y) } +if flags.length==0 \ +|| flags.inspect =~/"--help"/ + cmd=(/([^\/]+)$/).match($0)[1] + puts < 0 + texfiles_with_path.each do |texfile_with_path| + if texfile_with_path =~/.+\.tex/ + #puts texfile_with_path + if FileTest.file?(texfile_with_path) + file_basename_with_path = texfile_with_path.sub(/\.tex$/,'') + file_basename = file_basename_with_path.sub(/.*?([^\/]+)$/,'\1') + _out_path = out_path + if file_basename =~ /\.#{lngs}$/ + lng = file_basename.match(/\.#{lngs}$/)[1] + puts file_basename + puts lng + puts _out_path + unless _out_path.match(/\/#{lng}\/pdf$/) + _out_path = "#{out_path}/#{lng}/pdf" + FileUtils::mkdir_p(_out_path) + end + end + texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex -papersize=#{paper_size} #{texfile_with_path}\n} + puts texpdf_cmd + 2.times { |i| system(texpdf_cmd) } + if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path)) + FileUtils::Verbose::mv(%{#{pwd}/#{file_basename}.pdf}, %{#{_out_path}/#{file_basename}.pdf}) + puts (%{#{_out_path}/#{file_basename}.pdf}) + else + puts "issue with pdf file or output directory" + puts "pdf file: #{pwd}/#{file_basename}.pdf}" + puts "output dir: #{_out_path}/" + end + suffix = ['log', 'out', 'toc', 'aux'] + suffix.each { |s| FileUtils::rm_f(%{#{pwd}/#{file_basename}.#{s}})} + end + end + end +end +Dir.chdir(pwd) +__END__ +#+END_SRC diff --git a/org/out_odt.org b/org/out_odt.org new file mode 100644 index 0000000..0a7f93d --- /dev/null +++ b/org/out_odt.org @@ -0,0 +1,2517 @@ +-*- mode: org -*- +#+TITLE: doc_reform output odt +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:xml:odt: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* odt :odt: + +- cover object types +- zip contents +- xml closures? unnecessary, this is sax rather than dom no? + +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| function | filename | module | variable | output_odt | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| identify doc filetype | mimetype | odt_mimetypes | mimetypes | output_odt_fixed | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| doc manifest | manifest.rdf | | | output_odt_fixed | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| settings | settings.xml | outputODTsettings | | output_odt_fixed | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| doc xml styles | styles.xml | outputODTstyles | | output_odt_fixed | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| identify doc root * (imagelist) | META-INF/manifest.xml | odt_container_xml | meta_inf_container_xml | | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| doc content * | content.xml | odt_content | content_odt | | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| images * | Pictures/ | | | copy_odt_images | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| +| doc meta * (timestamp) | meta.xml | odt_metadata | | | +|---------------------------------+-----------------------+-------------------+------------------------+------------------| + +** _module template_ :odf:odt:module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/odt.d" :noweb yes +module doc_reform.output.odt; +template formatODT() { + <> + mixin DocReformOutputRgxInit; + struct formatODT { + static auto rgx = Rgx(); + <> + } +} +template outputODT() { + <> + mixin InternalMarkup; + mixin DocReformOutputRgxInit; + auto rgx = Rgx(); + // mixin outputXmlODT; + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> + <> +} +#+END_SRC + +** odt format objects +*** detail +**** odf structure + +- unless code + - images + - links + - internal / relative + - external + +**** object attrib +***** tags + +#+name: odt_format_objects +#+BEGIN_SRC d +string _tags(O)(const O obj){ + string _tags = ""; + if (obj.tags.anchor_tags.length > 0) { + foreach (tag_; obj.tags.anchor_tags) { + if (tag_.length > 0) { + _tags ~= format(q"┃ + + + +┃", + _special_characters(tag_, obj), + _special_characters(tag_, obj), + ); + } + } + } + return _tags; +} +#+END_SRC + +****** anchor tags + +#+name: odt_format_objects +#+BEGIN_SRC d +string _xhtml_anchor_tags(O)(O obj) { + const(string[]) anchor_tags = obj.tags.anchor_tags; + string tags=""; + if (anchor_tags.length > 0) { + foreach (tag; anchor_tags) { + if (!(tag.empty)) { + tags ~= ""; + } + } + } + return tags; +} +#+END_SRC + +***** ocn object number display + +#+name: odt_format_objects +#+BEGIN_SRC d +string obj_num(O)(const O obj){ // TODO + string _on; + _on = (obj.metainfo.object_number.empty) + ? "" + : (format(q"┃ + 「%s」┃", + obj.metainfo.object_number, + )); + return _on; +} +#+END_SRC + +***** footnotes + +#+name: odt_format_objects +#+begin_src d +string _footnotes()(string _txt){ + static auto rgx = Rgx(); + _txt = _txt.replaceAll( + rgx.inline_notes_al_regular_number_note, + format(q"┃ + + %s + + + + %s + + +┃", + "$1", "$1", "$2", + ) + ); + return _txt; +} +#+end_src + +***** bullet + +#+name: odt_format_objects +#+BEGIN_SRC d +string _bullet(O)(const O obj){ + string _b = ""; + if (obj.attrib.bullet) { + _b = format(q"┃● ┃",); + } + return _b; +} +#+END_SRC + +***** para (with bullet, indent levels, footnotes extracted) + +#+name: odt_format_objects +#+BEGIN_SRC d +string _indent(O)(string _txt, const O obj) { // TODO + // if (obj.attrib.indent_base > 0 || + // obj.attrib.indent_hang > 0 + // ) { + if (obj.metainfo.is_a == "toc") { + _txt = format(q"┃ +%s + %s%s%s +┃", + (obj.attrib.indent_base < 4) + ? "\n " : "", + obj.attrib.indent_base, + obj.attrib.indent_base, + _tags(obj), + _txt, + obj_num(obj), + ); + } else if (!empty(obj.metainfo.object_number)) { + if (obj.attrib.indent_base == 0 && obj.attrib.indent_hang == 0) { + _txt = format(q"┃ +%s + + + + + %s%s%s +┃", + _bullet(obj), + obj.metainfo.object_number, + obj.metainfo.object_number, + _tags(obj), + _txt, + obj_num(obj), + ); + } else if (obj.attrib.indent_base == obj.attrib.indent_hang) { + _txt = format(q"┃ +%s + + + + + %s%s%s +┃", + obj.attrib.indent_base, + _bullet(obj), + obj.metainfo.object_number, + obj.metainfo.object_number, + _tags(obj), + _txt, + obj_num(obj), + ); + } else { + _txt = format(q"┃ +%s + + + + + %s%s%s +┃", + obj.attrib.indent_base, + obj.attrib.indent_hang, + _bullet(obj), + obj.metainfo.object_number, + obj.metainfo.object_number, + _tags(obj), + _txt, + obj_num(obj), + ); + } + } else { + if (obj.attrib.indent_base == 0 && obj.attrib.indent_hang == 0) { /+ can omit and would explicitly set indent base and hang as 0 each below +/ + _txt = format(q"┃ +%s + %s%s%s +┃", + _bullet(obj), + _tags(obj), + _txt, + obj_num(obj), + ); + } else if (obj.attrib.indent_base == obj.attrib.indent_hang) { + _txt = format(q"┃ +%s + %s%s%s +┃", + obj.attrib.indent_base, + _bullet(obj), + _tags(obj), + _txt, + obj_num(obj), + ); + } else { + _txt = format(q"┃ +%s + %s%s%s +┃", + _bullet(obj), + obj.attrib.indent_base, + obj.attrib.indent_hang, + _tags(obj), + _txt, + obj_num(obj), + ); + } + } + return _txt; +} +#+END_SRC + +***** block type + +#+name: odt_format_objects +#+BEGIN_SRC d +string _block_type_delimiters(O)(string[] _block_lines, const O obj) { // TODO + string _block = ""; + foreach (i, _line; _block_lines) { + _line = _footnotes(_line); + if (i == 0) { + _block ~= format(q"┃ +%s + + + + + %s +┃", + _bullet(obj), + obj.metainfo.object_number, + obj.metainfo.object_number, + // _tags(obj), + _line, + ); + } else { + _block ~= format(q"┃ +%s┃", + _line); + } + } + _block ~= format(q"┃ + + 「%s」 + +┃", + obj_num(obj)); + return _block; +} +#+END_SRC + +**** object inline + +***** special characters + +#+name: odt_format_objects +#+BEGIN_SRC d +string _special_characters(O)(string _txt, const O obj) { + _txt = _txt + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_quotation, """) + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.nbsp_char, " "); + return _txt; +} +#+END_SRC + +***** preserve white space + +#+name: odt_format_objects +#+BEGIN_SRC d +string _preserve_white_spaces(O)(string _txt, const O obj) { + if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { + _txt = _txt + .replaceAll(rgx.space, " "); + } + return _txt; +} +#+END_SRC + +***** font_face + +#+name: odt_format_objects +#+BEGIN_SRC d +string _font_face(string _txt){ + _txt = _txt + .replaceAll(rgx.inline_strike, "$1") + .replaceAll(rgx.inline_insert, "$1") + .replaceAll(rgx.inline_cite, "$1") + .replaceAll(rgx.inline_emphasis, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_bold, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_italics, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_underscore, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_superscript, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_subscript, format(q"┃%s┃","$1")) + .replaceAll(rgx.inline_mono, format(q"┃%s┃","$1")); + return _txt; +} +#+END_SRC + +***** object number + +#+name: odt_format_objects +#+BEGIN_SRC d +auto _obj_num(O)(O obj) { // NOT USED YET + struct objNum { + string reference() { + return format(q"┃ + + + ┃", + obj.object_number, + obj.object_number, + ); + } + string display() { + return format(q"┃ + %s%s%s + ┃", + on_o, + obj.object_number, + on_c, + ); + } + } + return objNum(); +} +#+END_SRC + +***** break page + +#+name: odt_format_objects +#+BEGIN_SRC d +string _break_page()() { + return format(q"┃ + +┃", + ); +} +#+END_SRC + +#+BEGIN_SRC d +string _break_page()() { + return format(q"┃ + +┃", + ); +} +#+END_SRC + +***** empty lines break + +#+name: odt_format_objects +#+BEGIN_SRC d +string _empty_line_break(O)(string _txt, const O obj) { + if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { + _txt = _txt + .replaceAll(rgx.br_empty_line, "
"); + } + return _txt; +} +#+END_SRC + +***** links: url, mail + +#+name: odt_format_objects +#+BEGIN_SRC d +string _links(O)(string _txt, const O obj) { + if (obj.metainfo.is_a != "code") { + if (obj.metainfo.is_a == "toc") { + _txt = replaceAll!(m => + m[1] ~ "┤" + ~ (replaceAll!(n => + n["type"] ~ n["path"] ~ (n["file"].encodeComponent) + )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) + ~ "├" + )(_txt, rgx.inline_link_number_only) + .replaceAll(rgx.inline_link, + format(q"┃%s┃", + _special_characters("$3", obj), + _special_characters("$1", obj) + )); + } else { + _txt = replaceAll!(m => + m[1] ~ "┤" + ~ (replaceAll!(n => + n["type"] ~ n["path"] ~ (n["file"].encodeComponent) + )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) + ~ "├" + )(_txt, rgx.inline_link_number_only) + .replaceAll(rgx.inline_link, + format(q"┃%s┃", + _special_characters("$2", obj), + _special_characters("$1", obj) + )); + } + } + debug(links) { + if (obj.text.match(rgx.inline_link_number) + && _txt.match(rgx.inline_link_number_only) + ) { + writeln(">> ", _txt); + writeln("is_a: ", obj.metainfo.is_a); + } + } + return _txt; +} +#+END_SRC + +***** image + +#+name: odt_format_objects +#+BEGIN_SRC d +string _images(O)(string _txt, const O obj) { + if (_txt.match(rgx.inline_image)) { + _txt = _txt + .replaceAll(rgx.inline_image, + ("$1 $6")) + .replaceAll( + rgx.inline_link_empty, + ("$1")); + } + return _txt; +} +#+END_SRC + +**** markup hub (including font face) + +#+name: odt_format_objects +#+BEGIN_SRC d +string markup(O)(const O obj) { + /+ markup TODO +/ + string _txt = obj.text; + _txt = _special_characters(_txt, obj); // TODO & why both obj & obj.text, consider also in output_xmls.org + if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { + _txt = replaceAll!(m => _preserve_white_spaces(m[1], obj))(_txt, rgx.spaces_keep); + } // check that this does what you want, keep: leading spaces (indent) & more than single spaces within text + // _txt = _preserve_white_spaces(_txt, obj); // (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") + _txt = _font_face(_txt); + _txt = _images(_txt, obj); // (obj.metainfo.is_a != "code") + _txt = _links(_txt, obj); // (obj.metainfo.is_a != "code") + _txt = _empty_line_break(_txt, obj); // (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") + return _txt; +} +#+END_SRC + +*** objects +**** para type +***** heading + +#+name: odt_format_objects +#+BEGIN_SRC d +string heading(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "heading"); + string _o_txt_odt = markup(obj); + if (obj.metainfo.dummy_heading + && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { + _o_txt_odt = ""; + } else if (obj.metainfo.is_a == "toc") { + _o_txt_odt = format(q"┃%s + %s%s%s +┃", + _break_page, + obj.metainfo.heading_lev_markup, + obj.metainfo.heading_lev_markup, + _tags(obj), + _o_txt_odt, + obj_num(obj), + ); + } else { + _o_txt_odt = _footnotes(_o_txt_odt); + _o_txt_odt = format(q"┃%s + + + + + %s%s%s +┃", + _break_page, + obj.metainfo.heading_lev_markup, + obj.metainfo.heading_lev_markup, + obj.metainfo.object_number, + obj.metainfo.object_number, + _tags(obj), + _o_txt_odt, + obj_num(obj), + ); + } + return _o_txt_odt; +} +#+END_SRC + +***** para + +#+name: odt_format_objects +#+BEGIN_SRC d +string para(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + string _o_txt_odt; + if (obj.metainfo.dummy_heading + && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { + _o_txt_odt = ""; + } else { + _o_txt_odt = markup(obj); + _o_txt_odt = _footnotes(_o_txt_odt); + _o_txt_odt = _indent(_o_txt_odt, obj); // final setting? + } + return _o_txt_odt; +} +#+END_SRC + +**** block type +***** quote + +#+name: odt_format_objects +#+BEGIN_SRC d +string quote(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "quote"); + string _o_txt_odt = markup(obj); + _o_txt_odt = _footnotes(_o_txt_odt); // decide + return _o_txt_odt; +} +#+END_SRC + +***** group +- group delimiter + - preserves double newlines (paragraph delimiter) +- the "group" delimiter is different from the "block" delimiter in that groups do not preserve whitespace, the "block" mark does + +#+name: odt_format_objects +#+BEGIN_SRC d +string group(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "group"); + string _o_txt_odt = markup(obj); + /+ TODO + - split lines + - only double newlines (paragraph delimiter), (not line breaks, single new lines) + - no hard space indentation + +/ + string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); + _o_txt_odt = _block_type_delimiters(_block_lines, obj); + return _o_txt_odt; +} +#+END_SRC + +***** block +- block delimiter + - preserves spaces + - preserves newlines +- the "block" delimiter is different from the "group" delimiter, in that blocks preserve whitespace, the "group" mark does not + +- + - split lines + - each line including empty lines + - hard space indentation + - "^[ ]"   + - count number only at beginning of line and replace each + +#+name: odt_format_objects +#+BEGIN_SRC d +string block(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "block"); + string _o_txt_odt = markup(obj); + string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); + _o_txt_odt = _block_type_delimiters(_block_lines, obj); + return _o_txt_odt; +} +#+END_SRC + +***** verse +- poem delimiters + - creates verses where double newlines occur (paragraph delimiter) + - preserves spaces + - preserves newlines + +#+name: odt_format_objects +#+BEGIN_SRC d +string verse(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "verse"); + string _o_txt_odt = markup(obj); + string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); + _o_txt_odt = _block_type_delimiters(_block_lines, obj); + return _o_txt_odt; +} +#+END_SRC + +***** code + +#+name: odt_format_objects +#+BEGIN_SRC d +string code(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "code"); + string _o_txt_odt = markup(obj); + /+ TODO + - split lines + - each line including empty lines + - hard space indentation + - "^[ ]"   + - count number only at beginning of line and replace each + +/ + string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); + string _block = ""; + foreach (i, _line; _block_lines) { + if (i == 1) { + _block ~= format(q"┃ + + + + + +%s +┃", + obj.metainfo.object_number, + obj.metainfo.object_number, + _line, + ); + } else { + _block ~= format(q"┃ +%s┃", + _line); + } + } + _block ~= format(q"┃ + + 「%s」 + +┃", + obj_num(obj)); + _o_txt_odt = _block; + return _o_txt_odt; +} +#+END_SRC + +***** table +****** tablarize + +#+name: odt_format_objects +#+BEGIN_SRC d +auto tablarize(O)( + const O obj, + string _txt, +) { + string[] _table_rows = (_txt).split(rgx.table_delimiter_row); + string[] _table_cols; + string _table; + string _tablenote; + foreach(row_idx, row; _table_rows) { + _table_cols = row.split(rgx.table_delimiter_col); + _table ~= ""; + foreach(col_idx, cell; _table_cols) { + if ((_table_cols.length == 1) + && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) + _tablenote ~= cell; + } else { + _table ~= format(q"┃ + +%s + +┃", + (row_idx == 0 && obj.table.heading) ? "Table_Heading" : "P_table_cell", + cell, + ); + } + } + _table ~= ""; + } + auto t = tuple( + _table, + _tablenote, + ); + return t; +} +#+END_SRC + +****** table + +#+name: odt_format_objects +#+BEGIN_SRC d +int _table_number = 0; +string table(O,M)( + const O obj, + const M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "table"); + string _o_txt_odt = markup(obj); + auto t = tablarize(obj, _o_txt_odt); + string _note = t[1]; + _o_txt_odt = format(q"┃ + + + + + + + %s + + + 「%s」 +┃", + _table_number++, + obj.metainfo.object_number, + obj.metainfo.object_number, + obj.table.number_of_columns, + t[0], + obj.metainfo.object_number, + // _note, + ); + return _o_txt_odt; +} +#+END_SRC + +** write odt output :odf:odt:out: + +#+name: output_odt +#+BEGIN_SRC d +void writeOutputODT(W,I)( + const W odt_content, + I doc_matters, +) { + auto pth_odt = DocReformPathsODT!()(doc_matters); + auto fn_odt = pth_odt.odt_file; + auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); + void ODTzip()(string contents, string fn) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + (doc_matters.opt.action.debug_do) + ? zip_data.write(contents.dup) + : zip_data.write(contents.dup + .replaceAll(rgx.spaces_line_start, "") + .replaceAll(rgx.newline, "") + .strip + ); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_odt, zip.build()); + } + try { + if (!exists(pth_odt.base_pth)) { // check + pth_odt.base_pth.mkdirRecurse; + } + string fn; + File f; + { fn = pth_odt.mimetype("zip"); + ODTzip(odt_content.mimetype, fn); + } + { fn = pth_odt.manifest_rdf("zip"); + ODTzip(odt_content.manifest_rdf, fn); + } + { fn = pth_odt.settings_xml("zip"); + ODTzip(odt_content.settings_xml, fn); + } + { fn = pth_odt.styles_xml("zip"); + ODTzip(odt_content.styles_xml, fn); + } + { fn = pth_odt.content_xml("zip"); + ODTzip(odt_content.content_xml, fn); + } + { fn = pth_odt.manifest_xml("zip"); + ODTzip(odt_content.manifest_xml, fn); + } + { fn = pth_odt.meta_xml("zip"); + ODTzip(odt_content.meta_xml, fn); + } + { /+ (images) +/ + foreach (image; doc_matters.srcs.image_list) { + auto fn_src = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_out = pth_odt.image_dir("zip") ~ "/" ~ 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_odt, zip.build()); + } + } + } + } + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_odt.odt_file); + } + } catch (ErrnoException ex) { + // Handle error + } + if (doc_matters.opt.action.debug_do) { + pth_odt.mimetype("fs"); /+ (mimetype) +/ + pth_odt.manifest_rdf("fs"); /+ (manifest.rdf) +/ + pth_odt.settings_xml("fs"); /+ (settings.xml) +/ + pth_odt.styles_xml("fs"); /+ (styles_xml) +/ + + pth_odt.content_xml("fs"); + pth_odt.manifest_xml("fs"); + pth_odt.meta_xml("fs"); + } +} +#+END_SRC + +** odt output hub [#A] :odf:odt:out: + +#+name: output_odt +#+BEGIN_SRC d +void outputODT(D,I)( + const D doc_abstraction, + I doc_matters, +) { + struct ODT { + /+ fixed output +/ + string mimetype; + string manifest_rdf; + string settings_xml; + string styles_xml; + /+ variable output +/ + string content_xml; // substantive content + string manifest_xml; // image list changes + string meta_xml; // time stamp + } + // auto pth_odt = DocReformPathsODT!()(doc_matters); + auto odt = ODT(); + odt.mimetype = mimetype; + odt.manifest_rdf = manifest_rdf; + odt.settings_xml = settings_xml; + odt.styles_xml = styles_xml; + odt.content_xml = content_xml(doc_abstraction, doc_matters); + odt.manifest_xml = manifest_xml(doc_matters); + odt.meta_xml = meta_xml(doc_matters); + odt.writeOutputODT(doc_matters); + dirtree(doc_matters); + images_cp(doc_matters); // copy images +} +#+END_SRC + +* stuff +** shared +*** output imports + +#+name: output_imports +#+BEGIN_SRC d +import doc_reform.output; +import + std.digest.sha, + std.file, + std.outbuffer, + std.uri, + std.zip, + std.conv : to; +import + doc_reform.output.create_zip_file, + doc_reform.output.xmls, + doc_reform.output.xmls_css; +#+END_SRC + +*** make directory tree + +#+name: output_odt_fixed_dirtree +#+BEGIN_SRC d +void dirtree(I)( + I doc_matters, +) { + auto pth_odt = DocReformPathsODT!()(doc_matters); + if (doc_matters.opt.action.debug_do) { /+ (dir tree) +/ + if (!exists(pth_odt.meta_inf_dir("fs"))) { + pth_odt.meta_inf_dir("fs").mkdirRecurse; + } + if (!exists(pth_odt.image_dir("fs"))) { + pth_odt.image_dir("fs").mkdirRecurse; + } + } + if (!exists(pth_odt.base_pth)) { + pth_odt.base_pth.mkdirRecurse; + } + // return 0; +} +#+END_SRC + +** fixed items +*** mimetype :mimetype: + +#+name: output_odt_fixed_mimetype +#+BEGIN_SRC d +string mimetype() { + string mimetype_ = format(q"┃application/vnd.oasis.opendocument.text┃"); + return mimetype_; +} +#+END_SRC + +*** manifest.rdf :manifest_rdf: + +#+name: output_odt_fixed_manifest_rdf +#+BEGIN_SRC d +string manifest_rdf() { + string _manifest_rdf = format(q"┃ +#+END_SRC + +#+name: output_odt_fixed_manifest_rdf +#+BEGIN_SRC xml + + + + + + + + + + + + + + + + + +#+END_SRC + +#+name: output_odt_fixed_manifest_rdf +#+BEGIN_SRC d +┃"); + return _manifest_rdf; +} +#+END_SRC + +*** settings.xml :settings: + +#+name: output_odt_fixed_settings_xml +#+BEGIN_SRC d +string settings_xml() { + string _settings_xml = format(q"┃ +#+END_SRC + +#+name: output_odt_fixed_settings_xml +#+BEGIN_SRC xml + + + + 0 + 0 + 0 + 0 + true + false + + + view2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + true + 100 + false + + + + + true + false + false + true + true + false + true + false + false + + false + false + false + true + true + 0 + false + false + false + false + true + false + false + false + false + true + true + false + false + true + false + true + false + high-resolution + 1 + 0 + true + + + false + true + + false + true + false + true + false + true + false + + true + true + false + true + true + true + false + false + + false + 0 + false + false + true + true + + + +#+END_SRC + +#+name: output_odt_fixed_settings_xml +#+BEGIN_SRC d +┃"); + return _settings_xml; +} +#+END_SRC + +*** styles.xml :styles_xml: + +#+name: output_odt_fixed_styles_xml +#+BEGIN_SRC d +string styles_xml() { + string _styles_xml = format(q"┃ +#+END_SRC + +#+name: output_odt_fixed_styles_xml +#+BEGIN_SRC xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#+END_SRC + +#+name: output_odt_fixed_styles_xml +#+BEGIN_SRC d +┃"); + return _styles_xml; +} +#+END_SRC + +** moving parts +*** ↻ content.xml TODO :content_xml: +**** content head +***** head open + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +string odt_head(I)(I doc_matters) { + string _has_tables = format(q"┃ +#+END_SRC + +***** if table include within head + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#+END_SRC + +***** head + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +┃",); + string _odt_head = format(q"┃ +#+END_SRC + +***** head xml + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC xml + + + + + + + + + + + + + + %s + + + + + + + + + + + + + +#+END_SRC + +***** head close + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +┃", + (doc_matters.has.tables > 0) ? _has_tables : "", +); + return _odt_head; +} +#+END_SRC + +**** ↻ content body +***** body open + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +string odt_body(D,I)( + const D doc_abstraction, + I doc_matters, +) { + mixin formatODT; + auto odt_format = formatODT(); + string delimit = ""; + string doc_odt = ""; + string _txt = ""; +#+END_SRC + +***** ↻ the loop & outer switch (sections & objects) format output + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d + foreach (part; doc_matters.has.keys_seq.scroll) { + foreach (obj; doc_abstraction[part]) { + switch (obj.metainfo.is_of_part) { +#+END_SRC + +****** frontmatter + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d + case "frontmatter": assert(part == "head" || "toc"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + _txt = delimit ~ odt_format.heading(obj, doc_matters); + goto default; + case "toc": + _txt = odt_format.para(obj, doc_matters); + goto default; + default: + doc_odt ~= _txt; + _txt = ""; + break; + } + break; + default: break; + } + break; +#+END_SRC + +****** body + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d + case "body": assert(part == "body" || "head"); // surprise + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + _txt = delimit ~ odt_format.heading(obj, doc_matters); + goto default; + case "para": + _txt = odt_format.para(obj, doc_matters); + goto default; + default: + doc_odt ~= _txt; + _txt = ""; + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + _txt = odt_format.quote(obj, doc_matters); + goto default; + case "group": + _txt = odt_format.group(obj, doc_matters); + goto default; + case "block": + _txt = odt_format.block(obj, doc_matters); + goto default; + case "verse": + _txt = odt_format.verse(obj, doc_matters); + goto default; + case "code": + _txt = odt_format.code(obj, doc_matters); + goto default; + case "table": + _txt = odt_format.table(obj, doc_matters); + goto default; + default: + doc_odt ~= _txt; + _txt = ""; + break; + } + break; + default: break; + } + break; +#+END_SRC + +****** backmatter + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d + case "backmatter": + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + _txt = delimit ~ odt_format.heading(obj, doc_matters); + goto default; + case "endnote": assert(part == "endnotes"); + _txt = odt_format.para(obj, doc_matters); + goto default; + case "glossary": assert(part == "glossary"); + _txt = odt_format.para(obj, doc_matters); + goto default; + case "bibliography": assert(part == "bibliography"); + _txt = odt_format.para(obj, doc_matters); + goto default; + case "bookindex": assert(part == "bookindex"); + _txt = odt_format.para(obj, doc_matters); + goto default; + case "blurb": assert(part == "blurb"); + _txt = odt_format.para(obj, doc_matters); + goto default; + default: + doc_odt ~= _txt; + _txt = ""; + break; + } + break; + default: break; + } + break; + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + } + break; +#+END_SRC + +***** closings & post loop + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d + } + } + } + return doc_odt; +} +#+END_SRC + +**** content book index? + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +#+END_SRC + +**** content tail + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +string odt_tail() { + string _odt_tail = format(q"┃DocReform: <www.doc_reform.org> and <www.sisudoc.org> +┃",); + return _odt_tail; +} +#+END_SRC + +**** hub + +#+name: output_odt_variable_content_xml +#+BEGIN_SRC d +string content_xml(D,I)( + const D doc_abstraction, + I doc_matters, +) { + string _content_xml; + string break_line = (doc_matters.opt.action.debug_do) ? "\n" : ""; + string odt_break_page = format(q"┃┃",); + string br_pg = format(q"┃┃",); + _content_xml ~= odt_head(doc_matters); + _content_xml ~= odt_body(doc_abstraction, doc_matters); + _content_xml ~= odt_tail; + return _content_xml; +} +#+END_SRC + +*** manifest.xml (images list changes) :manifest_xml: + - META-INF/manifest.xml + - image list changes + +#+name: output_odt_variable_manifest_xml +#+BEGIN_SRC d +string manifest_xml(M)( + auto ref M doc_matters, +) { + string _bullet = format(q"┃┃"); + string[] _images = [ _bullet ]; + foreach (image; doc_matters.srcs.image_list) { + _images ~= format(q"┃ ┃", image); + } + string _manifest_xml = format(q"┃ +#+END_SRC + +#+name: output_odt_variable_manifest_xml +#+BEGIN_SRC xml + + + + + %s + + + + + +#+END_SRC + +#+name: output_odt_variable_manifest_xml +#+BEGIN_SRC d +┃", +_images.join("\n"), +); + return _manifest_xml; +} +#+END_SRC + +*** meta.xml (time stamp) :meta_xml: + +#+name: output_odt_variable_meta_xml +#+BEGIN_SRC d +string meta_xml(M)( + auto ref M doc_matters, +) { + /+ (meta_xml includes output time-stamp) +/ + string _meta_xml = format(q"┃ +#+END_SRC + +#+name: output_odt_variable_meta_xml +#+BEGIN_SRC xml + + + %s + %s + %s + en-US + + +#+END_SRC + +#+name: output_odt_variable_meta_xml +#+BEGIN_SRC d +┃", +doc_matters.generator_program.name_and_version, +doc_matters.generated_time, +doc_matters.generated_time, +); + return _meta_xml; +} +#+END_SRC + +*** copy images :images: + +#+name: output_odt_variable_copy_odt_images +#+BEGIN_SRC d +void images_cp(M)( + auto ref M doc_matters, +) { + { /+ (copy odt images) +/ + auto pth_odt = DocReformPathsODT!()(doc_matters); + foreach (image; doc_matters.srcs.image_list) { + auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_src_out_file = pth_odt.image_dir("fs") ~ "/" ~ image; + auto fn_src_out_zip = pth_odt.image_dir("zip") ~ "/" ~ image; + if (exists(fn_src_in)) { + if (doc_matters.opt.action.debug_do) { + if (doc_matters.opt.action.debug_do) { + fn_src_in.copy(fn_src_out_file); + } + } + } + } + } + // return 0; +} +#+END_SRC diff --git a/org/out_sqlite.org b/org/out_sqlite.org new file mode 100644 index 0000000..7115a41 --- /dev/null +++ b/org/out_sqlite.org @@ -0,0 +1,1931 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) output sqlite +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:db:sql:sqlite: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* sql +** _module, templates_ :module: +*** hub +**** collection + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +module doc_reform.output.sqlite; +<> +import d2sqlite3; +import std.typecons : Nullable; +mixin DocReformOutputRgxInit; +mixin InternalMarkup; +static auto rgx = Rgx(); +static auto mkup = InlineMarkup(); +long _metadata_tid_lastrowid; +template SQLiteHubBuildTablesAndPopulate() { + void SQLiteHubBuildTablesAndPopulate(D,M)( + const D doc_abstraction, + M doc_matters, + ) { + auto pth_sqlite = DocReformPathsSQLite!()(doc_matters.sqlite.filename, doc_matters.output_path); + pth_sqlite.base.mkdirRecurse; + auto db = Database(pth_sqlite.sqlite_file); + template SQLiteDbStatementComposite() { + void SQLiteDbStatementComposite(Db,D,M)( + Db db, + const D doc_abstraction, + M doc_matters, + ) { + <> + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_sqlite.sqlite_file); + } + } + } + SQLiteDbStatementComposite!()(db, doc_abstraction, doc_matters); + } +} +#+END_SRC + +**** discrete + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteHubDiscreteBuildTablesAndPopulate() { + void SQLiteHubDiscreteBuildTablesAndPopulate(D,M)( + const D doc_abstraction, + M doc_matters, + ) { + auto url_html = DocReformUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + auto pth_sqlite = DocReformPathsSQLiteDiscrete!()(doc_matters.output_path, doc_matters.src.language); + pth_sqlite.base.mkdirRecurse; + auto db = Database(pth_sqlite.sqlite_file(doc_matters.src.filename)); + template SQLiteDiscreteDbStatementComposite() { + void SQLiteDiscreteDbStatementComposite(Db,D,M)( + Db db, + const D doc_abstraction, + M doc_matters, + ) { + <> + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_sqlite.sqlite_file(doc_matters.src.filename)); + } + } + } + SQLiteDiscreteDbStatementComposite!()(db, doc_abstraction, doc_matters); + } +} +#+END_SRC + +*** db run + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteDbRun() { + void SQLiteDbRun(Db,St,O)( + Db db, + St db_statement, + O opt_action, + string note, + ) { + debug(sql_statement) { + writeln(db_statement); + } + try { + db.run( + "\nBEGIN;\n" ~ + db_statement ~ + "\nCOMMIT;\n" + ); + if (!(opt_action.sqlite_discrete) + && !(opt_action.sqlite_db_create) + ) { + } + } catch (ErrnoException ex) { + writeln("ERROR SQLite : ", ex); + } catch (Exception ex) { + writeln("ERROR SQLite : ", ex); + } + { /+ debug +/ + if (opt_action.debug_do + && opt_action.verbose) { + writeln(note); + if (opt_action.very_verbose) { + writeln(db_statement); + } + } + } + } +} +#+END_SRC + +*** munge + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLinsertDelimiter() { + auto SQLinsertDelimiter(string _txt) { + _txt = _txt + .replaceAll(rgx.quotation_mark_sql_insert_delimiter, "$0$0"); + return _txt; + } +} +template SQLiteFormatAndLoadObject() { + auto SQLiteFormatAndLoadObject(M)( + M doc_matters, + ) { + mixin DocReformOutputRgxInit; + struct sqlite_format_and_load_objects { + <> + <> + <> + <> + <> + } + return sqlite_format_and_load_objects(); + } +} +#+END_SRC + +*** sqlite instructions +**** create + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteTablesReCreate() { + string SQLiteTablesReCreate()() { + string _sql_instruct; + _sql_instruct = format(q"┃ + <> + <> + <> + <> + <> + <> + ┃",); + return _sql_instruct; + } +} +#+END_SRC + +**** delete + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteDeleteDocument() { + string SQLiteDeleteDocument(M)( + M doc_matters, + ) { + <> + return _delete_uid; + } +} +#+END_SRC + +**** insert + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteInsertMetadata() { + string SQLiteInsertMetadata(M)( + M doc_matters, + ) { + <> + <> + return _insert_metadata; + } +} +#+END_SRC + +**** insert doc objects loop + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteInsertDocObjectsLoop() { + string SQLiteInsertDocObjectsLoop(D,M)( + const D doc_abstraction, + M doc_matters, + ) { + string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); + auto url_html = DocReformUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + string insertDocObjectsRow(O)(O obj) { + <> + return _insert_doc_objects_row; + } + <> + } +} +#+END_SRC + +**** tables create + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteTablesCreate() { + void SQLiteTablesCreate(E,O)(E env, O opt_action) { + import d2sqlite3; + template SQLiteTablesReCreate() { + string SQLiteTablesReCreate()() { + string _sql_instruct; + _sql_instruct = format(q"┃ + <> + <> + <> + <> + <> + <> + ┃",); + return _sql_instruct; + } + } + if (opt_action.sqlite_db_create) { + string _db_statement; + auto pth_sqlite = DocReformPathsSQLite!()(opt_action.sqlite_filename, opt_action.output_dir_set); + pth_sqlite.base.mkdirRecurse; + auto db = Database(pth_sqlite.sqlite_file); + { + _db_statement ~= SQLiteTablesReCreate!()(); + } + SQLiteDbRun!()(db, _db_statement, opt_action, "TABLE RE-CREATE"); + } + } +} +#+END_SRC + +**** tables drop + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" +template SQLiteDbDrop() { + void SQLiteDbDrop(O)(O opt_action) { + writeln("db drop"); + if ((opt_action.sqlite_db_drop)) { + auto pth_sqlite = DocReformPathsSQLite!()(opt_action.sqlite_filename, opt_action.output_dir_set); + writeln("remove(", pth_sqlite.sqlite_file, ")"); + try { + remove(pth_sqlite.sqlite_file); + } catch (FileException ex) { + // handle error + } + } + } +} +#+END_SRC + +** 1. [#A] sqlite_db_statement :statement: +*** collection + +#+name: sqlite_db_statement_composite_collection +#+BEGIN_SRC d +{ + string _db_statement; + { + if ((doc_matters.opt.action.sqlite_db_create)) { + auto pth_sqlite = DocReformPathsSQLite!()(doc_matters.sqlite.filename, doc_matters.output_path); + pth_sqlite.base.mkdirRecurse; + _db_statement ~= SQLiteTablesReCreate!()(); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "TABLE RE-CREATE"); + } + if (doc_matters.opt.action.sqlite_delete) { + _db_statement ~= SQLiteDeleteDocument!()(doc_matters); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "DELETE Document"); + } + if (doc_matters.opt.action.sqlite_update) { + _db_statement ~= SQLiteDeleteDocument!()(doc_matters); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "DELETE Document"); + _db_statement ~= SQLiteInsertMetadata!()(doc_matters); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "INSERT MetaData"); + /+ get tid (lastrowid or max) for use in doc_objects table +/ + _db_statement ~= doc_abstraction.SQLiteInsertDocObjectsLoop!()(doc_matters); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "INSERT DocObjects"); + } + } + db.close; +} +#+END_SRC + +*** discrete + +#+name: sqlite_db_statement_composite_discrete +#+BEGIN_SRC d +{ + string _db_statement; + { + _db_statement ~= SQLiteTablesReCreate!()(); + _db_statement ~= SQLiteInsertMetadata!()(doc_matters); + _db_statement ~= doc_abstraction.SQLiteInsertDocObjectsLoop!()(doc_matters); + SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "table CREATE Tables, INSERT DocObjects"); + } + db.close; +} +#+END_SRC + +** 2. imports + +#+name: output_imports +#+BEGIN_SRC d +import doc_reform.output; +import + std.file, + std.uri, + std.conv : to; +#+END_SRC + +** 3. format and load template +*** 1. prepare objects (munge, sanitize, markup) +**** 1. _text_ generic munge (sanitize text for search) + +- [3/4] (search text, applies to all but code blocks) + - [ ] remove whitespace, paragraph on single line (formatting kept so far) + - [X] remove font face attributes + - [X] move embedded endnotes + - [X] place after text object + - [X] remove embedded endnote numbers (rely on html output to represent) + - [X] urls + - [X] clean url markers, leave plain link text + - [X] place urls after text object and its endnotes + +#+name: sanitize_text_for_search +#+BEGIN_SRC d +string generic_munge_sanitize_text_for_search( + string _txt, +) { + string _notes; + string _urls; + if (_txt.matchFirst(rgx.inline_notes_al_gen)) { + foreach (m; _txt.matchAll(rgx.inline_notes_al_gen_text)) { + _notes ~= "\n" ~ m["text"]; + } + _txt = _txt.replaceAll(rgx.inline_notes_al_gen, ""); + } + if (_txt.matchFirst(rgx.inline_link)) { + foreach (m; _txt.matchAll(rgx.inline_link)) { + if (m["link"].match(rgx.url)) { + _urls ~= "\n" ~ m["link"]; + } + } + _txt = _txt.replaceAll(rgx.inline_link_clean, ""); + } + if (_notes.length > 0) { + _txt ~= _notes; + } + if (_urls.length > 0) { + _txt ~= _urls; + } + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(_txt, "\n"); + } + } + debug(sql_text_clean) { + writeln(_txt); + } + return _txt; +} +#+END_SRC + +**** 2. _html_ + +light html objects +- place endnotes after text object +- light inline html markup + +***** munge +****** general munge (special characters, inline markup, move notes) + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string munge_html(M,O)( + M doc_matters, + const O obj, +) { + string _html_special_characters(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, " ") + .replaceAll(rgx.xhtml_line_break, "
"); + return _txt; + } + string _html_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 _notes; + string _urls; + string _txt = _html_font_face(_html_special_characters(obj.text)); + if (_txt.matchFirst(rgx.inline_notes_al_gen)) { + foreach (m; _txt.matchAll(rgx.inline_notes_al_gen_text)) { + _notes ~= "\n" ~ m["text"]; + } + _txt = _txt.replaceAll(rgx.inline_notes_al_gen_ref, "$1 "); + } + if (_notes.length > 0) { + _txt ~= _notes; + } + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(_txt, "\n"); + } + } + return _txt; +} +#+END_SRC + +****** special characters + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string html_special_characters(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, " ") + .replaceAll(rgx.xhtml_line_break, "
"); + return _txt; +} +#+END_SRC + +****** special characters for code + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string html_special_characters_code(string _txt){ + _txt = _txt + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_quotation, """) + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.nbsp_char, " "); + return _txt; +} +#+END_SRC + +****** font_face + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string html_font_face(string _txt){ + _txt = _txt + .replaceAll(rgx.inline_emphasis, "$1") + .replaceAll(rgx.inline_bold, "$1") + .replaceAll(rgx.inline_underscore, "$1") + .replaceAll(rgx.inline_italics, "$1") + .replaceAll(rgx.inline_superscript, "$1") + .replaceAll(rgx.inline_subscript, "$1") + .replaceAll(rgx.inline_strike, "$1") + .replaceAll(rgx.inline_insert, "$1") + .replaceAll(rgx.inline_mono, "$1") + .replaceAll(rgx.inline_cite, "$1"); + return _txt; +} +#+END_SRC + +****** inline markup +******* images + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string inline_images(M,O)( + M doc_matters, + const O obj, + string _txt, + string _suffix = ".html", + string _xml_type = "seg", +) { + string _img_pth; + if (_xml_type == "epub") { + _img_pth = "image/"; + } else if (_xml_type == "scroll") { + _img_pth = "../../image/"; + } else if (_xml_type == "seg") { + _img_pth = "../../../image/"; + } + if (_txt.match(rgx.inline_image)) { + _txt = _txt.replaceAll( // TODO bug where image dimensions (w or h) not given & consequently set to 0; should not be used (calculate earlier, abstraction) + rgx.inline_image, + ("$1 $6")); + } + return _txt; +} +#+END_SRC + +******* links +******** scroll, seg, epub + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string inline_links(M,O)( + M doc_matters, + const O obj, + string _txt, + string _xml_type = "seg", +) { + if (obj.has.inline_links) { + if (obj.metainfo.is_a != "code") { + _txt = replaceAll!(m => + m[1] ~ "┤" ~ to!string((obj.stow.link[m[2].to!ulong])).encode ~ "├" + )(_txt, rgx.inline_link_number_only); + } + if ((_txt.match(rgx.mark_internal_site_lnk)) + && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault + _txt = _txt.replaceAll( + rgx.inline_seg_link, + "$1"); + } + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + if (_xml_type == "seg") { + foreach (m; _txt.match(rgx.inline_link_hash)) { + if (m.captures[3] in doc_matters.has.tag_associations) { + if (m.captures[3] == doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"]) { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ pth_html.tail_fn_seg(doc_matters.src.filename, "$3.html") + ~ "├" + ); + } else { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"] + ~ ".html" + ~ "#" ~ "$3" + ~ "├" + ); + } + } else { + if (!(doc_matters.opt.action.quiet)) { + writeln( + "WARNING on internal document links, anchor to link <<" + ~ m.captures[3] + ~ ">> not found in document, " + ~ "anchor: " ~ m.captures[3] + ~ " document: " ~ doc_matters.src.filename + ); + } + } + } + } else { + if (auto m = _txt.match(rgx.inline_link_hash)) { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ "/" + ~ pth_html.tail_fn_scroll(doc_matters.src.filename) + ~ "#" ~ "$3" + ~ "├" + ); + } + } + _txt = _txt + .replaceAll( + rgx.inline_link_fn_suffix, + ("$1.html")) + .replaceAll( + rgx.inline_link, + ("$1")) + .replaceAll( + rgx.mark_internal_site_lnk, + ""); + } + debug(markup_links) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + debug(markup) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + return _txt; +} +#+END_SRC + +******* notes +******** scroll + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string inline_notes_scroll(M,O)( + M doc_matters, + const O obj, + string _txt, +) { + if (obj.has.inline_notes_reg) { + // _txt = font_face(_txt); + _txt = _txt.replaceAll( + rgx.inline_notes_al_regular_number_note, + (" $1 ") + ); + } + debug(markup_endnotes) { + if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + debug(markup) { + if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + return _txt; +} +#+END_SRC + +******** seg + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +auto inline_notes_seg(M,O)( + M doc_matters, + const O obj, + string _txt, +) { + string[] _endnotes; + if (obj.has.inline_notes_reg) { + /+ need markup for text, and separated footnote +/ + foreach(m; _txt.matchAll(rgx.inline_notes_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_al_regular_number_note, + (" $1 ") + ); + } else if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + debug(markup) { + writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + auto t = tuple( + _txt, + _endnotes, + ); + return t; +} +#+END_SRC + +******* inline markup + +#+name: sanitize_and_munge_inline_html +#+BEGIN_SRC d +string xml_type="seg"; /+ set html document type to be linked to here (seg|scroll) +/ +string inline_markup(M,O)( + M doc_matters, + const O obj, + string _txt, +) { + _txt = inline_images(doc_matters, obj, _txt, xml_type); + _txt = inline_links(doc_matters, obj, _txt, xml_type); + _txt = inline_notes_scroll(doc_matters, obj, _txt); + return _txt; +} +#+END_SRC + +***** objects +****** heading + +#+name: html_objects +#+BEGIN_SRC d +string html_heading(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "heading"); + string _txt = munge_html(doc_matters, obj); + _txt = inline_markup(doc_matters, obj, _txt); + string o = format(q"┃

+ %s +

┃", + obj.metainfo.is_a, + _txt, + ); + return o; +} +#+END_SRC + +******* +fancy+ + +##+name: prepare_objects_html +#+BEGIN_SRC d +string html_heading(M,O)( + M doc_matters, + const O obj, +) { + string o; + string _txt = munge_html(doc_matters, obj); + o = format(q"┃ + %s + ┃", + obj.metainfo.heading_lev_markup, + obj.metainfo.is_a, + _txt, + obj.metainfo.heading_lev_markup, + ); + return o; +} +#+END_SRC + +****** para + +#+name: html_objects +#+BEGIN_SRC d +string html_para(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + string _txt = munge_html(doc_matters, obj); + _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = inline_markup(doc_matters, obj, _txt); + string o = format(q"┃

+ %s +

┃", + obj.metainfo.is_a, + obj.attrib.indent_hang, + obj.attrib.indent_base, + _txt + ); + return o; +} +#+END_SRC + +****** quote + +#+name: html_objects +#+BEGIN_SRC d +string html_quote(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "quote"); + string _txt = munge_html(doc_matters, obj); + string o = format(q"┃

+ %s +

┃", + obj.metainfo.is_a, + _txt + ); + return o; +} +#+END_SRC + +****** group + +#+name: html_objects +#+BEGIN_SRC d +string html_group(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "group"); + string _txt = munge_html(doc_matters, obj); + string o = format(q"┃

+ %s +

┃", + obj.metainfo.is_a, + _txt + ); + return o; +} +#+END_SRC + +****** block + +#+name: html_objects +#+BEGIN_SRC d +string html_block(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "block"); + string _txt = munge_html(doc_matters, obj); + string o = format(q"┃ +

%s

┃", + obj.metainfo.is_a, + _txt.stripRight + ); + return o; +} +#+END_SRC + +****** verse + +#+name: html_objects +#+BEGIN_SRC d +string html_verse(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "verse"); + string _txt = munge_html(doc_matters, obj); + string o = format(q"┃

%s

┃", + obj.metainfo.is_a, + _txt + ); + return o; +} +#+END_SRC + +****** code + +#+name: html_objects +#+BEGIN_SRC d +string html_code(O)( + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "code"); + string _txt = html_special_characters_code(obj.text); + string o = format(q"┃

%s

┃", + obj.metainfo.is_a, + _txt + ); + return o; +} +#+END_SRC + +****** table + +#+name: html_objects +#+BEGIN_SRC d +string html_table(M,O)( + M doc_matters, + const O obj, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "table"); + auto _tablarize(O)( + const O obj, + string _txt, + ) { + string[] _table_rows = _txt.split(rgx.table_delimiter_row); + string[] _table_cols; + string _table; + string _tablenote; + foreach(row_idx, row; _table_rows) { + _table_cols = row.split(rgx.table_delimiter_col); + _table ~= ""; + foreach(col_idx, cell; _table_cols) { + if ((_table_cols.length == 1) + && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) + _tablenote ~= cell; + } else { + string _col_is = (row_idx == 0 && obj.table.heading) ? "th" : "td"; + string _align = ("style=\"text-align:" + ~ ((obj.table.column_aligns[col_idx] == "l") + ? "left\"" : "right\"")); + _table ~= "<" + ~ _col_is + ~ " width=\"" + ~ obj.table.column_widths[col_idx].to!string + ~ "%\" " + ~ _align + ~ ">"; + _table ~= cell; + _table ~= ""; + } + } + _table ~= ""; + } + auto t = tuple( + _table, + _tablenote, + ); + return t; + } + string _txt = munge_html(doc_matters, obj); + auto t = _tablarize(obj, _txt); + _txt = t[0]; + string _note = t[1]; + string o = format(q"┃

+ + %s +
+ %s +

┃", + obj.metainfo.is_a, + _txt, + _note + ); + return o; +} +#+END_SRC + +*** 2. hub (sqlite_format_and_load_objects) +**** sql related + +#+name: sqlite_load_object +#+BEGIN_SRC d +string sqlite_load_string(M,O)( + M doc_matters, + const O obj, +) { + string o; + return o; +} +#+END_SRC + +#+name: sqlite_load_object +#+BEGIN_SRC d +string postgresql_load_string(M,O)( + M doc_matters, + const O obj, +) { + string o; + return o; +} +#+END_SRC + +#+name: sqlite_load_object +#+BEGIN_SRC d +string sqlite_statement(O)( + const O obj, + string _txt, + string _html, +) { + void _sql_exe(O)( + string _sql, + ) { + writeln(_html); + writeln(_sql); + } + string _sql; + return _sql; +} +#+END_SRC + +**** heading + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] heading(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_heading(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** para + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] para(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_para(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** quote + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] quote(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_quote(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC +**** group + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] group(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_group(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** block + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] block(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_block(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** verse + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] verse(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_verse(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** code + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] code(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_code(obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +**** table + +#+name: hub_format_and_sqlite_load_objects +#+BEGIN_SRC d +string[string] table(M,O)( + M doc_matters, + const O obj, +) { + string[string] obj_txt = [ + "text": generic_munge_sanitize_text_for_search(obj.text), + "html": html_table(doc_matters, obj) + ]; + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + debug(sql_txt) { + writeln(obj_txt["text"]); + } + debug(sql_html) { + writeln(obj_txt["html"]); + } + } else { + // load sql + } + } + return obj_txt; +} +#+END_SRC + +** 4. ↻ loop, identify, load - loop template + +#+name: sqlite_objects_loop +#+BEGIN_SRC d +auto format_and_sqlite_load = SQLiteFormatAndLoadObject!()(doc_matters); +string[string] obj_txt; +string doc_text; +string[] _insert_doc_objects; +foreach (part; doc_matters.has.keys_seq.sql) { + foreach (obj; doc_abstraction[part]) { + switch (obj.metainfo.is_of_part) { + case "frontmatter": assert(part == "head", part); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + obj_txt = format_and_sqlite_load.heading(doc_matters, obj); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "body": // assert(part == "body", part); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + debug (asserts) { + if (part != "body") { + writeln(__LINE__, ": ", obj.text); + } + } + obj_txt = format_and_sqlite_load.heading(doc_matters, obj); + break; + case "para": + obj_txt = format_and_sqlite_load.para(doc_matters, obj); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + obj_txt = format_and_sqlite_load.quote(doc_matters, obj); + break; + case "group": + obj_txt = format_and_sqlite_load.group(doc_matters, obj); + break; + case "block": + obj_txt = format_and_sqlite_load.block(doc_matters, obj); + break; + case "poem": // double check on keeping both poem & verse + break; + case "verse": + obj_txt = format_and_sqlite_load.verse(doc_matters, obj); + break; + case "code": + obj_txt = format_and_sqlite_load.code(doc_matters, obj); + break; + case "table": + obj_txt = format_and_sqlite_load.table(doc_matters, obj); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "backmatter": + assert(part == "glossary" || "bibliography" || "bookindex" || "blurb" || "tail", part); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + obj_txt = format_and_sqlite_load.heading(doc_matters, obj); + break; + case "glossary": assert(part == "glossary", part); + obj_txt = format_and_sqlite_load.para(doc_matters, obj); + break; + case "bibliography": assert(part == "bibliography", part); + obj_txt = format_and_sqlite_load.para(doc_matters, obj); + break; + case "bookindex": assert(part == "bookindex", part); + obj_txt = format_and_sqlite_load.para(doc_matters, obj); + break; + case "blurb": assert(part == "blurb", part); + obj_txt = format_and_sqlite_load.para(doc_matters, obj); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); // check where empty value could come from + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check where empty value could come from + } + } + break; + } + if (obj.metainfo.is_a == "heading") { + if ((doc_matters.opt.action.very_verbose)) { + writeln( + "markup: ", obj.metainfo.heading_lev_markup, + "> ", obj.metainfo.dom_structure_markedup_tags_status, + "; collapsed: ", obj.metainfo.heading_lev_collapsed, + "> ", obj.metainfo.dom_structure_collapsed_tags_status, + "; ocn: ", obj.metainfo.ocn, + " node: ", obj.metainfo.node, + "; parent: ", obj.metainfo.parent_lev_markup, + "; ocn: ", obj.metainfo.parent_ocn, + "; ", + ); + } + } + if (!(obj.metainfo.is_a == "comment")) { + _insert_doc_objects ~= insertDocObjectsRow(obj); + } + } // loop closes +} +return _insert_doc_objects.join.to!(char[]).toUTF8; +#+END_SRC + +** 5. SQL statements :statement: +*** drop index and tables +**** DROP INDEX IF EXISTS + +#+name: sqlite_statement_drop_existing_index +#+BEGIN_SRC sql +DROP INDEX IF EXISTS idx_ocn; +DROP INDEX IF EXISTS idx_uid; +DROP INDEX IF EXISTS idx_digest_clean; +DROP INDEX IF EXISTS idx_digest_all; +DROP INDEX IF EXISTS idx_clean; +DROP INDEX IF EXISTS idx_title; +DROP INDEX IF EXISTS idx_creator_author; +DROP INDEX IF EXISTS src_filename; +DROP INDEX IF EXISTS idx_language_document_char; +DROP INDEX IF EXISTS idx_classify_topic_register; +#+END_SRC + +**** DROP TABLE IF EXISTS + +#+name: sqlite_statement_drop_existing_tables +#+BEGIN_SRC sql +DROP TABLE IF EXISTS metadata_and_text; +DROP TABLE IF EXISTS topic_register; +DROP TABLE IF EXISTS doc_objects; +DROP TABLE IF EXISTS urls; +#+END_SRC + +*** create tables and index +**** CREATE TABLE metadata_and_text + +#+name: sqlite_statement_create_table_metadata_and_src_txt +#+BEGIN_SRC sql +CREATE TABLE metadata_and_text ( + uid VARCHAR(256) UNIQUE, -- filename, language char, pod/txt (decide on delimiter [,;:/]) + src_composite_id_per_txt VARCHAR(256) NOT NULL, -- UNIQUE, z pod name if any + src filename + language code + src_composite_id_per_pod VARCHAR(256) NOT NULL, -- z pod name if any + src filename + title VARCHAR(800) NOT NULL, + title_main VARCHAR(400) NOT NULL, + title_sub VARCHAR(400) NULL, + title_short VARCHAR(400) NULL, + title_edition VARCHAR(10) NULL, + title_language VARCHAR(100) NULL, + title_language_char VARCHAR(6) NULL, + creator_author VARCHAR(600) NOT NULL, + creator_author_email VARCHAR(100) NULL, + creator_author_hon VARCHAR(100) NULL, + creator_author_nationality VARCHAR(100) NULL, + creator_editor VARCHAR(600) NULL, + creator_contributor VARCHAR(600) NULL, + creator_illustrator VARCHAR(600) NULL, + creator_photographer VARCHAR(600) NULL, + creator_translator VARCHAR(600) NULL, + creator_prepared_by VARCHAR(600) NULL, + creator_digitized_by VARCHAR(600) NULL, + creator_audio VARCHAR(600) NULL, + creator_video VARCHAR(600) NULL, + language_document VARCHAR(100) NULL, + language_document_char VARCHAR(6) NOT NULL, + language_original VARCHAR(100) NULL, + language_original_char VARCHAR(6) NULL, + date_added_to_site VARCHAR(10) NULL, + date_available VARCHAR(10) NULL, + date_created VARCHAR(10) NULL, + date_issued VARCHAR(10) NULL, + date_modified VARCHAR(10) NULL, + date_published VARCHAR(10) NULL, + date_valid VARCHAR(10) NULL, + date_translated VARCHAR(10) NULL, + date_original_publication VARCHAR(10) NULL, + date_generated VARCHAR(10) NULL, + original_title VARCHAR(800) NULL, + original_publisher VARCHAR(600) NULL, + original_language VARCHAR(100) NULL, + original_language_char VARCHAR(6) NULL, + original_source VARCHAR(600) NULL, + original_institution VARCHAR(600) NULL, + original_nationality VARCHAR(100) NULL, + rights_copyright VARCHAR(2500) NULL, + rights_copyright_audio VARCHAR(2500) NULL, + rights_copyright_cover VARCHAR(2500) NULL, + rights_copyright_illustrations VARCHAR(2500) NULL, + rights_copyright_photographs VARCHAR(2500) NULL, + rights_copyright_text VARCHAR(2500) NULL, + rights_copyright_translation VARCHAR(2500) NULL, + rights_copyright_video VARCHAR(2500) NULL, + rights_license VARCHAR(2500) NULL, + identifier_oclc VARCHAR(30) NULL, + identifier_isbn VARCHAR(16) NULL, + classify_topic_register VARCHAR(2500) NULL, + classify_subject VARCHAR(600) NULL, + classify_loc VARCHAR(30) NULL, + classify_dewey VARCHAR(30) NULL, + classify_keywords VARCHAR(600) NULL, + notes_abstract TEXT NULL, + notes_description TEXT NULL, + notes_comment TEXT NULL, + notes_coverage VARCHAR(200) NULL, + notes_relation VARCHAR(200) NULL, + notes_history VARCHAR(600) NULL, + notes_type VARCHAR(600) NULL, + notes_format VARCHAR(600) NULL, + notes_prefix TEXT NULL, + notes_prefix_a TEXT NULL, + notes_prefix_b TEXT NULL, + notes_suffix TEXT NULL, + publisher VARCHAR(600) NULL, + src_filename VARCHAR(256) NOT NULL, + src_fingerprint VARCHAR(256) NULL, + src_filesize VARCHAR(10) NULL, + src_wordcount VARCHAR(10) NULL, + pod_name VARCHAR(256) NULL, -- zipped pod, work to be done here + pod_fingerprint VARCHAR(256) NULL, -- zipped pod, work to be done here + pod_size VARCHAR(10) NULL, -- zipped pod, work to be done here + site_url_doc_root VARCHAR(256) NULL, -- url path to doc root + site_url_html_toc VARCHAR(256) NULL, + site_url_html_scroll VARCHAR(256) NULL, + site_url_epub VARCHAR(256) NULL, + links TEXT NULL +); +#+END_SRC + +**** CREATE TABLE topic_register + +#+name: sqlite_statement_create_table_topic_register +#+BEGIN_SRC sql +CREATE TABLE topic_register ( + -- tid BIGINT PRIMARY KEY, + uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, + -- src_composite_id_per_txt VARCHAR(256) NOT NULL, - UNIQUE, - z pod name if any + src filename + language code + -- src_composite_id_per_pod VARCHAR(256) NOT NULL, - z pod name if any + src filename + topic_register_lv0 VARCHAR(250) NOT NULL, + topic_register_lv1 VARCHAR(250) NULL, + topic_register_lv2 VARCHAR(250) NULL, + topic_register_lv3 VARCHAR(250) NULL, + topic_register_lv4 VARCHAR(250) NULL, + site_url_doc_root VARCHAR(256) NULL, -- url path to doc root + site_url_html_toc VARCHAR(256) NULL, + site_url_html_scroll VARCHAR(256) NULL +); +#+END_SRC + +**** CREATE TABLE site_urls ? + +#+name: sqlite_statement_create_table_site_urls +#+BEGIN_SRC sql +CREATE TABLE site_urls ( + -- tid BIGINT PRIMARY KEY, + uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, + src_composite_id_per_txt VARCHAR(256) NOT NULL, -- UNIQUE, - z pod name if any + src filename + language code + src_composite_id_per_pod VARCHAR(256) NOT NULL, -- z pod name if any + src filename + site_url_doc_root VARCHAR(256) NULL, -- url path to doc root + site_url_html_toc VARCHAR(256) NULL, + site_url_html_scroll VARCHAR(256) NULL +); +#+END_SRC + +**** CREATE TABLE doc_objects + +#+name: sqlite_statement_create_table_objects +#+BEGIN_SRC sql +CREATE TABLE doc_objects ( + lid BIGINT PRIMARY KEY, + uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, + ocn SMALLINT, + obj_id VARCHAR(6) NULL, + clean TEXT NULL, + body TEXT NULL, + seg VARCHAR(256) NULL, + lev_an VARCHAR(1), + is_of_type VARCHAR(16), + is_a VARCHAR(16), + lev SMALLINT NULL, + node VARCHAR(16) NULL, + parent VARCHAR(16) NULL, + last_decendant VARCHAR(16) NULL, -- headings only + digest_clean CHAR(256), + digest_all CHAR(256), + html_seg_url CHAR(256), + types CHAR(1) NULL +); +#+END_SRC + +**** CREATE INDEX + +#+name: sqlite_statement_create_index +#+BEGIN_SRC sql +CREATE INDEX idx_ocn ON doc_objects(ocn); +CREATE INDEX idx_digest_clean ON doc_objects(digest_clean); +CREATE INDEX idx_digest_all ON doc_objects(digest_all); +CREATE INDEX idx_clean ON doc_objects(clean); +CREATE INDEX idx_title ON metadata_and_text(title); +CREATE INDEX idx_author ON metadata_and_text(creator_author); +CREATE INDEX idx_uid ON metadata_and_text(uid); +CREATE INDEX idx_filename ON metadata_and_text(src_filename); +CREATE INDEX idx_language ON metadata_and_text(language_document_char); +CREATE INDEX idx_topics ON metadata_and_text(classify_topic_register); +#+END_SRC + +*** TODO local site link & info + +*** delete rows (delete document) +**** DELETE uid rows doc matters & metadata +***** sql statement: dlang format + +#+name: sqlite_formatted_delete +#+BEGIN_SRC d +string _uid = doc_matters.src.doc_uid; +string _delete_uid = format(q"┃ +#+END_SRC + +***** DELETE FROM ... WHERE + +#+name: sqlite_formatted_delete +#+BEGIN_SRC sql +DELETE FROM metadata_and_text +WHERE uid = '%s'; +DELETE FROM doc_objects +WHERE uid_metadata_and_text = '%s'; +#+END_SRC + +***** VALUES + +#+name: sqlite_formatted_delete +#+BEGIN_SRC d +┃", + _uid, + _uid, +); +#+END_SRC + +*** inserts +**** INSERT doc matters & metadata +***** sql statement: dlang format + +#+name: sqlite_formatted_insertions_doc_matters_metadata +#+BEGIN_SRC d +string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); +string _insert_metadata = format(q"┃ +#+END_SRC + +***** INSERT INTO + +#+name: sqlite_formatted_insertions_doc_matters_metadata +#+BEGIN_SRC sql + INSERT INTO metadata_and_text ( + uid, + src_filename, + src_composite_id_per_txt, + src_composite_id_per_pod, + title, + title_main, + title_sub, + title_short, + title_edition, + title_language, + creator_author, + creator_author_email, + creator_illustrator, + creator_translator, + language_document, + language_document_char, + date_added_to_site, + date_available, + date_created, + date_issued, + date_modified, + date_published, + date_valid, + rights_copyright, + rights_copyright_audio, + rights_copyright_cover, + rights_copyright_illustrations, + rights_copyright_photographs, + rights_copyright_text, + rights_copyright_translation, + rights_copyright_video, + rights_license, + identifier_oclc, + identifier_isbn, + classify_dewey, + classify_keywords, + classify_loc, + classify_subject, + classify_topic_register, + original_title, + original_publisher, + original_language, + original_language_char, + original_source, + notes_abstract, + notes_description, + publisher, + site_url_doc_root + ) +#+END_SRC + +***** VALUES + +#+name: sqlite_formatted_insertions_doc_matters_metadata +#+BEGIN_SRC sql + VALUES ( + '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' + ); +#+END_SRC + +***** dlang values for formatting + +#+name: sqlite_formatted_insertions_doc_matters_metadata +#+BEGIN_SRC d +┃", + _uid, + SQLinsertDelimiter!()(doc_matters.src.filename), + SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_doc), + SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_pod), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_full), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_main), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_subtitle), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_short), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_edition), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_language), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_email), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_illustrator), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_translator), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.language_document), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.language_document_char), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_added_to_site), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_available), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_created), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_issued), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_modified), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_published), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_valid), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_audio), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_cover), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_illustrations), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_photographs), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_text), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_translation), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_video), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_license), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.identifier_oclc), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.identifier_isbn), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_dewey), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_keywords), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_loc), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_subject), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_topic_register), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.notes_abstract), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.notes_description), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_title), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_publisher), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language_char), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_source), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.publisher), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root) +); +#+END_SRC + +**** INSERT topic register + +writeln(doc_matters.conf_make_meta.meta.classify_topic_register_arr); + +***** { if topic register then loop topic register array + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC d +if (doc_matters.conf_make_meta.meta.classify_topic_register_arr.length > 0) { + + string _insert_topics; + foreach (topic; doc_matters.conf_make_meta.meta.classify_topic_register_arr) { + string[] subject_tree = topic.split(mkup.sep); +#+END_SRC + +***** sql statement: dlang format + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC d +_insert_topics ~= format(q"┃ +#+END_SRC + +***** INSERT INTO + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC sql + INSERT INTO topic_register ( + uid_metadata_and_text, + topic_register_lv0, + topic_register_lv1, + topic_register_lv2, + topic_register_lv3, + topic_register_lv4 + ) +#+END_SRC + +***** VALUES + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC sql + VALUES ( + '%s', '%s', '%s', '%s', '%s', '%s' + ); +#+END_SRC + +***** dlang values for formatting + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC d +┃", + _uid, + (subject_tree.length > 0) ? subject_tree[0] : "", + (subject_tree.length > 1) ? subject_tree[1] : "", + (subject_tree.length > 2) ? subject_tree[2] : "", + (subject_tree.length > 3) ? subject_tree[3] : "", + (subject_tree.length > 4) ? subject_tree[4] : "" +); +#+END_SRC + +***** } close topic register & loop topic register array + +#+name: sqlite_formatted_insertions_topic_register +#+BEGIN_SRC d + } +} +#+END_SRC + +**** INSERT doc objects + +lid unique, increment by 1 per object, not ocn + +metadata tid document number unique +either: +- increment by adding 1 for each document, +- make hash of document filename or url and use? + +***** sql statement: dlang format + +#+name: sqlite_formatted_insertions_doc_objects +#+BEGIN_SRC d +string _insert_doc_objects_row = format(q"┃ +#+END_SRC + +***** INSERT INTO + +#+name: sqlite_formatted_insertions_doc_objects +#+BEGIN_SRC sql + INSERT INTO doc_objects ( + uid_metadata_and_text, + ocn, + obj_id, + clean, + body, + lev, + is_of_type, + is_a, + html_seg_url + ) +#+END_SRC + +***** VALUES + +#+name: sqlite_formatted_insertions_doc_objects +#+BEGIN_SRC sql + VALUES ( + '%s', %s, '%s', '%s', '%s', %s, '%s', '%s', '%s' + ); +#+END_SRC + +***** dlang values for formatting + +#+name: sqlite_formatted_insertions_doc_objects +#+BEGIN_SRC d +┃", + _uid, + obj.metainfo.ocn, + obj.metainfo.identifier, + SQLinsertDelimiter!()(obj_txt["text"]), + SQLinsertDelimiter!()(obj_txt["html"]), + obj.metainfo.heading_lev_markup, + obj.metainfo.is_of_type, + obj.metainfo.is_a, + url_html.fn_seg_obj_num(doc_matters.src.filename, obj.tags.html_segment_anchor_tag_is, obj.metainfo.identifier), +); +#+END_SRC + +* __END__ diff --git a/org/out_src_pod.org b/org/out_src_pod.org new file mode 100644 index 0000000..df6be5f --- /dev/null +++ b/org/out_src_pod.org @@ -0,0 +1,443 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) output pod +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:source:pod: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* pod +** _module template_ :module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/source_pod.d" +module doc_reform.output.source_pod; +template DocReformPod() { + <> + void DocReformPod(T)(T doc_matters) { + <> + <> + try { + <> + <> + <> + } catch (ErrnoException ex) { + // Handle error + } + } +} +#+END_SRC + +** init +*** imports + +#+name: output_imports +#+BEGIN_SRC d +import doc_reform.output; +import + std.digest.sha, + std.file, + std.outbuffer, + std.zip, + std.conv : to; +import + doc_reform.output.create_zip_file, + doc_reform.output.xmls; +#+END_SRC + +*** init + +#+name: source_pod_init +#+BEGIN_SRC d +debug(asserts) { + // static assert(is(typeof(doc_matters) == tuple)); +} +mixin DocReformOutputRgxInit; +string pwd = doc_matters.env.pwd; +auto src_path_info = doc_matters.src_path_info; +auto pth_dr_doc_src = doc_matters.src_path_info; +auto pths_pod = DocReformPathsPods!()(doc_matters); +mixin DocReformLanguageCodes; +auto lang = Lang(); +static auto rgx = Rgx(); +assert (doc_matters.src.filename.match(rgx.src_fn)); +#+END_SRC + +*** pod zip archive + +#+name: source_pod_archive +#+BEGIN_SRC d +auto pod_archive(Z)( + string _source_type, + string _data_in, + string _pth_out, + Z zip +) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = _pth_out; + auto zip_data = new OutBuffer(); + switch (_source_type) { + case "file_path_bin": + zip_data.write(cast(char[]) ((_data_in).read)); + goto default; + case "file_path_text": + zip_data.write((_data_in).readText); + goto default; + case "string": + zip_data.write(_data_in); + goto default; + default: + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + } + return zip; +} +#+END_SRC + +** mkdir :mkdir: + +#+name: source_pod_mkdirs +#+BEGIN_SRC d +/+ create directory structure +/ +if (!exists(pths_pod.pod_dir_())) { + // used both by pod zipped (& pod filesystem (unzipped) which makes its own recursive dirs) + pths_pod.pod_dir_().mkdirRecurse; +} +if (doc_matters.opt.action.source) { + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pths_pod.fn_pod_filelist(doc_matters.src.filename).filesystem_open_zpod); + } + if (!exists(pths_pod.text_root(doc_matters.src.filename).filesystem_open_zpod)) { + pths_pod.text_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; + } + if (!exists(pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod)) { + pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; + } + if (!exists(pths_pod.media_root(doc_matters.src.filename).filesystem_open_zpod)) { + pths_pod.media_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; + } + if (!exists(pths_pod.css(doc_matters.src.filename).filesystem_open_zpod)) { + pths_pod.css(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; + } + if (!exists(pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod)) { + pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; + } + if (!exists(pths_pod.doc_lng(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod)) { + pths_pod.doc_lng(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod.mkdirRecurse; + } +} +#+END_SRC + +** copy :copy: + +#+name: source_pod_copy +#+BEGIN_SRC d +debug(pod) { + writeln(__LINE__, ": ", + doc_matters.src.filename, " -> ", + pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod + ); +} +auto zip = new ZipArchive(); +auto fn_pod = pths_pod.pod_filename(doc_matters.src.filename).zpod; +{ /+ bundle images +/ + foreach (image; doc_matters.srcs.image_list) { + debug(podimages) { + writeln( + pth_dr_doc_src.image_root.to!string, "/", image, " -> ", + pths_pod.image_root(doc_matters.src.filename).zpod, "/", image + ); + } + auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_src_out_pod_zip_base + = pths_pod.image_root(doc_matters.src.filename).zpod.to!string + ~ "/" ~ image; + auto fn_src_out_filesystem + = pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod.to!string + ~ "/" ~ image; + if (exists(fn_src_in)) { + debug(io) { + writeln("(io debug) src out found: ", fn_src_in); + } + if (doc_matters.opt.action.source) { + fn_src_in.copy(fn_src_out_filesystem); + } + if (doc_matters.opt.action.pod) { + zip = pod_archive("file_path_bin", fn_src_in, fn_src_out_pod_zip_base, zip); + } + } else { + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln("WARNING (io) src out NOT found (image): ", fn_src_in); + } + } + } +} { /+ bundle dr_document_make +/ + auto fn_src_in = ((doc_matters.src.is_pod) + ? doc_matters.src.conf_dir_path + : pth_dr_doc_src.conf_root).to!string + ~ "/" ~ "dr_document_make"; + auto fn_src_out_pod_zip_base + = pths_pod.conf_root(doc_matters.src.filename).zpod.to!string ~ "/" ~ "dr_document_make"; + auto fn_src_out_filesystem + = pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod.to!string + ~ "/" ~ "dr_document_make"; + if (exists(fn_src_in)) { + debug(io) { + writeln("(io debug) src out found: ", fn_src_in); + } + if (doc_matters.opt.action.source) { + fn_src_in.copy(fn_src_out_filesystem); + } + if (doc_matters.opt.action.pod) { + zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); + } + } else { + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln("WARNING (io) src out NOT found (document make): ", fn_src_in); + } + } +} { /+ pod manifest +/ + auto fn_src_in = doc_matters.src.file_with_absolute_path.to!string; + auto fn_src_out_pod_zip_base + = pths_pod.pod_manifest(doc_matters.src.filename).zpod.to!string; + auto fn_src_out_filesystem + = pths_pod.pod_manifest(doc_matters.src.filename).filesystem_open_zpod.to!string; // needed without root path + auto fn_src_out_inside_pod + = pths_pod.pod_manifest(doc_matters.src.filename).zpod.to!string; // needed without root path + string[] filelist_src_out_pod_arr; + string[] filelist_src_zpod_arr; + if (exists(fn_src_in)) { + debug(io) { + writeln("(io debug) src in found: ", fn_src_in); + } + filelist_src_out_pod_arr ~= fn_src_out_pod_zip_base; + filelist_src_zpod_arr ~= fn_src_out_inside_pod; + { + import dyaml; + auto pod_filelist_yaml_string + = File(pths_pod.fn_pod_filelist(doc_matters.src.filename).filesystem_open_zpod, "w"); + Node _pmy; + string _pm = "doc:\n filename: " ~ doc_matters.src.filename ~ "\n language: " ~ doc_matters.pod.manifest_list_of_languages.to!string ~ "\n"; + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + _pmy = Loader.fromString(_pm).load(); + writeln("pod filename: ", _pmy["doc"]["filename"].get!string); + writeln("pod languages: ", doc_matters.pod.manifest_list_of_languages.to!string); + writeln("pod languages: ", doc_matters.src.language); + // foreach(string _l; _pmy["doc"]["language"]) { + // writeln("language: ", _l); + // } + } + if (doc_matters.opt.action.source) { + pod_filelist_yaml_string.writeln(_pm); + } + if (doc_matters.opt.action.pod) { + zip = pod_archive("string", _pm, fn_src_out_pod_zip_base, zip); + } + } + } +} { /+ bundle primary file (.ssm/.sst) +/ + auto fn_src_in = doc_matters.src.file_with_absolute_path.to!string; + auto fn_src_out_pod_zip_base + = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).zpod.to!string; + auto fn_src_out_filesystem + = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod.to!string; // needed without root path: + auto fn_src_out_inside_pod + = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).zpod.to!string; // needed without root path: + string[] filelist_src_out_pod_arr; + string[] filelist_src_zpod_arr; + if (exists(fn_src_in)) { + debug(io) { + writeln("(io debug) src in found: ", fn_src_in); + } + filelist_src_out_pod_arr ~= fn_src_out_pod_zip_base; + filelist_src_zpod_arr ~= fn_src_out_inside_pod; + string _pod_to_markup_file = doc_matters.src.pod_name ~ "/" ~ "media/text/" ~ doc_matters.src.language ~ "/" ~ doc_matters.src.filename; + if (doc_matters.opt.action.source) { + fn_src_in.copy(fn_src_out_filesystem); + } + if (doc_matters.opt.action.pod) { + auto _rgx = regex(r"(?P\S+?)(?P[a-z_-]+)/(?Pmedia/text/)(?P\S+?)/(?P\S+?\.ss[mt])"); + if (auto _x = fn_src_in.match(_rgx)){ + if (doc_matters.src.lng == doc_matters.pod.manifest_list_of_languages[$-1]) { + string _path_to_pod = _x.captures["path_to_pod"]; + string _podname = _x.captures["podname"]; + string _root_to_lang = _x.captures["from_root"]; + string _language = _x.captures["language"]; + string _filename = _x.captures["filename"]; + foreach (_lang; doc_matters.pod.manifest_list_of_languages) { + string _pth_mkup_src_in = _path_to_pod ~ _podname ~ "/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; + string _pth_mkup_src_out = "pod/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; + zip = pod_archive("file_path_text", _pth_mkup_src_in, _pth_mkup_src_out, zip); + } + } + } else { + zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); + } + } + } else { + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln("WARNING (io) src in NOT found (markup source): ", fn_src_in); + } + } +} { /+ bundle insert files (.ssi) +/ + if (doc_matters.srcs.file_insert_list.length > 0) { + auto _rgx = regex(r"(?P\S+?)(?P[a-z_-]+)/(?Pmedia/text/)(?P\S+?)/(?P\S+?\.ss[i])"); + foreach (insert_file; doc_matters.srcs.file_insert_list) { + debug(pod) { + writeln( + insert_file, " -> ", + pths_pod.fn_doc_insert( + doc_matters.src.filename, + insert_file, + doc_matters.src.language, + ).zpod + ); + } + if (auto _x = insert_file.match(_rgx)){ + if (doc_matters.src.lng == doc_matters.pod.manifest_list_of_languages[$-1]) { + string _path_to_pod = _x.captures["path_to_pod"]; + string _podname = _x.captures["podname"]; + string _root_to_lang = _x.captures["from_root"]; + string _language = _x.captures["language"]; + string _filename = _x.captures["filename"]; + foreach (_lang; doc_matters.pod.manifest_list_of_languages) { + string _pth_mkup_src_in = _path_to_pod ~ _podname ~ "/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; + string _pth_mkup_src_out = "pod/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; + if (exists(_pth_mkup_src_in)) { + if (doc_matters.opt.action.source) { + auto fn_src_out_filesystem // you need to change language sources + = pths_pod.fn_doc_insert( + doc_matters.src.filename, // doc_matters.src.filename + _pth_mkup_src_in, // insert_file + _lang, + ).filesystem_open_zpod.to!string; + _pth_mkup_src_in.copy(fn_src_out_filesystem); // check why here, thought dealt with elsewhere + } + if (doc_matters.opt.action.pod) { + zip = pod_archive("file_path_text", _pth_mkup_src_in, _pth_mkup_src_out, zip); + } + } else { + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln("WARNING (io) src out NOT found (insert file): ", _pth_mkup_src_in); + } + } + } + } + } else { + auto fn_src_in = insert_file; + auto fn_src_out_pod_zip_base + = pths_pod.fn_doc_insert( + doc_matters.src.filename, + insert_file, + doc_matters.src.language, + ).zpod.to!string; + auto fn_src_out_filesystem + = pths_pod.fn_doc_insert( + doc_matters.src.filename, + insert_file, + doc_matters.src.language, + ).filesystem_open_zpod.to!string; + if (exists(fn_src_in)) { + debug(io) { + writeln("(io debug) src out found: ", fn_src_in); + } + if (doc_matters.opt.action.source) { + fn_src_in.copy(fn_src_out_filesystem); + } + if (doc_matters.opt.action.pod) { + zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); + } + } else { + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln("WARNING (io) src out NOT found (insert file): ", fn_src_in); + } + } + } + } + } +} { + auto fn_src_in = doc_matters.src.filename; + if (doc_matters.opt.action.pod) { + if (exists(doc_matters.src.file_with_absolute_path)) { + createZipFile!()(fn_pod, zip.build()); + } else { + writeln("WARNING check missing source file(s): ", doc_matters.opt.action.pod); + } + if (!(exists(fn_pod))) { + writeln("WARNING failed to create pod zip archive: ", fn_pod); + } + } +} +#+END_SRC + +** sha256 of pod.zip, zip debug, read zip archive + +#+name: source_pod_copy +#+BEGIN_SRC d +if (exists(fn_pod)) { + try { + if (!(doc_matters.opt.action.quiet) + && doc_matters.opt.action.pod) { + auto data = (cast(byte[]) (fn_pod).read); + if (doc_matters.opt.action.verbose) { + writeln(" ", doc_matters.src.filename, " > "); + } + if (doc_matters.opt.action.pod) { + writefln(" %s\n %s %-(%02x%)", fn_pod, "sha256", data.sha256Of); + } + } + debug(pod) { + try { + auto zipped = new ZipArchive((fn_pod).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln("> ", filename, " length ", data.length); + } + } catch (ZipException ex) { + // Handle errors + } + if (doc_matters.src.filename == "dr_doc/media/text/en/the_wealth_of_networks.yochai_benkler.sst") { + assert( + ((data).sha256Of).toHexString + == "626F83A31ED82F42CF528E922C1643498A137ABA3F2E5AFF8A379EA79EA22A1E", + "\npod: sha256 value for " + ~ doc_matters.src.filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + if (doc_matters.src.filename == "dr_doc/media/text/en/sisu_markup_stress_test.sst") { + assert( + ((data).sha256Of).toHexString + == "AAE0C87AB3F6D5F7385AEEA6EE661F56D40475CFE87AD930C78C9FE07FFB0D91", + "\npod: sha256 value for " + ~ doc_matters.src.filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + } + } catch (ErrnoException ex) { + // Handle errors + } +} +#+END_SRC + +* __END__ diff --git a/org/out_xmls.org b/org/out_xmls.org new file mode 100644 index 0000000..ea1af4a --- /dev/null +++ b/org/out_xmls.org @@ -0,0 +1,3095 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) output xmls +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:xml: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* xml offspring (xhtml html epub) +** format xhtml objects :format: +*** _module template_ :module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/xmls.d" +module doc_reform.output.xmls; +template outputXHTMLs() { + <> + mixin DocReformOutputRgxInit; + struct outputXHTMLs { + static auto rgx = Rgx(); + <> + <> + } +} +#+END_SRC + +*** output imports + +#+name: output_imports +#+BEGIN_SRC d +import doc_reform.output; +import + std.digest.sha, + std.file, + std.outbuffer, + std.uri, + std.zip, + std.conv : to; +import + doc_reform.output.create_zip_file, + doc_reform.output.xmls, + doc_reform.output.xmls_css; +#+END_SRC + +*** misc +**** div delimiter + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string div_delimit( + string part, + return ref string previous_part +){ + string delimit = ""; + string delimit_ = ""; + if (part != previous_part) { + switch (part) { + case "head": + delimit_ ~= "\n
\n" ; + break; + case "toc": + delimit_ ~= "\n
\n" ; + break; + case "bookindex": + delimit_ ~= "\n
\n" ; + break; + default: + delimit_ ~= "\n
\n" ; + break; + } + if (previous_part.length > 0) { + delimit ~= "\n
"; + } + previous_part = part; + delimit ~= delimit_; + } + // you also need to close the last div, introduce a footer? + return delimit; +} +#+END_SRC + +**** special characters text + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string special_characters_text(string _txt){ + _txt = _txt + .replaceAll(rgx.xhtml_ampersand, "&") + .replaceAll(rgx.xhtml_quotation, """) + .replaceAll(rgx.xhtml_less_than, "<") + .replaceAll(rgx.xhtml_greater_than, ">") + .replaceAll(rgx.nbsp_char, " "); + return _txt; +} +#+END_SRC + +**** special characters + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string special_characters(O)( + const O obj, +){ + string _txt = special_characters_text(obj.text); + if (!(obj.metainfo.is_a == "code")) { + _txt = (_txt) + .replaceAll(rgx.xhtml_line_break, "
"); + } + return _txt; +} +#+END_SRC + +**** font_face + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string font_face(string _txt){ + _txt = _txt + .replaceAll(rgx.inline_emphasis, ("$1")) + .replaceAll(rgx.inline_bold, ("$1")) + .replaceAll(rgx.inline_underscore, ("$1")) + .replaceAll(rgx.inline_italics, ("$1")) + .replaceAll(rgx.inline_superscript, ("$1")) + .replaceAll(rgx.inline_subscript, ("$1")) + .replaceAll(rgx.inline_strike, ("$1")) + .replaceAll(rgx.inline_insert, ("$1")) + .replaceAll(rgx.inline_mono, ("$1")) + .replaceAll(rgx.inline_cite, ("$1")); + return _txt; +} +#+END_SRC + +**** anchor tags + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string _xhtml_anchor_tags(O)(O obj) { + const(string[]) anchor_tags = obj.tags.anchor_tags; + string tags=""; + if (anchor_tags.length > 0) { + foreach (tag; anchor_tags) { + if (!(tag.empty)) { + tags ~= ""; + } + } + } + return tags; +} +#+END_SRC + +**** doc head & tails +***** metadata + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string header_metadata(M)( + M doc_matters, +) { + string _publisher="Publisher"; // TODO + string o; + o = format(q"┃ + + + + + + + + + + + + + + +┃", + doc_matters.conf_make_meta.meta.title_full, + doc_matters.conf_make_meta.meta.creator_author, + _publisher, + doc_matters.conf_make_meta.meta.date_published, + doc_matters.conf_make_meta.meta.date_created, + doc_matters.conf_make_meta.meta.date_issued, + doc_matters.conf_make_meta.meta.date_available, + doc_matters.conf_make_meta.meta.date_valid, + doc_matters.conf_make_meta.meta.date_modified, + doc_matters.src.language, + doc_matters.conf_make_meta.meta.rights_copyright, + doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.name_and_version, + doc_matters.generator_program.url_home, + ); + return o; +} +#+END_SRC + +***** site info button + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string site_info_button(M)( + M doc_matters, +) { + string _locations; + if (doc_matters.conf_make_meta.make.home_button_text.length > 0) { + _locations = (doc_matters.conf_make_meta.make.home_button_text) + .replaceAll( + rgx.inline_link, + ("

$1

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

spine

\n

sources / git

\n

www.sisudoc.org

"; + } + string o; + o = format(q"┃
+ %s +
┃", + _locations, + ); + return o; +} +#+END_SRC + +***** search form + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string inline_search_form(M)( + M doc_matters, +) { + string _action="http://www.sisudoc.org/cgi-bin/search.cgi"; + string _db="DocReform.7a.manual"; + string o; + string _form; + if (doc_matters.opt.action.workon) { + _form = format(q"┃ + +
+ + + + + +
+ + +
+ ┃", + _action, + _db, + ); + } else { + _form = format(q"┃%s┃", + "", + ); + } + o = format(q"┃
%s +
┃", + _form, + ); + return o; +} +#+END_SRC + +***** html head & head banner + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string html_head(M)( + M doc_matters, + string type, +) { +string _manifest = ""; +if (doc_matters.opt.action.workon) { + _manifest = format(q"┃ + + + [ document manifest ] + + + ┃", + ); +} + string o; + o = format(q"┃ + + + + + %s%s + + + %s + + + + + + + +
+
+ %s +
+ %s +
+ %s%s┃", + doc_matters.conf_make_meta.meta.title_full, + (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" + : ", " ~ doc_matters.conf_make_meta.meta.creator_author, + header_metadata(doc_matters), + ((type == "seg") ? "../../../" : "../../") ~ "image/rb7.ico", + ((type == "seg") + ? "../../../css/html_seg.css" + : "../../css/html_scroll.css"), + doc_matters.src.language, + site_info_button(doc_matters), + _manifest, + inline_search_form(doc_matters), + ((type == "seg") ? "" : "\n
"), + ); + return o; +} +#+END_SRC + +***** epub seg head + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string epub3_seg_head(M)( + M doc_matters, +) { + string html_base = format(q"┃ +┃", +); + string html_simple = format(q"┃ +┃", + doc_matters.src.language, + doc_matters.src.language, + ); + string html_strict = format(q"┃ +┃", + doc_matters.src.language, + doc_matters.src.language, + ); + string o; + o = format(q"┃%s + + + %s%s + + + + + + + + + + + + + + + + + + + +┃", + html_simple, + doc_matters.conf_make_meta.meta.title_full, + (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" + : ", " ~ doc_matters.conf_make_meta.meta.creator_author, + doc_matters.conf_make_meta.meta.title_full, + (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" + : ", " ~ doc_matters.conf_make_meta.meta.creator_author, + doc_matters.conf_make_meta.meta.date_published, + doc_matters.conf_make_meta.meta.date_created, + doc_matters.conf_make_meta.meta.date_issued, + doc_matters.conf_make_meta.meta.date_available, + doc_matters.conf_make_meta.meta.date_valid, + doc_matters.conf_make_meta.meta.date_modified, + doc_matters.src.language, + doc_matters.conf_make_meta.meta.rights_copyright, + doc_matters.generator_program.name_and_version, + doc_matters.generator_program.url_home, + doc_matters.src.language, + ); + return o; +} +#+END_SRC + +***** xhtml tail + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string tail() { + string o; + o = format(q"┃ + + + +┃"); + return o; +} +#+END_SRC + +*** inline markup +**** images + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string inline_images(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "seg", +) { + string _img_pth; + if (_xml_type == "epub") { + _img_pth = "image/"; + } else if (_xml_type == "scroll") { + _img_pth = "../../image/"; + } else if (_xml_type == "seg") { + _img_pth = "../../../image/"; + } + if (_txt.match(rgx.inline_image)) { + _txt = _txt + .replaceAll(rgx.inline_image, + ("$1 $6")) + .replaceAll( + rgx.inline_link_empty, + ("$1")); + } + return _txt; +} +#+END_SRC + +**** links +***** scroll, seg, epub + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string inline_links(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "seg", +) { + string seg_lvs; + if (obj.has.inline_links) { + if (obj.metainfo.is_a != "code") { + _txt = replaceAll!(m => + m[1] ~ "┤" + ~ (replaceAll!(n => + n["type"] ~ n["path"] ~ (n["file"].encodeComponent) + )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) + ~ "├" + )(_txt, rgx.inline_link_number_only); + } + if ((_txt.match(rgx.mark_internal_site_lnk)) + && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault + _txt = _txt.replaceAll( + rgx.inline_seg_link, + "$1"); + } + if (_xml_type == "seg" || _xml_type == "epub") { + seg_lvs = (_xml_type == "epub") ? "seg_lv1_to_4" : "seg_lv4"; + foreach (m; _txt.match(rgx.inline_link_hash)) { + if (m.captures[3] in doc_matters.has.tag_associations) { + if ( + m.captures[3] + == doc_matters.has.tag_associations[(m.captures[3])][seg_lvs] + ) { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤$3" ~ _suffix ~ "├" + ); + } else { + _txt = _txt.replaceFirst( + rgx.inline_link_hash, + "┥$1┝┤" + ~ doc_matters.has.tag_associations[(m.captures[3])][seg_lvs] + ~ _suffix ~ "#" ~ "$3" + ~ "├" + ); + } + } else { + if (!(doc_matters.opt.action.quiet)) { + writeln( + "WARNING on internal document links, anchor to link <<" + ~ m.captures[3] + ~ ">> not found in document, " + ~ "anchor: " ~ m.captures[3] + ~ " document: " ~ doc_matters.src.filename + ); + } + } + } + } + _txt = _txt + .replaceAll( + rgx.inline_link_fn_suffix, + ("$1" ~ _suffix)) + .replaceAll( + rgx.inline_link, + ("$1")) + .replaceAll( + rgx.mark_internal_site_lnk, + ""); + } + debug(markup_links) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + debug(markup) { + if (_txt.match(rgx.inline_link)) { + writeln(__LINE__, + " (missed) markup link identified (", + obj.has.inline_links, + "): ", obj.metainfo.is_a, ": ", + obj.text + ); + } + } + return _txt; +} +#+END_SRC + +**** notes +***** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string inline_notes_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + if (obj.has.inline_notes_reg) { + _txt = font_face(_txt); + _txt = _txt.replaceAll( + rgx.inline_notes_al_regular_number_note, + (" $1 ") + ); + } + if (obj.has.inline_notes_star) { + _txt = font_face(_txt); + _txt = _txt.replaceAll( + rgx.inline_notes_al_special_char_note, + (" $1 ") + ); + } + debug(markup_endnotes) { + if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + debug(markup) { + if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + return _txt; +} +#+END_SRC + +***** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_notes_seg(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + string[] _endnotes; + if (obj.has.inline_notes_star) { + _txt = font_face(_txt); + /+ need markup for text, and separated footnote +/ + foreach(m; _txt.matchAll(rgx.inline_notes_al_special_char_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_al_special_char_note, + (" $1 ") + ); + } + if (obj.has.inline_notes_reg) { + _txt = font_face(_txt); + /+ need markup for text, and separated footnote +/ + foreach(m; _txt.matchAll(rgx.inline_notes_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_al_regular_number_note, + (" $1 ") + ); + } else if (_txt.match(rgx.inline_notes_al_regular_number_note)) { + debug(markup) { + writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); + } + } + auto t = tuple( + _txt, + _endnotes, + ); + return t; +} +#+END_SRC + +**** inline markup +***** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string inline_markup_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", +) { + if (obj.metainfo.dummy_heading + && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { + _txt = ""; + } else { + _txt = inline_images(_txt, obj, doc_matters, _suffix, "scroll"); + _txt = inline_links(_txt, obj, doc_matters, _suffix, "scroll"); + _txt = inline_notes_scroll(_txt, obj, doc_matters); + } + return _txt; +} +#+END_SRC + +***** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto inline_markup_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "seg", +) { + if (obj.metainfo.dummy_heading + && ((_xml_type == "epub" + && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) + || obj.metainfo.is_a == "heading") + ) { + _txt = ""; + } else { + _txt = inline_images(_txt, obj, doc_matters, _suffix, _xml_type); // TODO + _txt = inline_links(_txt, obj, doc_matters, _suffix, _xml_type); // TODO + } + auto t = inline_notes_seg(_txt, obj, doc_matters); + return t; +} +#+END_SRC + +*** toc +**** subtoc + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string lev4_heading_subtoc(O,M)( + const O obj, + M doc_matters, +) { + char[] lev4_subtoc; + lev4_subtoc ~= "
\n"; + foreach (subtoc; obj.tags.lev4_subtoc) { + if (auto m = subtoc.match(rgx.inline_link_subtoc)) { + auto indent = (m.captures[1].to!int - 3).to!string; // css assumptions based on use of em for left margin & indent + auto text = m.captures[2].to!string; + text = font_face(text); + auto link = m.captures[3].to!string; + lev4_subtoc ~= subtoc.replaceFirst(rgx.inline_link_subtoc, + format(q"┃

+ ۰ %s +

+┃", + indent, + indent, + link, + text, + )); + } + } + lev4_subtoc ~= "
\n"; + return lev4_subtoc.to!string; +} +#+END_SRC + +**** navigation pre next svg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto nav_pre_next_svg(O,M)( + const O obj, + M doc_matters, +) { + string prev, next, toc; + if (obj.tags.segment_anchor_tag_epub == "toc") { + toc = ""; + prev = ""; + } else { + toc = format(q"┃ + + ┃", + ); + } + if (obj.tags.segname_prev == "") { + prev = ""; + } else { + prev = format(q"┃ + + ┃", + obj.tags.segname_prev, + ); + } + if (obj.tags.segname_next == "") { + next = ""; + } else { + next = format(q"┃ + + ┃", + obj.tags.segname_next, + ); + } + string _toc_pre_next = format(q"┃
+ +
+
+
┃", + toc, + prev, + next, + ); + string _pre_next = format(q"┃
+ +
+
+
┃", + prev, + next, + ); + struct bar { + string toc_pre_next() { + return _toc_pre_next; + } + string pre_next() { + return _pre_next; + } + } + return bar(); +} +#+END_SRC + +*** heading +**** heading + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string heading(O,M)( + string _txt, + const O obj, + M doc_matters, + string _xml_type = "html", +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "heading"); + string tags = _xhtml_anchor_tags(obj); + string heading_lev_anchor_tag; + string _horizontal_rule = "
"; + if ((_xml_type != "html") + || (obj.metainfo.heading_lev_markup == 0 || obj.metainfo.heading_lev_markup > 4)) { + _horizontal_rule = ""; + } + _txt = font_face(_txt); + string o; + heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) + ? "" + : ""; + if (_txt.empty) { + o = format(q"┃%s + ┃", + _horizontal_rule, + ); + } else if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃%s +
+ + %s%s + %s + +
┃", + _horizontal_rule, + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.heading_lev_markup, + obj.metainfo.is_a, + obj.metainfo.identifier, + obj.metainfo.identifier, + tags, + heading_lev_anchor_tag, + _txt, + obj.metainfo.heading_lev_markup, + ); + } else { + o = format(q"┃%s +
+ %s%s + %s + +
┃", + _horizontal_rule, + obj.metainfo.heading_lev_markup, + obj.metainfo.is_a, + tags, + heading_lev_anchor_tag, + _txt, + obj.metainfo.heading_lev_markup, + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string heading_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", +) { + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = heading(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto heading_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0]; + string[] _endnotes = t[1]; + string o = heading(_txt, obj, doc_matters, _xml_type); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** para +**** para + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string para(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); + assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "para"); + assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); + string tags = _xhtml_anchor_tags(obj); + _txt = font_face(_txt); + string o; + _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; + _txt = _txt.replaceFirst(rgx.inline_link_anchor, + ""); + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

%s + %s +

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.attrib.indent_hang, + obj.attrib.indent_base, + obj.metainfo.identifier, + tags, + _txt + ); + } else { + o = format(q"┃
+

%s + %s +

+
┃", + obj.metainfo.is_a, + obj.attrib.indent_hang, + obj.attrib.indent_base, + tags, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string para_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", +) { + if (obj.metainfo.is_a == "toc" && _txt.match(rgx.inline_link_toc_to_backmatter)) { + _txt = _txt.replaceAll(rgx.inline_link_toc_to_backmatter, "┤#section_$1├"); + } + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = para(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto para_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0].to!string; + string[] _endnotes = t[1]; + string o = para(_txt, obj, doc_matters); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** quote +**** quote + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string quote(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "quote"); + _txt = font_face(_txt); + string o; + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

+ %s +

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.identifier, + _txt + ); + } else { + o = format(q"┃
+

+ %s +

+
┃", + obj.metainfo.is_a, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string quote_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", +) { + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = quote(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto quote_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0].to!string; + string[] _endnotes = t[1]; + string o = quote(_txt, obj, doc_matters); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** group +**** group + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string group(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "group"); + _txt = font_face(_txt); + string o; + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

+ %s +

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.identifier, + _txt + ); + } else { + o = format(q"┃
+

+ %s +

+
┃", + obj.metainfo.is_a, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string group_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = group(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto group_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0].to!string; + string[] _endnotes = t[1]; + string o = group(_txt, obj, doc_matters); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** block +**** block + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string block(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "block"); + _txt = font_face(_txt); + string o; + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

%s

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.identifier, + _txt.stripRight + ); + } else { + o = format(q"┃
+

%s

+
┃", + obj.metainfo.is_a, + _txt.stripRight + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string block_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = block(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto block_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0].to!string; + string[] _endnotes = t[1]; + string o = block(_txt, obj, doc_matters); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** poem verse +**** verse + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string verse(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "verse"); + _txt = font_face(_txt); + string o; + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

%s

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.identifier, + _txt + ); + } else { + o = format(q"┃
+

%s

+
┃", + obj.metainfo.is_a, + _txt + ); + } + return o; +} +#+END_SRC + +**** scroll + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string verse_scroll(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); + string o = verse(_txt, obj, doc_matters); + return o; +} +#+END_SRC + +**** seg + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto verse_seg(O,M)( + string _txt, + const O obj, + M doc_matters, + string _suffix = ".html", + string _xml_type = "html", +) { + auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); + _txt = t[0].to!string; + string[] _endnotes = t[1]; + string o = verse(_txt, obj, doc_matters); + auto u = tuple( + o, + _endnotes, + ); + return u; +} +#+END_SRC + +*** code + +#+name: xhtml_format_objects_code +#+BEGIN_SRC d +string code(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "code"); + string o; + string codelines(string _txt) { + string _codelines; + if (obj.code_block.linenumbers) { + string[] _block_lines = (_txt).split(rgx.br_newlines_linebreaks); + _codelines = "
\n";
+      foreach (k, _line; _block_lines) {
+        if (k == 1) {
+          _codelines ~= format(q"┃    %s
+┃",
+            _line,
+          );
+        } else {
+          _codelines ~= format(q"┃    %s
+┃",
+            _line,
+          );
+        }
+      }
+      _codelines ~= "  
"; + } else { + _codelines = "
\n";
+      _codelines ~= _txt;
+      _codelines ~= "  
"; + } + return _codelines; + } + if (!(obj.metainfo.identifier.empty)) { + o = format(q"┃
+ +

%s

+
┃", + obj.metainfo.identifier, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.identifier, + codelines(_txt) + ); + } else { + o = format(q"┃
+

%s

+
┃", + obj.metainfo.is_a, + codelines(_txt) + ); + } + return o; +} +#+END_SRC + +*** table +**** TODO tablarize + +align="left|right|center" +$100 + +"style=\"text-align:right\"" +"style=\"text-align:left\"" + +"style=\"text-align:" ~ "right\"" + +#+name: xhtml_format_objects +#+BEGIN_SRC d +auto tablarize(O)( + string _txt, + const O obj, +) { + 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; +} +#+END_SRC + +**** table + +#+name: xhtml_format_objects +#+BEGIN_SRC d +string table(O,M)( + string _txt, + const O obj, + M doc_matters, +) { + assert(obj.metainfo.is_of_part == "body"); + assert(obj.metainfo.is_of_section == "body"); + assert(obj.metainfo.is_of_type == "block"); + assert(obj.metainfo.is_a == "table"); + string tags = _xhtml_anchor_tags(obj); + _txt = font_face(_txt); + auto t = tablarize(_txt, obj); + _txt = t[0]; + string _note = t[1]; + string o; + o = format(q"┃
+ +

%s + + %s +
+ %s +

+
┃", + obj.metainfo.object_number, + (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), + obj.metainfo.is_a, + obj.metainfo.object_number, + tags, + _txt, + _note + ); + return o; +} +#+END_SRC + +* _html_ [#A] :html: +** _module template_ :module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/html.d" +module doc_reform.output.html; +template outputHTML() { + <> + mixin outputXHTMLs; + <> + <> + <> + <> +} +#+END_SRC + +** scroll :scroll: +*** ↻ loop & switch (sections & objects) format html output + +#+name: output_html_scroll +#+BEGIN_SRC d +void scroll(D,M)( + const D doc_abstraction, + M doc_matters, +) { + mixin DocReformOutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[] doc_html; + string[] doc; + string suffix = ".html"; + string previous_part = ""; + string delimit = ""; +#+END_SRC + +**** ↻ the loops & outer switch (sections & objects) format output + +#+name: output_html_scroll +#+BEGIN_SRC d + foreach (part; doc_matters.has.keys_seq.scroll) { + foreach (obj; doc_abstraction[part]) { + delimit = xhtml_format.div_delimit(part, previous_part); + string _txt = xhtml_format.special_characters(obj); + switch (obj.metainfo.is_of_part) { +#+END_SRC + +***** frontmatter + +#+name: output_html_scroll +#+BEGIN_SRC d + case "frontmatter": assert(part == "head" || "toc"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); + break; + case "toc": + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; +#+END_SRC + +***** body + +#+name: output_html_scroll +#+BEGIN_SRC d + case "body": assert(part == "body" || "head"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); + break; + case "para": + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + doc_html ~= xhtml_format.quote_scroll(_txt, obj, doc_matters); + break; + case "group": + doc_html ~= xhtml_format.group_scroll(_txt, obj, doc_matters); + break; + case "block": + doc_html ~= xhtml_format.block_scroll(_txt, obj, doc_matters); + break; + case "poem": + break; + case "verse": + doc_html ~= xhtml_format.verse_scroll(_txt, obj, doc_matters, suffix); + break; + case "code": + doc_html ~= xhtml_format.code(_txt, obj, doc_matters); + break; + case "table": + doc_html ~= xhtml_format.table(_txt, obj, doc_matters); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; +#+END_SRC + +***** backmatter + +#+name: output_html_scroll +#+BEGIN_SRC d + case "backmatter": + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "heading": + doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); + break; + case "endnote": assert(part == "endnotes"); + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + case "glossary": assert(part == "glossary"); + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + case "bibliography": assert(part == "bibliography"); + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + case "bookindex": assert(part == "bookindex"); + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + case "blurb": assert(part == "blurb"); + doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + } + break; +#+END_SRC + +***** closings & post loop + +#+name: output_html_scroll +#+BEGIN_SRC d + } + } + } + doc = xhtml_format.html_head(doc_matters, "scroll") ~ doc_html ~ xhtml_format.tail; + scroll_write_output(doc, doc_matters); +} +#+END_SRC + +*** write output file + +#+name: output_html_scroll +#+BEGIN_SRC d +void scroll_write_output(D,M)( + D doc, + M doc_matters, +) { + debug(asserts) { + static assert(is(typeof(doc) == string[])); + } + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + try { + if (!exists(pth_html.base)) { + pth_html.base.mkdirRecurse; + } + auto f = File(pth_html.fn_scroll(doc_matters.src.filename), "w"); + foreach (o; doc) { + f.writeln(o); + } + } catch (ErrnoException ex) { + // Handle error + } + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_html.fn_scroll(doc_matters.src.filename)); + } +} +#+END_SRC + +** seg :seg: +*** ↻ loop & switch (sections & objects) format html output + +#+name: output_html_seg +#+BEGIN_SRC d +void seg(D,M)( + const D doc_abstraction, + M doc_matters, +) { + mixin DocReformOutputRgxInit; + 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 previous_seg_filename = ""; + string suffix = ".html"; + string previous_part = ""; + string delimit = ""; +#+END_SRC + +**** ↻ the loop (sections & objects) format output + +#+name: output_html_seg +#+BEGIN_SRC d + foreach (part; doc_matters.has.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + delimit = xhtml_format.div_delimit(part, previous_part); + string _txt = xhtml_format.special_characters(obj); +#+END_SRC + +***** all headings + +#+name: output_html_seg +#+BEGIN_SRC d + if (obj.metainfo.is_a == "heading") { + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.metainfo.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(_txt, obj, doc_matters, suffix, "seg"); + top_level_headings[obj.metainfo.heading_lev_markup] = t[0]; + break; + } + break; + case 4: + segment_filename = obj.tags.segment_anchor_tag_epub; + doc_html[segment_filename] ~= xhtml_format.html_head(doc_matters, "seg"); + auto navigation_bar = xhtml_format.nav_pre_next_svg(obj, doc_matters); + doc_html[segment_filename] ~= navigation_bar.toc_pre_next; + previous_seg_filename = segment_filename; + foreach (top_level_heading; top_level_headings) { + doc_html[segment_filename] ~= top_level_heading; + } + auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html[segment_filename] ~= xhtml_format.lev4_heading_subtoc(obj, doc_matters); + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 5: .. case 7: + auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + } + } + break; + } +#+END_SRC + +***** non-heading + +#+name: output_html_seg +#+BEGIN_SRC d + } else { + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_part) { +#+END_SRC + +****** frontmatter + +#+name: output_html_seg +#+BEGIN_SRC d + case "frontmatter": assert(part == "head" || "toc"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "toc": + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; +#+END_SRC + +****** body + +#+name: output_html_seg +#+BEGIN_SRC d + case "body": assert(part == "body"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "para": + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "group": + auto t = xhtml_format.group_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "block": + auto t = xhtml_format.block_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "poem": + break; + case "verse": + auto t = xhtml_format.verse_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0].to!string; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "code": + doc_html[segment_filename] ~= xhtml_format.code(_txt, obj, doc_matters); + break; + case "table": + doc_html[segment_filename] ~= xhtml_format.table(_txt, obj, doc_matters); + doc_html_endnotes[segment_filename] ~= ""; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; +#+END_SRC + +****** backmatter + +#+name: output_html_seg +#+BEGIN_SRC d + case "backmatter": + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "endnote": assert(part == "endnotes"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0]; + break; + case "glossary": assert(part == "glossary"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bibliography": assert(part == "bibliography"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": assert(part == "bookindex"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + case "blurb": assert(part == "blurb"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); + doc_html[segment_filename] ~= t[0]; + doc_html_endnotes[segment_filename] ~= t[1]; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + } + } + break; + } +#+END_SRC + +***** closings & post loop + +#+name: output_html_seg +#+BEGIN_SRC d + } + } + } + seg_write_output(doc_html, doc_html_endnotes, doc_matters); +} +#+END_SRC + +*** write output files + +#+name: output_html_seg +#+BEGIN_SRC d +void seg_write_output(D,E,M)( + D doc_html, + E doc_html_endnotes, + M doc_matters, +) { + debug(asserts) { + static assert(is(typeof(doc_html) == string[][string])); + } + mixin DocReformOutputRgxInit; + auto rgx = Rgx(); + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + auto xhtml_format = outputXHTMLs(); + auto m = doc_matters.src.filename.matchFirst(rgx.src_fn); + try { + if (!exists(pth_html.seg(doc_matters.src.filename))) { + pth_html.seg(doc_matters.src.filename).mkdirRecurse; + } + foreach (seg_filename; doc_matters.has.segnames_lv4) { + auto f = File(pth_html.fn_seg(doc_matters.src.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 + } + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", pth_html.fn_seg(doc_matters.src.filename, "toc")); + } +} +#+END_SRC + +** css :css: + +#+name: output_html_css +#+BEGIN_SRC d +void css(M)(M doc_matters) { + auto css = DocReformCss(doc_matters); + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + try { + if (!exists(pth_html.css)) { + (pth_html.css).mkdirRecurse; + } + auto f = File(pth_html.fn_seg_css, "w"); + f.writeln(css.html_seg); + f = File(pth_html.fn_scroll_css, "w"); + f.writeln(css.html_scroll); + } catch (ErrnoException ex) { + // Handle error + } +} +#+END_SRC + +** images :images: + +#+name: copy_html_images +#+BEGIN_SRC d +void images_cp(M)( + M doc_matters, +) { + { /+ (copy html images) +/ + + auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); + if (!exists(pth_html.image)) { + pth_html.image.mkdirRecurse; + } + foreach (image; doc_matters.srcs.image_list) { + auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_src_out = pth_html.image ~ "/" ~ image; + debug(images_html) { + writeln(fn_src_in, " -> ", fn_src_out); + } + if (exists(fn_src_in)) { + fn_src_in.copy(fn_src_out); + } else { + if (!(doc_matters.opt.action.quiet)) { + writeln("WARNING image not found: ", fn_src_in); + } + } + } + } +} +#+END_SRC + +* _epub_ [#B] :epub: + +|-----------------------+--------------------------+---------------------------+----------------------------------| +| function | filename | module | variable | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| identify doc filetype | mimetype | epub3_mimetypes | mimetypes | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| identify doc root | META-INF/container.xml | epub3_container_xml | meta_inf_container_xml | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc manifest | OEBPS/content.opf | epub3_oebps_content | oebps_content_opf | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc navigation | OEBPS/toc_nav.xhtml | epub3_oebps_toc_nav_xhtml | oebps_toc_nav_xhtml | +| | OEBPS/toc.ncx | epub2_oebps_toc_ncx | oebps_toc_ncx | +|-----------------------+--------------------------+---------------------------+----------------------------------| +| doc contents | OEBPS/[files ... ].xhtml | outputEPub3 | doc_epub3[seg_filename] | +| | | | doc_epub3_endnotes[seg_filename] | +|-----------------------+--------------------------+---------------------------+----------------------------------| + +** _module template_ :module: + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/epub3.d" +module doc_reform.output.epub3; +template outputEPub3() { + <> + mixin InternalMarkup; + mixin outputXHTMLs; + <> + <> + <> + <> + <> +} +#+END_SRC + +** special (epub) files :format: +*** static +**** _identify doc filetype_ (mimetype) [static] + +- mimetype file indicating that zip file contains an EPUB + +#+name: output_epub3_fixed +#+BEGIN_SRC d +string epub3_mimetypes() { + string o; + o = format(q"┃application/epub+zip┃") ~ "\n"; + return o; +} +#+END_SRC + +**** _identify doc root_ (META-INF/container.xml) [static] rootfile: contains document root path + +- identifies the root package document (so systems can find it), [unchanged from epub2] + +#+name: output_epub3_fixed +#+BEGIN_SRC d +string epub3_container_xml() { + string o; + o = format(q"┃┃") ~ "\n"; + o ~= format(q"┃ + + +┃") ~ "\n\n"; + return o; +} +#+END_SRC + +*** constructs (in dir: OEBPS) +**** TODO _doc manifest_ (OEBPS/content.opf) manifest, register content: files, images etc. + +- manifest, listing all resources +- provides the default reading order +- identifies the navigation document + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub3_oebps_content(D,M,P)(D doc_abstraction, M doc_matters, P parts) { + auto xhtml_format = outputXHTMLs(); + auto pth_epub3 = DocReformPathsEPUB!()(doc_matters.output_path, doc_matters.src.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, + xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_full), + xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_main), + (doc_matters.conf_make_meta.meta.title_sub.empty) + ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_sub), + (doc_matters.conf_make_meta.meta.creator_author.empty) + ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.creator_author), + (doc_matters.conf_make_meta.meta.creator_author.empty) + ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.creator_author), + doc_matters.src.language, // language, fix (needed in dochead metadata) + (doc_matters.conf_make_meta.meta.date_published.empty) + ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.date_published), + (doc_matters.conf_make_meta.meta.rights_copyright.empty) + ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.rights_copyright), + _uuid, + _uuid, + _uuid, + (pth_epub3.fn_oebps_css).chompPrefix("OEBPS/"), + ); + content ~= " " ~ "" ~ "\n "; + content ~= parts["manifest_documents"]; + // TODO sort jpg & png + content ~= " " ~ "" ~ "\n "; + foreach (image; doc_matters.srcs.image_list) { + content ~= format(q"┃ +┃", + image.baseName.stripExtension, + (pth_epub3.doc_oebps_image).chompPrefix("OEBPS/"), + image, + image.extension.chompPrefix("."), + ); + } + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["spine"]; + content ~= " " ~ "" ~ "\n "; + content ~= " " ~ "" ~ "\n "; + content ~= parts["guide"]; + content ~= " " ~ "" ~ "\n "; + content ~= "" ~ ""; + debug(epubmanifest) { + foreach (part; doc_matters.has.keys_seq.seg) { // TODO + foreach (obj; doc_abstraction[part]) { + if (obj.metainfo.is_a == "heading") { + if (obj.metainfo.heading_lev_markup == 4) { + writefln( + "%s~ [%s.xhtml] %s", + obj.marked_up_level, + obj.tags.segment_anchor_tag_epub, + obj.text + ); + } else if (obj.metainfo.heading_lev_markup > 4) { + writefln( + "%s~ [%s.xhtml#%s] %s", + obj.marked_up_level, + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + obj.text + ); + } + } + } + } + } + return content; +} +#+END_SRC + +**** _doc navigation epub3_ (OEBPS/toc_nav.xhtml) epub3 navigable toc using Dom structure + +- toc_nav.xhtml declared as nav file in content.opf (epub3 navigation document) + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { + enum DomTags { none, open, close, close_and_open, open_still, } + auto markup = InlineMarkup(); + auto rgx = Rgx(); + string toc =format(" + + %s + + +
+
+

Contents

+
+ +
+ +\n"; + return toc; +} +#+END_SRC + +**** TODO _doc navigation epub2_ (OEBPS/toc.ncx) navigable toc using Dom structure + +- toc.ncx (epub2 navigation document) + - (replaced in epub3 by a declared xhtml nav file, in our case toc_nav.xhtml) + +#+name: output_epub3_constructs +#+BEGIN_SRC d +string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { + int counter = 0; + string _uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere + auto markup = InlineMarkup(); + auto rgx = Rgx(); + enum DomTags { none, open, close, close_and_open, open_still, } + string toc = format(q"┃ + + + + %s%s + + + + + + + + + %s + + + %s + +┃", + doc_matters.conf_make_meta.meta.title_full, // title + (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" + : " by " ~ doc_matters.conf_make_meta.meta.creator_author, // author + _uuid, // uuid + "3", // content depth + doc_matters.conf_make_meta.meta.title_full, // title + (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" + : doc_matters.conf_make_meta.meta.creator_author, // author + ); + foreach (sect; doc_matters.has.keys_seq.seg) { + foreach (obj; doc_abstraction[sect]) { + if (obj.metainfo.is_a == "heading") { + string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip; + string hashtag =(obj.metainfo.heading_lev_markup <= 4) ? "" : ("#" ~ obj.metainfo.ocn.to!string); + foreach_reverse (k; 0 .. 7) { + switch (obj.metainfo.dom_structure_markedup_tags_status[k]) { + case DomTags.close : + toc ~= "\n "; + break; + case DomTags.close_and_open : + ++counter; + toc ~= "\n "; + toc ~= format(q"┃ + + + %s + + ┃", + counter, + _txt, + obj.tags.segment_anchor_tag_epub, + hashtag, + ); + break; + case DomTags.open : + ++counter; + toc ~= format(q"┃ + + + %s + + ┃", + counter, + _txt, + obj.tags.segment_anchor_tag_epub, + hashtag, + ); + break; + default : + break; + } + } + } + } + } + toc ~= format(q"┃ + + + + +┃"); + return toc; +} +#+END_SRC + +** the document contents :seg: +*** ↻ loop & switch (sections & objects) format epub3 xhtml output + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d +void outputEPub3(D,I)( + const D doc_abstraction, + I doc_matters, +) { + mixin DocReformOutputRgxInit; + auto xhtml_format = outputXHTMLs(); + auto rgx = Rgx(); + string[] doc; + string segment_filename; + string[] top_level_headings = ["","","",""]; + string[string] oepbs_content_parts; + string suffix = ".xhtml"; + struct writeOut { /+ epub specific documents +/ + /+ fixed output +/ + string mimetypes; + string meta_inf_container_xml; + string oebps_toc_ncx; + string oebps_toc_nav_xhtml; + /+ variable output +/ + string oebps_content_opf; + string[][string] doc_epub3; + string[][string] doc_epub3_endnotes; + string[] doc_parts; + } + auto epubWrite = writeOut(); +#+END_SRC + +**** ↻ the loop (sections & objects) format output + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + foreach (part; doc_matters.has.keys_seq.seg) { + foreach (obj; doc_abstraction[part]) { + string _txt = xhtml_format.special_characters(obj); +#+END_SRC + +***** all headings + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + if (obj.metainfo.is_a == "heading") { + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.heading_lev_markup) { + case 0: .. case 3: + /+ fill buffer, and replace with new levels from 1 to 3 +/ + switch (obj.metainfo.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: + epubWrite.doc_parts ~= obj.tags.segment_anchor_tag_epub; + epubWrite.doc_epub3[obj.tags.segment_anchor_tag_epub] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[obj.tags.segment_anchor_tag_epub] ~= t[0]; + epubWrite.doc_epub3_endnotes[obj.tags.segment_anchor_tag_epub] ~= t[1]; + break; + } + break; + case 4: + segment_filename = obj.tags.segment_anchor_tag_epub; + epubWrite.doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters); + auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case 5: .. case 7: + auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case 8: .. case 9: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + writeln(__FILE__, ":", __LINE__, ": ", obj.text); + } + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); + } + } + break; + } +#+END_SRC + +***** non-heading + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + } else { + assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_part) { +#+END_SRC + +****** frontmatter + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + case "frontmatter": assert(part == "head" || "toc"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "toc": + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; +#+END_SRC + +****** body + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + case "body": assert(part == "body"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "para": + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + case "block": + switch (obj.metainfo.is_a) { + case "quote": + auto t = xhtml_format.quote_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "group": + auto t = xhtml_format.group_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "block": + auto t = xhtml_format.block_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "poem": + break; + case "verse": + auto t = xhtml_format.verse_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "code": + epubWrite.doc_epub3[segment_filename] ~= xhtml_format.code(_txt, obj, doc_matters); + break; + case "table": + epubWrite.doc_epub3[segment_filename] ~= xhtml_format.table(_txt, obj, doc_matters); + epubWrite.doc_epub3_endnotes[segment_filename] ~= ""; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; +#+END_SRC + +****** backmatter + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + case "backmatter": + assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); + switch (obj.metainfo.is_of_type) { + case "para": + switch (obj.metainfo.is_a) { + case "endnote": assert(part == "endnotes"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + break; + case "glossary": assert(part == "glossary"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "bibliography": assert(part == "bibliography"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "bookindex": assert(part == "bookindex"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + case "blurb": assert(part == "blurb"); + auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); + epubWrite.doc_epub3[segment_filename] ~= t[0]; + epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); + } + } + break; + } + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); + } + } + break; + } + break; + case "comment": + break; + default: + { /+ debug +/ + if (doc_matters.opt.action.debug_do + && doc_matters.opt.action.verbose) { + writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); + } + } + break; + } + } + if (obj.metainfo.is_a == "heading") { + assert(obj.text.length > 0); + if (obj.metainfo.heading_lev_markup <= 4) { + oepbs_content_parts["manifest_documents"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + obj.tags.segment_anchor_tag_epub, + ); + oepbs_content_parts["spine"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + ); + oepbs_content_parts["guide"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + obj.tags.segment_anchor_tag_epub, + ); + } else if (obj.metainfo.heading_lev_markup > 4) { + oepbs_content_parts["manifest_documents"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + ); + oepbs_content_parts["spine"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + ); + oepbs_content_parts["guide"] ~= + format(q"┃ +┃", + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + obj.tags.segment_anchor_tag_epub, + obj.metainfo.object_number, + ); + } +#+END_SRC + +***** closings & post loop + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + } + } + } + /+ epub specific documents +/ + epubWrite.mimetypes = epub3_mimetypes; + epubWrite.meta_inf_container_xml = epub3_container_xml; + epubWrite.oebps_toc_ncx = doc_abstraction.epub2_oebps_toc_ncx(doc_matters); + epubWrite.oebps_toc_nav_xhtml = doc_abstraction.epub3_oebps_toc_nav_xhtml(doc_matters); + epubWrite.oebps_content_opf = doc_abstraction.epub3_oebps_content(doc_matters, oepbs_content_parts); + epubWrite.epub3_write_output_files(doc_matters); +} +#+END_SRC + +** write output files :write:zip: + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d +void epub3_write_output_files(W,M)( + W epub_write, + M doc_matters, +) { + debug(asserts) { + static assert(is(typeof(epub_write.doc_epub3) == string[][string])); + static assert(is(typeof(epub_write.mimetypes) == string)); + static assert(is(typeof(epub_write.meta_inf_container_xml) == string)); + static assert(is(typeof(epub_write.oebps_toc_nav_xhtml) == string)); + static assert(is(typeof(epub_write.oebps_toc_ncx) == string)); + static assert(is(typeof(epub_write.oebps_content_opf) == string)); + } + static auto rgx = Rgx(); + auto pth_epub3 = DocReformPathsEPUB!()(doc_matters.output_path, doc_matters.src.language); + auto xhtml_format = outputXHTMLs(); + /+ zip file +/ + auto fn_epub = pth_epub3.epub_file(doc_matters.src.filename); + auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); + /+ zip archive member files +/ + void EPUBzip()(string contents, string fn) { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + (doc_matters.opt.action.debug_do) + ? zip_data.write(contents.dup) + : zip_data.write(contents.dup + .replaceAll(rgx.spaces_line_start, "") + .replaceAll(rgx.newline, " ") + .strip + ); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(fn_epub, zip.build()); + } + try { + if (!exists(pth_epub3.base)) { + pth_epub3.base.mkdirRecurse; + } + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename))) { + pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename))) { + pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename).mkdirRecurse; + } + if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename))) { + pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename).mkdirRecurse; + } + } + } + { /+ OEBPS/[segments].xhtml (the document contents) +/ + foreach (seg_filename; doc_matters.has.segnames_lv_0_to_4) { + string fn = pth_epub3.fn_oebps_content_xhtml(seg_filename); + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.src.filename, seg_filename); + auto f = File(fn_dbg, "w"); + foreach (docseg; epub_write.doc_epub3[seg_filename]) { + f.writeln(docseg); + } + foreach (docseg; epub_write.doc_epub3_endnotes[seg_filename]) { + f.writeln(docseg); + } + f.writeln(xhtml_format.tail); + } + } + foreach (docseg; epub_write.doc_epub3[seg_filename]) { + zip_data.write(docseg.dup); + } + foreach (docseg; epub_write.doc_epub3_endnotes[seg_filename]) { + zip_data.write(docseg.dup); + } + 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; + string fn_dbg; + File f; + { /+ mimetypes (identify zip file type) +/ + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.src.filename); + File(fn_dbg, "w").writeln(epub_write.mimetypes); + } + } + fn = pth_epub3.fn_mimetypes; + EPUBzip(epub_write.mimetypes, fn); + } + { /+ META-INF/container.xml (identify doc root) +/ + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.src.filename); + File(fn_dbg, "w").writeln(epub_write.meta_inf_container_xml); + } + } + fn = pth_epub3.fn_dmi_container_xml; + EPUBzip(epub_write.meta_inf_container_xml, fn); + } + { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.src.filename); + File(fn_dbg, "w").writeln(epub_write.oebps_toc_nav_xhtml); + } + } + fn = pth_epub3.fn_oebps_toc_nav_xhtml; + EPUBzip(epub_write.oebps_toc_nav_xhtml, fn); + } + { /+ OEBPS/toc.ncx (navigation toc epub2) +/ + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.src.filename); + File(fn_dbg, "w").writeln(epub_write.oebps_toc_ncx); + } + } + fn = pth_epub3.fn_oebps_toc_ncx; + EPUBzip(epub_write.oebps_toc_ncx, fn); + } + { /+ OEBPS/content.opf (doc manifest) +/ + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.src.filename); + File(fn_dbg, "w").writeln(epub_write.oebps_content_opf); + } + } + fn = pth_epub3.fn_oebps_content_opf; + EPUBzip(epub_write.oebps_content_opf, fn); + } + { /+ OEBPS/_dr/image (images) +/ + foreach (image; doc_matters.srcs.image_list) { + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + if (doc_matters.opt.action.very_verbose) { + writeln( + doc_matters.src.image_dir_path, "/", image, " -> ", + pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename), "/", image + ); + } + if (exists(doc_matters.src.image_dir_path ~ "/" ~ image)) { + (doc_matters.src.image_dir_path ~ "/" ~ image) + .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename)) ~ "/" ~ image); + } + } + } + auto fn_src = doc_matters.src.image_dir_path ~ "/" ~ image; + auto fn_out = pth_epub3.doc_oebps_image ~ "/" ~ 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 = DocReformCss(doc_matters); + { /+ debug +/ + if (doc_matters.opt.action.debug_do) { + fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.src.filename); + File(fn_dbg, "w").writeln(css.epub); + } + } + fn = pth_epub3.fn_oebps_css; + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn; + auto zip_data = new OutBuffer(); + zip_data.write(css.epub.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 + } + if (!(doc_matters.opt.action.quiet)) { + writeln(" ", fn_epub); + } +#+END_SRC + +** zip debug, read zip archive :zip: + +#+name: output_epub3_xhtml_seg +#+BEGIN_SRC d + debug(epub_archive) { + if (exists(fn_epub)) { + try { + auto zipped = new ZipArchive((fn_epub).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln(filename, " length ", data.length); + } + } catch (ZipException ex) { + // Handle errors + } + } + } +} +#+END_SRC + +* __END__ diff --git a/org/out_xmls_css.org b/org/out_xmls_css.org new file mode 100644 index 0000000..b16bee0 --- /dev/null +++ b/org/out_xmls_css.org @@ -0,0 +1,2364 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) defaults css +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+FILETAGS: :spine:output:xmls:css: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* 0. output css defaults :module:spine:output_xmls_css: +** _module template_ + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/xmls_css.d" +/++ + default css settings ++/ +module doc_reform.output.xmls_css; +template DocReformCss() { + import std.format; + auto DocReformCss(M)(M doc_matters) { +<> +<> + string _css_light_html_seg = format(q"┃ +<> +<> +┃", + _color_ocn_light, + _css_indent, + _color_ocn_light, +); + string _css_dark_html_seg = format(q"┃ +<> +<> +┃", + _color_ocn_dark, + _css_indent, + _color_ocn_dark, +); + string _css_light_html_scroll = format(q"┃ +<> +<> +┃", + _color_ocn_light, + _css_indent, + _color_ocn_light, +); + string _css_dark_html_scroll = format(q"┃ +<> +<> +┃", + _color_ocn_dark, + _css_indent, + _color_ocn_dark, +); + string _css_light_epub = format(q"┃ +<> +<> +┃", + _color_ocn_light, + _css_indent, + _color_ocn_light, +); + string _css_dark_epub = format(q"┃ +<> +<> +┃", + _color_ocn_dark, + _css_indent, + _color_ocn_dark, +); + auto css_() { + struct _CSS { + string html_seg = "/* DocReform css html seg stylesheet */\n"; + string html_scroll = "/* DocReform css html scroll stylesheet */\n"; + string epub = "/* DocReform css epub stylesheet */\n"; + } + return _CSS(); + } + auto css = css_(); + if (doc_matters.opt.action.css_theme_default) { + css.html_seg ~= _css_light_html_seg; + css.html_scroll ~= _css_light_html_scroll; + css.epub ~= _css_light_epub; + } else { + css.html_seg ~= _css_dark_html_seg; + css.html_scroll ~= _css_dark_html_scroll; + css.epub ~= _css_dark_epub; + } + return css; + } +} +#+END_SRC + +** css light theme +*** html shared +**** general + +#+name: css_light_shared +#+BEGIN_SRC css + *{ + padding : 0px; + margin : 0px; + } + body { + height : 100vh; + background-color : #FFFFFF; + } + body { + color : #000000; + background : #FFFFFF; + background-color : #FFFFFF; + } +#+END_SRC + +**** link + +#+name: css_light_shared +#+BEGIN_SRC css + 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 : %s; + text-decoration : none; + } + a.lnkocn:visited { + color : #32CD32; + text-decoration : none; + } + a.lnkocn:hover { + color : #777777; + font-size : 15px; + } + a:hover img { + background-color : #FFFFFF; + } + a:active { + color : #003399; + text-decoration : underline; + } +#+END_SRC + +**** div + +#+name: css_light_shared +#+BEGIN_SRC css + div { + margin-left : 0; + margin-right : 0; + } + div.p { + margin-left : 5%%; + margin-right : 1%%; + } + div.substance { + width : 100%%; + background-color : #FFFFFF; + } + div.ocn { + width : 5%%; + float : right; + top : 0; + background-color : #FFFFFF; + } + div.endnote { + width : 95%%; + background-color : #FFFFFF; + } + 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-left : 5%%; + margin-right : 2em; + margin-top : 1.8em; + margin-bottom : 1.8em; + } + span.currentlink { + text-decoration : none; + background-color : #AAAAAA; + } + div.toc a:visited { + color : #0000aa; + } + div.toc a:hover { + color : #000000; + background-color : #F9F9AA; + } + nav#toc ol { + list-style-type : none; + } +#+END_SRC + +**** paragraphs headings blocks +***** misc + +#+name: css_light_shared +#+BEGIN_SRC css + .norm, .bold, .verse, .group, .block, .alt { + line-height : 133%%; + margin-top : 12px; + margin-bottom : 0px; + padding-left : 0em; + text-indent : 0em; + } + p, h0, h1, h2, h3, h4, h5, h6, h7, ul, li { + display : block; + font-family : verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + margin-left : 5%%; + margin-right : 2em; + } + p { + font-size : 100%%; + font-weight : normal; + line-height : 133%%; + text-align : justify; + text-indent : 0mm; + margin-top : 0.8em; + margin-bottom : 0.8em; + } +#+END_SRC + +#+name: css_light_shared +#+BEGIN_SRC css + img { + max-width : 100%%; + height : auto; + } +#+END_SRC + +***** code block + +#+name: css_light_shared +#+BEGIN_SRC css + pre { + width : auto; + display : block; + clear : both; + color : #555555; + } + pre.codeline { + display : table; + clear : both; + table-layout : fixed; + margin-left : 5%%; + margin-right : 5%%; + width : 90%%; + white-space : pre-wrap; + border-style : none; + border-radius : 5px 5px 5px 5px; + box-shadow : 0 2px 5px #AAAAAA inset; + margin-bottom : 1em; + padding : 0.5em 1em; + page-break-inside : avoid; + word-wrap : break-word; + font-family : inconsolata, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; + white-space : pre; + white-space : pre-wrap; + white-space : -moz-pre-wrap; + white-space : -o-pre-wrap; + background-color : #EEEEEE; + color : #000000; + font-size : 95%%; + line-height : 100%%; + } + pre.codeline::before { + counter-reset : linenum; + } + pre.codeline span.tr { + display : table-row; + counter-increment : linenum; + } + pre.codeline span.th { + display : table-cell; + user-select : none; + -moz-user-select : none; + -webkit-user-select : none; + padding : 0.5em 0.5em; + /* background-color : #666666; */ + } + pre.codeline span.th::before { + content : counter(linenum) "."; + color : #999999; + text-align : right; + display : block; + } + pre.codeline span.th { + width : 4em; + } + pre.codeline code { + display : table-cell; + } + p.code { + border-style : none; + } +#+END_SRC + +***** paragraph general + +#+name: css_light_shared +#+BEGIN_SRC css + p.spaced { white-space : pre; } + p.block { + white-space : pre; + } + p.group { } + p.alt { } + p.verse { + white-space : pre; + margin-bottom : 6px; + } + 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, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; + background-color : #EEEEEE; + color : #000000; + } +#+END_SRC + +***** paragraph indent + +#+name: css_light_shared +#+BEGIN_SRC css +%s +#+END_SRC + +***** misc including tables & lists + +#+name: css_light_shared +#+BEGIN_SRC css + note { white-space : pre; } + label.ocn { + width : 2%%; + float : right; + top : 0; + font-size : 10px; + margin-top : 0px; + margin-bottom : 5px; + margin-right : 5px; + text-align : right; + color : %s; + -khtml-user-select : none; + -moz-user-select : none; + -ms-user-select : none; + -o-user-select : none; + -webkit-user-select : none; + user-select : none; + } + table { + display : block; + margin-left : 5%%; + margin-right : 2em; + background-color : inherit; + } + 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; + 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 { } +#+END_SRC + +***** headings + +#+name: css_light_shared +#+BEGIN_SRC css + 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 #808080; + } + 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; + } +#+END_SRC + +*** html seg +**** previous next + +#+name: css_light_html_seg +#+BEGIN_SRC css + .icon-bar { + width : 100%%; + overflow : auto; + margin : 0em 0em 0em; + } + .left-bar { + width : 85%%; + float : left; + display : inline; + overflow : auto; + } + .toc-button { + position : absolute; + top : 8px; + width : 2em; + height : 2em; + border-radius : 50%%; + background : #CCCCCC; + fill : #333333; + box-shadow : 0 2px 5px #AAAAAA inset; + } + .toc-button svg { + position : relative; + left : 25%%; + top : 25%%; + width : 150%%; + height : 150%%; + } + .toc-button p { + vertical-align : center; + font-size : 120%%; + } + .prev-next-button { + position : absolute; + top : 8px; + width : 2em; + height : 2em; + border-radius : 50%%; + background : #CCCCCC; + box-shadow : 0 2px 5px #AAAAAA inset; + } + .prev-next-button svg { + position : relative; + left : 20%%; + top : 20%%; + width : 60%%; + height : 60%%; + } + .menu { + right : 6em; + } + .previous { + right : 3em; + } + .next { + right : 0em; + } + .arrow { + fill : #333333; + } + .minitoc { + line-height : 100%%; + font-size : 90%%; + margin-top : 6px; + margin-bottom : 0px; + padding-left : 0em; + text-indent : 0em; + -khtml-user-select : none; + -moz-user-select : none; + -ms-user-select : none; + -o-user-select : none; + -webkit-user-select : none; + user-select : none; + } +#+END_SRC + +**** flex + +#+name: css_light_html_seg +#+BEGIN_SRC css + /* flex */ + .flex-menu-bar { + display : -webkit-flex; + display : flex; + -webkit-flex-wrap : wrap; + -webkit-align-items : center; + align-items : center; + width : 100%%; + margin-left : 5%%; + margin-right : 2%%; + background-color : #FFFFFF; + } + .flex-menu-option { + background-color : #FFFFFF; + margin-right : 4px; + } + .flex-list { + display : -webkit-flex; + display : flex; + -webkit-align-items : center; + display : block; + align-items : center; + width : 100%%; + background-color : #FFFFFF; + } + .flex-list-item { + background-color : #FFFFFF; + margin : 4px; + } +#+END_SRC + +**** TODO grid + +Consider what if anything should be used here + +#+name: css_light_html_seg +#+BEGIN_SRC css + /* grid */ + .wrapper { + display : grid; + grid-template-columns : 100%%; + grid-template-areas : + "headband" + "doc_header" + "doc_title" + "doc_toc" + "doc_prefix" + "doc_intro" + "doc_body" + "doc_endnotes" + "doc_glossary" + "doc_biblio" + "doc_bookindex" + "doc_blurb" + "doc_suffix"; + margin : 0px; + padding : 0px; + background-color : #FFFFFF; + } + .delimit { + border-style : none; + border-color : #FFFFFF; + padding : 10px; + } + .headband { + grid-area : headband; + background-color : #FFFFFF; + } + .doc_header { + grid-area : doc_header; + } + .doc_title { + grid-area : doc_title; + } + .doc_toc { + grid-area : doc_toc; + } + .doc_prefix { + grid-area : doc_prefix; + } + .doc_intro { + grid-area : doc_intro; + } + .doc_body { + grid-area : doc_body; + } + .doc_endnotes { + grid-area : doc_endnotes; + } + .doc_glossary { + grid-area : doc_glossary; + } + .doc_biblio { + grid-area : doc_biblio; + } + .doc_bookindex { + grid-area : doc_bookindex; + } + .doc_blurb { + grid-area : doc_blurb; + } + .doc_suffix { + grid-area : doc_suffix; + } + .nav-ul { + list-style : none; + float : left; + } + .nav-li { + float : left; + padding-right : 0.7em; + } + .nav-li a { + text-decoration : none; + color : #FFFFFF; + } + footer { + background-color : #00704E; + } +#+END_SRC + +*** html scroll +**** flex + +#+name: css_light_html_scroll +#+BEGIN_SRC css + /* flex */ + .flex-menu-bar { + display : -webkit-flex; + display : flex; + -webkit-flex-wrap : wrap; + -webkit-align-items : center; + align-items : center; + width : 100%%; + margin-left : 5%%; + margin-right : 2%%; + background-color : #FFFFFF; + } + .flex-menu-option { + background-color : #FFFFFF; + margin-right : 4px; + } + .flex-list { + display : -webkit-flex; + display : flex; + -webkit-align-items : center; + display : block; + align-items : center; + width : 100%%; + background-color : #FFFFFF; + } + .flex-list-item { + background-color : #FFFFFF; + margin : 4px; + } +#+END_SRC + +**** grid + +#+name: css_light_html_scroll +#+BEGIN_SRC css + /* grid */ + .wrapper { + display : grid; + grid-template-columns : 100%%; + grid-template-areas : + "headband" + "doc_header" + "doc_title" + "doc_toc" + "doc_prefix" + "doc_intro" + "doc_body" + "doc_endnotes" + "doc_glossary" + "doc_biblio" + "doc_bookindex" + "doc_blurb" + "doc_suffix"; + margin : 0px; + padding : 0px; + background-color : #FFFFFF; + } + .delimit { + border-style : none; + border-color : #FFFFFF; + padding : 10px; + } + .headband { + grid-area : headband; + background-color : #FFFFFF; + } + .doc_header { + grid-area : doc_header; + } + .doc_title { + grid-area : doc_title; + } + .doc_toc { + grid-area : doc_toc; + } + .doc_prefix { + grid-area : doc_prefix; + } + .doc_intro { + grid-area : doc_intro; + } + .doc_body { + grid-area : doc_body; + } + .doc_endnotes { + grid-area : doc_endnotes; + } + .doc_glossary { + grid-area : doc_glossary; + } + .doc_biblio { + grid-area : doc_biblio; + } + .doc_bookindex { + grid-area : doc_bookindex; + } + .doc_blurb { + grid-area : doc_blurb; + } + .doc_suffix { + grid-area : doc_suffix; + } + .nav-ul { + list-style : none; + float : left; + } + .nav-li { + float : left; + padding-right : 0.7em; + } + .nav-li a { + text-decoration : none; + color : #FFFFFF; + } + footer { + background-color : #00704E; + } +#+END_SRC + +*** epub xhtml + +#+name: css_light_epub +#+BEGIN_SRC css +#+END_SRC + +** css dark theme +*** html shared +**** general + +#+name: css_dark_shared +#+BEGIN_SRC css + *{ + padding : 0px; + margin : 0px; + } + body { + height : 100vh; + background-color : #000000; + } + body { + color : #CCCCCC; + background : #000000; + background-color : #000000; + } +#+END_SRC + +**** link + +#+name: css_dark_shared +#+BEGIN_SRC css + a:link { + color : #FFFFFF; + text-decoration : none; + } + a:visited { + color : #999999; + text-decoration : none; + } + a:hover { + color : #000000; + background-color : #555555; + } + a.lnkocn:link { + color : %s; + text-decoration : none; + } + a.lnkocn:visited { + color : #9ACD32; + text-decoration : none; + } + a.lnkocn:hover { + color : #BBBBBB; + font-size : 15px; + } + a:hover img { + background-color : #000000; + } + a:active { + color : #888888; + text-decoration : underline; + } +#+END_SRC + +**** div + +#+name: css_dark_shared +#+BEGIN_SRC css + div { + margin-left : 0; + margin-right : 0; + } + div.p { + margin-left : 5%%; + margin-right : 1%%; + } + div.substance { + width : 100%%; + background-color : #000000; + } + div.ocn { + width : 5%%; + float : right; + top : 0; + background-color : #000000; + } + div.endnote { + width : 95%%; + background-color : #000000; + } + div.toc { + position : absolute; + float : left; + margin : 0; + padding : 0; + padding-top : 0.5em; + border : 0; + width : 13em; + background-color : #111111; + margin-right : 1em; + } + div.summary { + margin : 0; + padding : 0; + border-left : 13em solid #111111; + padding-left : 1em; + background-color : #111111; + } + div.content, div.main_column { + margin : 0; + padding : 0; + border-left : 13em solid #000000; + padding-left : 1em; + padding-right : 1em; + } + div.content0, div.main_column0 { + margin : 0; + padding : 0; + border-left : 0%% solid #000000; + 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 : #111111; + } + div.toc a, span.currentlink{ + display : block; + text-decoration : none; + padding-left : 0.5em; + color : #FF00AA; + } + hr { + width : 90%%; + margin-left : 5%%; + margin-right : 2em; + margin-top : 1.8em; + margin-bottom : 1.8em; + } + span.currentlink { + text-decoration : none; + background-color : #AAAAF9; + } + div.toc a:visited { + color : #FF00AA; + } + div.toc a:hover { + color : #CCCCCC; + background-color : #F9F9AA; + } + nav#toc ol { + list-style-type : none; + } +#+END_SRC + +**** paragraphs headings blocks +***** misc + +#+name: css_dark_shared +#+BEGIN_SRC css + .norm, .bold, .verse, .group, .block, .alt { + line-height : 133%%; + margin-top : 12px; + margin-bottom : 0px; + padding-left : 0em; + text-indent : 0em; + } + p, h0, h1, h2, h3, h4, h5, h6, h7, ul, li { + display : block; + font-family : verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + margin-left : 5%%; + margin-right : 2em; + } + p { + font-size : 100%%; + font-weight : normal; + line-height : 133%%; + text-align : justify; + text-indent : 0mm; + margin-top : 0.8em; + margin-bottom : 0.8em; + } +#+END_SRC + +#+name: css_dark_shared +#+BEGIN_SRC css + img { + max-width : 100%%; + height : auto; + } +#+END_SRC + +***** code block + +#+name: css_dark_shared +#+BEGIN_SRC css + pre { + width : auto; + display : block; + clear : both; + color : #555555; + } + pre.codeline { + display : table; + clear : both; + table-layout : fixed; + margin-left : 5%%; + margin-right : 5%%; + width : 90%%; + white-space : pre-wrap; + border-style : none; + border-radius : 5px 5px 5px 5px; + box-shadow : 0 2px 5px #AAAAAA inset; + margin-bottom : 1em; + padding : 0.5em 1em; + page-break-inside : avoid; + word-wrap : break-word; + font-family : inconsolata, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; + white-space : pre; + white-space : pre-wrap; + white-space : -moz-pre-wrap; + white-space : -o-pre-wrap; + background-color : #555555; + color : #DDDDDD; + font-size : 95%%; + line-height : 100%%; + } + pre.codeline::before { + counter-reset : linenum; + } + pre.codeline span.tr { + display : table-row; + counter-increment : linenum; + } + pre.codeline span.th { + display : table-cell; + user-select : none; + -moz-user-select : none; + -webkit-user-select : none; + padding : 0.5em 0.5em; + } + pre.codeline span.th::before { + content : counter(linenum) "."; + color : #999999; + text-align : right; + display : block; + } + pre.codeline span.th { + width : 4em; + } + pre.codeline code { + display : table-cell; + } + p.code { + border-style : none; + } +#+END_SRC + +***** paragraph general + +#+name: css_dark_shared +#+BEGIN_SRC css + p.spaced { white-space : pre; } + p.block { + white-space : pre; + } + p.group { } + p.alt { } + p.verse { + white-space : pre; + margin-bottom : 6px; + } + 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 : #EEEEEE; + 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 : #555555; + 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, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; + background-color : #555555; + color : #DDDDDD; + } +#+END_SRC + +***** paragraph indent + +#+name: css_dark_shared +#+BEGIN_SRC css +%s +#+END_SRC + +***** misc including tables & lists + +#+name: css_dark_shared +#+BEGIN_SRC css + note { white-space : pre; } + label.ocn { + width : 2%%; + float : right; + top : 0; + font-size : 10px; + margin-top : 0px; + margin-bottom : 5px; + margin-right : 5px; + text-align : right; + color : %s; + -khtml-user-select : none; + -moz-user-select : none; + -ms-user-select : none; + -o-user-select : none; + -webkit-user-select : none; + user-select : none; + } + table { + display : block; + margin-left : 5%%; + margin-right : 2em; + background-color : inherit; + } + 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; + 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 : (../image_sys/bullet_09.png) no-repeat 0px 6px; + } + ul { } +#+END_SRC + +***** headings + +#+name: css_dark_shared +#+BEGIN_SRC css + 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 #999999; + } + 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; + } +#+END_SRC + +*** html seg +**** previous next + +#+name: css_dark_html_seg +#+BEGIN_SRC css + .icon-bar { + width : 100%%; + overflow : auto; + margin : 0em 0em 0em; + } + .left-bar { + width : 85%%; + float : left; + display : inline; + overflow : auto; + } + .toc-button { + position : absolute; + top : 8px; + width : 2em; + height : 2em; + border-radius : 50%%; + background : #555555; + fill : #DDDDDD; + box-shadow : 0 2px 5px #EEEEEE inset; + } + .toc-button svg { + position : relative; + left : 25%%; + top : 25%%; + width : 150%%; + height : 150%%; + } + .toc-button p { + vertical-align : center; + font-size : 120%%; + } + .prev-next-button { + position : absolute; + top : 8px; + width : 2em; + height : 2em; + border-radius : 50%%; + background : #555555; + box-shadow : 0 2px 5px #AAAAAA inset; + } + .prev-next-button svg { + position : relative; + left : 20%%; + top : 20%%; + width : 60%%; + height : 60%%; + } + .menu { + right : 6em; + } + .previous { + right : 3em; + } + .next { + right : 0em; + } + .arrow { + fill : #DDDDDD; + } + .minitoc { + line-height : 100%%; + font-size : 90%%; + margin-top : 6px; + margin-bottom : 0px; + padding-left : 0em; + text-indent : 0em; + -khtml-user-select : none; + -moz-user-select : none; + -ms-user-select : none; + -o-user-select : none; + -webkit-user-select : none; + user-select : none; + } +#+END_SRC + +**** flex + +#+name: css_dark_html_seg +#+BEGIN_SRC css + /* flex */ + .flex-menu-bar { + display : -webkit-flex; + display : flex; + -webkit-flex-wrap : wrap; + -webkit-align-items : center; + align-items : center; + width : 100%%; + margin-left : 5%%; + margin-right : 2%%; + background-color : #000000; + } + .flex-menu-option { + background-color : #000000; + margin-right : 4px; + } + .flex-list { + display : -webkit-flex; + display : flex; + -webkit-align-items : center; + display : block; + align-items : center; + width : 100%%; + background-color : #000000; + } + .flex-list-item { + background-color : #000000; + margin : 4px; + } +#+END_SRC + +**** TODO grid + +Consider what if anything should be used here + +#+name: css_dark_html_seg +#+BEGIN_SRC css + /* grid */ + .wrapper { + display : grid; + grid-template-columns : 100%%; + grid-template-areas : + "headband" + "doc_header" + "doc_title" + "doc_toc" + "doc_prefix" + "doc_intro" + "doc_body" + "doc_endnotes" + "doc_glossary" + "doc_biblio" + "doc_bookindex" + "doc_blurb" + "doc_suffix"; + margin : 0px; + padding : 0px; + background-color : #000000; + } + .delimit { + border-style : none; + border-color : #000000; + padding : 10px; + } + .headband { + grid-area : headband; + background-color : #000000; + } + .doc_header { + grid-area : doc_header; + } + .doc_title { + grid-area : doc_title; + } + .doc_toc { + grid-area : doc_toc; + } + .doc_prefix { + grid-area : doc_prefix; + } + .doc_intro { + grid-area : doc_intro; + } + .doc_body { + grid-area : doc_body; + } + .doc_endnotes { + grid-area : doc_endnotes; + } + .doc_glossary { + grid-area : doc_glossary; + } + .doc_biblio { + grid-area : doc_biblio; + } + .doc_bookindex { + grid-area : doc_bookindex; + } + .doc_blurb { + grid-area : doc_blurb; + } + .doc_suffix { + grid-area : doc_suffix; + } + .nav-ul { + list-style : none; + float : left; + } + .nav-li { + float : left; + padding-right : 0.7em; + } + .nav-li a { + text-decoration : none; + color : #000000; + } + footer { + background-color : #FF704E; + } +#+END_SRC + +*** html scroll +**** flex + +#+name: css_dark_html_scroll +#+BEGIN_SRC css + /* flex */ + .flex-menu-bar { + display : -webkit-flex; + display : flex; + -webkit-flex-wrap : wrap; + -webkit-align-items : center; + align-items : center; + width : 100%%; + margin-left : 5%%; + margin-right : 2%%; + background-color : #000000; + } + .flex-menu-option { + background-color : #000000; + margin-right : 4px; + } + .flex-list { + display : -webkit-flex; + display : flex; + -webkit-align-items : center; + display : block; + align-items : center; + width : 100%%; + background-color : #000000; + } + .flex-list-item { + background-color : #000000; + margin : 4px; + } +#+END_SRC + +**** grid + +#+name: css_dark_html_scroll +#+BEGIN_SRC css + /* grid */ + .wrapper { + display : grid; + grid-template-columns : 100%%; + grid-template-areas : + "headband" + "doc_header" + "doc_title" + "doc_toc" + "doc_prefix" + "doc_intro" + "doc_body" + "doc_endnotes" + "doc_glossary" + "doc_biblio" + "doc_bookindex" + "doc_blurb" + "doc_suffix"; + margin : 0px; + padding : 0px; + background-color : #000000; + } + .delimit { + border-style : none; + border-color : #000000; + padding : 10px; + } + .headband { + grid-area : headband; + background-color : #000000; + } + .doc_header { + grid-area : doc_header; + } + .doc_title { + grid-area : doc_title; + } + .doc_toc { + grid-area : doc_toc; + } + .doc_prefix { + grid-area : doc_prefix; + } + .doc_intro { + grid-area : doc_intro; + } + .doc_body { + grid-area : doc_body; + } + .doc_endnotes { + grid-area : doc_endnotes; + } + .doc_glossary { + grid-area : doc_glossary; + } + .doc_biblio { + grid-area : doc_biblio; + } + .doc_bookindex { + grid-area : doc_bookindex; + } + .doc_blurb { + grid-area : doc_blurb; + } + .doc_suffix { + grid-area : doc_suffix; + } + .nav-ul { + list-style : none; + float : left; + } + .nav-li { + float : left; + padding-right : 0.7em; + } + .nav-li a { + text-decoration : none; + color : #000000; + } + footer { + background-color : #FF704E; + } +#+END_SRC + +*** epub xhtml + +#+name: css_dark_epub +#+BEGIN_SRC css +#+END_SRC + +** variables +*** ocn (visible or hidden) + +#+name: css_insert_shared_insert_variable_ocn_color_values +#+BEGIN_SRC css + string _color_ocn_light = (doc_matters.opt.action.ocn_hidden) ? "#FFFFFF" : "#777777"; + string _color_ocn_dark = (doc_matters.opt.action.ocn_hidden) ? "#000000" : "#BBBBBB"; +#+END_SRC + +*** indent levels +#+name: css_insert_shared_insert_variable_indent_values +#+BEGIN_SRC css + string _css_indent = format(q"┃ + /* 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; + } +┃"); +#+END_SRC + +* __END__ diff --git a/org/out_zip.org b/org/out_zip.org new file mode 100644 index 0000000..3007412 --- /dev/null +++ b/org/out_zip.org @@ -0,0 +1,45 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) output zip +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah +#+DESCRIPTION: documents - structuring, publishing in multiple formats & search +#+KEYWORDS +#+LANGUAGE: en +#+STARTUP: indent content hideblocks hidestars +#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc +#+OPTIONS: author:nil email:nil creator:nil timestamp:nil +#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+FILETAGS: :spine:rel:output: +#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) + +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* _zip_ :module:spine:create_zip_file: +** module template + +#+BEGIN_SRC d :tangle "../src/doc_reform/output/create_zip_file.d" +module doc_reform.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 + } + } +} +#+END_SRC + +* __END__ diff --git a/org/output_harvest_metadata.org b/org/output_harvest_metadata.org deleted file mode 100644 index b2c7b1a..0000000 --- a/org/output_harvest_metadata.org +++ /dev/null @@ -1,862 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_manifest) metadata (multidocument) harvests -#+DESCRIPTION: documents - structuring, various output representations & search -#+FILETAGS: :spine:hub: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -* document harvest _summary_ :module:spine:metadoc_show_summary: - -** _module template_ metadoc harvest - -#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvest.d" -module doc_reform.meta.metadoc_harvest; -template DocReformMetaDocHarvest() { - auto DocReformMetaDocHarvest(T,H)( - T doc_matters, - H hvst, - ) { - <> - mixin InternalMarkup; - <> - <> - } -} -#+END_SRC - -** init -*** imports - -#+name: metadoc_harvest_imports -#+BEGIN_SRC d -import - doc_reform.meta.defaults, - doc_reform.meta.rgx; -import - std.array, - std.exception, - std.regex, - std.stdio, - std.string, - std.traits, - std.typecons, - std.uni, - std.utf, - std.conv : to; -#+END_SRC - -*** initialize :report: - -#+name: metadoc_harvest_initialize -#+BEGIN_SRC d -auto markup = InlineMarkup(); -#+END_SRC - -** harvest summary - -#+name: meta_metadoc_harvest_summary -#+BEGIN_SRC d -auto min_repeat_number = 66; -auto char_repeat_number = (doc_matters.conf_make_meta.meta.title_full.length - + doc_matters.conf_make_meta.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", - markup.repeat_character_by_number_provided("-", char_repeat_number), - doc_matters.conf_make_meta.meta.title_full, - doc_matters.conf_make_meta.meta.creator_author, - doc_matters.src.filename, - doc_matters.conf_make_meta.meta.classify_topic_register_arr, - markup.repeat_character_by_number_provided("-", char_repeat_number), -); -#+END_SRC - -** return harvest - -#+name: meta_metadoc_harvest -#+BEGIN_SRC d -import doc_reform.output.paths_output; -auto pth_html_abs = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); -auto pth_html_rel = DocReformDocRootTreeHTML!()(doc_matters.src.language); -hvst.harvest.title = doc_matters.conf_make_meta.meta.title_full; -hvst.harvest.author = doc_matters.conf_make_meta.meta.creator_author; -hvst.harvest.author_surname = doc_matters.conf_make_meta.meta.creator_author_surname; -hvst.harvest.author_surname_fn = doc_matters.conf_make_meta.meta.creator_author_surname_fn; -hvst.harvest.author_arr = doc_matters.conf_make_meta.meta.creator_author_arr; -hvst.harvest.language_original = doc_matters.conf_make_meta.meta.original_language; -hvst.harvest.language = doc_matters.src.language; -hvst.harvest.uid = doc_matters.src.doc_uid; -hvst.harvest.date_published = doc_matters.conf_make_meta.meta.date_published; -hvst.harvest.topic_register_arr = doc_matters.conf_make_meta.meta.classify_topic_register_arr; -hvst.harvest.path_html_scroll = pth_html_rel.fn_scroll(doc_matters.src.filename); -hvst.harvest.path_html_segtoc = pth_html_rel.fn_seg(doc_matters.src.filename, "toc"); -hvst.harvest.path_abs_html_scroll = pth_html_abs.fn_scroll(doc_matters.src.filename); -hvst.harvest.path_abs_html_segtoc = pth_html_abs.fn_seg(doc_matters.src.filename, "toc"); -return hvst.harvest; -#+END_SRC - -** _module template_ metadoc harvest topics -*** _module template_ metadoc harvest topics template - -#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvests_topics.d" -module doc_reform.meta.metadoc_harvests_topics; - import - std.algorithm, - std.array, - std.exception, - std.regex, - std.stdio, - std.string, - std.conv : to; - import - doc_reform.meta.defaults, - doc_reform.meta.rgx; - mixin DocReformHarvest; - mixin InternalMarkup; - mixin DocReformRgxInit; -template DocReformMetaDocHarvestsTopics() { - auto mkup = InlineMarkup(); - void DocReformMetaDocHarvestsTopics(H,M,O)( - H hvst, - M _make_and_meta_struct, - O _opt_action, - ) { - <> -<> -<> -<> -<> -<> - <> - topics -<> - <> - } -} -#+END_SRC - -*** order topic register - -#+NAME: harvested_topics -#+BEGIN_SRC d -auto min_repeat_number = 42; -string[] _document_topic_register; -string[] _topic_register; -string[] _sub_topic_register; -string[] topics = []; -string _auth = ""; -foreach(k, doc_harvest; hvst.harvests) { - _topic_register = []; - foreach(topic; doc_harvest.topic_register_arr.sort) { - _sub_topic_register = []; - string _spaces; - string[] subject_tree = topic.split(mkup.sep); - switch (subject_tree.length) { - case 1: - hvst.subject_trees[subject_tree[0]]["_a"]["_a"]["_a"] ~= doc_harvest; - break; - case 2: - hvst.subject_trees[subject_tree[0]][subject_tree[1]]["_a"]["_a"] ~= doc_harvest; - break; - case 3: - hvst.subject_trees[subject_tree[0]][subject_tree[1]][subject_tree[2]]["_a"] ~= doc_harvest; - break; - case 4: - hvst.subject_trees[subject_tree[0]][subject_tree[1]][subject_tree[2]][subject_tree[3]] ~= doc_harvest; - break; - default: - break; - } - _topic_register ~= _sub_topic_register.join("\n"); - } - auto char_repeat_number = (doc_harvest.title.length - + doc_harvest.author.length + 16); - char_repeat_number = (char_repeat_number > min_repeat_number) - ? char_repeat_number - : min_repeat_number; - _document_topic_register ~= format( - "\"%s\", %s%s\n%s", - doc_harvest.title, - doc_harvest.author, - (doc_harvest.date_published.length > 0) ? " (" ~ doc_harvest.date_published ~ ")" : "", - _topic_register.sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable).release.join("\n"), - ); -} -#+END_SRC - -*** harvested topics html head - -#+NAME: harvested_topics_html_head_1 -#+BEGIN_SRC d - topics ~= format(q"┃ - - - -Metadata Harvest - Topics -#+END_SRC - -*** harvested topics html head - -#+NAME: harvested_topics_html_head_2 -#+BEGIN_SRC d - - - - - -

Metadata Harvest - Topics (output organised by language & filetype)

-

[ HOME ] also see Metadata Harvest - Authors

-

ABCDEFGHIJKLMNOPQRSTUVWXYZ,  -

-
-

English   

-
-#+END_SRC - -*** harvested topics html head theme insert - -#+NAME: harvested_topics_html_head_theme -#+BEGIN_SRC d -┃", - _opt_action.css_theme_default ? theme_light_0 : theme_dark_0, - _opt_action.css_theme_default ? theme_light_1 : theme_dark_1, -) ~ "\n"; -#+END_SRC - -*** harvested topics html - -#+NAME: harvested_topics_html -#+BEGIN_SRC d -char _prev_k = "_".to!char; -int _kn; -foreach(k0; - hvst.subject_trees.keys - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) -) { - if (k0.toUpper.to!(char[])[0] != _prev_k) { - topics ~= format(q"┃

%s

┃", - k0.toUpper.to!(char[])[0], - k0.toUpper.to!(char[])[0], - ); - _prev_k = k0.toUpper.to!(char[])[0]; - } - if (k0 != "_a") { - topics ~= format(q"┃

%s

┃", - k0.translate([' ' : "_"]), k0,) ~ "\n"; - if (_opt_action.very_verbose) { - writeln("", k0); - } - if ("_a" in hvst.subject_trees[k0]) { - foreach (t_a_; - hvst.subject_trees[k0]["_a"]["_a"]["_a"] - .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) - ) { - _auth = []; - if (t_a_.author_arr.length < 2) { - _auth = format(q"┃ %s┃", - t_a_.author_surname.translate([' ' : "_"]), - t_a_.author, - ); - } else { - foreach (a; t_a_.author_arr) { - _auth ~= format(q"┃ %s,┃", - t_a_.author_surname.translate([' ' : "_"]), - a, - ); - } - } - topics ~= format(q"┃

"%s" -%s┃", - t_a_.path_html_segtoc, - t_a_.title, - _auth, - ) ~ "\n"; - if (_opt_action.very_verbose) { - writeln("- ", t_a_.title, " - ", t_a_.author); - } - } - } - foreach(k1; - hvst.subject_trees[k0].keys - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) - ) { - if (k1 != "_a") { - topics ~= format(q"┃

%s

┃", - k1.translate([' ' : "_"]), k1,) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" ", k1); - } - if ("_a" in hvst.subject_trees[k0][k1]) { - foreach (t_a_; - hvst.subject_trees[k0][k1]["_a"]["_a"] - .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) - ) { - _auth = []; - if (t_a_.author_arr.length < 2) { - _auth = format(q"┃ %s┃", - t_a_.author_surname.translate([' ' : "_"]), - t_a_.author, - ); - } else { - foreach (a; t_a_.author_arr) { - _auth ~= format(q"┃ %s,┃", - t_a_.author_surname.translate([' ' : "_"]), - a, - ); - } - } - topics ~= format(q"┃

%s -%s┃", - t_a_.path_html_segtoc, - t_a_.title, - _auth, - ) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" - ", t_a_.title, " - ", t_a_.author); - } - } - } - } - foreach(k2; - hvst.subject_trees[k0][k1].keys - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) - ) { - if (k2 != "_a") { - topics ~= format(q"┃

%s

┃", - k2.translate([' ' : "_"]), k2,) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" ", k2); - } - if ("_a" in hvst.subject_trees[k0][k1][k2]) { - foreach (t_a_; - hvst.subject_trees[k0][k1][k2]["_a"] - .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) - ) { - _auth = []; - if (t_a_.author_arr.length < 2) { - _auth = format(q"┃ %s┃", - t_a_.author_surname.translate([' ' : "_"]), - t_a_.author, - ); - } else { - foreach (a; t_a_.author_arr) { - _auth ~= format(q"┃ %s,┃", - t_a_.author_surname.translate([' ' : "_"]), - a, - ); - } - } - topics ~= format(q"┃

%s -%s┃", - t_a_.path_html_segtoc, - t_a_.title, - _auth, - ) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" - ", t_a_.title, " - ", t_a_.author); - } - } - } - } - foreach(k3; - hvst.subject_trees[k0][k1][k2].keys - .sort!("toUpper(a) < toUpper(b)", SwapStrategy.unstable) - ) { - if (k3 != "_a") { - topics ~= format(q"┃

%s

┃", - k3.translate([' ' : "_"]), k3,) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" ", k3); - } - { - foreach (t_a_; - hvst.subject_trees[k0][k1][k2][k3] - .multiSort!("toUpper(a.title) < toUpper(b.title)", "a.author < b.author", SwapStrategy.unstable) - ) { - _auth = []; - if (t_a_.author_arr.length < 2) { - _auth = format(q"┃%s┃", - t_a_.author_surname.translate([' ' : "_"]), - t_a_.author, - ); - } else { - foreach (a; t_a_.author_arr) { - _auth ~= format(q"┃ %s,┃", - t_a_.author_surname.translate([' ' : "_"]), - a, - ); - } - } - topics ~= format(q"┃

%s -%s┃", - t_a_.path_html_segtoc, - t_a_.title, - _auth, - ) ~ "\n"; - if (_opt_action.very_verbose) { - writeln(" - ", t_a_.title, " - ", t_a_.author); - } - } - } - } - } - } - } - } -} -#+END_SRC - -*** harvested topics write - -#+NAME: harvested_topics_html_write -#+BEGIN_SRC d -import doc_reform.output.paths_output; -auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); -try { - auto f = File(out_pth.harvest("topics.html"), "w"); - foreach (o; topics) { - f.writeln(o); - } -} catch (ErrnoException ex) { - // Handle error -} -#+END_SRC - -** _module template_ metadoc harvests authors -*** _module template_ metadoc harvest authors - -#+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvests_authors.d" -module doc_reform.meta.metadoc_harvests_authors; - import - std.algorithm, - std.array, - std.exception, - std.regex, - std.stdio, - std.string, - std.conv : to; - import - doc_reform.meta.defaults, - doc_reform.meta.rgx; - mixin DocReformHarvest; - mixin InternalMarkup; - mixin DocReformRgxInit; -template DocReformMetaDocHarvestsAuthors() { - auto mkup = InlineMarkup(); - void DocReformMetaDocHarvestsAuthors(H,M,O)( - H harvests, - M _make_and_meta_struct, - O _opt_action, - ) { -<> -<> -<> -<> -<> - authors -<> - <> - } -} -#+END_SRC - -*** harvested authors html head - -#+NAME: harvested_authors_html_head_1 -#+BEGIN_SRC d - string[] authors = []; - authors ~= format(q"┃ - - - - -Metadata Harvest - Authors -#+END_SRC - -*** harvested authors html head - -#+NAME: harvested_authors_html_head_2 -#+BEGIN_SRC d - - - - - -

Metadata Harvest - Authors (output organised by language & filetype)

-

[ HOME ] also see Metadata Harvest - Topics

-

-
-

English   

-
-

ABCDEFGHIJKLMNOPQRSTUVWXYZ,  -#+END_SRC - -*** harvested authors html theme inserts - -#+NAME: harvested_authors_html_head_theme -#+BEGIN_SRC d -┃", - _opt_action.css_theme_default ? theme_light_0 : theme_dark_0, - _opt_action.css_theme_default ? theme_light_1 : theme_dark_1, -) ~ "\n"; - string[string] _au; - string[] _auth_date_title; - string[] _author_date_title; - string _prev_auth = ""; - char _prev_k = "_".to!char; - foreach(doc_harvest; - harvests - .multiSort!( - "toUpper(a.author_surname_fn) < toUpper(b.author_surname_fn)", - "a.date_published < b.date_published", - "a.title < b.title", - SwapStrategy.unstable - ) - ) { - if (doc_harvest.author_surname_fn != _prev_auth) { - _au[doc_harvest.author_surname_fn] - = format(q"┃

%s

%s "%s" [%s]

┃", - doc_harvest.author_surname.translate([' ' : "_"]), - doc_harvest.author_surname_fn, - (doc_harvest.date_published.length > 0) - ? doc_harvest.date_published : "", - doc_harvest.path_html_segtoc, - doc_harvest.title, - doc_harvest.language, - ); - _prev_auth = doc_harvest.author_surname_fn; - } else { - _au[doc_harvest.author_surname_fn] - ~= format(q"┃

%s "%s" [%s]

┃", - (doc_harvest.date_published.length > 0) - ? doc_harvest.date_published : "", - doc_harvest.path_html_segtoc, - doc_harvest.title, - doc_harvest.language, - ); - } - _author_date_title ~= format(q"┃%s %s "%s" [%s]%s┃", - doc_harvest.author_surname_fn, - (doc_harvest.date_published.length > 0) - ? "(" ~ doc_harvest.date_published ~ ")" : "", - doc_harvest.title, - doc_harvest.language, - (_opt_action.very_verbose) ? "\n " ~ doc_harvest.path_abs_html_scroll : "", - ); - } - foreach (k; _au.keys.sort) { - if (k.toUpper.to!(char[])[0] != _prev_k) { - authors ~= format(q"┃

%s

┃", - k.toUpper.to!(char[])[0], - k.toUpper.to!(char[])[0], - ); - _prev_k = k.toUpper.to!(char[])[0]; - } - authors ~= _au[k]; - } -#+END_SRC - -*** harvested authors write - -#+NAME: harvested_authors_html_write -#+BEGIN_SRC d -import doc_reform.output.paths_output; -auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); -try { - auto f = File(out_pth.harvest("authors.html"), "w"); - foreach (o; authors) { - f.writeln(o); - } -} catch (ErrnoException ex) { - // Handle error -} -if (_opt_action.verbose - || _opt_action.very_verbose -) { - foreach(_adt; _author_date_title.sort) { - writeln(_adt); - } -} -#+END_SRC - -** harvested authors & topics shared html -*** themes -**** head - -#+NAME: harvested_html_themes -#+BEGIN_SRC d -string theme_dark_0 = format(q"┃ - body { - color : #CCCCCC; - background : #000000; - background-color : #000000; - } - a:link { - color : #FFFFFF; - text-decoration : none; - } - a:visited { - color : #999999; - text-decoration : none; - } - a:hover { - color : #000000; - background-color : #555555; - } - a:hover img { - background-color : #000000; - } - a:active { - color : #888888; - text-decoration : underline; - } - a.lev0:hover { - color : #FFFFFF; - background-color : #000000; - } - a.lev1:hover { - color : #FFFFFF; - background : #333333; - } - a.lev2:hover { - color : #FFFFFF; - background : #555555; - } - a.lev3:hover { - color : #FFFFFF; - background : #777777; - } -┃"); -string theme_light_0 = format(q"┃ - body { - color : #000000; - 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:hover img { - background-color : #FFFFFF; - } - a:active { - color : #003399; - text-decoration : underline; - } - a.lev0:hover { - color : #000000; - background-color : #FFFFFF; - } - a.lev1:hover { - color : #FFFFFF; - background : #444444; - } - a.lev2:hover { - background : #888888; - } - a.lev3:hover { - background : #BBBBBB; - } -┃"); -#+END_SRC - -**** levels - -#+NAME: harvested_html_themes -#+BEGIN_SRC d -string theme_dark_1 = format(q"┃ - h1 { - color : #FFFFFF; - background : #000000; - } - p.letter { - color : #FFFFFF; - background : #333333; - } - p.lev0 { - color : #FFFFFF; - background : #000000; - } - p.lev1 { - color : #FFFFFF; - background : #333333; - } - p.lev2 { - background : #555555; - } - p.lev3 { - background : #777777; - } - p.lev4 { - background : #AAAAAA; - } - p.lev5 { - } -┃"); -string theme_light_1 = format(q"┃ - h1 { - color : #FFFFFF; - background : #000088; - } - p.letter { - color : #FFFFFF; - background : #880000; - } - p.lev0 { - color : #FFFFFF; - background : #000000; - } - p.lev1 { - color : #FFFFFF; - background : #444444; - } - p.lev2 { - background : #888888; - } - p.lev3 { - background : #BBBBBB; - } - p.lev4 { - background : #EEEEEE; - } - p.lev5 { - } -┃"); -#+END_SRC - -*** harvested html head - -#+NAME: harvested_html_head -#+BEGIN_SRC d - - - - - - - - -#+END_SRC - -*** harvested html bottom - -#+NAME: harvested_html_bottom -#+BEGIN_SRC d - ~= format(q"┃ -
- - - - - - - - -┃") ~ "\n"; -#+END_SRC diff --git a/org/output_latex.org b/org/output_latex.org deleted file mode 100644 index f9c6d55..0000000 --- a/org/output_latex.org +++ /dev/null @@ -1,1879 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) output latex -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:latex:pdf: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* latex -** _module template_ :latex:pdf:module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/latex.d" :noweb yes -module doc_reform.output.latex; -template outputLaTeX() { - <> - mixin InternalMarkup; // watch - mixin DocReformOutputRgxInit; - auto rgx = Rgx(); - mixin DocReformLanguageCodes; - auto lang = Lang(); - <> -<> - <> - <> -<> - <> - <> -<> - <> - <> - <> - <> -<> - <> - <> -} -#+END_SRC - -** write latex output :latex:out: - -#+name: output_latex -#+BEGIN_SRC d -void writeOutputLaTeX(T,M)( - const T latex_content, - M doc_matters, -) { - auto pth_latex = DocReformPathsLaTeX(doc_matters); - try { - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(latex_content.head); - writeln(latex_content.content); - writeln(latex_content.tail); - } - } - if (!exists(pth_latex.latex_path_stuff)) { - (pth_latex.latex_path_stuff).mkdirRecurse; - } - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_latex.latex_file_with_path); - } - auto f = File(pth_latex.latex_file_with_path, "w"); - f.writeln(latex_content.head); - f.writeln(latex_content.content); - f.writeln(latex_content.tail); - foreach (image; doc_matters.srcs.image_list) { - auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_src_out_file = pth_latex.latex_path_stuff ~ "/" ~ image; - if (exists(fn_src_in)) { - fn_src_in.copy(fn_src_out_file); - } - } - } catch (ErrnoException ex) { - // handle error - } -} -#+END_SRC - -** latex output hub [#A] :latex:pdf:out: - -#+name: output_latex -#+BEGIN_SRC d -void outputLaTeX(D,M)( - const D doc_abstraction, - M doc_matters, -) { - struct LaTeX { - string head; - string content; - string tail; - } - auto latex = LaTeX(); - latex.head = latex_head(doc_matters); - latex.content = latex_body(doc_abstraction, doc_matters); - latex.tail = latex_tail(doc_matters); - latex.writeOutputLaTeX(doc_matters); -} -#+END_SRC - -* stuff -** output imports - -#+name: output_latex_imports -#+BEGIN_SRC d -import doc_reform.output; -import - std.digest.sha, - std.file, - std.outbuffer, - std.uri, - std.conv : to; -#+END_SRC - -** shared -*** paper dimensions (struct) - -#+name: output_latex_shared -#+BEGIN_SRC d - auto paper() { - struct PaperType { - auto a4() { - struct A4 { - auto portrait() { - struct V { - uint w = 160; - uint h = 228; - uint img_px = 450; - } - return V(); - } - auto landscape() { - struct H { - uint w = 238; - uint h = 160; - uint img_px = 300; - } - return H(); - } - } - return A4(); - } - auto a5() { - struct A5 { - auto portrait() { - struct V { - uint w = 112; - uint h = 162; - uint img_px = 280; - } - return V(); - } - auto landscape() { - struct H { - uint w = 152; - uint h = 100; - uint img_px = 190; - } - return H(); - } - } - return A5(); - } - auto b4() { - struct B4 { - auto portrait() { - struct V { - uint w = 140; - uint h = 204; - uint img_px = 356; - } - return V(); - } - auto landscape() { - struct H { - uint w = 200; - uint h = 130; - uint img_px = 260; - } - return H(); - } - } - return B4(); - } - auto letter() { - struct Letter { - auto portrait() { - struct V { - uint w = 166; - uint h = 212; - uint img_px = 468; - } - return V(); - } - auto landscape() { - struct H { - uint w = 226; - uint h = 166; - uint img_px = 290; - } - return H(); - } - } - return Letter(); - } - auto legal() { - struct Legal { - auto portrait() { - struct V { - uint w = 168; - uint h = 286; - uint img_px = 474; - } - return V(); - } - auto landscape() { - struct H { - uint w = 296; - uint h = 166; - uint img_px = 420; - } - return H(); - } - } - return Legal(); - } - } - return PaperType(); - } -#+END_SRC - -*** latex \escape special characters -**** general - -#+name: output_latex_shared -#+BEGIN_SRC d -string sp_char_esc(O)( - string _txt, - const O obj, -) { - string _unescape_sp_char_esc()(string _txt) { - _txt = _txt - .replaceAll(rgx.latex_special_char_escaped, - format(q"┃%s┃", "$1")) - .replaceAll(rgx.latex_special_char_escaped_braced, - format(q"┃%s┃", "$1")); - return _txt; - } - string _unescape_fontface_esc()(string _txt) { - _txt = _txt.replaceAll(rgx.latex_identify_inline_fontface, - format(q"┃%s%s┃", "$1", "$2")); - return _txt; - } - if (obj.metainfo.is_a != "code") { - _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char_for_escape); - _txt = replaceAll!(m => "{\\" ~ m[1] ~ "}")(_txt, rgx.latex_special_char_for_escape_and_braces); - _txt = replaceAll!(m => _unescape_sp_char_esc(m[0]))(_txt, rgx.latex_identify_inline_link); - _txt = replaceAll!(m => _unescape_fontface_esc(m[0]))(_txt, rgx.latex_identify_inline_fontface); - } - return _txt; -} -#+END_SRC - -#+name: output_latex_shared -#+BEGIN_SRC d -string sp_char_esc_txt()( - string _txt, -) { - string _unescape_sp_char_esc()(string _txt) { - _txt = _txt - .replaceAll(rgx.latex_special_char_escaped, - format(q"┃%s┃", "$1")) - .replaceAll(rgx.latex_special_char_escaped_braced, - format(q"┃%s┃", "$1")); - return _txt; - } - string _unescape_fontface_esc()(string _txt) { - _txt = _txt.replaceAll(rgx.latex_identify_inline_fontface, - format(q"┃%s%s┃", "$1", "$2")); - return _txt; - } - _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char_for_escape); - _txt = replaceAll!(m => "{\\" ~ m[1] ~ "}")(_txt, rgx.latex_special_char_for_escape_and_braces); - _txt = replaceAll!(m => _unescape_sp_char_esc(m[0]))(_txt, rgx.latex_identify_inline_link); - _txt = replaceAll!(m => _unescape_fontface_esc(m[0]))(_txt, rgx.latex_identify_inline_fontface); - return _txt; -} -#+END_SRC - -*** not used latex \escape special characters - -#+BEGIN_SRC d -string sp_char_esc()( - string _txt, -) { - _txt = replaceAll!(m => "\\" ~ m[1])(_txt, rgx.latex_special_char); - return _txt; -} -#+END_SRC - -*** inline markup -**** fontface - -- bold, italics, underscore, strikethrough - -#+name: output_latex_shared -#+BEGIN_SRC d -string fontface()( - string _txt, -) { -_txt = _txt - .replaceAll(rgx.inline_emphasis, format(q"┃\begin{bfseries}%s\end{bfseries}┃", "$1")) - .replaceAll(rgx.inline_bold, format(q"┃\begin{bfseries}%s\end{bfseries}┃", "$1")) - .replaceAll(rgx.inline_italics, format(q"┃\emph{%s}┃", "$1")) - .replaceAll(rgx.inline_italics, format(q"┃\uline{%s}┃", "$1")) - .replaceAll(rgx.inline_superscript, format(q"┃$$^{\textrm{%s}}$$┃", "$1")) - .replaceAll(rgx.inline_subscript, format(q"┃$$_{\textrm{%s}}$$┃", "$1")) - .replaceAll(rgx.inline_strike, format(q"┃\sout{%s}┃", "$1")) - .replaceAll(rgx.inline_insert, format(q"┃\uline{%s}┃", "$1")) - .replaceAll(rgx.inline_mono, format(q"┃\begin{monosp}%s\end{monosp}┃", "$1")) - .replaceAll(rgx.inline_italics, format(q"┃``%s''┃", "$1")); - return _txt; -} -#+END_SRC - -**** spaces -***** leading hardspace - -#+name: output_latex_shared -#+BEGIN_SRC d -string leading_hardspaces()( - string _txt, -) { - string hardspaces(string _spaces) { - _spaces = _spaces - .replaceAll(rgx.space, "\\hardspace "); - return _spaces; - } - _txt = replaceAll!(m => hardspaces(m[0]))(_txt, rgx.spaces_line_start); - return _txt; -} -#+END_SRC - -***** nbsp character - -#+name: output_latex_shared -#+BEGIN_SRC d -string nbsp_char()(string _txt) { - if (_txt.match(rgx.nbsp_char)) { - _txt = _txt.replaceAll(rgx.nbsp_char, "\\hardspace "); - } - return _txt; -} -#+END_SRC - -***** remove nbsp character - -#+name: output_latex_shared -#+BEGIN_SRC d -string nbsp_char_to_space()(string _txt) { - if (_txt.match(rgx.nbsp_char)) { - _txt = _txt.replaceAll(rgx.nbsp_char, " "); - } - return _txt; -} -#+END_SRC - -**** links and images -***** links / urls - -#+name: output_latex_shared -#+BEGIN_SRC d -string links_and_images(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - if (obj.has.inline_links) { // TODO some images do not have inline links ... image without link - string _width_adjust(string _width) { - if (_width.to!int > 300) { _width = "300"; } // will need to vary max with papersize & orientation - return _width; - } - string _latex_image_path(string _image_path) { - auto pth_latex = DocReformPathsLaTeX(doc_matters); - _image_path = pth_latex.latex_path_stuff ~ "/" ~ _image_path; - return _image_path; - } - string _if_images(string _linked_content) { - if (_linked_content.match(rgx.inline_image_info)) { - _linked_content = replaceAll!(m => - format(q"┃\includegraphics*[width=%spt]{%s}%s┃", - _width_adjust(m[2]), _latex_image_path(m[1]), " \\\\\n") - )(_linked_content, rgx.inline_image_info); - } - return _linked_content; - } - string _check_link(string _link) { - _link = _link - .replaceFirst(rgx.latex_clean_internal_link, "") - .replaceAll(rgx.latex_special_char_for_escape_url, "\\$1"); - return _link; - } - if (obj.metainfo.is_a != "code") { - _txt = replaceAll!(m => - m[1] ~ "┤" ~ to!string((obj.stow.link[m[2].to!ulong])).encode ~ "├" - )(_txt, rgx.inline_link_number_only); - _txt = replaceAll!(m => - ((m[1] == m[2]) && (m[2].match(rgx.uri))) - ? format(q"┃\begin{scriptsize}\lefthalfcap\url{%s}\righthalfcup\end{scriptsize}┃", _check_link(m[1])) - : (m[2].match(rgx.uri)) // ERROR - ? format(q"┃%s\href{%s}%s{%s}┃", "\\\\\n", _check_link(m[2]), "\n", _if_images(m[1])) - : format(q"┃\hyperlink{%s}{%s}┃", _check_link(m[2]), _if_images(m[1])) - )(_txt, rgx.inline_link); - } - } - return _txt; -} -#+END_SRC - -*** footnotes -**** footnotes - -#+name: output_latex_shared -#+BEGIN_SRC d -string footnotes()( - string _txt, -) { - if (_txt.match(rgx.inline_notes_al_gen)) { - string _tex_note = q"┃\hypertarget{noteref_%s}{}\footnote[%s]{%% -\label{note_%s}%s}┃"; - _txt = _txt.replaceAll(rgx.inline_notes_al_regular_number_note, - format(_tex_note, - "$1", "$1", "$1", - "$2".strip - ).strip - ); - } - return _txt; -} -#+END_SRC - -**** footnote remove - -#+name: output_latex_shared -#+BEGIN_SRC d -string remove_footnotes()( - string _txt, -) { - if (_txt.match(rgx.inline_notes_al_gen)) { - _txt = replaceAll!(m => "")(_txt, rgx.inline_notes_al_gen); - } - return _txt; -} -#+END_SRC - -*** para -**** para - -#+name: output_latex_shared -#+BEGIN_SRC d -string para(O)( - string _txt, - O obj, -) { - if (obj.metainfo.is_of_type == "para") { - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s┃"; - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.footnotes - ).strip; - } - return _txt; -} -#+END_SRC - -**** bookindex para - -#+name: output_latex_shared -#+BEGIN_SRC d -string bookindex(O)( - string _txt, - O obj, -) { - if (obj.metainfo.is_of_type == "para" - && obj.metainfo.is_a == "bookindex" - ) { - string _tex_para; - _tex_para = q"┃%s┃"; - _txt = format(_tex_para, - _txt.replaceAll(rgx.latex_clean_bookindex_linebreak, "\n") ~ "\n\\\\\n" - ); - } - return _txt; -} -#+END_SRC - -*** bullets & indentation - -#+name: output_latex_head -#+BEGIN_SRC d -string bullets_and_indentation(O)( - string _txt, - O obj, -) { - string _tex_para; - string _hang; string _indent; - int _paper_margin = -10; - int _indent_increment = 8; // 5; 10; - if (obj.attrib.bullet) { - int _bullet_space = 5; - _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin + _bullet_space).to!string; - _txt = format(q"┃\begin{Bullet}{%smm}$\txtbullet$\hspace{\enspace}%s\end{Bullet}┃", - _indent, - _txt.footnotes - ).strip; - } else if ( - obj.attrib.indent_base != 0 - && obj.attrib.indent_base == obj.attrib.indent_hang - ) { - _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin).to!string; - _tex_para = q"┃\begin{ParagraphIndent}{%smm}%s \end{ParagraphIndent}┃"; - _txt = format(_tex_para, - _indent, - _txt.footnotes - ).strip; - } else if ( - obj.attrib.indent_base != 0 - || obj.attrib.indent_hang != 0 - ) { - _indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin).to!string; - _hang = (((obj.attrib.indent_hang - obj.attrib.indent_base) * _indent_increment)).to!string; - _tex_para = q"┃\begin{ParagraphHang}{%smm}{%smm}%s \end{ParagraphHang}┃"; - _txt = format(_tex_para, - _indent, _hang, - _txt.footnotes - ).strip; - } - return _txt; -} -#+END_SRC - -*** heading - -#+name: output_latex_shared_0 -#+BEGIN_SRC d - string heading(O,M)( - string _txt, - O obj, - M doc_matters, - string _part = "" - ) { - if (obj.metainfo.is_a == "heading") { - string _tex_para; - string _pg_break; - string _sect; - string _post; - string _title_add; - string _columns = ""; - switch (obj.metainfo.heading_lev_markup) { - case 0: // A == TITLE - _pg_break = "\\begin{document}\n"; - goto default; - case 1: // B == part: section heading level - _pg_break = "\\clearpage\n"; - goto default; - case 2: // C == part: section heading level - _pg_break = "\\clearpage\n"; - goto default; - case 3: // D == part: section heading level - _pg_break = "\\clearpage\n"; - goto default; - case 4: // 1 == section - _columns = (_part != "bookindex") - ? "" : "\n\\\\\n\\begin{multicols}{2}"; - _pg_break = "\\clearpage\n"; - _sect = "section"; - _post = ""; - _title_add = format(q"┃ -\markboth{%s}{%s}┃", - doc_matters.conf_make_meta.meta.title_full, - doc_matters.conf_make_meta.meta.title_full, - ); - goto default; - case 5: // 2 == subsection - _pg_break = ""; - // _pg_break = "newpage"; // doubt this is necessary - _sect = "subsection"; - _post = " \\\n"; - _title_add = ""; - goto default; - case 6: // 3 == subsubsection - _pg_break = ""; - // _pg_break = "newpage"; // doubt this is necessary - _sect = "subsubsection"; - _post = " \\\n"; - _title_add = ""; - goto default; - default: - if (obj.metainfo.heading_lev_markup == 0) { - _tex_para = q"┃\begin{document} -\title{%s} -\author{ \textnormal{%s}} -\date{\begin{tiny}%s\end{tiny}} -\pagenumbering{roman}\maketitle -\pagestyle{fancy} -\newpage -\markboth{%s}{%s} -\\\\[3]\ \linebreak Copyright {\begin{small}{\copyright\end{small}} %s \\ -%s -\pagestyle{fancy} -\clearpage┃"; - _txt = format(_tex_para, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.creator_author).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.date_published).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.rights_copyright).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.rights_license).sp_char_esc_txt, - ); - } else if (obj.metainfo.heading_lev_markup < 4) { - _tex_para = q"┃%s\part*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} -\addcontentsline{toc}{part}{%s} -\markboth{%s}┃"; - _txt = format(_tex_para, - _pg_break, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.strip.footnotes, - _txt.strip.remove_footnotes, - (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, - ); - } else if (obj.metainfo.heading_lev_markup > 3) { - if (obj.metainfo.heading_lev_markup == 4 - && _txt.match(regex(r"^Table of Contents$"))) { - _tex_para = q"┃ -\pagenumbering{none} -\setcounter{page}{1} -\setlength{\parskip}{1ex plus0.5ex minus0.2ex} -\part*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{1}{1}\end{tiny}}}%s \newline %s} - -\clearpage -\markboth{%s}{%s} -\pagenumbering{gobble} -\renewcommand{\contentsname}{} -\tableofcontents -\markboth{%s}{%s} - -\clearpage -\pagenumbering{arabic} -\setcounter{page}{1} -\markboth{%s}{%s} -%% \null -\clearpage -\setcounter{page}{1}┃"; - _txt = format(_tex_para, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.creator_author).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_main).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - (doc_matters.conf_make_meta.meta.title_full).sp_char_esc_txt, - ); - } else if (obj.metainfo.heading_lev_markup == 4 - && _part == "bookindex" - && _txt.match(regex(r"^Index$")) - ) { - _tex_para = q"┃%s\%s*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} -\addcontentsline{toc}{%s}{%s%s}%s%s┃"; - _txt = format(_tex_para, - _pg_break, - _sect.strip, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.footnotes.strip, - _sect, - _txt.remove_footnotes.strip, - _post, - _title_add, - _columns, - ); - } else if (obj.metainfo.dummy_heading - && obj.metainfo.heading_lev_markup == 4 - ) { /+ dummy headings completely omitted +/ - _txt = ""; - } else { - _tex_para = q"┃%s\%s*{\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}%s} -\addcontentsline{toc}{%s}{%s%s}%s┃"; - _txt = format(_tex_para, - _pg_break, - _sect.strip, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.footnotes.strip, - _sect, - _txt.remove_footnotes.strip, - _post, - _title_add, - ); - } - } - break; - } - } - return _txt.strip; - } -#+END_SRC - -*** grouped text -**** group - -- (hardspace not honored) clear hardspace marker - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -string group(O,M)( - string _txt, - O obj, - M doc_matters, -) { - if (obj.metainfo.is_a == "group") { - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex} -\begin{footnotesize} -%s -\end{footnotesize} -┃"; - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.footnotes.strip - ).strip; - } - return _txt; -} -#+END_SRC - -**** block - -- (hardspace honored) \hardspace - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -string block(O,M)( - string _txt, - O obj, - M doc_matters, -) { - if (obj.metainfo.is_a == "block") { - // _txt = _txt.nbsp_char; - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex} -\begin{footnotesize} -%s -\end{footnotesize} -\setlength{\parskip}{1ex plus0.5ex minus0.2ex} -┃"; // \hardspace - /+ try both: +/ - _txt = _txt.split(rgx.br_newlines_linebreaks).join("\n\n"); // _txt = _txt.split(rgx.br_newlines_linebreaks).join(" \\\n"); - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.nbsp_char.footnotes.strip - ).strip; - } - return _txt; -} -#+END_SRC - -**** verse - -- (hardspace honored) \hardspace - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -string verse(O,M)( - string _txt, - O obj, - M doc_matters, -) { - if (obj.metainfo.is_a == "verse") { - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex} -\begin{footnotesize} - -%s - -\end{footnotesize} -\setlength{\parskip}{1ex plus0.5ex minus0.2ex} -\linebreak -┃"; // \hardspace - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.nbsp_char.footnotes.split("\n").join("\n\n").strip - ).strip; - } - return _txt; -} -#+END_SRC - -**** codeblock - -- (hardspace honored) \begin{lstlisting} clear hardspace marker - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -string codeblock(O,M)( - string _txt, - O obj, - M doc_matters, -) { - if (obj.metainfo.is_a == "code") { - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}\begin{Codeblock} -\begin{lstlisting} -%s -\end{lstlisting} -\end{Codeblock} -\setlength{\parskip}{1ex plus0.5ex minus0.2ex} -┃"; - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _txt.nbsp_char_to_space - ).strip; - } - return _txt; -} -#+END_SRC - -**** table - -- own set of rules - -***** tablarize - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -auto tablarize(O)( - string _txt, - const O obj, -) { - string[] _table_rows = (_txt).split(rgx.table_delimiter_row); - string[] _table_cols; - string _table; - string _tablenote; - foreach(row_idx, row; _table_rows) { - _table_cols = row.split(rgx.table_delimiter_col); - _table ~= ""; - foreach(col_idx, cell; _table_cols) { - if ((_table_cols.length == 1) - && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) - _tablenote ~= cell; - } else { - // // _table ~= "\\bfseries "; - // _table ~= cell; - // _table ~= (_table_cols.length > (col_idx + 1)) ? "&" : ""; - _table ~= format(q"┃%s%s┃", - cell, - (_table_cols.length > (col_idx + 1)) ? "&" : "" - ); - } - } - _table ~= "\\\\"; - } - auto t = tuple( - _table, - _tablenote, - ); - return t; -} -#+END_SRC - -***** table - -#+name: output_latex_shared_0 -#+BEGIN_SRC d -string table(O,M)( - string _txt, - O obj, - M doc_matters, -) { - if (obj.metainfo.is_a == "table") { - auto _t = _txt.tablarize(obj); - string _table = _t[0]; - string _t_n = _t[1]; - string papertype = "a4"; - uint pw = 0; - switch (papertype) { - case "a4": pw = (paper.a4.portrait.w - 20); break; - case "a5": pw = (paper.a5.portrait.w - 20); break; - case "b4": pw = (paper.b4.portrait.w - 20); break; - case "letter": pw = (paper.letter.portrait.w - 20); break; - case "legal": pw = (paper.legal.portrait.w - 20); break; - default: pw = 0; break; - } - // auto textwidth = (pw - 24); - string _colw = ""; - foreach (w; obj.table.column_widths) { - _colw ~= format(q"┃p{%.0fmm}┃", - (w * pw / 100) - // (w * (pw - 24)/ 100) - // (w * textwidth / 100) - ); - } - string _tex_para; - _tex_para = q"┃\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{%s}{%s}\end{tiny}}} -\setlength{\LTleft}{0pt} -\setlength{\LTright}{\fill} -\begin{tiny} -\begin{longtable}{%s} -%s -\end{longtable} -\end{tiny} -┃"; - _txt = format(_tex_para, - obj.metainfo.object_number, - obj.metainfo.object_number, - _colw, - _table, - ).strip; - } - return _txt; -} -#+END_SRC - -** latex parts -*** latex head :head: -**** latex head function - -#+name: output_latex_head -#+BEGIN_SRC d -string latex_head(M)( - M doc_matters, -) { -#+END_SRC - -**** latex head options -***** paper type dimensions -****** struct - -#+name: output_latex_head -#+BEGIN_SRC d - struct paperType { - string a4_portrait; - string a4_landscape; - string us_letter_portrait; - string us_letter_landscape; - } - auto paper = paperType(); -#+END_SRC - -****** footer - -#+name: output_latex_head -#+BEGIN_SRC d - string _footer(M)(M doc_matters) { - string _ft = "\\lfoot[\\textrm{\\thepage}]"; - string _ft_1 = format(q"┃{\tiny \href{%s}{%s}}┃", "http://sisudoc.org", "SiSU",); - string _ft_2 = format(q"┃ -\cfoot{\href{%s}{%s}}┃", "http://git.sisudoc.org", "git",); - if (doc_matters.conf_make_meta.make.footer.length > 0) { - if (doc_matters.conf_make_meta.make.footer.length > 0) { - if (doc_matters.conf_make_meta.make.footer[0].matchAll(rgx.inline_link)) { - _ft ~= doc_matters.conf_make_meta.make.footer[0] - .replace(rgx.inline_link, "{\\tiny \\href{$2}{$1}}"); - } else { - _ft ~= _ft_1; - } - } - if (doc_matters.conf_make_meta.make.footer.length > 1) { - if (doc_matters.conf_make_meta.make.footer[1].matchAll(rgx.inline_link)) { - _ft ~= doc_matters.conf_make_meta.make.footer[1] - .replace(rgx.inline_link, "\n\\cfoot{\\href{$2}{$1}}"); - } else { - _ft ~= _ft_2; - } - } - } else { - _ft ~= _ft_1; - _ft ~= _ft_2; - } - return _ft; - } -#+END_SRC - -****** a4, portrait - -#+name: output_latex_head_1_format_string -#+BEGIN_SRC d - paper.a4_portrait = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\documentclass[12pt,a4paper,titlepage]{scrartcl} -\setlength{\textheight}{228mm} \setlength{\textwidth}{160mm} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** a4, landscape - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - paper.a4_landscape = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\documentclass[11pt,a4paper,landscape,titlepage,twocolumn]{scrartcl} -\setlength{\textheight}{160mm} \setlength{\textwidth}{238mm} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** us letter, portrait - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - paper.us_letter_portrait = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\documentclass[12pt,letterpaper,titlepage]{scrartcl} -\setlength{\textheight}{212mm} \setlength{\textwidth}{166mm} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** us letter, landscape - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - paper.us_letter_landscape = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\documentclass[11pt,letterpaper,landscape,titlepage,twocolumn]{scrartcl} -\setlength{\textheight}{166mm} \setlength{\textwidth}{226mm} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -***** paper margins -****** struct - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - struct paperMargins { - string portrait; - string landscape; - } - auto margins = paperMargins(); -#+END_SRC - -****** portrait - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - margins.portrait = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\setlength{\oddsidemargin}{0mm} \setlength{\evensidemargin}{0mm} -\setlength{\topmargin}{-12pt} \setlength{\headheight}{12pt} -\setlength{\headsep}{35pt} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** landscape - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - margins.landscape = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\setlength{\oddsidemargin}{6mm} \setlength{\evensidemargin}{6mm} -\setlength{\topmargin}{-12mm} \setlength{\headheight}{12pt} -\setlength{\headsep}{20pt} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -***** multicol -****** struct - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - struct columnsMulti { - string portrait; - string landscape; - } - auto multicol = columnsMulti(); -#+END_SRC - -****** portrait - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - multicol.portrait = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\usepackage{multicol} -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** landscape - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - multicol.landscape = ""; -#+END_SRC - -***** color links -****** struct - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - struct colorLinks { - string mono; - string color; - } - auto links = colorLinks(); -#+END_SRC - -****** mono - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - links.mono = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\usepackage[xetex, - colorlinks=true, - urlcolor=myblack, - filecolor=myblack, - linkcolor=myblack, -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -****** color - -#+name: output_latex_head_1_tex -#+BEGIN_SRC d - links.color = format(q"┃ -#+END_SRC - -#+name: output_latex_head_1_tex -#+BEGIN_SRC latex -\usepackage[xetex, - colorlinks=true, - urlcolor=myblue, %% \href{...}{...} external url - filecolor=mygreen, %% \href{...} local file - linkcolor=myred, %% \href{...} and \pageref{...} -#+END_SRC - -#+name: output_latex_head_1_format_string_variables -#+BEGIN_SRC d -┃", - ); -#+END_SRC - -**** latex head starts - -#+name: output_latex_head_0_format_string -#+BEGIN_SRC d - string _latex_head = format(q"┃%%%% DocReform LaTeX output -#+END_SRC - -***** description comment - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -%%%% Generated by: %s -%%%% D version: %s -%%%% LaTeX output last Generated on: %s -%%%% %s %s - -#+END_SRC - -***** paper type (a4, letter, ...; ( portrait | landscape )) - -- paper.a4_portrait -- paper.a4_landscape -- paper.us_letter_portrait -- paper.us_letter_landscape - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -%s -#+END_SRC - -***** paper margins (portrait | landscape) - -- margins.portrait -- margins.landscape - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -%s -#+END_SRC - -***** margin shared - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\setlength{\marginparsep}{4mm} -\setlength{\marginparwidth}{8mm} -#+END_SRC - -***** multicol (portrait | landscape) - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -%s -#+END_SRC - -***** language & font - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage{polyglossia, ucs, fontspec, xltxtra, xunicode} -\setmainlanguage{%s} -\setotherlanguage{%s} -\setmainfont{Liberation Sans} -\setmonofont[Scale=0.85]{Liberation Mono} -#+END_SRC - -%% \setsansfont{Liberation Sans} -%% \setromanfont{Liberation Serif} - -***** latex head - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage{alltt} -\usepackage{thumbpdf} -#+END_SRC - -***** color links: no = mono | yes = color - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -%s -#+END_SRC - -***** metadata - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex - pdftitle={%s}, - pdfauthor={%s}, - pdfsubject={%s}, - pdfkeywords={}, - pageanchor=true, - plainpages=true, - pdfpagelabels=true, - pagebackref, - bookmarks=true, - bookmarksopen=true, - pdfmenubar=true, - pdfpagemode=UseOutline, - pdffitwindow=true, - pdfwindowui=true, - plainpages=false, - pdfstartview=FitH -] -{hyperref} -#+END_SRC - -%% pdfusetitle=true, -%% pdfpagelayout=SinglePage, -%% pdfpagelayout=TwoColumnRight, -%% pdfpagelayout=TwoColumnLeft, -%% pdfstartpage=3, - -%%%% trace lost characters -%% \tracinglostchars = 1 -%% \tracingonline = 1 - -***** define colors - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage[usenames]{color} -\definecolor{myblack}{rgb}{0,0,0} -\definecolor{myred}{rgb}{0.75,0,0} -\definecolor{mygreen}{rgb}{0,0.5,0} -\definecolor{myblue}{rgb}{0,0,0.5} -\definecolor{mywhite}{rgb}{1,1,1} -#+END_SRC - -***** latex head - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage{url} -\urlstyle{sf} -#+END_SRC - -%%\usepackage{breakurl} - -***** latex head - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage{textcomp} -\usepackage[parfill]{parskip} -\usepackage[normalem]{ulem} -\usepackage{soul} -\usepackage{longtable} -\usepackage[tc]{titlepic} -\usepackage{graphicx} -\makeatletter -\parindent0pt -\usepackage{amssymb} -\usepackage{listings} -\usepackage{color} -\usepackage{textcomp} -\setcounter{secnumdepth}{2} -\setcounter{tocdepth}{4} -\makeatletter -#+END_SRC - -***** indent, bullet, list - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage[multiple,ragged]{footmisc} -\setlength\footnotemargin{12pt} -\usepackage[para]{manyfoot} -\DeclareNewFootnote{A} -\newenvironment{ParagraphIndent}[1]%% -{ -\begin{list}{}{%% -\setlength\topsep{0pt}%% -\addtolength{\leftmargin}{#1} -\setlength\parsep{0pt plus 1pt}%% -} -\item[] -} -{\end{list}} -\newenvironment{ParagraphHang}[2]%% -{ -\begin{list}{}{%% -\setlength\topsep{0pt}%% -\addtolength{\leftmargin}{#1} -\itemindent=#2 -\setlength\parsep{0pt plus 1pt}%% -} -\item[] -} -{\end{list}} -\newenvironment{Bullet}[1]%% -{ -\begin{list}{}{%% -\setlength\topsep{0pt}%% -\addtolength{\leftmargin}{#1} -\itemindent=-1em -\setlength\parsep{0pt plus 1pt}%% -} -\item[] -} -{\end{list}} -#+END_SRC - -%%\DeclareNewFootnote[para]{A} - -***** part, section, subsection, paragraph, subparagraph - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\usepackage{fancyhdr} -\lhead{} -\renewcommand{\part}{\@startsection - {part}{1}{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\bfseries\large\upshape\raggedright}} -\renewcommand{\section}{\@startsection - {section}{2}{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\bfseries\large\upshape\raggedright}} -\renewcommand{\subsection}{\@startsection - {subsection}{3}{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\bfseries\large\upshape\raggedright}} -\renewcommand{\subsubsection}{\@startsection - {subsubsection}{4}{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\normalfont\normalsize\bfseries\raggedright}} -\renewcommand{\paragraph}{\@startsection - {paragraph}{5}{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\normalfont\normalsize\itshape\raggedright}} -\renewcommand{\subparagraph}{\@startsection - {subparagraph}%%{6}%%{-2mm}%% - {-\baselineskip}{0.5\baselineskip}%% - {\normalfont\normalsize\itshape\raggedright}} -#+END_SRC - -%% \makeatother - -***** latex head misc. including defined commands - -#+name: output_latex_head_0_tex -#+BEGIN_SRC latex -\selectlanguage{%s} -\lhead[ ]{ } -\chead[ \fancyplain{} \bfseries \footnotesize \leftmark ]{ \fancyplain{} \bfseries \footnotesize \rightmark } -\rhead[ ]{ } -%s -\rfoot[\tiny \href{}{}]{\textrm{\thepage}} -\tolerance=300 -\clubpenalty=300 -\widowpenalty=300 -\makeatother -\makeatother -\chardef\txtbullet="2022 -\chardef\tilde="7E -\def\asterisk{{\rm \char42} } -\definecolor{Light}{gray}{.92} -\newcommand{\Codeblock}[1]{\normaltext\raggedright\small\ttfamily\texbackslash#1} -\newcommand{\monosp}[1]{\normaltext\ttfamily\texbackslash#1} -\newcommand{\parasep}{\\ \begin{center}*\hspace{2em}*\hspace{2em}*\end{center} \\} -\newcommand{\hardspace}{{~}} -\newcommand{\caret}{{\^{~}}} -\newcommand{\pipe}{{\textbar}} -\newcommand{\curlyopen}{{} -\newcommand{\curlyclose}{}} -\newcommand{\lt}{{UseTextSymbol{OML}{<}}} -\newcommand{\gt}{{UseTextSymbol{OML}{>}}} -\newcommand{\slash}{{/}} -\newcommand{\underscore}{\_} -\newcommand{\exclaim}{\Verbatim{!}} -\definecolor{listinggray}{gray}{0.9} -\definecolor{lbcolor}{rgb}{0.9,0.9,0.9} -\lstset{ - backgroundcolor=\color{lbcolor}, - tabsize=4, - rulecolor=, - language=, - basicstyle=\scriptsize, - upquote=true, - aboveskip={1.5\baselineskip}, - columns=fixed, - showstringspaces=false, - extendedchars=true, - breaklines=true, - prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, - frame=single, - showtabs=false, - showspaces=false, - showstringspaces=false, - identifierstyle=\ttfamily, - keywordstyle=\color[rgb]{0,0,1}, - commentstyle=\color[rgb]{0.133,0.545,0.133}, - stringstyle=\color[rgb]{0.627,0.126,0.941}, -} -#+END_SRC - -%%\chardef\asterisk="2A -%%\newcommand{\hardspace}{\hspace{.5em}} - -**** latex head format inclusions - -#+name: output_latex_head_0_format_string_variables -#+BEGIN_SRC d -┃", - doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.name_and_version.strip, - doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.compiler.strip, - doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.stime.strip, - doc_matters.generator_program.project_name.strip, - doc_matters.generator_program.url_home.strip, - paper.a4_portrait.strip, - margins.portrait.strip, - multicol.portrait.strip, - lang.codes[doc_matters.src.language]["xlp"], - "english", - links.mono.strip, // links.color.strip, - doc_matters.conf_make_meta.meta.title_full.strip, - doc_matters.conf_make_meta.meta.creator_author.strip, - doc_matters.conf_make_meta.meta.classify_subject.strip, - lang.codes[doc_matters.src.language]["xlp"], - _footer(doc_matters), -); -#+END_SRC - -**** latex head return - -#+name: output_latex_head_close -#+BEGIN_SRC d - return _latex_head.strip; -} -#+END_SRC - -*** ↻ latex body :content:body: -**** latex body function - -#+name: output_latex_body -#+BEGIN_SRC d -string latex_body(D,M)( - const D doc_abstraction, - M doc_matters, -) { - string _latex_body = ""; - bool _multicolumns = false; - string _txt; -#+END_SRC - -**** ↻ loop open - -#+name: output_latex_body -#+BEGIN_SRC d - foreach (part; doc_matters.has.keys_seq.latex) { - foreach (obj; doc_abstraction[part]) { - switch (obj.metainfo.is_of_part) { -#+END_SRC - -**** ↻ within loop -***** frontmatter - -#+name: output_latex_body -#+BEGIN_SRC d - case "frontmatter": assert(part == "head" || "toc"); - _txt = obj.text - .sp_char_esc(obj) - .fontface; - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - _txt = _txt.heading(obj, doc_matters); - goto default; - case "toc": - break; - default: - _latex_body ~= _txt ~ "\n\n"; - _txt = ""; - break; - } - break; - default: break; - } - break; -#+END_SRC - -***** body - -#+name: output_latex_body -#+BEGIN_SRC d - case "body": assert(part == "body" || "head"); // surprise - _txt = obj.text - .sp_char_esc(obj) - .fontface; - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - _txt = _txt.heading(obj, doc_matters); - goto default; - case "para": - _txt = _txt.para(obj) - .bullets_and_indentation(obj) - .links_and_images(obj, doc_matters); - goto default; - default: - _latex_body ~= _txt ~ "\n\n"; - _txt = ""; - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - goto default; // TODO - case "group": - /+ (hardspaces not honored) [remove any hardspace marker] +/ - _txt = _txt.group(obj, doc_matters) - .links_and_images(obj, doc_matters); - goto default; - case "block": - /+ (hardspace honored) \hardspace +/ - _txt = _txt.block(obj, doc_matters) - .links_and_images(obj, doc_matters); - goto default; - case "verse": - /+ (hardspace honored) \hardspace +/ - _txt = _txt.verse(obj, doc_matters) - .links_and_images(obj, doc_matters); - goto default; - case "code": - /+ (hardspace honored) \begin{lstlisting} clear hardspace marker +/ - _txt = _txt.codeblock(obj, doc_matters); - goto default; - case "table": - _txt = _txt.table(obj, doc_matters); - goto default; // TODO - default: - _latex_body ~= _txt ~ "\n\n"; - _txt = ""; - break; - } - break; - default: break; - } - break; -#+END_SRC - -***** backmatter - -#+name: output_latex_body -#+BEGIN_SRC d - case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - _txt = obj.text - .sp_char_esc(obj) - .fontface; - switch (obj.metainfo.is_of_type) { - case "para": - if (part != "bookindex" && _multicolumns) { - _multicolumns = false; - _latex_body ~= "\n\\end{multicols}\n"; - } - switch (obj.metainfo.is_a) { - case "heading": - if (part == "bookindex") { - _multicolumns = true; - } - _txt = _txt.heading(obj, doc_matters, part); - goto default; - case "endnote": assert(part == "endnotes"); - _txt = _txt.para(obj) - .bullets_and_indentation(obj) - .links_and_images(obj, doc_matters); - goto default; - case "glossary": assert(part == "glossary"); - _txt = _txt.para(obj) - .bullets_and_indentation(obj) - .links_and_images(obj, doc_matters); - goto default; - case "bibliography": assert(part == "bibliography"); - _txt = _txt.para(obj) - .bullets_and_indentation(obj); - goto default; - case "bookindex": assert(part == "bookindex"); - /+ two column, special section +/ - _txt = _txt.bookindex(obj) - .links_and_images(obj, doc_matters); - goto default; - case "blurb": assert(part == "blurb"); - _txt = _txt.para(obj) - .bullets_and_indentation(obj) - .links_and_images(obj, doc_matters); - goto default; - default: - _latex_body ~= (part == "bookindex" && obj.metainfo.is_a != "heading") - ? _txt : (_txt ~ "\n\n"); - _txt = ""; - break; - } - break; - default: break; - } - break; -#+END_SRC - -***** after - -#+name: output_latex_body -#+BEGIN_SRC d - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - } - break; - } - } - } - if (_multicolumns) { - _multicolumns = false; - _latex_body ~= "\n\\end{multicols}\n"; - } -#+END_SRC - -**** latex body return - -#+name: output_latex_body -#+BEGIN_SRC d - return _latex_body; -} -#+END_SRC - -*** latex tail :tail: -**** latex tail function - -#+name: output_latex_tail -#+BEGIN_SRC d -string latex_tail(M)( - M doc_matters, -) { -#+END_SRC - -**** latex tail starts - -#+name: output_latex_tail -#+BEGIN_SRC d - string _latex_tail = format(q"┃ -#+END_SRC - -***** latex tail format inclusions - - -***** latex document end - -#+name: output_latex_tail_tex -#+BEGIN_SRC latex - -\end{document} -#+END_SRC - -**** latex tail format inclusions - -#+name: output_latex_tail_close -#+BEGIN_SRC d -┃", - // doc_matters.conf_make_meta.meta.title_full, - // doc_matters.conf_make_meta.meta.creator_author, -); -#+END_SRC - -**** latex tail return - -#+name: output_latex_tail_close -#+BEGIN_SRC d - return _latex_tail; -} -#+END_SRC - -* latex system command helper script -** latex command, ruby script - -#+BEGIN_SRC ruby :tangle "../util/dr_tex.rb" :tangle-mode (identity #o755) :shebang #!/usr/bin/env ruby -require 'fileutils' -pwd = Dir.pwd -argv,texfiles_with_path,flags=[],[],[] -lngs = %{(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)} -Regexp.new(lngs, Regexp::IGNORECASE) -argv=$* -argv.sort.each{|y| (y =~/^--\S+$/i) ? (flags << y) : (texfiles_with_path << y) } -if flags.length==0 \ -|| flags.inspect =~/"--help"/ - cmd=(/([^\/]+)$/).match($0)[1] - puts < 0 - texfiles_with_path.each do |texfile_with_path| - if texfile_with_path =~/.+\.tex/ - #puts texfile_with_path - if FileTest.file?(texfile_with_path) - file_basename_with_path = texfile_with_path.sub(/\.tex$/,'') - file_basename = file_basename_with_path.sub(/.*?([^\/]+)$/,'\1') - _out_path = out_path - if file_basename =~ /\.#{lngs}$/ - lng = file_basename.match(/\.#{lngs}$/)[1] - puts file_basename - puts lng - puts _out_path - unless _out_path.match(/\/#{lng}\/pdf$/) - _out_path = "#{out_path}/#{lng}/pdf" - FileUtils::mkdir_p(_out_path) - end - end - texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex -papersize=#{paper_size} #{texfile_with_path}\n} - puts texpdf_cmd - 2.times { |i| system(texpdf_cmd) } - if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path)) - FileUtils::Verbose::mv(%{#{pwd}/#{file_basename}.pdf}, %{#{_out_path}/#{file_basename}.pdf}) - puts (%{#{_out_path}/#{file_basename}.pdf}) - else - puts "issue with pdf file or output directory" - puts "pdf file: #{pwd}/#{file_basename}.pdf}" - puts "output dir: #{_out_path}/" - end - suffix = ['log', 'out', 'toc', 'aux'] - suffix.each { |s| FileUtils::rm_f(%{#{pwd}/#{file_basename}.#{s}})} - end - end - end -end -Dir.chdir(pwd) -__END__ -#+END_SRC diff --git a/org/output_odt.org b/org/output_odt.org deleted file mode 100644 index 0a7f93d..0000000 --- a/org/output_odt.org +++ /dev/null @@ -1,2517 +0,0 @@ --*- mode: org -*- -#+TITLE: doc_reform output odt -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:xml:odt: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :results silent :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* odt :odt: - -- cover object types -- zip contents -- xml closures? unnecessary, this is sax rather than dom no? - -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| function | filename | module | variable | output_odt | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| identify doc filetype | mimetype | odt_mimetypes | mimetypes | output_odt_fixed | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| doc manifest | manifest.rdf | | | output_odt_fixed | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| settings | settings.xml | outputODTsettings | | output_odt_fixed | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| doc xml styles | styles.xml | outputODTstyles | | output_odt_fixed | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| identify doc root * (imagelist) | META-INF/manifest.xml | odt_container_xml | meta_inf_container_xml | | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| doc content * | content.xml | odt_content | content_odt | | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| images * | Pictures/ | | | copy_odt_images | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| -| doc meta * (timestamp) | meta.xml | odt_metadata | | | -|---------------------------------+-----------------------+-------------------+------------------------+------------------| - -** _module template_ :odf:odt:module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/odt.d" :noweb yes -module doc_reform.output.odt; -template formatODT() { - <> - mixin DocReformOutputRgxInit; - struct formatODT { - static auto rgx = Rgx(); - <> - } -} -template outputODT() { - <> - mixin InternalMarkup; - mixin DocReformOutputRgxInit; - auto rgx = Rgx(); - // mixin outputXmlODT; - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> - <> -} -#+END_SRC - -** odt format objects -*** detail -**** odf structure - -- unless code - - images - - links - - internal / relative - - external - -**** object attrib -***** tags - -#+name: odt_format_objects -#+BEGIN_SRC d -string _tags(O)(const O obj){ - string _tags = ""; - if (obj.tags.anchor_tags.length > 0) { - foreach (tag_; obj.tags.anchor_tags) { - if (tag_.length > 0) { - _tags ~= format(q"┃ - - - -┃", - _special_characters(tag_, obj), - _special_characters(tag_, obj), - ); - } - } - } - return _tags; -} -#+END_SRC - -****** anchor tags - -#+name: odt_format_objects -#+BEGIN_SRC d -string _xhtml_anchor_tags(O)(O obj) { - const(string[]) anchor_tags = obj.tags.anchor_tags; - string tags=""; - if (anchor_tags.length > 0) { - foreach (tag; anchor_tags) { - if (!(tag.empty)) { - tags ~= ""; - } - } - } - return tags; -} -#+END_SRC - -***** ocn object number display - -#+name: odt_format_objects -#+BEGIN_SRC d -string obj_num(O)(const O obj){ // TODO - string _on; - _on = (obj.metainfo.object_number.empty) - ? "" - : (format(q"┃ - 「%s」┃", - obj.metainfo.object_number, - )); - return _on; -} -#+END_SRC - -***** footnotes - -#+name: odt_format_objects -#+begin_src d -string _footnotes()(string _txt){ - static auto rgx = Rgx(); - _txt = _txt.replaceAll( - rgx.inline_notes_al_regular_number_note, - format(q"┃ - - %s - - - - %s - - -┃", - "$1", "$1", "$2", - ) - ); - return _txt; -} -#+end_src - -***** bullet - -#+name: odt_format_objects -#+BEGIN_SRC d -string _bullet(O)(const O obj){ - string _b = ""; - if (obj.attrib.bullet) { - _b = format(q"┃● ┃",); - } - return _b; -} -#+END_SRC - -***** para (with bullet, indent levels, footnotes extracted) - -#+name: odt_format_objects -#+BEGIN_SRC d -string _indent(O)(string _txt, const O obj) { // TODO - // if (obj.attrib.indent_base > 0 || - // obj.attrib.indent_hang > 0 - // ) { - if (obj.metainfo.is_a == "toc") { - _txt = format(q"┃ -%s - %s%s%s -┃", - (obj.attrib.indent_base < 4) - ? "\n " : "", - obj.attrib.indent_base, - obj.attrib.indent_base, - _tags(obj), - _txt, - obj_num(obj), - ); - } else if (!empty(obj.metainfo.object_number)) { - if (obj.attrib.indent_base == 0 && obj.attrib.indent_hang == 0) { - _txt = format(q"┃ -%s - - - - - %s%s%s -┃", - _bullet(obj), - obj.metainfo.object_number, - obj.metainfo.object_number, - _tags(obj), - _txt, - obj_num(obj), - ); - } else if (obj.attrib.indent_base == obj.attrib.indent_hang) { - _txt = format(q"┃ -%s - - - - - %s%s%s -┃", - obj.attrib.indent_base, - _bullet(obj), - obj.metainfo.object_number, - obj.metainfo.object_number, - _tags(obj), - _txt, - obj_num(obj), - ); - } else { - _txt = format(q"┃ -%s - - - - - %s%s%s -┃", - obj.attrib.indent_base, - obj.attrib.indent_hang, - _bullet(obj), - obj.metainfo.object_number, - obj.metainfo.object_number, - _tags(obj), - _txt, - obj_num(obj), - ); - } - } else { - if (obj.attrib.indent_base == 0 && obj.attrib.indent_hang == 0) { /+ can omit and would explicitly set indent base and hang as 0 each below +/ - _txt = format(q"┃ -%s - %s%s%s -┃", - _bullet(obj), - _tags(obj), - _txt, - obj_num(obj), - ); - } else if (obj.attrib.indent_base == obj.attrib.indent_hang) { - _txt = format(q"┃ -%s - %s%s%s -┃", - obj.attrib.indent_base, - _bullet(obj), - _tags(obj), - _txt, - obj_num(obj), - ); - } else { - _txt = format(q"┃ -%s - %s%s%s -┃", - _bullet(obj), - obj.attrib.indent_base, - obj.attrib.indent_hang, - _tags(obj), - _txt, - obj_num(obj), - ); - } - } - return _txt; -} -#+END_SRC - -***** block type - -#+name: odt_format_objects -#+BEGIN_SRC d -string _block_type_delimiters(O)(string[] _block_lines, const O obj) { // TODO - string _block = ""; - foreach (i, _line; _block_lines) { - _line = _footnotes(_line); - if (i == 0) { - _block ~= format(q"┃ -%s - - - - - %s -┃", - _bullet(obj), - obj.metainfo.object_number, - obj.metainfo.object_number, - // _tags(obj), - _line, - ); - } else { - _block ~= format(q"┃ -%s┃", - _line); - } - } - _block ~= format(q"┃ - - 「%s」 - -┃", - obj_num(obj)); - return _block; -} -#+END_SRC - -**** object inline - -***** special characters - -#+name: odt_format_objects -#+BEGIN_SRC d -string _special_characters(O)(string _txt, const O obj) { - _txt = _txt - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_quotation, """) - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.nbsp_char, " "); - return _txt; -} -#+END_SRC - -***** preserve white space - -#+name: odt_format_objects -#+BEGIN_SRC d -string _preserve_white_spaces(O)(string _txt, const O obj) { - if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { - _txt = _txt - .replaceAll(rgx.space, " "); - } - return _txt; -} -#+END_SRC - -***** font_face - -#+name: odt_format_objects -#+BEGIN_SRC d -string _font_face(string _txt){ - _txt = _txt - .replaceAll(rgx.inline_strike, "$1") - .replaceAll(rgx.inline_insert, "$1") - .replaceAll(rgx.inline_cite, "$1") - .replaceAll(rgx.inline_emphasis, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_bold, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_italics, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_underscore, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_superscript, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_subscript, format(q"┃%s┃","$1")) - .replaceAll(rgx.inline_mono, format(q"┃%s┃","$1")); - return _txt; -} -#+END_SRC - -***** object number - -#+name: odt_format_objects -#+BEGIN_SRC d -auto _obj_num(O)(O obj) { // NOT USED YET - struct objNum { - string reference() { - return format(q"┃ - - - ┃", - obj.object_number, - obj.object_number, - ); - } - string display() { - return format(q"┃ - %s%s%s - ┃", - on_o, - obj.object_number, - on_c, - ); - } - } - return objNum(); -} -#+END_SRC - -***** break page - -#+name: odt_format_objects -#+BEGIN_SRC d -string _break_page()() { - return format(q"┃ - -┃", - ); -} -#+END_SRC - -#+BEGIN_SRC d -string _break_page()() { - return format(q"┃ - -┃", - ); -} -#+END_SRC - -***** empty lines break - -#+name: odt_format_objects -#+BEGIN_SRC d -string _empty_line_break(O)(string _txt, const O obj) { - if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { - _txt = _txt - .replaceAll(rgx.br_empty_line, "
"); - } - return _txt; -} -#+END_SRC - -***** links: url, mail - -#+name: odt_format_objects -#+BEGIN_SRC d -string _links(O)(string _txt, const O obj) { - if (obj.metainfo.is_a != "code") { - if (obj.metainfo.is_a == "toc") { - _txt = replaceAll!(m => - m[1] ~ "┤" - ~ (replaceAll!(n => - n["type"] ~ n["path"] ~ (n["file"].encodeComponent) - )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) - ~ "├" - )(_txt, rgx.inline_link_number_only) - .replaceAll(rgx.inline_link, - format(q"┃%s┃", - _special_characters("$3", obj), - _special_characters("$1", obj) - )); - } else { - _txt = replaceAll!(m => - m[1] ~ "┤" - ~ (replaceAll!(n => - n["type"] ~ n["path"] ~ (n["file"].encodeComponent) - )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) - ~ "├" - )(_txt, rgx.inline_link_number_only) - .replaceAll(rgx.inline_link, - format(q"┃%s┃", - _special_characters("$2", obj), - _special_characters("$1", obj) - )); - } - } - debug(links) { - if (obj.text.match(rgx.inline_link_number) - && _txt.match(rgx.inline_link_number_only) - ) { - writeln(">> ", _txt); - writeln("is_a: ", obj.metainfo.is_a); - } - } - return _txt; -} -#+END_SRC - -***** image - -#+name: odt_format_objects -#+BEGIN_SRC d -string _images(O)(string _txt, const O obj) { - if (_txt.match(rgx.inline_image)) { - _txt = _txt - .replaceAll(rgx.inline_image, - ("$1 $6")) - .replaceAll( - rgx.inline_link_empty, - ("$1")); - } - return _txt; -} -#+END_SRC - -**** markup hub (including font face) - -#+name: odt_format_objects -#+BEGIN_SRC d -string markup(O)(const O obj) { - /+ markup TODO +/ - string _txt = obj.text; - _txt = _special_characters(_txt, obj); // TODO & why both obj & obj.text, consider also in output_xmls.org - if (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") { - _txt = replaceAll!(m => _preserve_white_spaces(m[1], obj))(_txt, rgx.spaces_keep); - } // check that this does what you want, keep: leading spaces (indent) & more than single spaces within text - // _txt = _preserve_white_spaces(_txt, obj); // (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") - _txt = _font_face(_txt); - _txt = _images(_txt, obj); // (obj.metainfo.is_a != "code") - _txt = _links(_txt, obj); // (obj.metainfo.is_a != "code") - _txt = _empty_line_break(_txt, obj); // (obj.metainfo.is_a == "code" || obj.metainfo.is_a == "verse" || obj.metainfo.is_a == "block") - return _txt; -} -#+END_SRC - -*** objects -**** para type -***** heading - -#+name: odt_format_objects -#+BEGIN_SRC d -string heading(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "heading"); - string _o_txt_odt = markup(obj); - if (obj.metainfo.dummy_heading - && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { - _o_txt_odt = ""; - } else if (obj.metainfo.is_a == "toc") { - _o_txt_odt = format(q"┃%s - %s%s%s -┃", - _break_page, - obj.metainfo.heading_lev_markup, - obj.metainfo.heading_lev_markup, - _tags(obj), - _o_txt_odt, - obj_num(obj), - ); - } else { - _o_txt_odt = _footnotes(_o_txt_odt); - _o_txt_odt = format(q"┃%s - - - - - %s%s%s -┃", - _break_page, - obj.metainfo.heading_lev_markup, - obj.metainfo.heading_lev_markup, - obj.metainfo.object_number, - obj.metainfo.object_number, - _tags(obj), - _o_txt_odt, - obj_num(obj), - ); - } - return _o_txt_odt; -} -#+END_SRC - -***** para - -#+name: odt_format_objects -#+BEGIN_SRC d -string para(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - string _o_txt_odt; - if (obj.metainfo.dummy_heading - && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { - _o_txt_odt = ""; - } else { - _o_txt_odt = markup(obj); - _o_txt_odt = _footnotes(_o_txt_odt); - _o_txt_odt = _indent(_o_txt_odt, obj); // final setting? - } - return _o_txt_odt; -} -#+END_SRC - -**** block type -***** quote - -#+name: odt_format_objects -#+BEGIN_SRC d -string quote(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "quote"); - string _o_txt_odt = markup(obj); - _o_txt_odt = _footnotes(_o_txt_odt); // decide - return _o_txt_odt; -} -#+END_SRC - -***** group -- group delimiter - - preserves double newlines (paragraph delimiter) -- the "group" delimiter is different from the "block" delimiter in that groups do not preserve whitespace, the "block" mark does - -#+name: odt_format_objects -#+BEGIN_SRC d -string group(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "group"); - string _o_txt_odt = markup(obj); - /+ TODO - - split lines - - only double newlines (paragraph delimiter), (not line breaks, single new lines) - - no hard space indentation - +/ - string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); - _o_txt_odt = _block_type_delimiters(_block_lines, obj); - return _o_txt_odt; -} -#+END_SRC - -***** block -- block delimiter - - preserves spaces - - preserves newlines -- the "block" delimiter is different from the "group" delimiter, in that blocks preserve whitespace, the "group" mark does not - -- - - split lines - - each line including empty lines - - hard space indentation - - "^[ ]"   - - count number only at beginning of line and replace each - -#+name: odt_format_objects -#+BEGIN_SRC d -string block(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "block"); - string _o_txt_odt = markup(obj); - string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); - _o_txt_odt = _block_type_delimiters(_block_lines, obj); - return _o_txt_odt; -} -#+END_SRC - -***** verse -- poem delimiters - - creates verses where double newlines occur (paragraph delimiter) - - preserves spaces - - preserves newlines - -#+name: odt_format_objects -#+BEGIN_SRC d -string verse(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "verse"); - string _o_txt_odt = markup(obj); - string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); - _o_txt_odt = _block_type_delimiters(_block_lines, obj); - return _o_txt_odt; -} -#+END_SRC - -***** code - -#+name: odt_format_objects -#+BEGIN_SRC d -string code(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "code"); - string _o_txt_odt = markup(obj); - /+ TODO - - split lines - - each line including empty lines - - hard space indentation - - "^[ ]"   - - count number only at beginning of line and replace each - +/ - string[] _block_lines = (_o_txt_odt).split(rgx.br_newlines_linebreaks); - string _block = ""; - foreach (i, _line; _block_lines) { - if (i == 1) { - _block ~= format(q"┃ - - - - - -%s -┃", - obj.metainfo.object_number, - obj.metainfo.object_number, - _line, - ); - } else { - _block ~= format(q"┃ -%s┃", - _line); - } - } - _block ~= format(q"┃ - - 「%s」 - -┃", - obj_num(obj)); - _o_txt_odt = _block; - return _o_txt_odt; -} -#+END_SRC - -***** table -****** tablarize - -#+name: odt_format_objects -#+BEGIN_SRC d -auto tablarize(O)( - const O obj, - string _txt, -) { - string[] _table_rows = (_txt).split(rgx.table_delimiter_row); - string[] _table_cols; - string _table; - string _tablenote; - foreach(row_idx, row; _table_rows) { - _table_cols = row.split(rgx.table_delimiter_col); - _table ~= ""; - foreach(col_idx, cell; _table_cols) { - if ((_table_cols.length == 1) - && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) - _tablenote ~= cell; - } else { - _table ~= format(q"┃ - -%s - -┃", - (row_idx == 0 && obj.table.heading) ? "Table_Heading" : "P_table_cell", - cell, - ); - } - } - _table ~= ""; - } - auto t = tuple( - _table, - _tablenote, - ); - return t; -} -#+END_SRC - -****** table - -#+name: odt_format_objects -#+BEGIN_SRC d -int _table_number = 0; -string table(O,M)( - const O obj, - const M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "table"); - string _o_txt_odt = markup(obj); - auto t = tablarize(obj, _o_txt_odt); - string _note = t[1]; - _o_txt_odt = format(q"┃ - - - - - - - %s - - - 「%s」 -┃", - _table_number++, - obj.metainfo.object_number, - obj.metainfo.object_number, - obj.table.number_of_columns, - t[0], - obj.metainfo.object_number, - // _note, - ); - return _o_txt_odt; -} -#+END_SRC - -** write odt output :odf:odt:out: - -#+name: output_odt -#+BEGIN_SRC d -void writeOutputODT(W,I)( - const W odt_content, - I doc_matters, -) { - auto pth_odt = DocReformPathsODT!()(doc_matters); - auto fn_odt = pth_odt.odt_file; - auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); - void ODTzip()(string contents, string fn) { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - (doc_matters.opt.action.debug_do) - ? zip_data.write(contents.dup) - : zip_data.write(contents.dup - .replaceAll(rgx.spaces_line_start, "") - .replaceAll(rgx.newline, "") - .strip - ); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_odt, zip.build()); - } - try { - if (!exists(pth_odt.base_pth)) { // check - pth_odt.base_pth.mkdirRecurse; - } - string fn; - File f; - { fn = pth_odt.mimetype("zip"); - ODTzip(odt_content.mimetype, fn); - } - { fn = pth_odt.manifest_rdf("zip"); - ODTzip(odt_content.manifest_rdf, fn); - } - { fn = pth_odt.settings_xml("zip"); - ODTzip(odt_content.settings_xml, fn); - } - { fn = pth_odt.styles_xml("zip"); - ODTzip(odt_content.styles_xml, fn); - } - { fn = pth_odt.content_xml("zip"); - ODTzip(odt_content.content_xml, fn); - } - { fn = pth_odt.manifest_xml("zip"); - ODTzip(odt_content.manifest_xml, fn); - } - { fn = pth_odt.meta_xml("zip"); - ODTzip(odt_content.meta_xml, fn); - } - { /+ (images) +/ - foreach (image; doc_matters.srcs.image_list) { - auto fn_src = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_out = pth_odt.image_dir("zip") ~ "/" ~ 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_odt, zip.build()); - } - } - } - } - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_odt.odt_file); - } - } catch (ErrnoException ex) { - // Handle error - } - if (doc_matters.opt.action.debug_do) { - pth_odt.mimetype("fs"); /+ (mimetype) +/ - pth_odt.manifest_rdf("fs"); /+ (manifest.rdf) +/ - pth_odt.settings_xml("fs"); /+ (settings.xml) +/ - pth_odt.styles_xml("fs"); /+ (styles_xml) +/ - - pth_odt.content_xml("fs"); - pth_odt.manifest_xml("fs"); - pth_odt.meta_xml("fs"); - } -} -#+END_SRC - -** odt output hub [#A] :odf:odt:out: - -#+name: output_odt -#+BEGIN_SRC d -void outputODT(D,I)( - const D doc_abstraction, - I doc_matters, -) { - struct ODT { - /+ fixed output +/ - string mimetype; - string manifest_rdf; - string settings_xml; - string styles_xml; - /+ variable output +/ - string content_xml; // substantive content - string manifest_xml; // image list changes - string meta_xml; // time stamp - } - // auto pth_odt = DocReformPathsODT!()(doc_matters); - auto odt = ODT(); - odt.mimetype = mimetype; - odt.manifest_rdf = manifest_rdf; - odt.settings_xml = settings_xml; - odt.styles_xml = styles_xml; - odt.content_xml = content_xml(doc_abstraction, doc_matters); - odt.manifest_xml = manifest_xml(doc_matters); - odt.meta_xml = meta_xml(doc_matters); - odt.writeOutputODT(doc_matters); - dirtree(doc_matters); - images_cp(doc_matters); // copy images -} -#+END_SRC - -* stuff -** shared -*** output imports - -#+name: output_imports -#+BEGIN_SRC d -import doc_reform.output; -import - std.digest.sha, - std.file, - std.outbuffer, - std.uri, - std.zip, - std.conv : to; -import - doc_reform.output.create_zip_file, - doc_reform.output.xmls, - doc_reform.output.xmls_css; -#+END_SRC - -*** make directory tree - -#+name: output_odt_fixed_dirtree -#+BEGIN_SRC d -void dirtree(I)( - I doc_matters, -) { - auto pth_odt = DocReformPathsODT!()(doc_matters); - if (doc_matters.opt.action.debug_do) { /+ (dir tree) +/ - if (!exists(pth_odt.meta_inf_dir("fs"))) { - pth_odt.meta_inf_dir("fs").mkdirRecurse; - } - if (!exists(pth_odt.image_dir("fs"))) { - pth_odt.image_dir("fs").mkdirRecurse; - } - } - if (!exists(pth_odt.base_pth)) { - pth_odt.base_pth.mkdirRecurse; - } - // return 0; -} -#+END_SRC - -** fixed items -*** mimetype :mimetype: - -#+name: output_odt_fixed_mimetype -#+BEGIN_SRC d -string mimetype() { - string mimetype_ = format(q"┃application/vnd.oasis.opendocument.text┃"); - return mimetype_; -} -#+END_SRC - -*** manifest.rdf :manifest_rdf: - -#+name: output_odt_fixed_manifest_rdf -#+BEGIN_SRC d -string manifest_rdf() { - string _manifest_rdf = format(q"┃ -#+END_SRC - -#+name: output_odt_fixed_manifest_rdf -#+BEGIN_SRC xml - - - - - - - - - - - - - - - - - -#+END_SRC - -#+name: output_odt_fixed_manifest_rdf -#+BEGIN_SRC d -┃"); - return _manifest_rdf; -} -#+END_SRC - -*** settings.xml :settings: - -#+name: output_odt_fixed_settings_xml -#+BEGIN_SRC d -string settings_xml() { - string _settings_xml = format(q"┃ -#+END_SRC - -#+name: output_odt_fixed_settings_xml -#+BEGIN_SRC xml - - - - 0 - 0 - 0 - 0 - true - false - - - view2 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 2 - true - 100 - false - - - - - true - false - false - true - true - false - true - false - false - - false - false - false - true - true - 0 - false - false - false - false - true - false - false - false - false - true - true - false - false - true - false - true - false - high-resolution - 1 - 0 - true - - - false - true - - false - true - false - true - false - true - false - - true - true - false - true - true - true - false - false - - false - 0 - false - false - true - true - - - -#+END_SRC - -#+name: output_odt_fixed_settings_xml -#+BEGIN_SRC d -┃"); - return _settings_xml; -} -#+END_SRC - -*** styles.xml :styles_xml: - -#+name: output_odt_fixed_styles_xml -#+BEGIN_SRC d -string styles_xml() { - string _styles_xml = format(q"┃ -#+END_SRC - -#+name: output_odt_fixed_styles_xml -#+BEGIN_SRC xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#+END_SRC - -#+name: output_odt_fixed_styles_xml -#+BEGIN_SRC d -┃"); - return _styles_xml; -} -#+END_SRC - -** moving parts -*** ↻ content.xml TODO :content_xml: -**** content head -***** head open - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -string odt_head(I)(I doc_matters) { - string _has_tables = format(q"┃ -#+END_SRC - -***** if table include within head - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#+END_SRC - -***** head - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -┃",); - string _odt_head = format(q"┃ -#+END_SRC - -***** head xml - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC xml - - - - - - - - - - - - - - %s - - - - - - - - - - - - - -#+END_SRC - -***** head close - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -┃", - (doc_matters.has.tables > 0) ? _has_tables : "", -); - return _odt_head; -} -#+END_SRC - -**** ↻ content body -***** body open - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -string odt_body(D,I)( - const D doc_abstraction, - I doc_matters, -) { - mixin formatODT; - auto odt_format = formatODT(); - string delimit = ""; - string doc_odt = ""; - string _txt = ""; -#+END_SRC - -***** ↻ the loop & outer switch (sections & objects) format output - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d - foreach (part; doc_matters.has.keys_seq.scroll) { - foreach (obj; doc_abstraction[part]) { - switch (obj.metainfo.is_of_part) { -#+END_SRC - -****** frontmatter - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d - case "frontmatter": assert(part == "head" || "toc"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - _txt = delimit ~ odt_format.heading(obj, doc_matters); - goto default; - case "toc": - _txt = odt_format.para(obj, doc_matters); - goto default; - default: - doc_odt ~= _txt; - _txt = ""; - break; - } - break; - default: break; - } - break; -#+END_SRC - -****** body - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d - case "body": assert(part == "body" || "head"); // surprise - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - _txt = delimit ~ odt_format.heading(obj, doc_matters); - goto default; - case "para": - _txt = odt_format.para(obj, doc_matters); - goto default; - default: - doc_odt ~= _txt; - _txt = ""; - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - _txt = odt_format.quote(obj, doc_matters); - goto default; - case "group": - _txt = odt_format.group(obj, doc_matters); - goto default; - case "block": - _txt = odt_format.block(obj, doc_matters); - goto default; - case "verse": - _txt = odt_format.verse(obj, doc_matters); - goto default; - case "code": - _txt = odt_format.code(obj, doc_matters); - goto default; - case "table": - _txt = odt_format.table(obj, doc_matters); - goto default; - default: - doc_odt ~= _txt; - _txt = ""; - break; - } - break; - default: break; - } - break; -#+END_SRC - -****** backmatter - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d - case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - _txt = delimit ~ odt_format.heading(obj, doc_matters); - goto default; - case "endnote": assert(part == "endnotes"); - _txt = odt_format.para(obj, doc_matters); - goto default; - case "glossary": assert(part == "glossary"); - _txt = odt_format.para(obj, doc_matters); - goto default; - case "bibliography": assert(part == "bibliography"); - _txt = odt_format.para(obj, doc_matters); - goto default; - case "bookindex": assert(part == "bookindex"); - _txt = odt_format.para(obj, doc_matters); - goto default; - case "blurb": assert(part == "blurb"); - _txt = odt_format.para(obj, doc_matters); - goto default; - default: - doc_odt ~= _txt; - _txt = ""; - break; - } - break; - default: break; - } - break; - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - } - break; -#+END_SRC - -***** closings & post loop - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d - } - } - } - return doc_odt; -} -#+END_SRC - -**** content book index? - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -#+END_SRC - -**** content tail - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -string odt_tail() { - string _odt_tail = format(q"┃DocReform: <www.doc_reform.org> and <www.sisudoc.org> -┃",); - return _odt_tail; -} -#+END_SRC - -**** hub - -#+name: output_odt_variable_content_xml -#+BEGIN_SRC d -string content_xml(D,I)( - const D doc_abstraction, - I doc_matters, -) { - string _content_xml; - string break_line = (doc_matters.opt.action.debug_do) ? "\n" : ""; - string odt_break_page = format(q"┃┃",); - string br_pg = format(q"┃┃",); - _content_xml ~= odt_head(doc_matters); - _content_xml ~= odt_body(doc_abstraction, doc_matters); - _content_xml ~= odt_tail; - return _content_xml; -} -#+END_SRC - -*** manifest.xml (images list changes) :manifest_xml: - - META-INF/manifest.xml - - image list changes - -#+name: output_odt_variable_manifest_xml -#+BEGIN_SRC d -string manifest_xml(M)( - auto ref M doc_matters, -) { - string _bullet = format(q"┃┃"); - string[] _images = [ _bullet ]; - foreach (image; doc_matters.srcs.image_list) { - _images ~= format(q"┃ ┃", image); - } - string _manifest_xml = format(q"┃ -#+END_SRC - -#+name: output_odt_variable_manifest_xml -#+BEGIN_SRC xml - - - - - %s - - - - - -#+END_SRC - -#+name: output_odt_variable_manifest_xml -#+BEGIN_SRC d -┃", -_images.join("\n"), -); - return _manifest_xml; -} -#+END_SRC - -*** meta.xml (time stamp) :meta_xml: - -#+name: output_odt_variable_meta_xml -#+BEGIN_SRC d -string meta_xml(M)( - auto ref M doc_matters, -) { - /+ (meta_xml includes output time-stamp) +/ - string _meta_xml = format(q"┃ -#+END_SRC - -#+name: output_odt_variable_meta_xml -#+BEGIN_SRC xml - - - %s - %s - %s - en-US - - -#+END_SRC - -#+name: output_odt_variable_meta_xml -#+BEGIN_SRC d -┃", -doc_matters.generator_program.name_and_version, -doc_matters.generated_time, -doc_matters.generated_time, -); - return _meta_xml; -} -#+END_SRC - -*** copy images :images: - -#+name: output_odt_variable_copy_odt_images -#+BEGIN_SRC d -void images_cp(M)( - auto ref M doc_matters, -) { - { /+ (copy odt images) +/ - auto pth_odt = DocReformPathsODT!()(doc_matters); - foreach (image; doc_matters.srcs.image_list) { - auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_src_out_file = pth_odt.image_dir("fs") ~ "/" ~ image; - auto fn_src_out_zip = pth_odt.image_dir("zip") ~ "/" ~ image; - if (exists(fn_src_in)) { - if (doc_matters.opt.action.debug_do) { - if (doc_matters.opt.action.debug_do) { - fn_src_in.copy(fn_src_out_file); - } - } - } - } - } - // return 0; -} -#+END_SRC diff --git a/org/output_sqlite.org b/org/output_sqlite.org deleted file mode 100644 index 7115a41..0000000 --- a/org/output_sqlite.org +++ /dev/null @@ -1,1931 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) output sqlite -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:db:sql:sqlite: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* sql -** _module, templates_ :module: -*** hub -**** collection - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -module doc_reform.output.sqlite; -<> -import d2sqlite3; -import std.typecons : Nullable; -mixin DocReformOutputRgxInit; -mixin InternalMarkup; -static auto rgx = Rgx(); -static auto mkup = InlineMarkup(); -long _metadata_tid_lastrowid; -template SQLiteHubBuildTablesAndPopulate() { - void SQLiteHubBuildTablesAndPopulate(D,M)( - const D doc_abstraction, - M doc_matters, - ) { - auto pth_sqlite = DocReformPathsSQLite!()(doc_matters.sqlite.filename, doc_matters.output_path); - pth_sqlite.base.mkdirRecurse; - auto db = Database(pth_sqlite.sqlite_file); - template SQLiteDbStatementComposite() { - void SQLiteDbStatementComposite(Db,D,M)( - Db db, - const D doc_abstraction, - M doc_matters, - ) { - <> - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_sqlite.sqlite_file); - } - } - } - SQLiteDbStatementComposite!()(db, doc_abstraction, doc_matters); - } -} -#+END_SRC - -**** discrete - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteHubDiscreteBuildTablesAndPopulate() { - void SQLiteHubDiscreteBuildTablesAndPopulate(D,M)( - const D doc_abstraction, - M doc_matters, - ) { - auto url_html = DocReformUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); - auto pth_sqlite = DocReformPathsSQLiteDiscrete!()(doc_matters.output_path, doc_matters.src.language); - pth_sqlite.base.mkdirRecurse; - auto db = Database(pth_sqlite.sqlite_file(doc_matters.src.filename)); - template SQLiteDiscreteDbStatementComposite() { - void SQLiteDiscreteDbStatementComposite(Db,D,M)( - Db db, - const D doc_abstraction, - M doc_matters, - ) { - <> - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_sqlite.sqlite_file(doc_matters.src.filename)); - } - } - } - SQLiteDiscreteDbStatementComposite!()(db, doc_abstraction, doc_matters); - } -} -#+END_SRC - -*** db run - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteDbRun() { - void SQLiteDbRun(Db,St,O)( - Db db, - St db_statement, - O opt_action, - string note, - ) { - debug(sql_statement) { - writeln(db_statement); - } - try { - db.run( - "\nBEGIN;\n" ~ - db_statement ~ - "\nCOMMIT;\n" - ); - if (!(opt_action.sqlite_discrete) - && !(opt_action.sqlite_db_create) - ) { - } - } catch (ErrnoException ex) { - writeln("ERROR SQLite : ", ex); - } catch (Exception ex) { - writeln("ERROR SQLite : ", ex); - } - { /+ debug +/ - if (opt_action.debug_do - && opt_action.verbose) { - writeln(note); - if (opt_action.very_verbose) { - writeln(db_statement); - } - } - } - } -} -#+END_SRC - -*** munge - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLinsertDelimiter() { - auto SQLinsertDelimiter(string _txt) { - _txt = _txt - .replaceAll(rgx.quotation_mark_sql_insert_delimiter, "$0$0"); - return _txt; - } -} -template SQLiteFormatAndLoadObject() { - auto SQLiteFormatAndLoadObject(M)( - M doc_matters, - ) { - mixin DocReformOutputRgxInit; - struct sqlite_format_and_load_objects { - <> - <> - <> - <> - <> - } - return sqlite_format_and_load_objects(); - } -} -#+END_SRC - -*** sqlite instructions -**** create - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteTablesReCreate() { - string SQLiteTablesReCreate()() { - string _sql_instruct; - _sql_instruct = format(q"┃ - <> - <> - <> - <> - <> - <> - ┃",); - return _sql_instruct; - } -} -#+END_SRC - -**** delete - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteDeleteDocument() { - string SQLiteDeleteDocument(M)( - M doc_matters, - ) { - <> - return _delete_uid; - } -} -#+END_SRC - -**** insert - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteInsertMetadata() { - string SQLiteInsertMetadata(M)( - M doc_matters, - ) { - <> - <> - return _insert_metadata; - } -} -#+END_SRC - -**** insert doc objects loop - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteInsertDocObjectsLoop() { - string SQLiteInsertDocObjectsLoop(D,M)( - const D doc_abstraction, - M doc_matters, - ) { - string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); - auto url_html = DocReformUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); - string insertDocObjectsRow(O)(O obj) { - <> - return _insert_doc_objects_row; - } - <> - } -} -#+END_SRC - -**** tables create - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteTablesCreate() { - void SQLiteTablesCreate(E,O)(E env, O opt_action) { - import d2sqlite3; - template SQLiteTablesReCreate() { - string SQLiteTablesReCreate()() { - string _sql_instruct; - _sql_instruct = format(q"┃ - <> - <> - <> - <> - <> - <> - ┃",); - return _sql_instruct; - } - } - if (opt_action.sqlite_db_create) { - string _db_statement; - auto pth_sqlite = DocReformPathsSQLite!()(opt_action.sqlite_filename, opt_action.output_dir_set); - pth_sqlite.base.mkdirRecurse; - auto db = Database(pth_sqlite.sqlite_file); - { - _db_statement ~= SQLiteTablesReCreate!()(); - } - SQLiteDbRun!()(db, _db_statement, opt_action, "TABLE RE-CREATE"); - } - } -} -#+END_SRC - -**** tables drop - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/sqlite.d" -template SQLiteDbDrop() { - void SQLiteDbDrop(O)(O opt_action) { - writeln("db drop"); - if ((opt_action.sqlite_db_drop)) { - auto pth_sqlite = DocReformPathsSQLite!()(opt_action.sqlite_filename, opt_action.output_dir_set); - writeln("remove(", pth_sqlite.sqlite_file, ")"); - try { - remove(pth_sqlite.sqlite_file); - } catch (FileException ex) { - // handle error - } - } - } -} -#+END_SRC - -** 1. [#A] sqlite_db_statement :statement: -*** collection - -#+name: sqlite_db_statement_composite_collection -#+BEGIN_SRC d -{ - string _db_statement; - { - if ((doc_matters.opt.action.sqlite_db_create)) { - auto pth_sqlite = DocReformPathsSQLite!()(doc_matters.sqlite.filename, doc_matters.output_path); - pth_sqlite.base.mkdirRecurse; - _db_statement ~= SQLiteTablesReCreate!()(); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "TABLE RE-CREATE"); - } - if (doc_matters.opt.action.sqlite_delete) { - _db_statement ~= SQLiteDeleteDocument!()(doc_matters); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "DELETE Document"); - } - if (doc_matters.opt.action.sqlite_update) { - _db_statement ~= SQLiteDeleteDocument!()(doc_matters); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "DELETE Document"); - _db_statement ~= SQLiteInsertMetadata!()(doc_matters); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "INSERT MetaData"); - /+ get tid (lastrowid or max) for use in doc_objects table +/ - _db_statement ~= doc_abstraction.SQLiteInsertDocObjectsLoop!()(doc_matters); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "INSERT DocObjects"); - } - } - db.close; -} -#+END_SRC - -*** discrete - -#+name: sqlite_db_statement_composite_discrete -#+BEGIN_SRC d -{ - string _db_statement; - { - _db_statement ~= SQLiteTablesReCreate!()(); - _db_statement ~= SQLiteInsertMetadata!()(doc_matters); - _db_statement ~= doc_abstraction.SQLiteInsertDocObjectsLoop!()(doc_matters); - SQLiteDbRun!()(db, _db_statement, doc_matters.opt.action, "table CREATE Tables, INSERT DocObjects"); - } - db.close; -} -#+END_SRC - -** 2. imports - -#+name: output_imports -#+BEGIN_SRC d -import doc_reform.output; -import - std.file, - std.uri, - std.conv : to; -#+END_SRC - -** 3. format and load template -*** 1. prepare objects (munge, sanitize, markup) -**** 1. _text_ generic munge (sanitize text for search) - -- [3/4] (search text, applies to all but code blocks) - - [ ] remove whitespace, paragraph on single line (formatting kept so far) - - [X] remove font face attributes - - [X] move embedded endnotes - - [X] place after text object - - [X] remove embedded endnote numbers (rely on html output to represent) - - [X] urls - - [X] clean url markers, leave plain link text - - [X] place urls after text object and its endnotes - -#+name: sanitize_text_for_search -#+BEGIN_SRC d -string generic_munge_sanitize_text_for_search( - string _txt, -) { - string _notes; - string _urls; - if (_txt.matchFirst(rgx.inline_notes_al_gen)) { - foreach (m; _txt.matchAll(rgx.inline_notes_al_gen_text)) { - _notes ~= "\n" ~ m["text"]; - } - _txt = _txt.replaceAll(rgx.inline_notes_al_gen, ""); - } - if (_txt.matchFirst(rgx.inline_link)) { - foreach (m; _txt.matchAll(rgx.inline_link)) { - if (m["link"].match(rgx.url)) { - _urls ~= "\n" ~ m["link"]; - } - } - _txt = _txt.replaceAll(rgx.inline_link_clean, ""); - } - if (_notes.length > 0) { - _txt ~= _notes; - } - if (_urls.length > 0) { - _txt ~= _urls; - } - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(_txt, "\n"); - } - } - debug(sql_text_clean) { - writeln(_txt); - } - return _txt; -} -#+END_SRC - -**** 2. _html_ - -light html objects -- place endnotes after text object -- light inline html markup - -***** munge -****** general munge (special characters, inline markup, move notes) - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string munge_html(M,O)( - M doc_matters, - const O obj, -) { - string _html_special_characters(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, " ") - .replaceAll(rgx.xhtml_line_break, "
"); - return _txt; - } - string _html_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 _notes; - string _urls; - string _txt = _html_font_face(_html_special_characters(obj.text)); - if (_txt.matchFirst(rgx.inline_notes_al_gen)) { - foreach (m; _txt.matchAll(rgx.inline_notes_al_gen_text)) { - _notes ~= "\n" ~ m["text"]; - } - _txt = _txt.replaceAll(rgx.inline_notes_al_gen_ref, "$1 "); - } - if (_notes.length > 0) { - _txt ~= _notes; - } - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(_txt, "\n"); - } - } - return _txt; -} -#+END_SRC - -****** special characters - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string html_special_characters(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, " ") - .replaceAll(rgx.xhtml_line_break, "
"); - return _txt; -} -#+END_SRC - -****** special characters for code - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string html_special_characters_code(string _txt){ - _txt = _txt - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_quotation, """) - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.nbsp_char, " "); - return _txt; -} -#+END_SRC - -****** font_face - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string html_font_face(string _txt){ - _txt = _txt - .replaceAll(rgx.inline_emphasis, "$1") - .replaceAll(rgx.inline_bold, "$1") - .replaceAll(rgx.inline_underscore, "$1") - .replaceAll(rgx.inline_italics, "$1") - .replaceAll(rgx.inline_superscript, "$1") - .replaceAll(rgx.inline_subscript, "$1") - .replaceAll(rgx.inline_strike, "$1") - .replaceAll(rgx.inline_insert, "$1") - .replaceAll(rgx.inline_mono, "$1") - .replaceAll(rgx.inline_cite, "$1"); - return _txt; -} -#+END_SRC - -****** inline markup -******* images - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string inline_images(M,O)( - M doc_matters, - const O obj, - string _txt, - string _suffix = ".html", - string _xml_type = "seg", -) { - string _img_pth; - if (_xml_type == "epub") { - _img_pth = "image/"; - } else if (_xml_type == "scroll") { - _img_pth = "../../image/"; - } else if (_xml_type == "seg") { - _img_pth = "../../../image/"; - } - if (_txt.match(rgx.inline_image)) { - _txt = _txt.replaceAll( // TODO bug where image dimensions (w or h) not given & consequently set to 0; should not be used (calculate earlier, abstraction) - rgx.inline_image, - ("$1 $6")); - } - return _txt; -} -#+END_SRC - -******* links -******** scroll, seg, epub - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string inline_links(M,O)( - M doc_matters, - const O obj, - string _txt, - string _xml_type = "seg", -) { - if (obj.has.inline_links) { - if (obj.metainfo.is_a != "code") { - _txt = replaceAll!(m => - m[1] ~ "┤" ~ to!string((obj.stow.link[m[2].to!ulong])).encode ~ "├" - )(_txt, rgx.inline_link_number_only); - } - if ((_txt.match(rgx.mark_internal_site_lnk)) - && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault - _txt = _txt.replaceAll( - rgx.inline_seg_link, - "$1"); - } - auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); - if (_xml_type == "seg") { - foreach (m; _txt.match(rgx.inline_link_hash)) { - if (m.captures[3] in doc_matters.has.tag_associations) { - if (m.captures[3] == doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"]) { - _txt = _txt.replaceFirst( - rgx.inline_link_hash, - "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root - ~ "/" - ~ pth_html.tail_fn_seg(doc_matters.src.filename, "$3.html") - ~ "├" - ); - } else { - _txt = _txt.replaceFirst( - rgx.inline_link_hash, - "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root - ~ "/" - ~ doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"] - ~ ".html" - ~ "#" ~ "$3" - ~ "├" - ); - } - } else { - if (!(doc_matters.opt.action.quiet)) { - writeln( - "WARNING on internal document links, anchor to link <<" - ~ m.captures[3] - ~ ">> not found in document, " - ~ "anchor: " ~ m.captures[3] - ~ " document: " ~ doc_matters.src.filename - ); - } - } - } - } else { - if (auto m = _txt.match(rgx.inline_link_hash)) { - _txt = _txt.replaceFirst( - rgx.inline_link_hash, - "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root - ~ "/" - ~ pth_html.tail_fn_scroll(doc_matters.src.filename) - ~ "#" ~ "$3" - ~ "├" - ); - } - } - _txt = _txt - .replaceAll( - rgx.inline_link_fn_suffix, - ("$1.html")) - .replaceAll( - rgx.inline_link, - ("$1")) - .replaceAll( - rgx.mark_internal_site_lnk, - ""); - } - debug(markup_links) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.has.inline_links, - "): ", obj.metainfo.is_a, ": ", - obj.text - ); - } - } - debug(markup) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.has.inline_links, - "): ", obj.metainfo.is_a, ": ", - obj.text - ); - } - } - return _txt; -} -#+END_SRC - -******* notes -******** scroll - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string inline_notes_scroll(M,O)( - M doc_matters, - const O obj, - string _txt, -) { - if (obj.has.inline_notes_reg) { - // _txt = font_face(_txt); - _txt = _txt.replaceAll( - rgx.inline_notes_al_regular_number_note, - (" $1 ") - ); - } - debug(markup_endnotes) { - if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - debug(markup) { - if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - return _txt; -} -#+END_SRC - -******** seg - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -auto inline_notes_seg(M,O)( - M doc_matters, - const O obj, - string _txt, -) { - string[] _endnotes; - if (obj.has.inline_notes_reg) { - /+ need markup for text, and separated footnote +/ - foreach(m; _txt.matchAll(rgx.inline_notes_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_al_regular_number_note, - (" $1 ") - ); - } else if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - debug(markup) { - writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - auto t = tuple( - _txt, - _endnotes, - ); - return t; -} -#+END_SRC - -******* inline markup - -#+name: sanitize_and_munge_inline_html -#+BEGIN_SRC d -string xml_type="seg"; /+ set html document type to be linked to here (seg|scroll) +/ -string inline_markup(M,O)( - M doc_matters, - const O obj, - string _txt, -) { - _txt = inline_images(doc_matters, obj, _txt, xml_type); - _txt = inline_links(doc_matters, obj, _txt, xml_type); - _txt = inline_notes_scroll(doc_matters, obj, _txt); - return _txt; -} -#+END_SRC - -***** objects -****** heading - -#+name: html_objects -#+BEGIN_SRC d -string html_heading(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "heading"); - string _txt = munge_html(doc_matters, obj); - _txt = inline_markup(doc_matters, obj, _txt); - string o = format(q"┃

- %s -

┃", - obj.metainfo.is_a, - _txt, - ); - return o; -} -#+END_SRC - -******* +fancy+ - -##+name: prepare_objects_html -#+BEGIN_SRC d -string html_heading(M,O)( - M doc_matters, - const O obj, -) { - string o; - string _txt = munge_html(doc_matters, obj); - o = format(q"┃ - %s - ┃", - obj.metainfo.heading_lev_markup, - obj.metainfo.is_a, - _txt, - obj.metainfo.heading_lev_markup, - ); - return o; -} -#+END_SRC - -****** para - -#+name: html_objects -#+BEGIN_SRC d -string html_para(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - string _txt = munge_html(doc_matters, obj); - _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; - _txt = inline_markup(doc_matters, obj, _txt); - string o = format(q"┃

- %s -

┃", - obj.metainfo.is_a, - obj.attrib.indent_hang, - obj.attrib.indent_base, - _txt - ); - return o; -} -#+END_SRC - -****** quote - -#+name: html_objects -#+BEGIN_SRC d -string html_quote(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "quote"); - string _txt = munge_html(doc_matters, obj); - string o = format(q"┃

- %s -

┃", - obj.metainfo.is_a, - _txt - ); - return o; -} -#+END_SRC - -****** group - -#+name: html_objects -#+BEGIN_SRC d -string html_group(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "group"); - string _txt = munge_html(doc_matters, obj); - string o = format(q"┃

- %s -

┃", - obj.metainfo.is_a, - _txt - ); - return o; -} -#+END_SRC - -****** block - -#+name: html_objects -#+BEGIN_SRC d -string html_block(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "block"); - string _txt = munge_html(doc_matters, obj); - string o = format(q"┃ -

%s

┃", - obj.metainfo.is_a, - _txt.stripRight - ); - return o; -} -#+END_SRC - -****** verse - -#+name: html_objects -#+BEGIN_SRC d -string html_verse(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "verse"); - string _txt = munge_html(doc_matters, obj); - string o = format(q"┃

%s

┃", - obj.metainfo.is_a, - _txt - ); - return o; -} -#+END_SRC - -****** code - -#+name: html_objects -#+BEGIN_SRC d -string html_code(O)( - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "code"); - string _txt = html_special_characters_code(obj.text); - string o = format(q"┃

%s

┃", - obj.metainfo.is_a, - _txt - ); - return o; -} -#+END_SRC - -****** table - -#+name: html_objects -#+BEGIN_SRC d -string html_table(M,O)( - M doc_matters, - const O obj, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "table"); - auto _tablarize(O)( - const O obj, - string _txt, - ) { - string[] _table_rows = _txt.split(rgx.table_delimiter_row); - string[] _table_cols; - string _table; - string _tablenote; - foreach(row_idx, row; _table_rows) { - _table_cols = row.split(rgx.table_delimiter_col); - _table ~= ""; - foreach(col_idx, cell; _table_cols) { - if ((_table_cols.length == 1) - && (_table_rows.length <= row_idx+2)) { // check row_idx+2 (rather than == ++row_idx) - _tablenote ~= cell; - } else { - string _col_is = (row_idx == 0 && obj.table.heading) ? "th" : "td"; - string _align = ("style=\"text-align:" - ~ ((obj.table.column_aligns[col_idx] == "l") - ? "left\"" : "right\"")); - _table ~= "<" - ~ _col_is - ~ " width=\"" - ~ obj.table.column_widths[col_idx].to!string - ~ "%\" " - ~ _align - ~ ">"; - _table ~= cell; - _table ~= ""; - } - } - _table ~= ""; - } - auto t = tuple( - _table, - _tablenote, - ); - return t; - } - string _txt = munge_html(doc_matters, obj); - auto t = _tablarize(obj, _txt); - _txt = t[0]; - string _note = t[1]; - string o = format(q"┃

- - %s -
- %s -

┃", - obj.metainfo.is_a, - _txt, - _note - ); - return o; -} -#+END_SRC - -*** 2. hub (sqlite_format_and_load_objects) -**** sql related - -#+name: sqlite_load_object -#+BEGIN_SRC d -string sqlite_load_string(M,O)( - M doc_matters, - const O obj, -) { - string o; - return o; -} -#+END_SRC - -#+name: sqlite_load_object -#+BEGIN_SRC d -string postgresql_load_string(M,O)( - M doc_matters, - const O obj, -) { - string o; - return o; -} -#+END_SRC - -#+name: sqlite_load_object -#+BEGIN_SRC d -string sqlite_statement(O)( - const O obj, - string _txt, - string _html, -) { - void _sql_exe(O)( - string _sql, - ) { - writeln(_html); - writeln(_sql); - } - string _sql; - return _sql; -} -#+END_SRC - -**** heading - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] heading(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_heading(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** para - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] para(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_para(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** quote - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] quote(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_quote(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC -**** group - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] group(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_group(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** block - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] block(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_block(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** verse - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] verse(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_verse(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** code - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] code(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_code(obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -**** table - -#+name: hub_format_and_sqlite_load_objects -#+BEGIN_SRC d -string[string] table(M,O)( - M doc_matters, - const O obj, -) { - string[string] obj_txt = [ - "text": generic_munge_sanitize_text_for_search(obj.text), - "html": html_table(doc_matters, obj) - ]; - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - debug(sql_txt) { - writeln(obj_txt["text"]); - } - debug(sql_html) { - writeln(obj_txt["html"]); - } - } else { - // load sql - } - } - return obj_txt; -} -#+END_SRC - -** 4. ↻ loop, identify, load - loop template - -#+name: sqlite_objects_loop -#+BEGIN_SRC d -auto format_and_sqlite_load = SQLiteFormatAndLoadObject!()(doc_matters); -string[string] obj_txt; -string doc_text; -string[] _insert_doc_objects; -foreach (part; doc_matters.has.keys_seq.sql) { - foreach (obj; doc_abstraction[part]) { - switch (obj.metainfo.is_of_part) { - case "frontmatter": assert(part == "head", part); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - obj_txt = format_and_sqlite_load.heading(doc_matters, obj); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "body": // assert(part == "body", part); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - debug (asserts) { - if (part != "body") { - writeln(__LINE__, ": ", obj.text); - } - } - obj_txt = format_and_sqlite_load.heading(doc_matters, obj); - break; - case "para": - obj_txt = format_and_sqlite_load.para(doc_matters, obj); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - obj_txt = format_and_sqlite_load.quote(doc_matters, obj); - break; - case "group": - obj_txt = format_and_sqlite_load.group(doc_matters, obj); - break; - case "block": - obj_txt = format_and_sqlite_load.block(doc_matters, obj); - break; - case "poem": // double check on keeping both poem & verse - break; - case "verse": - obj_txt = format_and_sqlite_load.verse(doc_matters, obj); - break; - case "code": - obj_txt = format_and_sqlite_load.code(doc_matters, obj); - break; - case "table": - obj_txt = format_and_sqlite_load.table(doc_matters, obj); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "backmatter": - assert(part == "glossary" || "bibliography" || "bookindex" || "blurb" || "tail", part); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - obj_txt = format_and_sqlite_load.heading(doc_matters, obj); - break; - case "glossary": assert(part == "glossary", part); - obj_txt = format_and_sqlite_load.para(doc_matters, obj); - break; - case "bibliography": assert(part == "bibliography", part); - obj_txt = format_and_sqlite_load.para(doc_matters, obj); - break; - case "bookindex": assert(part == "bookindex", part); - obj_txt = format_and_sqlite_load.para(doc_matters, obj); - break; - case "blurb": assert(part == "blurb", part); - obj_txt = format_and_sqlite_load.para(doc_matters, obj); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); // check where empty value could come from - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check where empty value could come from - } - } - break; - } - if (obj.metainfo.is_a == "heading") { - if ((doc_matters.opt.action.very_verbose)) { - writeln( - "markup: ", obj.metainfo.heading_lev_markup, - "> ", obj.metainfo.dom_structure_markedup_tags_status, - "; collapsed: ", obj.metainfo.heading_lev_collapsed, - "> ", obj.metainfo.dom_structure_collapsed_tags_status, - "; ocn: ", obj.metainfo.ocn, - " node: ", obj.metainfo.node, - "; parent: ", obj.metainfo.parent_lev_markup, - "; ocn: ", obj.metainfo.parent_ocn, - "; ", - ); - } - } - if (!(obj.metainfo.is_a == "comment")) { - _insert_doc_objects ~= insertDocObjectsRow(obj); - } - } // loop closes -} -return _insert_doc_objects.join.to!(char[]).toUTF8; -#+END_SRC - -** 5. SQL statements :statement: -*** drop index and tables -**** DROP INDEX IF EXISTS - -#+name: sqlite_statement_drop_existing_index -#+BEGIN_SRC sql -DROP INDEX IF EXISTS idx_ocn; -DROP INDEX IF EXISTS idx_uid; -DROP INDEX IF EXISTS idx_digest_clean; -DROP INDEX IF EXISTS idx_digest_all; -DROP INDEX IF EXISTS idx_clean; -DROP INDEX IF EXISTS idx_title; -DROP INDEX IF EXISTS idx_creator_author; -DROP INDEX IF EXISTS src_filename; -DROP INDEX IF EXISTS idx_language_document_char; -DROP INDEX IF EXISTS idx_classify_topic_register; -#+END_SRC - -**** DROP TABLE IF EXISTS - -#+name: sqlite_statement_drop_existing_tables -#+BEGIN_SRC sql -DROP TABLE IF EXISTS metadata_and_text; -DROP TABLE IF EXISTS topic_register; -DROP TABLE IF EXISTS doc_objects; -DROP TABLE IF EXISTS urls; -#+END_SRC - -*** create tables and index -**** CREATE TABLE metadata_and_text - -#+name: sqlite_statement_create_table_metadata_and_src_txt -#+BEGIN_SRC sql -CREATE TABLE metadata_and_text ( - uid VARCHAR(256) UNIQUE, -- filename, language char, pod/txt (decide on delimiter [,;:/]) - src_composite_id_per_txt VARCHAR(256) NOT NULL, -- UNIQUE, z pod name if any + src filename + language code - src_composite_id_per_pod VARCHAR(256) NOT NULL, -- z pod name if any + src filename - title VARCHAR(800) NOT NULL, - title_main VARCHAR(400) NOT NULL, - title_sub VARCHAR(400) NULL, - title_short VARCHAR(400) NULL, - title_edition VARCHAR(10) NULL, - title_language VARCHAR(100) NULL, - title_language_char VARCHAR(6) NULL, - creator_author VARCHAR(600) NOT NULL, - creator_author_email VARCHAR(100) NULL, - creator_author_hon VARCHAR(100) NULL, - creator_author_nationality VARCHAR(100) NULL, - creator_editor VARCHAR(600) NULL, - creator_contributor VARCHAR(600) NULL, - creator_illustrator VARCHAR(600) NULL, - creator_photographer VARCHAR(600) NULL, - creator_translator VARCHAR(600) NULL, - creator_prepared_by VARCHAR(600) NULL, - creator_digitized_by VARCHAR(600) NULL, - creator_audio VARCHAR(600) NULL, - creator_video VARCHAR(600) NULL, - language_document VARCHAR(100) NULL, - language_document_char VARCHAR(6) NOT NULL, - language_original VARCHAR(100) NULL, - language_original_char VARCHAR(6) NULL, - date_added_to_site VARCHAR(10) NULL, - date_available VARCHAR(10) NULL, - date_created VARCHAR(10) NULL, - date_issued VARCHAR(10) NULL, - date_modified VARCHAR(10) NULL, - date_published VARCHAR(10) NULL, - date_valid VARCHAR(10) NULL, - date_translated VARCHAR(10) NULL, - date_original_publication VARCHAR(10) NULL, - date_generated VARCHAR(10) NULL, - original_title VARCHAR(800) NULL, - original_publisher VARCHAR(600) NULL, - original_language VARCHAR(100) NULL, - original_language_char VARCHAR(6) NULL, - original_source VARCHAR(600) NULL, - original_institution VARCHAR(600) NULL, - original_nationality VARCHAR(100) NULL, - rights_copyright VARCHAR(2500) NULL, - rights_copyright_audio VARCHAR(2500) NULL, - rights_copyright_cover VARCHAR(2500) NULL, - rights_copyright_illustrations VARCHAR(2500) NULL, - rights_copyright_photographs VARCHAR(2500) NULL, - rights_copyright_text VARCHAR(2500) NULL, - rights_copyright_translation VARCHAR(2500) NULL, - rights_copyright_video VARCHAR(2500) NULL, - rights_license VARCHAR(2500) NULL, - identifier_oclc VARCHAR(30) NULL, - identifier_isbn VARCHAR(16) NULL, - classify_topic_register VARCHAR(2500) NULL, - classify_subject VARCHAR(600) NULL, - classify_loc VARCHAR(30) NULL, - classify_dewey VARCHAR(30) NULL, - classify_keywords VARCHAR(600) NULL, - notes_abstract TEXT NULL, - notes_description TEXT NULL, - notes_comment TEXT NULL, - notes_coverage VARCHAR(200) NULL, - notes_relation VARCHAR(200) NULL, - notes_history VARCHAR(600) NULL, - notes_type VARCHAR(600) NULL, - notes_format VARCHAR(600) NULL, - notes_prefix TEXT NULL, - notes_prefix_a TEXT NULL, - notes_prefix_b TEXT NULL, - notes_suffix TEXT NULL, - publisher VARCHAR(600) NULL, - src_filename VARCHAR(256) NOT NULL, - src_fingerprint VARCHAR(256) NULL, - src_filesize VARCHAR(10) NULL, - src_wordcount VARCHAR(10) NULL, - pod_name VARCHAR(256) NULL, -- zipped pod, work to be done here - pod_fingerprint VARCHAR(256) NULL, -- zipped pod, work to be done here - pod_size VARCHAR(10) NULL, -- zipped pod, work to be done here - site_url_doc_root VARCHAR(256) NULL, -- url path to doc root - site_url_html_toc VARCHAR(256) NULL, - site_url_html_scroll VARCHAR(256) NULL, - site_url_epub VARCHAR(256) NULL, - links TEXT NULL -); -#+END_SRC - -**** CREATE TABLE topic_register - -#+name: sqlite_statement_create_table_topic_register -#+BEGIN_SRC sql -CREATE TABLE topic_register ( - -- tid BIGINT PRIMARY KEY, - uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, - -- src_composite_id_per_txt VARCHAR(256) NOT NULL, - UNIQUE, - z pod name if any + src filename + language code - -- src_composite_id_per_pod VARCHAR(256) NOT NULL, - z pod name if any + src filename - topic_register_lv0 VARCHAR(250) NOT NULL, - topic_register_lv1 VARCHAR(250) NULL, - topic_register_lv2 VARCHAR(250) NULL, - topic_register_lv3 VARCHAR(250) NULL, - topic_register_lv4 VARCHAR(250) NULL, - site_url_doc_root VARCHAR(256) NULL, -- url path to doc root - site_url_html_toc VARCHAR(256) NULL, - site_url_html_scroll VARCHAR(256) NULL -); -#+END_SRC - -**** CREATE TABLE site_urls ? - -#+name: sqlite_statement_create_table_site_urls -#+BEGIN_SRC sql -CREATE TABLE site_urls ( - -- tid BIGINT PRIMARY KEY, - uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, - src_composite_id_per_txt VARCHAR(256) NOT NULL, -- UNIQUE, - z pod name if any + src filename + language code - src_composite_id_per_pod VARCHAR(256) NOT NULL, -- z pod name if any + src filename - site_url_doc_root VARCHAR(256) NULL, -- url path to doc root - site_url_html_toc VARCHAR(256) NULL, - site_url_html_scroll VARCHAR(256) NULL -); -#+END_SRC - -**** CREATE TABLE doc_objects - -#+name: sqlite_statement_create_table_objects -#+BEGIN_SRC sql -CREATE TABLE doc_objects ( - lid BIGINT PRIMARY KEY, - uid_metadata_and_text VARCHAR(256) REFERENCES metadata_and_text(uid) ON DELETE CASCADE, - ocn SMALLINT, - obj_id VARCHAR(6) NULL, - clean TEXT NULL, - body TEXT NULL, - seg VARCHAR(256) NULL, - lev_an VARCHAR(1), - is_of_type VARCHAR(16), - is_a VARCHAR(16), - lev SMALLINT NULL, - node VARCHAR(16) NULL, - parent VARCHAR(16) NULL, - last_decendant VARCHAR(16) NULL, -- headings only - digest_clean CHAR(256), - digest_all CHAR(256), - html_seg_url CHAR(256), - types CHAR(1) NULL -); -#+END_SRC - -**** CREATE INDEX - -#+name: sqlite_statement_create_index -#+BEGIN_SRC sql -CREATE INDEX idx_ocn ON doc_objects(ocn); -CREATE INDEX idx_digest_clean ON doc_objects(digest_clean); -CREATE INDEX idx_digest_all ON doc_objects(digest_all); -CREATE INDEX idx_clean ON doc_objects(clean); -CREATE INDEX idx_title ON metadata_and_text(title); -CREATE INDEX idx_author ON metadata_and_text(creator_author); -CREATE INDEX idx_uid ON metadata_and_text(uid); -CREATE INDEX idx_filename ON metadata_and_text(src_filename); -CREATE INDEX idx_language ON metadata_and_text(language_document_char); -CREATE INDEX idx_topics ON metadata_and_text(classify_topic_register); -#+END_SRC - -*** TODO local site link & info - -*** delete rows (delete document) -**** DELETE uid rows doc matters & metadata -***** sql statement: dlang format - -#+name: sqlite_formatted_delete -#+BEGIN_SRC d -string _uid = doc_matters.src.doc_uid; -string _delete_uid = format(q"┃ -#+END_SRC - -***** DELETE FROM ... WHERE - -#+name: sqlite_formatted_delete -#+BEGIN_SRC sql -DELETE FROM metadata_and_text -WHERE uid = '%s'; -DELETE FROM doc_objects -WHERE uid_metadata_and_text = '%s'; -#+END_SRC - -***** VALUES - -#+name: sqlite_formatted_delete -#+BEGIN_SRC d -┃", - _uid, - _uid, -); -#+END_SRC - -*** inserts -**** INSERT doc matters & metadata -***** sql statement: dlang format - -#+name: sqlite_formatted_insertions_doc_matters_metadata -#+BEGIN_SRC d -string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); -string _insert_metadata = format(q"┃ -#+END_SRC - -***** INSERT INTO - -#+name: sqlite_formatted_insertions_doc_matters_metadata -#+BEGIN_SRC sql - INSERT INTO metadata_and_text ( - uid, - src_filename, - src_composite_id_per_txt, - src_composite_id_per_pod, - title, - title_main, - title_sub, - title_short, - title_edition, - title_language, - creator_author, - creator_author_email, - creator_illustrator, - creator_translator, - language_document, - language_document_char, - date_added_to_site, - date_available, - date_created, - date_issued, - date_modified, - date_published, - date_valid, - rights_copyright, - rights_copyright_audio, - rights_copyright_cover, - rights_copyright_illustrations, - rights_copyright_photographs, - rights_copyright_text, - rights_copyright_translation, - rights_copyright_video, - rights_license, - identifier_oclc, - identifier_isbn, - classify_dewey, - classify_keywords, - classify_loc, - classify_subject, - classify_topic_register, - original_title, - original_publisher, - original_language, - original_language_char, - original_source, - notes_abstract, - notes_description, - publisher, - site_url_doc_root - ) -#+END_SRC - -***** VALUES - -#+name: sqlite_formatted_insertions_doc_matters_metadata -#+BEGIN_SRC sql - VALUES ( - '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' - ); -#+END_SRC - -***** dlang values for formatting - -#+name: sqlite_formatted_insertions_doc_matters_metadata -#+BEGIN_SRC d -┃", - _uid, - SQLinsertDelimiter!()(doc_matters.src.filename), - SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_doc), - SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_pod), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_full), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_main), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_subtitle), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_short), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_edition), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_language), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_email), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_illustrator), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_translator), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.language_document), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.language_document_char), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_added_to_site), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_available), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_created), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_issued), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_modified), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_published), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.date_valid), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_audio), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_cover), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_illustrations), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_photographs), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_text), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_translation), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_copyright_video), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.rights_license), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.identifier_oclc), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.identifier_isbn), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_dewey), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_keywords), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_loc), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_subject), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.classify_topic_register), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.notes_abstract), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.notes_description), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_title), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_publisher), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language_char), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_source), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.publisher), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root) -); -#+END_SRC - -**** INSERT topic register - -writeln(doc_matters.conf_make_meta.meta.classify_topic_register_arr); - -***** { if topic register then loop topic register array - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC d -if (doc_matters.conf_make_meta.meta.classify_topic_register_arr.length > 0) { - - string _insert_topics; - foreach (topic; doc_matters.conf_make_meta.meta.classify_topic_register_arr) { - string[] subject_tree = topic.split(mkup.sep); -#+END_SRC - -***** sql statement: dlang format - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC d -_insert_topics ~= format(q"┃ -#+END_SRC - -***** INSERT INTO - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC sql - INSERT INTO topic_register ( - uid_metadata_and_text, - topic_register_lv0, - topic_register_lv1, - topic_register_lv2, - topic_register_lv3, - topic_register_lv4 - ) -#+END_SRC - -***** VALUES - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC sql - VALUES ( - '%s', '%s', '%s', '%s', '%s', '%s' - ); -#+END_SRC - -***** dlang values for formatting - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC d -┃", - _uid, - (subject_tree.length > 0) ? subject_tree[0] : "", - (subject_tree.length > 1) ? subject_tree[1] : "", - (subject_tree.length > 2) ? subject_tree[2] : "", - (subject_tree.length > 3) ? subject_tree[3] : "", - (subject_tree.length > 4) ? subject_tree[4] : "" -); -#+END_SRC - -***** } close topic register & loop topic register array - -#+name: sqlite_formatted_insertions_topic_register -#+BEGIN_SRC d - } -} -#+END_SRC - -**** INSERT doc objects - -lid unique, increment by 1 per object, not ocn - -metadata tid document number unique -either: -- increment by adding 1 for each document, -- make hash of document filename or url and use? - -***** sql statement: dlang format - -#+name: sqlite_formatted_insertions_doc_objects -#+BEGIN_SRC d -string _insert_doc_objects_row = format(q"┃ -#+END_SRC - -***** INSERT INTO - -#+name: sqlite_formatted_insertions_doc_objects -#+BEGIN_SRC sql - INSERT INTO doc_objects ( - uid_metadata_and_text, - ocn, - obj_id, - clean, - body, - lev, - is_of_type, - is_a, - html_seg_url - ) -#+END_SRC - -***** VALUES - -#+name: sqlite_formatted_insertions_doc_objects -#+BEGIN_SRC sql - VALUES ( - '%s', %s, '%s', '%s', '%s', %s, '%s', '%s', '%s' - ); -#+END_SRC - -***** dlang values for formatting - -#+name: sqlite_formatted_insertions_doc_objects -#+BEGIN_SRC d -┃", - _uid, - obj.metainfo.ocn, - obj.metainfo.identifier, - SQLinsertDelimiter!()(obj_txt["text"]), - SQLinsertDelimiter!()(obj_txt["html"]), - obj.metainfo.heading_lev_markup, - obj.metainfo.is_of_type, - obj.metainfo.is_a, - url_html.fn_seg_obj_num(doc_matters.src.filename, obj.tags.html_segment_anchor_tag_is, obj.metainfo.identifier), -); -#+END_SRC - -* __END__ diff --git a/org/output_src_pod.org b/org/output_src_pod.org deleted file mode 100644 index df6be5f..0000000 --- a/org/output_src_pod.org +++ /dev/null @@ -1,443 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) output pod -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:source:pod: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* pod -** _module template_ :module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/source_pod.d" -module doc_reform.output.source_pod; -template DocReformPod() { - <> - void DocReformPod(T)(T doc_matters) { - <> - <> - try { - <> - <> - <> - } catch (ErrnoException ex) { - // Handle error - } - } -} -#+END_SRC - -** init -*** imports - -#+name: output_imports -#+BEGIN_SRC d -import doc_reform.output; -import - std.digest.sha, - std.file, - std.outbuffer, - std.zip, - std.conv : to; -import - doc_reform.output.create_zip_file, - doc_reform.output.xmls; -#+END_SRC - -*** init - -#+name: source_pod_init -#+BEGIN_SRC d -debug(asserts) { - // static assert(is(typeof(doc_matters) == tuple)); -} -mixin DocReformOutputRgxInit; -string pwd = doc_matters.env.pwd; -auto src_path_info = doc_matters.src_path_info; -auto pth_dr_doc_src = doc_matters.src_path_info; -auto pths_pod = DocReformPathsPods!()(doc_matters); -mixin DocReformLanguageCodes; -auto lang = Lang(); -static auto rgx = Rgx(); -assert (doc_matters.src.filename.match(rgx.src_fn)); -#+END_SRC - -*** pod zip archive - -#+name: source_pod_archive -#+BEGIN_SRC d -auto pod_archive(Z)( - string _source_type, - string _data_in, - string _pth_out, - Z zip -) { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = _pth_out; - auto zip_data = new OutBuffer(); - switch (_source_type) { - case "file_path_bin": - zip_data.write(cast(char[]) ((_data_in).read)); - goto default; - case "file_path_text": - zip_data.write((_data_in).readText); - goto default; - case "string": - zip_data.write(_data_in); - goto default; - default: - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - } - return zip; -} -#+END_SRC - -** mkdir :mkdir: - -#+name: source_pod_mkdirs -#+BEGIN_SRC d -/+ create directory structure +/ -if (!exists(pths_pod.pod_dir_())) { - // used both by pod zipped (& pod filesystem (unzipped) which makes its own recursive dirs) - pths_pod.pod_dir_().mkdirRecurse; -} -if (doc_matters.opt.action.source) { - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pths_pod.fn_pod_filelist(doc_matters.src.filename).filesystem_open_zpod); - } - if (!exists(pths_pod.text_root(doc_matters.src.filename).filesystem_open_zpod)) { - pths_pod.text_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; - } - if (!exists(pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod)) { - pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; - } - if (!exists(pths_pod.media_root(doc_matters.src.filename).filesystem_open_zpod)) { - pths_pod.media_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; - } - if (!exists(pths_pod.css(doc_matters.src.filename).filesystem_open_zpod)) { - pths_pod.css(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; - } - if (!exists(pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod)) { - pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod.mkdirRecurse; - } - if (!exists(pths_pod.doc_lng(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod)) { - pths_pod.doc_lng(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod.mkdirRecurse; - } -} -#+END_SRC - -** copy :copy: - -#+name: source_pod_copy -#+BEGIN_SRC d -debug(pod) { - writeln(__LINE__, ": ", - doc_matters.src.filename, " -> ", - pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod - ); -} -auto zip = new ZipArchive(); -auto fn_pod = pths_pod.pod_filename(doc_matters.src.filename).zpod; -{ /+ bundle images +/ - foreach (image; doc_matters.srcs.image_list) { - debug(podimages) { - writeln( - pth_dr_doc_src.image_root.to!string, "/", image, " -> ", - pths_pod.image_root(doc_matters.src.filename).zpod, "/", image - ); - } - auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_src_out_pod_zip_base - = pths_pod.image_root(doc_matters.src.filename).zpod.to!string - ~ "/" ~ image; - auto fn_src_out_filesystem - = pths_pod.image_root(doc_matters.src.filename).filesystem_open_zpod.to!string - ~ "/" ~ image; - if (exists(fn_src_in)) { - debug(io) { - writeln("(io debug) src out found: ", fn_src_in); - } - if (doc_matters.opt.action.source) { - fn_src_in.copy(fn_src_out_filesystem); - } - if (doc_matters.opt.action.pod) { - zip = pod_archive("file_path_bin", fn_src_in, fn_src_out_pod_zip_base, zip); - } - } else { - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln("WARNING (io) src out NOT found (image): ", fn_src_in); - } - } - } -} { /+ bundle dr_document_make +/ - auto fn_src_in = ((doc_matters.src.is_pod) - ? doc_matters.src.conf_dir_path - : pth_dr_doc_src.conf_root).to!string - ~ "/" ~ "dr_document_make"; - auto fn_src_out_pod_zip_base - = pths_pod.conf_root(doc_matters.src.filename).zpod.to!string ~ "/" ~ "dr_document_make"; - auto fn_src_out_filesystem - = pths_pod.conf_root(doc_matters.src.filename).filesystem_open_zpod.to!string - ~ "/" ~ "dr_document_make"; - if (exists(fn_src_in)) { - debug(io) { - writeln("(io debug) src out found: ", fn_src_in); - } - if (doc_matters.opt.action.source) { - fn_src_in.copy(fn_src_out_filesystem); - } - if (doc_matters.opt.action.pod) { - zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); - } - } else { - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln("WARNING (io) src out NOT found (document make): ", fn_src_in); - } - } -} { /+ pod manifest +/ - auto fn_src_in = doc_matters.src.file_with_absolute_path.to!string; - auto fn_src_out_pod_zip_base - = pths_pod.pod_manifest(doc_matters.src.filename).zpod.to!string; - auto fn_src_out_filesystem - = pths_pod.pod_manifest(doc_matters.src.filename).filesystem_open_zpod.to!string; // needed without root path - auto fn_src_out_inside_pod - = pths_pod.pod_manifest(doc_matters.src.filename).zpod.to!string; // needed without root path - string[] filelist_src_out_pod_arr; - string[] filelist_src_zpod_arr; - if (exists(fn_src_in)) { - debug(io) { - writeln("(io debug) src in found: ", fn_src_in); - } - filelist_src_out_pod_arr ~= fn_src_out_pod_zip_base; - filelist_src_zpod_arr ~= fn_src_out_inside_pod; - { - import dyaml; - auto pod_filelist_yaml_string - = File(pths_pod.fn_pod_filelist(doc_matters.src.filename).filesystem_open_zpod, "w"); - Node _pmy; - string _pm = "doc:\n filename: " ~ doc_matters.src.filename ~ "\n language: " ~ doc_matters.pod.manifest_list_of_languages.to!string ~ "\n"; - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - _pmy = Loader.fromString(_pm).load(); - writeln("pod filename: ", _pmy["doc"]["filename"].get!string); - writeln("pod languages: ", doc_matters.pod.manifest_list_of_languages.to!string); - writeln("pod languages: ", doc_matters.src.language); - // foreach(string _l; _pmy["doc"]["language"]) { - // writeln("language: ", _l); - // } - } - if (doc_matters.opt.action.source) { - pod_filelist_yaml_string.writeln(_pm); - } - if (doc_matters.opt.action.pod) { - zip = pod_archive("string", _pm, fn_src_out_pod_zip_base, zip); - } - } - } -} { /+ bundle primary file (.ssm/.sst) +/ - auto fn_src_in = doc_matters.src.file_with_absolute_path.to!string; - auto fn_src_out_pod_zip_base - = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).zpod.to!string; - auto fn_src_out_filesystem - = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).filesystem_open_zpod.to!string; // needed without root path: - auto fn_src_out_inside_pod - = pths_pod.fn_doc(doc_matters.src.filename, doc_matters.src.language).zpod.to!string; // needed without root path: - string[] filelist_src_out_pod_arr; - string[] filelist_src_zpod_arr; - if (exists(fn_src_in)) { - debug(io) { - writeln("(io debug) src in found: ", fn_src_in); - } - filelist_src_out_pod_arr ~= fn_src_out_pod_zip_base; - filelist_src_zpod_arr ~= fn_src_out_inside_pod; - string _pod_to_markup_file = doc_matters.src.pod_name ~ "/" ~ "media/text/" ~ doc_matters.src.language ~ "/" ~ doc_matters.src.filename; - if (doc_matters.opt.action.source) { - fn_src_in.copy(fn_src_out_filesystem); - } - if (doc_matters.opt.action.pod) { - auto _rgx = regex(r"(?P\S+?)(?P[a-z_-]+)/(?Pmedia/text/)(?P\S+?)/(?P\S+?\.ss[mt])"); - if (auto _x = fn_src_in.match(_rgx)){ - if (doc_matters.src.lng == doc_matters.pod.manifest_list_of_languages[$-1]) { - string _path_to_pod = _x.captures["path_to_pod"]; - string _podname = _x.captures["podname"]; - string _root_to_lang = _x.captures["from_root"]; - string _language = _x.captures["language"]; - string _filename = _x.captures["filename"]; - foreach (_lang; doc_matters.pod.manifest_list_of_languages) { - string _pth_mkup_src_in = _path_to_pod ~ _podname ~ "/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; - string _pth_mkup_src_out = "pod/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; - zip = pod_archive("file_path_text", _pth_mkup_src_in, _pth_mkup_src_out, zip); - } - } - } else { - zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); - } - } - } else { - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln("WARNING (io) src in NOT found (markup source): ", fn_src_in); - } - } -} { /+ bundle insert files (.ssi) +/ - if (doc_matters.srcs.file_insert_list.length > 0) { - auto _rgx = regex(r"(?P\S+?)(?P[a-z_-]+)/(?Pmedia/text/)(?P\S+?)/(?P\S+?\.ss[i])"); - foreach (insert_file; doc_matters.srcs.file_insert_list) { - debug(pod) { - writeln( - insert_file, " -> ", - pths_pod.fn_doc_insert( - doc_matters.src.filename, - insert_file, - doc_matters.src.language, - ).zpod - ); - } - if (auto _x = insert_file.match(_rgx)){ - if (doc_matters.src.lng == doc_matters.pod.manifest_list_of_languages[$-1]) { - string _path_to_pod = _x.captures["path_to_pod"]; - string _podname = _x.captures["podname"]; - string _root_to_lang = _x.captures["from_root"]; - string _language = _x.captures["language"]; - string _filename = _x.captures["filename"]; - foreach (_lang; doc_matters.pod.manifest_list_of_languages) { - string _pth_mkup_src_in = _path_to_pod ~ _podname ~ "/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; - string _pth_mkup_src_out = "pod/" ~ _root_to_lang ~ _lang ~ "/" ~ _filename; - if (exists(_pth_mkup_src_in)) { - if (doc_matters.opt.action.source) { - auto fn_src_out_filesystem // you need to change language sources - = pths_pod.fn_doc_insert( - doc_matters.src.filename, // doc_matters.src.filename - _pth_mkup_src_in, // insert_file - _lang, - ).filesystem_open_zpod.to!string; - _pth_mkup_src_in.copy(fn_src_out_filesystem); // check why here, thought dealt with elsewhere - } - if (doc_matters.opt.action.pod) { - zip = pod_archive("file_path_text", _pth_mkup_src_in, _pth_mkup_src_out, zip); - } - } else { - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln("WARNING (io) src out NOT found (insert file): ", _pth_mkup_src_in); - } - } - } - } - } else { - auto fn_src_in = insert_file; - auto fn_src_out_pod_zip_base - = pths_pod.fn_doc_insert( - doc_matters.src.filename, - insert_file, - doc_matters.src.language, - ).zpod.to!string; - auto fn_src_out_filesystem - = pths_pod.fn_doc_insert( - doc_matters.src.filename, - insert_file, - doc_matters.src.language, - ).filesystem_open_zpod.to!string; - if (exists(fn_src_in)) { - debug(io) { - writeln("(io debug) src out found: ", fn_src_in); - } - if (doc_matters.opt.action.source) { - fn_src_in.copy(fn_src_out_filesystem); - } - if (doc_matters.opt.action.pod) { - zip = pod_archive("file_path_text", fn_src_in, fn_src_out_pod_zip_base, zip); - } - } else { - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln("WARNING (io) src out NOT found (insert file): ", fn_src_in); - } - } - } - } - } -} { - auto fn_src_in = doc_matters.src.filename; - if (doc_matters.opt.action.pod) { - if (exists(doc_matters.src.file_with_absolute_path)) { - createZipFile!()(fn_pod, zip.build()); - } else { - writeln("WARNING check missing source file(s): ", doc_matters.opt.action.pod); - } - if (!(exists(fn_pod))) { - writeln("WARNING failed to create pod zip archive: ", fn_pod); - } - } -} -#+END_SRC - -** sha256 of pod.zip, zip debug, read zip archive - -#+name: source_pod_copy -#+BEGIN_SRC d -if (exists(fn_pod)) { - try { - if (!(doc_matters.opt.action.quiet) - && doc_matters.opt.action.pod) { - auto data = (cast(byte[]) (fn_pod).read); - if (doc_matters.opt.action.verbose) { - writeln(" ", doc_matters.src.filename, " > "); - } - if (doc_matters.opt.action.pod) { - writefln(" %s\n %s %-(%02x%)", fn_pod, "sha256", data.sha256Of); - } - } - debug(pod) { - try { - auto zipped = new ZipArchive((fn_pod).read); - foreach (filename, member; zipped.directory) { - auto data = zipped.expand(member); - writeln("> ", filename, " length ", data.length); - } - } catch (ZipException ex) { - // Handle errors - } - if (doc_matters.src.filename == "dr_doc/media/text/en/the_wealth_of_networks.yochai_benkler.sst") { - assert( - ((data).sha256Of).toHexString - == "626F83A31ED82F42CF528E922C1643498A137ABA3F2E5AFF8A379EA79EA22A1E", - "\npod: sha256 value for " - ~ doc_matters.src.filename - ~ " has changed, is now: " - ~ ((data).sha256Of).toHexString - ); - } - if (doc_matters.src.filename == "dr_doc/media/text/en/sisu_markup_stress_test.sst") { - assert( - ((data).sha256Of).toHexString - == "AAE0C87AB3F6D5F7385AEEA6EE661F56D40475CFE87AD930C78C9FE07FFB0D91", - "\npod: sha256 value for " - ~ doc_matters.src.filename - ~ " has changed, is now: " - ~ ((data).sha256Of).toHexString - ); - } - } - } catch (ErrnoException ex) { - // Handle errors - } -} -#+END_SRC - -* __END__ diff --git a/org/output_xmls.org b/org/output_xmls.org deleted file mode 100644 index ea1af4a..0000000 --- a/org/output_xmls.org +++ /dev/null @@ -1,3095 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) output xmls -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:xml: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* xml offspring (xhtml html epub) -** format xhtml objects :format: -*** _module template_ :module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/xmls.d" -module doc_reform.output.xmls; -template outputXHTMLs() { - <> - mixin DocReformOutputRgxInit; - struct outputXHTMLs { - static auto rgx = Rgx(); - <> - <> - } -} -#+END_SRC - -*** output imports - -#+name: output_imports -#+BEGIN_SRC d -import doc_reform.output; -import - std.digest.sha, - std.file, - std.outbuffer, - std.uri, - std.zip, - std.conv : to; -import - doc_reform.output.create_zip_file, - doc_reform.output.xmls, - doc_reform.output.xmls_css; -#+END_SRC - -*** misc -**** div delimiter - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string div_delimit( - string part, - return ref string previous_part -){ - string delimit = ""; - string delimit_ = ""; - if (part != previous_part) { - switch (part) { - case "head": - delimit_ ~= "\n
\n" ; - break; - case "toc": - delimit_ ~= "\n
\n" ; - break; - case "bookindex": - delimit_ ~= "\n
\n" ; - break; - default: - delimit_ ~= "\n
\n" ; - break; - } - if (previous_part.length > 0) { - delimit ~= "\n
"; - } - previous_part = part; - delimit ~= delimit_; - } - // you also need to close the last div, introduce a footer? - return delimit; -} -#+END_SRC - -**** special characters text - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string special_characters_text(string _txt){ - _txt = _txt - .replaceAll(rgx.xhtml_ampersand, "&") - .replaceAll(rgx.xhtml_quotation, """) - .replaceAll(rgx.xhtml_less_than, "<") - .replaceAll(rgx.xhtml_greater_than, ">") - .replaceAll(rgx.nbsp_char, " "); - return _txt; -} -#+END_SRC - -**** special characters - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string special_characters(O)( - const O obj, -){ - string _txt = special_characters_text(obj.text); - if (!(obj.metainfo.is_a == "code")) { - _txt = (_txt) - .replaceAll(rgx.xhtml_line_break, "
"); - } - return _txt; -} -#+END_SRC - -**** font_face - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string font_face(string _txt){ - _txt = _txt - .replaceAll(rgx.inline_emphasis, ("$1")) - .replaceAll(rgx.inline_bold, ("$1")) - .replaceAll(rgx.inline_underscore, ("$1")) - .replaceAll(rgx.inline_italics, ("$1")) - .replaceAll(rgx.inline_superscript, ("$1")) - .replaceAll(rgx.inline_subscript, ("$1")) - .replaceAll(rgx.inline_strike, ("$1")) - .replaceAll(rgx.inline_insert, ("$1")) - .replaceAll(rgx.inline_mono, ("$1")) - .replaceAll(rgx.inline_cite, ("$1")); - return _txt; -} -#+END_SRC - -**** anchor tags - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string _xhtml_anchor_tags(O)(O obj) { - const(string[]) anchor_tags = obj.tags.anchor_tags; - string tags=""; - if (anchor_tags.length > 0) { - foreach (tag; anchor_tags) { - if (!(tag.empty)) { - tags ~= ""; - } - } - } - return tags; -} -#+END_SRC - -**** doc head & tails -***** metadata - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string header_metadata(M)( - M doc_matters, -) { - string _publisher="Publisher"; // TODO - string o; - o = format(q"┃ - - - - - - - - - - - - - - -┃", - doc_matters.conf_make_meta.meta.title_full, - doc_matters.conf_make_meta.meta.creator_author, - _publisher, - doc_matters.conf_make_meta.meta.date_published, - doc_matters.conf_make_meta.meta.date_created, - doc_matters.conf_make_meta.meta.date_issued, - doc_matters.conf_make_meta.meta.date_available, - doc_matters.conf_make_meta.meta.date_valid, - doc_matters.conf_make_meta.meta.date_modified, - doc_matters.src.language, - doc_matters.conf_make_meta.meta.rights_copyright, - doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.name_and_version, - doc_matters.generator_program.url_home, - ); - return o; -} -#+END_SRC - -***** site info button - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string site_info_button(M)( - M doc_matters, -) { - string _locations; - if (doc_matters.conf_make_meta.make.home_button_text.length > 0) { - _locations = (doc_matters.conf_make_meta.make.home_button_text) - .replaceAll( - rgx.inline_link, - ("

$1

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

spine

\n

sources / git

\n

www.sisudoc.org

"; - } - string o; - o = format(q"┃
- %s -
┃", - _locations, - ); - return o; -} -#+END_SRC - -***** search form - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string inline_search_form(M)( - M doc_matters, -) { - string _action="http://www.sisudoc.org/cgi-bin/search.cgi"; - string _db="DocReform.7a.manual"; - string o; - string _form; - if (doc_matters.opt.action.workon) { - _form = format(q"┃ - -
- - - - - -
- - -
- ┃", - _action, - _db, - ); - } else { - _form = format(q"┃%s┃", - "", - ); - } - o = format(q"┃
%s -
┃", - _form, - ); - return o; -} -#+END_SRC - -***** html head & head banner - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string html_head(M)( - M doc_matters, - string type, -) { -string _manifest = ""; -if (doc_matters.opt.action.workon) { - _manifest = format(q"┃ - - - [ document manifest ] - - - ┃", - ); -} - string o; - o = format(q"┃ - - - - - %s%s - - - %s - - - - - - - -
-
- %s -
- %s -
- %s%s┃", - doc_matters.conf_make_meta.meta.title_full, - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : ", " ~ doc_matters.conf_make_meta.meta.creator_author, - header_metadata(doc_matters), - ((type == "seg") ? "../../../" : "../../") ~ "image/rb7.ico", - ((type == "seg") - ? "../../../css/html_seg.css" - : "../../css/html_scroll.css"), - doc_matters.src.language, - site_info_button(doc_matters), - _manifest, - inline_search_form(doc_matters), - ((type == "seg") ? "" : "\n
"), - ); - return o; -} -#+END_SRC - -***** epub seg head - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string epub3_seg_head(M)( - M doc_matters, -) { - string html_base = format(q"┃ -┃", -); - string html_simple = format(q"┃ -┃", - doc_matters.src.language, - doc_matters.src.language, - ); - string html_strict = format(q"┃ -┃", - doc_matters.src.language, - doc_matters.src.language, - ); - string o; - o = format(q"┃%s - - - %s%s - - - - - - - - - - - - - - - - - - - -┃", - html_simple, - doc_matters.conf_make_meta.meta.title_full, - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : ", " ~ doc_matters.conf_make_meta.meta.creator_author, - doc_matters.conf_make_meta.meta.title_full, - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : ", " ~ doc_matters.conf_make_meta.meta.creator_author, - doc_matters.conf_make_meta.meta.date_published, - doc_matters.conf_make_meta.meta.date_created, - doc_matters.conf_make_meta.meta.date_issued, - doc_matters.conf_make_meta.meta.date_available, - doc_matters.conf_make_meta.meta.date_valid, - doc_matters.conf_make_meta.meta.date_modified, - doc_matters.src.language, - doc_matters.conf_make_meta.meta.rights_copyright, - doc_matters.generator_program.name_and_version, - doc_matters.generator_program.url_home, - doc_matters.src.language, - ); - return o; -} -#+END_SRC - -***** xhtml tail - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string tail() { - string o; - o = format(q"┃ - - - -┃"); - return o; -} -#+END_SRC - -*** inline markup -**** images - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string inline_images(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "seg", -) { - string _img_pth; - if (_xml_type == "epub") { - _img_pth = "image/"; - } else if (_xml_type == "scroll") { - _img_pth = "../../image/"; - } else if (_xml_type == "seg") { - _img_pth = "../../../image/"; - } - if (_txt.match(rgx.inline_image)) { - _txt = _txt - .replaceAll(rgx.inline_image, - ("$1 $6")) - .replaceAll( - rgx.inline_link_empty, - ("$1")); - } - return _txt; -} -#+END_SRC - -**** links -***** scroll, seg, epub - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string inline_links(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "seg", -) { - string seg_lvs; - if (obj.has.inline_links) { - if (obj.metainfo.is_a != "code") { - _txt = replaceAll!(m => - m[1] ~ "┤" - ~ (replaceAll!(n => - n["type"] ~ n["path"] ~ (n["file"].encodeComponent) - )((obj.stow.link[m["num"].to!ulong]).to!string, rgx.uri_identify_components)) - ~ "├" - )(_txt, rgx.inline_link_number_only); - } - if ((_txt.match(rgx.mark_internal_site_lnk)) - && (_xml_type == "scroll")) { // conditions reversed to avoid: gdc compiled program run segfault - _txt = _txt.replaceAll( - rgx.inline_seg_link, - "$1"); - } - if (_xml_type == "seg" || _xml_type == "epub") { - seg_lvs = (_xml_type == "epub") ? "seg_lv1_to_4" : "seg_lv4"; - foreach (m; _txt.match(rgx.inline_link_hash)) { - if (m.captures[3] in doc_matters.has.tag_associations) { - if ( - m.captures[3] - == doc_matters.has.tag_associations[(m.captures[3])][seg_lvs] - ) { - _txt = _txt.replaceFirst( - rgx.inline_link_hash, - "┥$1┝┤$3" ~ _suffix ~ "├" - ); - } else { - _txt = _txt.replaceFirst( - rgx.inline_link_hash, - "┥$1┝┤" - ~ doc_matters.has.tag_associations[(m.captures[3])][seg_lvs] - ~ _suffix ~ "#" ~ "$3" - ~ "├" - ); - } - } else { - if (!(doc_matters.opt.action.quiet)) { - writeln( - "WARNING on internal document links, anchor to link <<" - ~ m.captures[3] - ~ ">> not found in document, " - ~ "anchor: " ~ m.captures[3] - ~ " document: " ~ doc_matters.src.filename - ); - } - } - } - } - _txt = _txt - .replaceAll( - rgx.inline_link_fn_suffix, - ("$1" ~ _suffix)) - .replaceAll( - rgx.inline_link, - ("$1")) - .replaceAll( - rgx.mark_internal_site_lnk, - ""); - } - debug(markup_links) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.has.inline_links, - "): ", obj.metainfo.is_a, ": ", - obj.text - ); - } - } - debug(markup) { - if (_txt.match(rgx.inline_link)) { - writeln(__LINE__, - " (missed) markup link identified (", - obj.has.inline_links, - "): ", obj.metainfo.is_a, ": ", - obj.text - ); - } - } - return _txt; -} -#+END_SRC - -**** notes -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string inline_notes_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - if (obj.has.inline_notes_reg) { - _txt = font_face(_txt); - _txt = _txt.replaceAll( - rgx.inline_notes_al_regular_number_note, - (" $1 ") - ); - } - if (obj.has.inline_notes_star) { - _txt = font_face(_txt); - _txt = _txt.replaceAll( - rgx.inline_notes_al_special_char_note, - (" $1 ") - ); - } - debug(markup_endnotes) { - if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - debug(markup) { - if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - writeln(__LINE__, " (missed) markup endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - return _txt; -} -#+END_SRC - -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_notes_seg(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - string[] _endnotes; - if (obj.has.inline_notes_star) { - _txt = font_face(_txt); - /+ need markup for text, and separated footnote +/ - foreach(m; _txt.matchAll(rgx.inline_notes_al_special_char_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_al_special_char_note, - (" $1 ") - ); - } - if (obj.has.inline_notes_reg) { - _txt = font_face(_txt); - /+ need markup for text, and separated footnote +/ - foreach(m; _txt.matchAll(rgx.inline_notes_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_al_regular_number_note, - (" $1 ") - ); - } else if (_txt.match(rgx.inline_notes_al_regular_number_note)) { - debug(markup) { - writeln(__LINE__, " endnote: ", obj.metainfo.is_a, ": ", obj.text); - } - } - auto t = tuple( - _txt, - _endnotes, - ); - return t; -} -#+END_SRC - -**** inline markup -***** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string inline_markup_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", -) { - if (obj.metainfo.dummy_heading - && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) { - _txt = ""; - } else { - _txt = inline_images(_txt, obj, doc_matters, _suffix, "scroll"); - _txt = inline_links(_txt, obj, doc_matters, _suffix, "scroll"); - _txt = inline_notes_scroll(_txt, obj, doc_matters); - } - return _txt; -} -#+END_SRC - -***** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto inline_markup_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "seg", -) { - if (obj.metainfo.dummy_heading - && ((_xml_type == "epub" - && (obj.metainfo.is_a == "toc" || obj.metainfo.is_a == "heading")) - || obj.metainfo.is_a == "heading") - ) { - _txt = ""; - } else { - _txt = inline_images(_txt, obj, doc_matters, _suffix, _xml_type); // TODO - _txt = inline_links(_txt, obj, doc_matters, _suffix, _xml_type); // TODO - } - auto t = inline_notes_seg(_txt, obj, doc_matters); - return t; -} -#+END_SRC - -*** toc -**** subtoc - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string lev4_heading_subtoc(O,M)( - const O obj, - M doc_matters, -) { - char[] lev4_subtoc; - lev4_subtoc ~= "
\n"; - foreach (subtoc; obj.tags.lev4_subtoc) { - if (auto m = subtoc.match(rgx.inline_link_subtoc)) { - auto indent = (m.captures[1].to!int - 3).to!string; // css assumptions based on use of em for left margin & indent - auto text = m.captures[2].to!string; - text = font_face(text); - auto link = m.captures[3].to!string; - lev4_subtoc ~= subtoc.replaceFirst(rgx.inline_link_subtoc, - format(q"┃

- ۰ %s -

-┃", - indent, - indent, - link, - text, - )); - } - } - lev4_subtoc ~= "
\n"; - return lev4_subtoc.to!string; -} -#+END_SRC - -**** navigation pre next svg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto nav_pre_next_svg(O,M)( - const O obj, - M doc_matters, -) { - string prev, next, toc; - if (obj.tags.segment_anchor_tag_epub == "toc") { - toc = ""; - prev = ""; - } else { - toc = format(q"┃ - - ┃", - ); - } - if (obj.tags.segname_prev == "") { - prev = ""; - } else { - prev = format(q"┃ - - ┃", - obj.tags.segname_prev, - ); - } - if (obj.tags.segname_next == "") { - next = ""; - } else { - next = format(q"┃ - - ┃", - obj.tags.segname_next, - ); - } - string _toc_pre_next = format(q"┃
- -
-
-
┃", - toc, - prev, - next, - ); - string _pre_next = format(q"┃
- -
-
-
┃", - prev, - next, - ); - struct bar { - string toc_pre_next() { - return _toc_pre_next; - } - string pre_next() { - return _pre_next; - } - } - return bar(); -} -#+END_SRC - -*** heading -**** heading - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string heading(O,M)( - string _txt, - const O obj, - M doc_matters, - string _xml_type = "html", -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "heading"); - string tags = _xhtml_anchor_tags(obj); - string heading_lev_anchor_tag; - string _horizontal_rule = "
"; - if ((_xml_type != "html") - || (obj.metainfo.heading_lev_markup == 0 || obj.metainfo.heading_lev_markup > 4)) { - _horizontal_rule = ""; - } - _txt = font_face(_txt); - string o; - heading_lev_anchor_tag = (obj.tags.heading_lev_anchor_tag.empty) - ? "" - : ""; - if (_txt.empty) { - o = format(q"┃%s - ┃", - _horizontal_rule, - ); - } else if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃%s -
- - %s%s - %s - -
┃", - _horizontal_rule, - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.heading_lev_markup, - obj.metainfo.is_a, - obj.metainfo.identifier, - obj.metainfo.identifier, - tags, - heading_lev_anchor_tag, - _txt, - obj.metainfo.heading_lev_markup, - ); - } else { - o = format(q"┃%s -
- %s%s - %s - -
┃", - _horizontal_rule, - obj.metainfo.heading_lev_markup, - obj.metainfo.is_a, - tags, - heading_lev_anchor_tag, - _txt, - obj.metainfo.heading_lev_markup, - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string heading_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", -) { - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = heading(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto heading_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0]; - string[] _endnotes = t[1]; - string o = heading(_txt, obj, doc_matters, _xml_type); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** para -**** para - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string para(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body" || "frontmatter" || "backmatter"); - assert(obj.metainfo.is_of_section == "body" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "para"); - assert(obj.metainfo.is_a == "para" || "toc" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb"); - string tags = _xhtml_anchor_tags(obj); - _txt = font_face(_txt); - string o; - _txt = (obj.attrib.bullet) ? ("●  " ~ _txt) : _txt; - _txt = _txt.replaceFirst(rgx.inline_link_anchor, - ""); - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

%s - %s -

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.attrib.indent_hang, - obj.attrib.indent_base, - obj.metainfo.identifier, - tags, - _txt - ); - } else { - o = format(q"┃
-

%s - %s -

-
┃", - obj.metainfo.is_a, - obj.attrib.indent_hang, - obj.attrib.indent_base, - tags, - _txt - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string para_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", -) { - if (obj.metainfo.is_a == "toc" && _txt.match(rgx.inline_link_toc_to_backmatter)) { - _txt = _txt.replaceAll(rgx.inline_link_toc_to_backmatter, "┤#section_$1├"); - } - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = para(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto para_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0].to!string; - string[] _endnotes = t[1]; - string o = para(_txt, obj, doc_matters); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** quote -**** quote - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string quote(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "quote"); - _txt = font_face(_txt); - string o; - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

- %s -

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.identifier, - _txt - ); - } else { - o = format(q"┃
-

- %s -

-
┃", - obj.metainfo.is_a, - _txt - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string quote_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", -) { - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = quote(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto quote_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0].to!string; - string[] _endnotes = t[1]; - string o = quote(_txt, obj, doc_matters); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** group -**** group - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string group(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "group"); - _txt = font_face(_txt); - string o; - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

- %s -

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.identifier, - _txt - ); - } else { - o = format(q"┃
-

- %s -

-
┃", - obj.metainfo.is_a, - _txt - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string group_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = group(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto group_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0].to!string; - string[] _endnotes = t[1]; - string o = group(_txt, obj, doc_matters); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** block -**** block - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string block(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "block"); - _txt = font_face(_txt); - string o; - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

%s

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.identifier, - _txt.stripRight - ); - } else { - o = format(q"┃
-

%s

-
┃", - obj.metainfo.is_a, - _txt.stripRight - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string block_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = block(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto block_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0].to!string; - string[] _endnotes = t[1]; - string o = block(_txt, obj, doc_matters); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** poem verse -**** verse - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string verse(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body" || "glossary" || "bibliography" || "bookindex" || "blurb"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "verse"); - _txt = font_face(_txt); - string o; - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

%s

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.identifier, - _txt - ); - } else { - o = format(q"┃
-

%s

-
┃", - obj.metainfo.is_a, - _txt - ); - } - return o; -} -#+END_SRC - -**** scroll - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string verse_scroll(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - _txt = inline_markup_scroll(_txt, obj, doc_matters, _suffix); - string o = verse(_txt, obj, doc_matters); - return o; -} -#+END_SRC - -**** seg - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto verse_seg(O,M)( - string _txt, - const O obj, - M doc_matters, - string _suffix = ".html", - string _xml_type = "html", -) { - auto t = inline_markup_seg(_txt, obj, doc_matters, _suffix, _xml_type); - _txt = t[0].to!string; - string[] _endnotes = t[1]; - string o = verse(_txt, obj, doc_matters); - auto u = tuple( - o, - _endnotes, - ); - return u; -} -#+END_SRC - -*** code - -#+name: xhtml_format_objects_code -#+BEGIN_SRC d -string code(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "code"); - string o; - string codelines(string _txt) { - string _codelines; - if (obj.code_block.linenumbers) { - string[] _block_lines = (_txt).split(rgx.br_newlines_linebreaks); - _codelines = "
\n";
-      foreach (k, _line; _block_lines) {
-        if (k == 1) {
-          _codelines ~= format(q"┃    %s
-┃",
-            _line,
-          );
-        } else {
-          _codelines ~= format(q"┃    %s
-┃",
-            _line,
-          );
-        }
-      }
-      _codelines ~= "  
"; - } else { - _codelines = "
\n";
-      _codelines ~= _txt;
-      _codelines ~= "  
"; - } - return _codelines; - } - if (!(obj.metainfo.identifier.empty)) { - o = format(q"┃
- -

%s

-
┃", - obj.metainfo.identifier, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.identifier, - codelines(_txt) - ); - } else { - o = format(q"┃
-

%s

-
┃", - obj.metainfo.is_a, - codelines(_txt) - ); - } - return o; -} -#+END_SRC - -*** table -**** TODO tablarize - -align="left|right|center" -$100 - -"style=\"text-align:right\"" -"style=\"text-align:left\"" - -"style=\"text-align:" ~ "right\"" - -#+name: xhtml_format_objects -#+BEGIN_SRC d -auto tablarize(O)( - string _txt, - const O obj, -) { - 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; -} -#+END_SRC - -**** table - -#+name: xhtml_format_objects -#+BEGIN_SRC d -string table(O,M)( - string _txt, - const O obj, - M doc_matters, -) { - assert(obj.metainfo.is_of_part == "body"); - assert(obj.metainfo.is_of_section == "body"); - assert(obj.metainfo.is_of_type == "block"); - assert(obj.metainfo.is_a == "table"); - string tags = _xhtml_anchor_tags(obj); - _txt = font_face(_txt); - auto t = tablarize(_txt, obj); - _txt = t[0]; - string _note = t[1]; - string o; - o = format(q"┃
- -

%s - - %s -
- %s -

-
┃", - obj.metainfo.object_number, - (doc_matters.opt.action.ocn_off) ? "" : ((obj.metainfo.object_number.empty) ? "" : obj.metainfo.identifier), - obj.metainfo.is_a, - obj.metainfo.object_number, - tags, - _txt, - _note - ); - return o; -} -#+END_SRC - -* _html_ [#A] :html: -** _module template_ :module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/html.d" -module doc_reform.output.html; -template outputHTML() { - <> - mixin outputXHTMLs; - <> - <> - <> - <> -} -#+END_SRC - -** scroll :scroll: -*** ↻ loop & switch (sections & objects) format html output - -#+name: output_html_scroll -#+BEGIN_SRC d -void scroll(D,M)( - const D doc_abstraction, - M doc_matters, -) { - mixin DocReformOutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[] doc_html; - string[] doc; - string suffix = ".html"; - string previous_part = ""; - string delimit = ""; -#+END_SRC - -**** ↻ the loops & outer switch (sections & objects) format output - -#+name: output_html_scroll -#+BEGIN_SRC d - foreach (part; doc_matters.has.keys_seq.scroll) { - foreach (obj; doc_abstraction[part]) { - delimit = xhtml_format.div_delimit(part, previous_part); - string _txt = xhtml_format.special_characters(obj); - switch (obj.metainfo.is_of_part) { -#+END_SRC - -***** frontmatter - -#+name: output_html_scroll -#+BEGIN_SRC d - case "frontmatter": assert(part == "head" || "toc"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); - break; - case "toc": - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; -#+END_SRC - -***** body - -#+name: output_html_scroll -#+BEGIN_SRC d - case "body": assert(part == "body" || "head"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); - break; - case "para": - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - doc_html ~= xhtml_format.quote_scroll(_txt, obj, doc_matters); - break; - case "group": - doc_html ~= xhtml_format.group_scroll(_txt, obj, doc_matters); - break; - case "block": - doc_html ~= xhtml_format.block_scroll(_txt, obj, doc_matters); - break; - case "poem": - break; - case "verse": - doc_html ~= xhtml_format.verse_scroll(_txt, obj, doc_matters, suffix); - break; - case "code": - doc_html ~= xhtml_format.code(_txt, obj, doc_matters); - break; - case "table": - doc_html ~= xhtml_format.table(_txt, obj, doc_matters); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; -#+END_SRC - -***** backmatter - -#+name: output_html_scroll -#+BEGIN_SRC d - case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "heading": - doc_html ~= delimit ~ xhtml_format.heading_scroll(_txt, obj, doc_matters, suffix); - break; - case "endnote": assert(part == "endnotes"); - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - case "glossary": assert(part == "glossary"); - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - case "bibliography": assert(part == "bibliography"); - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - case "bookindex": assert(part == "bookindex"); - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - case "blurb": assert(part == "blurb"); - doc_html ~= xhtml_format.para_scroll(_txt, obj, doc_matters, suffix); - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - } - break; -#+END_SRC - -***** closings & post loop - -#+name: output_html_scroll -#+BEGIN_SRC d - } - } - } - doc = xhtml_format.html_head(doc_matters, "scroll") ~ doc_html ~ xhtml_format.tail; - scroll_write_output(doc, doc_matters); -} -#+END_SRC - -*** write output file - -#+name: output_html_scroll -#+BEGIN_SRC d -void scroll_write_output(D,M)( - D doc, - M doc_matters, -) { - debug(asserts) { - static assert(is(typeof(doc) == string[])); - } - auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); - try { - if (!exists(pth_html.base)) { - pth_html.base.mkdirRecurse; - } - auto f = File(pth_html.fn_scroll(doc_matters.src.filename), "w"); - foreach (o; doc) { - f.writeln(o); - } - } catch (ErrnoException ex) { - // Handle error - } - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_html.fn_scroll(doc_matters.src.filename)); - } -} -#+END_SRC - -** seg :seg: -*** ↻ loop & switch (sections & objects) format html output - -#+name: output_html_seg -#+BEGIN_SRC d -void seg(D,M)( - const D doc_abstraction, - M doc_matters, -) { - mixin DocReformOutputRgxInit; - 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 previous_seg_filename = ""; - string suffix = ".html"; - string previous_part = ""; - string delimit = ""; -#+END_SRC - -**** ↻ the loop (sections & objects) format output - -#+name: output_html_seg -#+BEGIN_SRC d - foreach (part; doc_matters.has.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - delimit = xhtml_format.div_delimit(part, previous_part); - string _txt = xhtml_format.special_characters(obj); -#+END_SRC - -***** all headings - -#+name: output_html_seg -#+BEGIN_SRC d - if (obj.metainfo.is_a == "heading") { - assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.metainfo.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(_txt, obj, doc_matters, suffix, "seg"); - top_level_headings[obj.metainfo.heading_lev_markup] = t[0]; - break; - } - break; - case 4: - segment_filename = obj.tags.segment_anchor_tag_epub; - doc_html[segment_filename] ~= xhtml_format.html_head(doc_matters, "seg"); - auto navigation_bar = xhtml_format.nav_pre_next_svg(obj, doc_matters); - doc_html[segment_filename] ~= navigation_bar.toc_pre_next; - previous_seg_filename = segment_filename; - foreach (top_level_heading; top_level_headings) { - doc_html[segment_filename] ~= top_level_heading; - } - auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html[segment_filename] ~= xhtml_format.lev4_heading_subtoc(obj, doc_matters); - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case 5: .. case 7: - auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); - } - } - break; - } -#+END_SRC - -***** non-heading - -#+name: output_html_seg -#+BEGIN_SRC d - } else { - assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_part) { -#+END_SRC - -****** frontmatter - -#+name: output_html_seg -#+BEGIN_SRC d - case "frontmatter": assert(part == "head" || "toc"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "toc": - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; -#+END_SRC - -****** body - -#+name: output_html_seg -#+BEGIN_SRC d - case "body": assert(part == "body"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "para": - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "group": - auto t = xhtml_format.group_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "block": - auto t = xhtml_format.block_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "poem": - break; - case "verse": - auto t = xhtml_format.verse_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0].to!string; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "code": - doc_html[segment_filename] ~= xhtml_format.code(_txt, obj, doc_matters); - break; - case "table": - doc_html[segment_filename] ~= xhtml_format.table(_txt, obj, doc_matters); - doc_html_endnotes[segment_filename] ~= ""; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; -#+END_SRC - -****** backmatter - -#+name: output_html_seg -#+BEGIN_SRC d - case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "endnote": assert(part == "endnotes"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0]; - break; - case "glossary": assert(part == "glossary"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "bibliography": assert(part == "bibliography"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": assert(part == "bookindex"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - case "blurb": assert(part == "blurb"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "seg"); - doc_html[segment_filename] ~= t[0]; - doc_html_endnotes[segment_filename] ~= t[1]; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); - } - } - break; - } -#+END_SRC - -***** closings & post loop - -#+name: output_html_seg -#+BEGIN_SRC d - } - } - } - seg_write_output(doc_html, doc_html_endnotes, doc_matters); -} -#+END_SRC - -*** write output files - -#+name: output_html_seg -#+BEGIN_SRC d -void seg_write_output(D,E,M)( - D doc_html, - E doc_html_endnotes, - M doc_matters, -) { - debug(asserts) { - static assert(is(typeof(doc_html) == string[][string])); - } - mixin DocReformOutputRgxInit; - auto rgx = Rgx(); - auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); - auto xhtml_format = outputXHTMLs(); - auto m = doc_matters.src.filename.matchFirst(rgx.src_fn); - try { - if (!exists(pth_html.seg(doc_matters.src.filename))) { - pth_html.seg(doc_matters.src.filename).mkdirRecurse; - } - foreach (seg_filename; doc_matters.has.segnames_lv4) { - auto f = File(pth_html.fn_seg(doc_matters.src.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 - } - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", pth_html.fn_seg(doc_matters.src.filename, "toc")); - } -} -#+END_SRC - -** css :css: - -#+name: output_html_css -#+BEGIN_SRC d -void css(M)(M doc_matters) { - auto css = DocReformCss(doc_matters); - auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); - try { - if (!exists(pth_html.css)) { - (pth_html.css).mkdirRecurse; - } - auto f = File(pth_html.fn_seg_css, "w"); - f.writeln(css.html_seg); - f = File(pth_html.fn_scroll_css, "w"); - f.writeln(css.html_scroll); - } catch (ErrnoException ex) { - // Handle error - } -} -#+END_SRC - -** images :images: - -#+name: copy_html_images -#+BEGIN_SRC d -void images_cp(M)( - M doc_matters, -) { - { /+ (copy html images) +/ - - auto pth_html = DocReformPathsHTML!()(doc_matters.output_path, doc_matters.src.language); - if (!exists(pth_html.image)) { - pth_html.image.mkdirRecurse; - } - foreach (image; doc_matters.srcs.image_list) { - auto fn_src_in = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_src_out = pth_html.image ~ "/" ~ image; - debug(images_html) { - writeln(fn_src_in, " -> ", fn_src_out); - } - if (exists(fn_src_in)) { - fn_src_in.copy(fn_src_out); - } else { - if (!(doc_matters.opt.action.quiet)) { - writeln("WARNING image not found: ", fn_src_in); - } - } - } - } -} -#+END_SRC - -* _epub_ [#B] :epub: - -|-----------------------+--------------------------+---------------------------+----------------------------------| -| function | filename | module | variable | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| identify doc filetype | mimetype | epub3_mimetypes | mimetypes | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| identify doc root | META-INF/container.xml | epub3_container_xml | meta_inf_container_xml | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc manifest | OEBPS/content.opf | epub3_oebps_content | oebps_content_opf | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc navigation | OEBPS/toc_nav.xhtml | epub3_oebps_toc_nav_xhtml | oebps_toc_nav_xhtml | -| | OEBPS/toc.ncx | epub2_oebps_toc_ncx | oebps_toc_ncx | -|-----------------------+--------------------------+---------------------------+----------------------------------| -| doc contents | OEBPS/[files ... ].xhtml | outputEPub3 | doc_epub3[seg_filename] | -| | | | doc_epub3_endnotes[seg_filename] | -|-----------------------+--------------------------+---------------------------+----------------------------------| - -** _module template_ :module: - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/epub3.d" -module doc_reform.output.epub3; -template outputEPub3() { - <> - mixin InternalMarkup; - mixin outputXHTMLs; - <> - <> - <> - <> - <> -} -#+END_SRC - -** special (epub) files :format: -*** static -**** _identify doc filetype_ (mimetype) [static] - -- mimetype file indicating that zip file contains an EPUB - -#+name: output_epub3_fixed -#+BEGIN_SRC d -string epub3_mimetypes() { - string o; - o = format(q"┃application/epub+zip┃") ~ "\n"; - return o; -} -#+END_SRC - -**** _identify doc root_ (META-INF/container.xml) [static] rootfile: contains document root path - -- identifies the root package document (so systems can find it), [unchanged from epub2] - -#+name: output_epub3_fixed -#+BEGIN_SRC d -string epub3_container_xml() { - string o; - o = format(q"┃┃") ~ "\n"; - o ~= format(q"┃ - - -┃") ~ "\n\n"; - return o; -} -#+END_SRC - -*** constructs (in dir: OEBPS) -**** TODO _doc manifest_ (OEBPS/content.opf) manifest, register content: files, images etc. - -- manifest, listing all resources -- provides the default reading order -- identifies the navigation document - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub3_oebps_content(D,M,P)(D doc_abstraction, M doc_matters, P parts) { - auto xhtml_format = outputXHTMLs(); - auto pth_epub3 = DocReformPathsEPUB!()(doc_matters.output_path, doc_matters.src.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, - xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_full), - xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_main), - (doc_matters.conf_make_meta.meta.title_sub.empty) - ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.title_sub), - (doc_matters.conf_make_meta.meta.creator_author.empty) - ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.creator_author), - (doc_matters.conf_make_meta.meta.creator_author.empty) - ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.creator_author), - doc_matters.src.language, // language, fix (needed in dochead metadata) - (doc_matters.conf_make_meta.meta.date_published.empty) - ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.date_published), - (doc_matters.conf_make_meta.meta.rights_copyright.empty) - ? "" : xhtml_format.special_characters_text(doc_matters.conf_make_meta.meta.rights_copyright), - _uuid, - _uuid, - _uuid, - (pth_epub3.fn_oebps_css).chompPrefix("OEBPS/"), - ); - content ~= " " ~ "" ~ "\n "; - content ~= parts["manifest_documents"]; - // TODO sort jpg & png - content ~= " " ~ "" ~ "\n "; - foreach (image; doc_matters.srcs.image_list) { - content ~= format(q"┃ -┃", - image.baseName.stripExtension, - (pth_epub3.doc_oebps_image).chompPrefix("OEBPS/"), - image, - image.extension.chompPrefix("."), - ); - } - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["spine"]; - content ~= " " ~ "" ~ "\n "; - content ~= " " ~ "" ~ "\n "; - content ~= parts["guide"]; - content ~= " " ~ "" ~ "\n "; - content ~= "" ~ ""; - debug(epubmanifest) { - foreach (part; doc_matters.has.keys_seq.seg) { // TODO - foreach (obj; doc_abstraction[part]) { - if (obj.metainfo.is_a == "heading") { - if (obj.metainfo.heading_lev_markup == 4) { - writefln( - "%s~ [%s.xhtml] %s", - obj.marked_up_level, - obj.tags.segment_anchor_tag_epub, - obj.text - ); - } else if (obj.metainfo.heading_lev_markup > 4) { - writefln( - "%s~ [%s.xhtml#%s] %s", - obj.marked_up_level, - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - obj.text - ); - } - } - } - } - } - return content; -} -#+END_SRC - -**** _doc navigation epub3_ (OEBPS/toc_nav.xhtml) epub3 navigable toc using Dom structure - -- toc_nav.xhtml declared as nav file in content.opf (epub3 navigation document) - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub3_oebps_toc_nav_xhtml(D,I)(D doc_abstraction, I doc_matters) { - enum DomTags { none, open, close, close_and_open, open_still, } - auto markup = InlineMarkup(); - auto rgx = Rgx(); - string toc =format(" - - %s - - -
-
-

Contents

-
- -
- -\n"; - return toc; -} -#+END_SRC - -**** TODO _doc navigation epub2_ (OEBPS/toc.ncx) navigable toc using Dom structure - -- toc.ncx (epub2 navigation document) - - (replaced in epub3 by a declared xhtml nav file, in our case toc_nav.xhtml) - -#+name: output_epub3_constructs -#+BEGIN_SRC d -string epub2_oebps_toc_ncx(D,I)(D doc_abstraction, I doc_matters) { - int counter = 0; - string _uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere - auto markup = InlineMarkup(); - auto rgx = Rgx(); - enum DomTags { none, open, close, close_and_open, open_still, } - string toc = format(q"┃ - - - - %s%s - - - - - - - - - %s - - - %s - -┃", - doc_matters.conf_make_meta.meta.title_full, // title - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : " by " ~ doc_matters.conf_make_meta.meta.creator_author, // author - _uuid, // uuid - "3", // content depth - doc_matters.conf_make_meta.meta.title_full, // title - (doc_matters.conf_make_meta.meta.creator_author.empty) ? "" - : doc_matters.conf_make_meta.meta.creator_author, // author - ); - foreach (sect; doc_matters.has.keys_seq.seg) { - foreach (obj; doc_abstraction[sect]) { - if (obj.metainfo.is_a == "heading") { - string _txt = obj.text.replaceAll(rgx.inline_notes_al_gen, "").strip; - string hashtag =(obj.metainfo.heading_lev_markup <= 4) ? "" : ("#" ~ obj.metainfo.ocn.to!string); - foreach_reverse (k; 0 .. 7) { - switch (obj.metainfo.dom_structure_markedup_tags_status[k]) { - case DomTags.close : - toc ~= "\n "; - break; - case DomTags.close_and_open : - ++counter; - toc ~= "\n "; - toc ~= format(q"┃ - - - %s - - ┃", - counter, - _txt, - obj.tags.segment_anchor_tag_epub, - hashtag, - ); - break; - case DomTags.open : - ++counter; - toc ~= format(q"┃ - - - %s - - ┃", - counter, - _txt, - obj.tags.segment_anchor_tag_epub, - hashtag, - ); - break; - default : - break; - } - } - } - } - } - toc ~= format(q"┃ - - - - -┃"); - return toc; -} -#+END_SRC - -** the document contents :seg: -*** ↻ loop & switch (sections & objects) format epub3 xhtml output - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d -void outputEPub3(D,I)( - const D doc_abstraction, - I doc_matters, -) { - mixin DocReformOutputRgxInit; - auto xhtml_format = outputXHTMLs(); - auto rgx = Rgx(); - string[] doc; - string segment_filename; - string[] top_level_headings = ["","","",""]; - string[string] oepbs_content_parts; - string suffix = ".xhtml"; - struct writeOut { /+ epub specific documents +/ - /+ fixed output +/ - string mimetypes; - string meta_inf_container_xml; - string oebps_toc_ncx; - string oebps_toc_nav_xhtml; - /+ variable output +/ - string oebps_content_opf; - string[][string] doc_epub3; - string[][string] doc_epub3_endnotes; - string[] doc_parts; - } - auto epubWrite = writeOut(); -#+END_SRC - -**** ↻ the loop (sections & objects) format output - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - foreach (part; doc_matters.has.keys_seq.seg) { - foreach (obj; doc_abstraction[part]) { - string _txt = xhtml_format.special_characters(obj); -#+END_SRC - -***** all headings - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - if (obj.metainfo.is_a == "heading") { - assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.heading_lev_markup) { - case 0: .. case 3: - /+ fill buffer, and replace with new levels from 1 to 3 +/ - switch (obj.metainfo.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: - epubWrite.doc_parts ~= obj.tags.segment_anchor_tag_epub; - epubWrite.doc_epub3[obj.tags.segment_anchor_tag_epub] ~= xhtml_format.epub3_seg_head(doc_matters); - auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[obj.tags.segment_anchor_tag_epub] ~= t[0]; - epubWrite.doc_epub3_endnotes[obj.tags.segment_anchor_tag_epub] ~= t[1]; - break; - } - break; - case 4: - segment_filename = obj.tags.segment_anchor_tag_epub; - epubWrite.doc_epub3[segment_filename] ~= xhtml_format.epub3_seg_head(doc_matters); - auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case 5: .. case 7: - auto t = xhtml_format.heading_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case 8: .. case 9: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); - writeln(__FILE__, ":", __LINE__, ": ", obj.text); - } - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a, ": ", obj.metainfo.heading_lev_markup); - } - } - break; - } -#+END_SRC - -***** non-heading - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - } else { - assert(part == "head" || "toc" || "body" || "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_part) { -#+END_SRC - -****** frontmatter - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - case "frontmatter": assert(part == "head" || "toc"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "toc": - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; -#+END_SRC - -****** body - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - case "body": assert(part == "body"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "para": - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - case "block": - switch (obj.metainfo.is_a) { - case "quote": - auto t = xhtml_format.quote_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "group": - auto t = xhtml_format.group_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "block": - auto t = xhtml_format.block_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "poem": - break; - case "verse": - auto t = xhtml_format.verse_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0].to!string; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "code": - epubWrite.doc_epub3[segment_filename] ~= xhtml_format.code(_txt, obj, doc_matters); - break; - case "table": - epubWrite.doc_epub3[segment_filename] ~= xhtml_format.table(_txt, obj, doc_matters); - epubWrite.doc_epub3_endnotes[segment_filename] ~= ""; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; -#+END_SRC - -****** backmatter - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - case "backmatter": - assert(part == "endnotes" || "glossary" || "bibliography" || "bookindex" || "blurb" || "tail"); - switch (obj.metainfo.is_of_type) { - case "para": - switch (obj.metainfo.is_a) { - case "endnote": assert(part == "endnotes"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - break; - case "glossary": assert(part == "glossary"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "bibliography": assert(part == "bibliography"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "bookindex": assert(part == "bookindex"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - case "blurb": assert(part == "blurb"); - auto t = xhtml_format.para_seg(_txt, obj, doc_matters, suffix, "epub"); - epubWrite.doc_epub3[segment_filename] ~= t[0]; - epubWrite.doc_epub3_endnotes[segment_filename] ~= t[1]; - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_a); - } - } - break; - } - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_type); - } - } - break; - } - break; - case "comment": - break; - default: - { /+ debug +/ - if (doc_matters.opt.action.debug_do - && doc_matters.opt.action.verbose) { - writeln(__FILE__, ":", __LINE__, ": ", obj.metainfo.is_of_part); - } - } - break; - } - } - if (obj.metainfo.is_a == "heading") { - assert(obj.text.length > 0); - if (obj.metainfo.heading_lev_markup <= 4) { - oepbs_content_parts["manifest_documents"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - obj.tags.segment_anchor_tag_epub, - ); - oepbs_content_parts["spine"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - ); - oepbs_content_parts["guide"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - obj.tags.segment_anchor_tag_epub, - ); - } else if (obj.metainfo.heading_lev_markup > 4) { - oepbs_content_parts["manifest_documents"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - ); - oepbs_content_parts["spine"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - ); - oepbs_content_parts["guide"] ~= - format(q"┃ -┃", - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - obj.tags.segment_anchor_tag_epub, - obj.metainfo.object_number, - ); - } -#+END_SRC - -***** closings & post loop - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - } - } - } - /+ epub specific documents +/ - epubWrite.mimetypes = epub3_mimetypes; - epubWrite.meta_inf_container_xml = epub3_container_xml; - epubWrite.oebps_toc_ncx = doc_abstraction.epub2_oebps_toc_ncx(doc_matters); - epubWrite.oebps_toc_nav_xhtml = doc_abstraction.epub3_oebps_toc_nav_xhtml(doc_matters); - epubWrite.oebps_content_opf = doc_abstraction.epub3_oebps_content(doc_matters, oepbs_content_parts); - epubWrite.epub3_write_output_files(doc_matters); -} -#+END_SRC - -** write output files :write:zip: - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d -void epub3_write_output_files(W,M)( - W epub_write, - M doc_matters, -) { - debug(asserts) { - static assert(is(typeof(epub_write.doc_epub3) == string[][string])); - static assert(is(typeof(epub_write.mimetypes) == string)); - static assert(is(typeof(epub_write.meta_inf_container_xml) == string)); - static assert(is(typeof(epub_write.oebps_toc_nav_xhtml) == string)); - static assert(is(typeof(epub_write.oebps_toc_ncx) == string)); - static assert(is(typeof(epub_write.oebps_content_opf) == string)); - } - static auto rgx = Rgx(); - auto pth_epub3 = DocReformPathsEPUB!()(doc_matters.output_path, doc_matters.src.language); - auto xhtml_format = outputXHTMLs(); - /+ zip file +/ - auto fn_epub = pth_epub3.epub_file(doc_matters.src.filename); - auto zip = new ZipArchive(); // ZipArchive zip = new ZipArchive(); - /+ zip archive member files +/ - void EPUBzip()(string contents, string fn) { - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - (doc_matters.opt.action.debug_do) - ? zip_data.write(contents.dup) - : zip_data.write(contents.dup - .replaceAll(rgx.spaces_line_start, "") - .replaceAll(rgx.newline, " ") - .strip - ); - zip_arc_member_file.expandedData = zip_data.toBytes(); - zip.addMember(zip_arc_member_file); - createZipFile!()(fn_epub, zip.build()); - } - try { - if (!exists(pth_epub3.base)) { - pth_epub3.base.mkdirRecurse; - } - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - if (!exists(pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename))) { - pth_epub3.dbg_doc_meta_inf(doc_matters.src.filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename))) { - pth_epub3.dbg_doc_oebps_css(doc_matters.src.filename).mkdirRecurse; - } - if (!exists(pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename))) { - pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename).mkdirRecurse; - } - } - } - { /+ OEBPS/[segments].xhtml (the document contents) +/ - foreach (seg_filename; doc_matters.has.segnames_lv_0_to_4) { - string fn = pth_epub3.fn_oebps_content_xhtml(seg_filename); - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - string fn_dbg = pth_epub3.dbg_fn_oebps_content_xhtml(doc_matters.src.filename, seg_filename); - auto f = File(fn_dbg, "w"); - foreach (docseg; epub_write.doc_epub3[seg_filename]) { - f.writeln(docseg); - } - foreach (docseg; epub_write.doc_epub3_endnotes[seg_filename]) { - f.writeln(docseg); - } - f.writeln(xhtml_format.tail); - } - } - foreach (docseg; epub_write.doc_epub3[seg_filename]) { - zip_data.write(docseg.dup); - } - foreach (docseg; epub_write.doc_epub3_endnotes[seg_filename]) { - zip_data.write(docseg.dup); - } - 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; - string fn_dbg; - File f; - { /+ mimetypes (identify zip file type) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_mimetypes(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.mimetypes); - } - } - fn = pth_epub3.fn_mimetypes; - EPUBzip(epub_write.mimetypes, fn); - } - { /+ META-INF/container.xml (identify doc root) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_dmi_container_xml(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.meta_inf_container_xml); - } - } - fn = pth_epub3.fn_dmi_container_xml; - EPUBzip(epub_write.meta_inf_container_xml, fn); - } - { /+ OEBPS/toc_nav.xhtml (navigation toc epub3) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_nav_xhtml(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.oebps_toc_nav_xhtml); - } - } - fn = pth_epub3.fn_oebps_toc_nav_xhtml; - EPUBzip(epub_write.oebps_toc_nav_xhtml, fn); - } - { /+ OEBPS/toc.ncx (navigation toc epub2) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_oebps_toc_ncx(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.oebps_toc_ncx); - } - } - fn = pth_epub3.fn_oebps_toc_ncx; - EPUBzip(epub_write.oebps_toc_ncx, fn); - } - { /+ OEBPS/content.opf (doc manifest) +/ - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_oebps_content_opf(doc_matters.src.filename); - File(fn_dbg, "w").writeln(epub_write.oebps_content_opf); - } - } - fn = pth_epub3.fn_oebps_content_opf; - EPUBzip(epub_write.oebps_content_opf, fn); - } - { /+ OEBPS/_dr/image (images) +/ - foreach (image; doc_matters.srcs.image_list) { - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - if (doc_matters.opt.action.very_verbose) { - writeln( - doc_matters.src.image_dir_path, "/", image, " -> ", - pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename), "/", image - ); - } - if (exists(doc_matters.src.image_dir_path ~ "/" ~ image)) { - (doc_matters.src.image_dir_path ~ "/" ~ image) - .copy((pth_epub3.dbg_doc_oebps_image(doc_matters.src.filename)) ~ "/" ~ image); - } - } - } - auto fn_src = doc_matters.src.image_dir_path ~ "/" ~ image; - auto fn_out = pth_epub3.doc_oebps_image ~ "/" ~ 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 = DocReformCss(doc_matters); - { /+ debug +/ - if (doc_matters.opt.action.debug_do) { - fn_dbg = pth_epub3.dbg_fn_oebps_css(doc_matters.src.filename); - File(fn_dbg, "w").writeln(css.epub); - } - } - fn = pth_epub3.fn_oebps_css; - auto zip_arc_member_file = new ArchiveMember(); - zip_arc_member_file.name = fn; - auto zip_data = new OutBuffer(); - zip_data.write(css.epub.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 - } - if (!(doc_matters.opt.action.quiet)) { - writeln(" ", fn_epub); - } -#+END_SRC - -** zip debug, read zip archive :zip: - -#+name: output_epub3_xhtml_seg -#+BEGIN_SRC d - debug(epub_archive) { - if (exists(fn_epub)) { - try { - auto zipped = new ZipArchive((fn_epub).read); - foreach (filename, member; zipped.directory) { - auto data = zipped.expand(member); - writeln(filename, " length ", data.length); - } - } catch (ZipException ex) { - // Handle errors - } - } - } -} -#+END_SRC - -* __END__ diff --git a/org/output_xmls_css.org b/org/output_xmls_css.org deleted file mode 100644 index b16bee0..0000000 --- a/org/output_xmls_css.org +++ /dev/null @@ -1,2364 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) defaults css -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:output:xmls:css: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* 0. output css defaults :module:spine:output_xmls_css: -** _module template_ - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/xmls_css.d" -/++ - default css settings -+/ -module doc_reform.output.xmls_css; -template DocReformCss() { - import std.format; - auto DocReformCss(M)(M doc_matters) { -<> -<> - string _css_light_html_seg = format(q"┃ -<> -<> -┃", - _color_ocn_light, - _css_indent, - _color_ocn_light, -); - string _css_dark_html_seg = format(q"┃ -<> -<> -┃", - _color_ocn_dark, - _css_indent, - _color_ocn_dark, -); - string _css_light_html_scroll = format(q"┃ -<> -<> -┃", - _color_ocn_light, - _css_indent, - _color_ocn_light, -); - string _css_dark_html_scroll = format(q"┃ -<> -<> -┃", - _color_ocn_dark, - _css_indent, - _color_ocn_dark, -); - string _css_light_epub = format(q"┃ -<> -<> -┃", - _color_ocn_light, - _css_indent, - _color_ocn_light, -); - string _css_dark_epub = format(q"┃ -<> -<> -┃", - _color_ocn_dark, - _css_indent, - _color_ocn_dark, -); - auto css_() { - struct _CSS { - string html_seg = "/* DocReform css html seg stylesheet */\n"; - string html_scroll = "/* DocReform css html scroll stylesheet */\n"; - string epub = "/* DocReform css epub stylesheet */\n"; - } - return _CSS(); - } - auto css = css_(); - if (doc_matters.opt.action.css_theme_default) { - css.html_seg ~= _css_light_html_seg; - css.html_scroll ~= _css_light_html_scroll; - css.epub ~= _css_light_epub; - } else { - css.html_seg ~= _css_dark_html_seg; - css.html_scroll ~= _css_dark_html_scroll; - css.epub ~= _css_dark_epub; - } - return css; - } -} -#+END_SRC - -** css light theme -*** html shared -**** general - -#+name: css_light_shared -#+BEGIN_SRC css - *{ - padding : 0px; - margin : 0px; - } - body { - height : 100vh; - background-color : #FFFFFF; - } - body { - color : #000000; - background : #FFFFFF; - background-color : #FFFFFF; - } -#+END_SRC - -**** link - -#+name: css_light_shared -#+BEGIN_SRC css - 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 : %s; - text-decoration : none; - } - a.lnkocn:visited { - color : #32CD32; - text-decoration : none; - } - a.lnkocn:hover { - color : #777777; - font-size : 15px; - } - a:hover img { - background-color : #FFFFFF; - } - a:active { - color : #003399; - text-decoration : underline; - } -#+END_SRC - -**** div - -#+name: css_light_shared -#+BEGIN_SRC css - div { - margin-left : 0; - margin-right : 0; - } - div.p { - margin-left : 5%%; - margin-right : 1%%; - } - div.substance { - width : 100%%; - background-color : #FFFFFF; - } - div.ocn { - width : 5%%; - float : right; - top : 0; - background-color : #FFFFFF; - } - div.endnote { - width : 95%%; - background-color : #FFFFFF; - } - 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-left : 5%%; - margin-right : 2em; - margin-top : 1.8em; - margin-bottom : 1.8em; - } - span.currentlink { - text-decoration : none; - background-color : #AAAAAA; - } - div.toc a:visited { - color : #0000aa; - } - div.toc a:hover { - color : #000000; - background-color : #F9F9AA; - } - nav#toc ol { - list-style-type : none; - } -#+END_SRC - -**** paragraphs headings blocks -***** misc - -#+name: css_light_shared -#+BEGIN_SRC css - .norm, .bold, .verse, .group, .block, .alt { - line-height : 133%%; - margin-top : 12px; - margin-bottom : 0px; - padding-left : 0em; - text-indent : 0em; - } - p, h0, h1, h2, h3, h4, h5, h6, h7, ul, li { - display : block; - font-family : verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - margin-left : 5%%; - margin-right : 2em; - } - p { - font-size : 100%%; - font-weight : normal; - line-height : 133%%; - text-align : justify; - text-indent : 0mm; - margin-top : 0.8em; - margin-bottom : 0.8em; - } -#+END_SRC - -#+name: css_light_shared -#+BEGIN_SRC css - img { - max-width : 100%%; - height : auto; - } -#+END_SRC - -***** code block - -#+name: css_light_shared -#+BEGIN_SRC css - pre { - width : auto; - display : block; - clear : both; - color : #555555; - } - pre.codeline { - display : table; - clear : both; - table-layout : fixed; - margin-left : 5%%; - margin-right : 5%%; - width : 90%%; - white-space : pre-wrap; - border-style : none; - border-radius : 5px 5px 5px 5px; - box-shadow : 0 2px 5px #AAAAAA inset; - margin-bottom : 1em; - padding : 0.5em 1em; - page-break-inside : avoid; - word-wrap : break-word; - font-family : inconsolata, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; - white-space : pre; - white-space : pre-wrap; - white-space : -moz-pre-wrap; - white-space : -o-pre-wrap; - background-color : #EEEEEE; - color : #000000; - font-size : 95%%; - line-height : 100%%; - } - pre.codeline::before { - counter-reset : linenum; - } - pre.codeline span.tr { - display : table-row; - counter-increment : linenum; - } - pre.codeline span.th { - display : table-cell; - user-select : none; - -moz-user-select : none; - -webkit-user-select : none; - padding : 0.5em 0.5em; - /* background-color : #666666; */ - } - pre.codeline span.th::before { - content : counter(linenum) "."; - color : #999999; - text-align : right; - display : block; - } - pre.codeline span.th { - width : 4em; - } - pre.codeline code { - display : table-cell; - } - p.code { - border-style : none; - } -#+END_SRC - -***** paragraph general - -#+name: css_light_shared -#+BEGIN_SRC css - p.spaced { white-space : pre; } - p.block { - white-space : pre; - } - p.group { } - p.alt { } - p.verse { - white-space : pre; - margin-bottom : 6px; - } - 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, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; - background-color : #EEEEEE; - color : #000000; - } -#+END_SRC - -***** paragraph indent - -#+name: css_light_shared -#+BEGIN_SRC css -%s -#+END_SRC - -***** misc including tables & lists - -#+name: css_light_shared -#+BEGIN_SRC css - note { white-space : pre; } - label.ocn { - width : 2%%; - float : right; - top : 0; - font-size : 10px; - margin-top : 0px; - margin-bottom : 5px; - margin-right : 5px; - text-align : right; - color : %s; - -khtml-user-select : none; - -moz-user-select : none; - -ms-user-select : none; - -o-user-select : none; - -webkit-user-select : none; - user-select : none; - } - table { - display : block; - margin-left : 5%%; - margin-right : 2em; - background-color : inherit; - } - 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; - 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 { } -#+END_SRC - -***** headings - -#+name: css_light_shared -#+BEGIN_SRC css - 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 #808080; - } - 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; - } -#+END_SRC - -*** html seg -**** previous next - -#+name: css_light_html_seg -#+BEGIN_SRC css - .icon-bar { - width : 100%%; - overflow : auto; - margin : 0em 0em 0em; - } - .left-bar { - width : 85%%; - float : left; - display : inline; - overflow : auto; - } - .toc-button { - position : absolute; - top : 8px; - width : 2em; - height : 2em; - border-radius : 50%%; - background : #CCCCCC; - fill : #333333; - box-shadow : 0 2px 5px #AAAAAA inset; - } - .toc-button svg { - position : relative; - left : 25%%; - top : 25%%; - width : 150%%; - height : 150%%; - } - .toc-button p { - vertical-align : center; - font-size : 120%%; - } - .prev-next-button { - position : absolute; - top : 8px; - width : 2em; - height : 2em; - border-radius : 50%%; - background : #CCCCCC; - box-shadow : 0 2px 5px #AAAAAA inset; - } - .prev-next-button svg { - position : relative; - left : 20%%; - top : 20%%; - width : 60%%; - height : 60%%; - } - .menu { - right : 6em; - } - .previous { - right : 3em; - } - .next { - right : 0em; - } - .arrow { - fill : #333333; - } - .minitoc { - line-height : 100%%; - font-size : 90%%; - margin-top : 6px; - margin-bottom : 0px; - padding-left : 0em; - text-indent : 0em; - -khtml-user-select : none; - -moz-user-select : none; - -ms-user-select : none; - -o-user-select : none; - -webkit-user-select : none; - user-select : none; - } -#+END_SRC - -**** flex - -#+name: css_light_html_seg -#+BEGIN_SRC css - /* flex */ - .flex-menu-bar { - display : -webkit-flex; - display : flex; - -webkit-flex-wrap : wrap; - -webkit-align-items : center; - align-items : center; - width : 100%%; - margin-left : 5%%; - margin-right : 2%%; - background-color : #FFFFFF; - } - .flex-menu-option { - background-color : #FFFFFF; - margin-right : 4px; - } - .flex-list { - display : -webkit-flex; - display : flex; - -webkit-align-items : center; - display : block; - align-items : center; - width : 100%%; - background-color : #FFFFFF; - } - .flex-list-item { - background-color : #FFFFFF; - margin : 4px; - } -#+END_SRC - -**** TODO grid - -Consider what if anything should be used here - -#+name: css_light_html_seg -#+BEGIN_SRC css - /* grid */ - .wrapper { - display : grid; - grid-template-columns : 100%%; - grid-template-areas : - "headband" - "doc_header" - "doc_title" - "doc_toc" - "doc_prefix" - "doc_intro" - "doc_body" - "doc_endnotes" - "doc_glossary" - "doc_biblio" - "doc_bookindex" - "doc_blurb" - "doc_suffix"; - margin : 0px; - padding : 0px; - background-color : #FFFFFF; - } - .delimit { - border-style : none; - border-color : #FFFFFF; - padding : 10px; - } - .headband { - grid-area : headband; - background-color : #FFFFFF; - } - .doc_header { - grid-area : doc_header; - } - .doc_title { - grid-area : doc_title; - } - .doc_toc { - grid-area : doc_toc; - } - .doc_prefix { - grid-area : doc_prefix; - } - .doc_intro { - grid-area : doc_intro; - } - .doc_body { - grid-area : doc_body; - } - .doc_endnotes { - grid-area : doc_endnotes; - } - .doc_glossary { - grid-area : doc_glossary; - } - .doc_biblio { - grid-area : doc_biblio; - } - .doc_bookindex { - grid-area : doc_bookindex; - } - .doc_blurb { - grid-area : doc_blurb; - } - .doc_suffix { - grid-area : doc_suffix; - } - .nav-ul { - list-style : none; - float : left; - } - .nav-li { - float : left; - padding-right : 0.7em; - } - .nav-li a { - text-decoration : none; - color : #FFFFFF; - } - footer { - background-color : #00704E; - } -#+END_SRC - -*** html scroll -**** flex - -#+name: css_light_html_scroll -#+BEGIN_SRC css - /* flex */ - .flex-menu-bar { - display : -webkit-flex; - display : flex; - -webkit-flex-wrap : wrap; - -webkit-align-items : center; - align-items : center; - width : 100%%; - margin-left : 5%%; - margin-right : 2%%; - background-color : #FFFFFF; - } - .flex-menu-option { - background-color : #FFFFFF; - margin-right : 4px; - } - .flex-list { - display : -webkit-flex; - display : flex; - -webkit-align-items : center; - display : block; - align-items : center; - width : 100%%; - background-color : #FFFFFF; - } - .flex-list-item { - background-color : #FFFFFF; - margin : 4px; - } -#+END_SRC - -**** grid - -#+name: css_light_html_scroll -#+BEGIN_SRC css - /* grid */ - .wrapper { - display : grid; - grid-template-columns : 100%%; - grid-template-areas : - "headband" - "doc_header" - "doc_title" - "doc_toc" - "doc_prefix" - "doc_intro" - "doc_body" - "doc_endnotes" - "doc_glossary" - "doc_biblio" - "doc_bookindex" - "doc_blurb" - "doc_suffix"; - margin : 0px; - padding : 0px; - background-color : #FFFFFF; - } - .delimit { - border-style : none; - border-color : #FFFFFF; - padding : 10px; - } - .headband { - grid-area : headband; - background-color : #FFFFFF; - } - .doc_header { - grid-area : doc_header; - } - .doc_title { - grid-area : doc_title; - } - .doc_toc { - grid-area : doc_toc; - } - .doc_prefix { - grid-area : doc_prefix; - } - .doc_intro { - grid-area : doc_intro; - } - .doc_body { - grid-area : doc_body; - } - .doc_endnotes { - grid-area : doc_endnotes; - } - .doc_glossary { - grid-area : doc_glossary; - } - .doc_biblio { - grid-area : doc_biblio; - } - .doc_bookindex { - grid-area : doc_bookindex; - } - .doc_blurb { - grid-area : doc_blurb; - } - .doc_suffix { - grid-area : doc_suffix; - } - .nav-ul { - list-style : none; - float : left; - } - .nav-li { - float : left; - padding-right : 0.7em; - } - .nav-li a { - text-decoration : none; - color : #FFFFFF; - } - footer { - background-color : #00704E; - } -#+END_SRC - -*** epub xhtml - -#+name: css_light_epub -#+BEGIN_SRC css -#+END_SRC - -** css dark theme -*** html shared -**** general - -#+name: css_dark_shared -#+BEGIN_SRC css - *{ - padding : 0px; - margin : 0px; - } - body { - height : 100vh; - background-color : #000000; - } - body { - color : #CCCCCC; - background : #000000; - background-color : #000000; - } -#+END_SRC - -**** link - -#+name: css_dark_shared -#+BEGIN_SRC css - a:link { - color : #FFFFFF; - text-decoration : none; - } - a:visited { - color : #999999; - text-decoration : none; - } - a:hover { - color : #000000; - background-color : #555555; - } - a.lnkocn:link { - color : %s; - text-decoration : none; - } - a.lnkocn:visited { - color : #9ACD32; - text-decoration : none; - } - a.lnkocn:hover { - color : #BBBBBB; - font-size : 15px; - } - a:hover img { - background-color : #000000; - } - a:active { - color : #888888; - text-decoration : underline; - } -#+END_SRC - -**** div - -#+name: css_dark_shared -#+BEGIN_SRC css - div { - margin-left : 0; - margin-right : 0; - } - div.p { - margin-left : 5%%; - margin-right : 1%%; - } - div.substance { - width : 100%%; - background-color : #000000; - } - div.ocn { - width : 5%%; - float : right; - top : 0; - background-color : #000000; - } - div.endnote { - width : 95%%; - background-color : #000000; - } - div.toc { - position : absolute; - float : left; - margin : 0; - padding : 0; - padding-top : 0.5em; - border : 0; - width : 13em; - background-color : #111111; - margin-right : 1em; - } - div.summary { - margin : 0; - padding : 0; - border-left : 13em solid #111111; - padding-left : 1em; - background-color : #111111; - } - div.content, div.main_column { - margin : 0; - padding : 0; - border-left : 13em solid #000000; - padding-left : 1em; - padding-right : 1em; - } - div.content0, div.main_column0 { - margin : 0; - padding : 0; - border-left : 0%% solid #000000; - 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 : #111111; - } - div.toc a, span.currentlink{ - display : block; - text-decoration : none; - padding-left : 0.5em; - color : #FF00AA; - } - hr { - width : 90%%; - margin-left : 5%%; - margin-right : 2em; - margin-top : 1.8em; - margin-bottom : 1.8em; - } - span.currentlink { - text-decoration : none; - background-color : #AAAAF9; - } - div.toc a:visited { - color : #FF00AA; - } - div.toc a:hover { - color : #CCCCCC; - background-color : #F9F9AA; - } - nav#toc ol { - list-style-type : none; - } -#+END_SRC - -**** paragraphs headings blocks -***** misc - -#+name: css_dark_shared -#+BEGIN_SRC css - .norm, .bold, .verse, .group, .block, .alt { - line-height : 133%%; - margin-top : 12px; - margin-bottom : 0px; - padding-left : 0em; - text-indent : 0em; - } - p, h0, h1, h2, h3, h4, h5, h6, h7, ul, li { - display : block; - font-family : verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - margin-left : 5%%; - margin-right : 2em; - } - p { - font-size : 100%%; - font-weight : normal; - line-height : 133%%; - text-align : justify; - text-indent : 0mm; - margin-top : 0.8em; - margin-bottom : 0.8em; - } -#+END_SRC - -#+name: css_dark_shared -#+BEGIN_SRC css - img { - max-width : 100%%; - height : auto; - } -#+END_SRC - -***** code block - -#+name: css_dark_shared -#+BEGIN_SRC css - pre { - width : auto; - display : block; - clear : both; - color : #555555; - } - pre.codeline { - display : table; - clear : both; - table-layout : fixed; - margin-left : 5%%; - margin-right : 5%%; - width : 90%%; - white-space : pre-wrap; - border-style : none; - border-radius : 5px 5px 5px 5px; - box-shadow : 0 2px 5px #AAAAAA inset; - margin-bottom : 1em; - padding : 0.5em 1em; - page-break-inside : avoid; - word-wrap : break-word; - font-family : inconsolata, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; - white-space : pre; - white-space : pre-wrap; - white-space : -moz-pre-wrap; - white-space : -o-pre-wrap; - background-color : #555555; - color : #DDDDDD; - font-size : 95%%; - line-height : 100%%; - } - pre.codeline::before { - counter-reset : linenum; - } - pre.codeline span.tr { - display : table-row; - counter-increment : linenum; - } - pre.codeline span.th { - display : table-cell; - user-select : none; - -moz-user-select : none; - -webkit-user-select : none; - padding : 0.5em 0.5em; - } - pre.codeline span.th::before { - content : counter(linenum) "."; - color : #999999; - text-align : right; - display : block; - } - pre.codeline span.th { - width : 4em; - } - pre.codeline code { - display : table-cell; - } - p.code { - border-style : none; - } -#+END_SRC - -***** paragraph general - -#+name: css_dark_shared -#+BEGIN_SRC css - p.spaced { white-space : pre; } - p.block { - white-space : pre; - } - p.group { } - p.alt { } - p.verse { - white-space : pre; - margin-bottom : 6px; - } - 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 : #EEEEEE; - 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 : #555555; - 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, "liberation mono", "bitstream vera mono", "dejavu mono", monaco, consolas, "andale mono", "courier new", "courier 10 pitch", courier, monospace; - background-color : #555555; - color : #DDDDDD; - } -#+END_SRC - -***** paragraph indent - -#+name: css_dark_shared -#+BEGIN_SRC css -%s -#+END_SRC - -***** misc including tables & lists - -#+name: css_dark_shared -#+BEGIN_SRC css - note { white-space : pre; } - label.ocn { - width : 2%%; - float : right; - top : 0; - font-size : 10px; - margin-top : 0px; - margin-bottom : 5px; - margin-right : 5px; - text-align : right; - color : %s; - -khtml-user-select : none; - -moz-user-select : none; - -ms-user-select : none; - -o-user-select : none; - -webkit-user-select : none; - user-select : none; - } - table { - display : block; - margin-left : 5%%; - margin-right : 2em; - background-color : inherit; - } - 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; - 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 : (../image_sys/bullet_09.png) no-repeat 0px 6px; - } - ul { } -#+END_SRC - -***** headings - -#+name: css_dark_shared -#+BEGIN_SRC css - 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 #999999; - } - 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; - } -#+END_SRC - -*** html seg -**** previous next - -#+name: css_dark_html_seg -#+BEGIN_SRC css - .icon-bar { - width : 100%%; - overflow : auto; - margin : 0em 0em 0em; - } - .left-bar { - width : 85%%; - float : left; - display : inline; - overflow : auto; - } - .toc-button { - position : absolute; - top : 8px; - width : 2em; - height : 2em; - border-radius : 50%%; - background : #555555; - fill : #DDDDDD; - box-shadow : 0 2px 5px #EEEEEE inset; - } - .toc-button svg { - position : relative; - left : 25%%; - top : 25%%; - width : 150%%; - height : 150%%; - } - .toc-button p { - vertical-align : center; - font-size : 120%%; - } - .prev-next-button { - position : absolute; - top : 8px; - width : 2em; - height : 2em; - border-radius : 50%%; - background : #555555; - box-shadow : 0 2px 5px #AAAAAA inset; - } - .prev-next-button svg { - position : relative; - left : 20%%; - top : 20%%; - width : 60%%; - height : 60%%; - } - .menu { - right : 6em; - } - .previous { - right : 3em; - } - .next { - right : 0em; - } - .arrow { - fill : #DDDDDD; - } - .minitoc { - line-height : 100%%; - font-size : 90%%; - margin-top : 6px; - margin-bottom : 0px; - padding-left : 0em; - text-indent : 0em; - -khtml-user-select : none; - -moz-user-select : none; - -ms-user-select : none; - -o-user-select : none; - -webkit-user-select : none; - user-select : none; - } -#+END_SRC - -**** flex - -#+name: css_dark_html_seg -#+BEGIN_SRC css - /* flex */ - .flex-menu-bar { - display : -webkit-flex; - display : flex; - -webkit-flex-wrap : wrap; - -webkit-align-items : center; - align-items : center; - width : 100%%; - margin-left : 5%%; - margin-right : 2%%; - background-color : #000000; - } - .flex-menu-option { - background-color : #000000; - margin-right : 4px; - } - .flex-list { - display : -webkit-flex; - display : flex; - -webkit-align-items : center; - display : block; - align-items : center; - width : 100%%; - background-color : #000000; - } - .flex-list-item { - background-color : #000000; - margin : 4px; - } -#+END_SRC - -**** TODO grid - -Consider what if anything should be used here - -#+name: css_dark_html_seg -#+BEGIN_SRC css - /* grid */ - .wrapper { - display : grid; - grid-template-columns : 100%%; - grid-template-areas : - "headband" - "doc_header" - "doc_title" - "doc_toc" - "doc_prefix" - "doc_intro" - "doc_body" - "doc_endnotes" - "doc_glossary" - "doc_biblio" - "doc_bookindex" - "doc_blurb" - "doc_suffix"; - margin : 0px; - padding : 0px; - background-color : #000000; - } - .delimit { - border-style : none; - border-color : #000000; - padding : 10px; - } - .headband { - grid-area : headband; - background-color : #000000; - } - .doc_header { - grid-area : doc_header; - } - .doc_title { - grid-area : doc_title; - } - .doc_toc { - grid-area : doc_toc; - } - .doc_prefix { - grid-area : doc_prefix; - } - .doc_intro { - grid-area : doc_intro; - } - .doc_body { - grid-area : doc_body; - } - .doc_endnotes { - grid-area : doc_endnotes; - } - .doc_glossary { - grid-area : doc_glossary; - } - .doc_biblio { - grid-area : doc_biblio; - } - .doc_bookindex { - grid-area : doc_bookindex; - } - .doc_blurb { - grid-area : doc_blurb; - } - .doc_suffix { - grid-area : doc_suffix; - } - .nav-ul { - list-style : none; - float : left; - } - .nav-li { - float : left; - padding-right : 0.7em; - } - .nav-li a { - text-decoration : none; - color : #000000; - } - footer { - background-color : #FF704E; - } -#+END_SRC - -*** html scroll -**** flex - -#+name: css_dark_html_scroll -#+BEGIN_SRC css - /* flex */ - .flex-menu-bar { - display : -webkit-flex; - display : flex; - -webkit-flex-wrap : wrap; - -webkit-align-items : center; - align-items : center; - width : 100%%; - margin-left : 5%%; - margin-right : 2%%; - background-color : #000000; - } - .flex-menu-option { - background-color : #000000; - margin-right : 4px; - } - .flex-list { - display : -webkit-flex; - display : flex; - -webkit-align-items : center; - display : block; - align-items : center; - width : 100%%; - background-color : #000000; - } - .flex-list-item { - background-color : #000000; - margin : 4px; - } -#+END_SRC - -**** grid - -#+name: css_dark_html_scroll -#+BEGIN_SRC css - /* grid */ - .wrapper { - display : grid; - grid-template-columns : 100%%; - grid-template-areas : - "headband" - "doc_header" - "doc_title" - "doc_toc" - "doc_prefix" - "doc_intro" - "doc_body" - "doc_endnotes" - "doc_glossary" - "doc_biblio" - "doc_bookindex" - "doc_blurb" - "doc_suffix"; - margin : 0px; - padding : 0px; - background-color : #000000; - } - .delimit { - border-style : none; - border-color : #000000; - padding : 10px; - } - .headband { - grid-area : headband; - background-color : #000000; - } - .doc_header { - grid-area : doc_header; - } - .doc_title { - grid-area : doc_title; - } - .doc_toc { - grid-area : doc_toc; - } - .doc_prefix { - grid-area : doc_prefix; - } - .doc_intro { - grid-area : doc_intro; - } - .doc_body { - grid-area : doc_body; - } - .doc_endnotes { - grid-area : doc_endnotes; - } - .doc_glossary { - grid-area : doc_glossary; - } - .doc_biblio { - grid-area : doc_biblio; - } - .doc_bookindex { - grid-area : doc_bookindex; - } - .doc_blurb { - grid-area : doc_blurb; - } - .doc_suffix { - grid-area : doc_suffix; - } - .nav-ul { - list-style : none; - float : left; - } - .nav-li { - float : left; - padding-right : 0.7em; - } - .nav-li a { - text-decoration : none; - color : #000000; - } - footer { - background-color : #FF704E; - } -#+END_SRC - -*** epub xhtml - -#+name: css_dark_epub -#+BEGIN_SRC css -#+END_SRC - -** variables -*** ocn (visible or hidden) - -#+name: css_insert_shared_insert_variable_ocn_color_values -#+BEGIN_SRC css - string _color_ocn_light = (doc_matters.opt.action.ocn_hidden) ? "#FFFFFF" : "#777777"; - string _color_ocn_dark = (doc_matters.opt.action.ocn_hidden) ? "#000000" : "#BBBBBB"; -#+END_SRC - -*** indent levels -#+name: css_insert_shared_insert_variable_indent_values -#+BEGIN_SRC css - string _css_indent = format(q"┃ - /* 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; - } -┃"); -#+END_SRC - -* __END__ diff --git a/org/output_zip.org b/org/output_zip.org deleted file mode 100644 index 3007412..0000000 --- a/org/output_zip.org +++ /dev/null @@ -1,45 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) output zip -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+KEYWORDS -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+FILETAGS: :spine:rel:output: -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -- [[./spine.org][spine]] [[./][org/]] -- [[./output_hub.org][output_hub]] - -* _zip_ :module:spine:create_zip_file: -** module template - -#+BEGIN_SRC d :tangle "../src/doc_reform/output/create_zip_file.d" -module doc_reform.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 - } - } -} -#+END_SRC - -* __END__ diff --git a/org/source_files_read.org b/org/source_files_read.org deleted file mode 100644 index 121b070..0000000 --- a/org/source_files_read.org +++ /dev/null @@ -1,667 +0,0 @@ --*- mode: org -*- -#+TITLE: spine (doc_reform) markup source raw -#+DESCRIPTION: documents - structuring, publishing in multiple formats & search -#+FILETAGS: :spine:sourcefile:read: -#+AUTHOR: Ralph Amissah -#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] -#+COPYRIGHT: Copyright (C) 2015 - 2019 Ralph Amissah -#+LANGUAGE: en -#+STARTUP: indent content hideblocks hidestars -#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc -#+OPTIONS: author:nil email:nil creator:nil timestamp:nil -#+PROPERTY: header-args :padline no :exports code :cache no :noweb yes -#+EXPORT_SELECT_TAGS: export -#+EXPORT_EXCLUDE_TAGS: noexport -#+TAGS: assert(a) class(c) debug(d) mixin(m) spine(s) tangle(T) template(t) WEB(W) noexport(n) - -[[./spine.org][spine]] [[./][org/]] -* imports - -#+name: imports_std -#+BEGIN_SRC d -import - doc_reform.meta, - doc_reform.source.paths_source, - std.file, - std.path; -#+END_SRC - -* A. get _config file_ (read in) -** _module template_ :module:config_files: - -#+BEGIN_SRC d :tangle "../src/doc_reform/source/read_config_files.d" -/++ - read configuration files
- - read config files
- meta_config_files.d -+/ -module doc_reform.source.read_config_files; -<> -<> -#+END_SRC - -*** 0. read config files (config_local_site & dr_document_make) (yaml) -**** 1. site configuration - -#+name: meta_config_file_hub -#+BEGIN_SRC d -static template readConfigSite() { - import - doc_reform.meta.rgx; - <> - mixin DocReformRgxInit; - final auto readConfigSite(M,E)( - M _manifested, - E _env, - string _cli_config_path_set = "" - ) { - static auto rgx = Rgx(); - string config_file_str; - string conf_filename = "NONE"; - auto _conf_file_details = ConfigFilePaths!()(_manifested, _env, _cli_config_path_set); - string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; - foreach(conf_fn; [_conf_file_details.config_filename_site]) { - foreach(pth; possible_config_path_locations) { - char[] conf_file; - conf_filename = conf_fn; - if (exists(pth)) { - auto f_attrib = pth.getLinkAttributes; - if ( - possible_config_path_locations.length == 1 - && f_attrib.attrIsFile - ) { - conf_file = pth.to!(char[]); - conf_filename = pth.baseName; - } else if (f_attrib.attrIsDir) { - conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; - conf_filename = conf_fn; - } - try { - if (exists(conf_file)) { - if (conf_file.getLinkAttributes.attrIsFile) { - config_file_str = conf_file.readText; - break; - } - } - } catch (ErrnoException ex) { - } catch (FileException ex) { - } - } - } - if (config_file_str.length > 0) { break; } - } - struct _ConfContent { - string filename() { - return conf_filename; - } - string filetype() { - string _ft = ""; - if (content.match(rgx.yaml_config)) { - _ft = "yaml"; - } - return _ft; - } - string content() { - return config_file_str; - } - } - return _ConfContent(); - } -} -#+END_SRC - -**** 2. document make/config - -#+name: meta_config_file_hub -#+BEGIN_SRC d -static template readConfigDoc() { - import - doc_reform.meta.rgx; - <> - mixin DocReformRgxInit; - final auto readConfigDoc(M,E)(M _manifested, E _env) { - static auto rgx = Rgx(); - string config_file_str; - string conf_filename = "NONE"; - auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); - string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.dr_document_make; - foreach(conf_fn; [_conf_file_details.config_filename_document]) { - foreach(pth; possible_config_path_locations) { - auto conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; - conf_filename = conf_fn; - if (config_file_str.length > 0) { - break; - } - try { - if (exists(conf_file)) { - if (conf_file.getLinkAttributes.attrIsFile) { - config_file_str = conf_file.readText; - break; - } - } - } catch (ErrnoException ex) { - } catch (FileException ex) { - } - } - if (config_file_str.length > 0) { break; } - } - struct _ConfContent { - string filename() { - return conf_filename; - } - string content() { - return config_file_str; - } - string filetype() { - string _ft = ""; - if (content.match(rgx.yaml_config)) { - _ft = "yaml"; - } - return _ft; - } - } - return _ConfContent(); - } -} -#+END_SRC - -*** 1. YAML config files get - -#+name: meta_config_file_yaml -#+BEGIN_SRC d -static template configYAML() { - import dyaml; // - <> - YAMLDocument configYAML(string configuration, string conf_yaml_filename) { - Node _yaml_conf; - try { - _yaml_conf = Loader.fromString(configuration).load() - } catch(ErrnoException e) { - stderr.writeln("Yaml problem with content for ", conf_yaml_filename); - stderr.writeln(e.msg); - } - return _yaml_conf; - } -} -#+END_SRC - -*** 2. YAML config (config_local_site & dr_document_make) :file:config:hub: - -#+name: meta_config_file_hub -#+BEGIN_SRC d -static template configReadSiteYAML() { - <> - final YAMLDocument configReadSiteYAML(M,E)(M _manifested, E _env) { - string _configuration = configReadInSiteYAML!()(_manifested, _env); - auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); - string _conf_yaml_fn = _conf_file_details.config_filename_site; - YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); - return _yaml_conf; - } -} -static template configReadDocYAML() { - <> - final YAMLDocument configReadDocYAML(M,E)(M _manifested, E _env) { - string _configuration = configReadInDocYAML!()(_manifested, _env); - auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); - string _conf_yaml_fn = _conf_file_details.config_filename_document; - YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml_fn); - return _yaml_conf; - } -} -#+END_SRC - -* B. get _markup source_, read file :module:source_files: -** _module template_ (includes tuple) - -#+BEGIN_SRC d :tangle "../src/doc_reform/source/read_source_files.d" -/++ - module source_read_source_files;
- - open markup files
- - if master file scan for addional files to import/insert -+/ -module doc_reform.source.read_source_files; -static template DocReformRawMarkupContent() { - import - doc_reform.meta.rgx; - <> - mixin DocReformRgxInit; - static auto rgx = Rgx(); - string[] _images=[]; - auto _extract_images(S)(S content_block) { - string[] images_; - string _content_block = content_block.to!string; - if (auto m = _content_block.matchAll(rgx.image)) { - images_ ~= m.captures[1].to!string; - } - return images_; - } - auto rawsrc = RawMarkupContent(); - auto DocReformRawMarkupContent(O,Fn)(O _opt_action, Fn fn_src) { - auto _0_header_1_body_content_2_insert_filelist_tuple - = rawsrc.sourceContentSplitIntoHeaderAndBody(_opt_action, 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(O)(O _opt_action, in string source_txt_str, in string fn_src="") { - auto raw = MarkupRawUnit(); - string[] insert_file_list; - string[] images_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(_opt_action, sourcefile_body_content, fn_src); - static assert(!isTypeTuple!(tu)); - sourcefile_body_content = tu[0]; - insert_file_list = tu[1].dup; - images_list = tu[2].dup; - } else if (_opt_action.source || _opt_action.pod) { - auto ins = Inserts(); - auto tu - = ins.scan_master_src_for_insert_files_and_import_content(_opt_action, sourcefile_body_content, fn_src); - static assert(!isTypeTuple!(tu)); - images_list = tu[2].dup; - } - string header_type = ""; - if (header_raw.match(rgx.yaml_config)) { - header_type = "yaml"; - } - t = tuple( - header_raw, - sourcefile_body_content, - header_type, - insert_file_list, - images_list - ); - static assert(t.length==5); - return t; - } - } - struct MarkupRawUnit { - import std.file; - <> - <> - <> - <> - <> - <> - } - struct Inserts { - auto scan_subdoc_source(O)( - O _opt_action, - char[][] markup_sourcefile_insert_content, - string fn_src - ) { - mixin DocReformRgxInitFlags; - <> - foreach (line; markup_sourcefile_insert_content) { - <> - } // end src subdoc (inserts) loop - <> - } - auto scan_master_src_for_insert_files_and_import_content(O)( - O _opt_action, - char[][] sourcefile_body_content, - string fn_src - ) { - import std.algorithm; - mixin DocReformRgxInitFlags; - <> - foreach (line; sourcefile_body_content) { - <> - } // end src doc loop - <> - } - } -} -#+END_SRC - -** get markup source, read file :source:markup: -*** read file, source string [#A] :string: - -#+name: meta_markup_source_raw_read_file_source_string -#+BEGIN_SRC d -final private string readInMarkupSource(in char[] fn_src) { - enforce( - exists(fn_src)!=0, - "file not found: «" ~ - fn_src ~ "»" - ); - string source_txt_str; - try { - if (exists(fn_src)) { - if (fn_src.getLinkAttributes.attrIsFile) { - source_txt_str = fn_src.readText; - } else { - } - } - } catch (ErrnoException ex) { - } catch (UTFException ex) { - // Handle validation errors - } catch (FileException ex) { - // Handle errors - } - std.utf.validate(source_txt_str); - return source_txt_str; -} -#+END_SRC - -*** document header & content, array.length == 2 [#A] :array: - -here you split document header and body, an array.length == 2 -split is on first match of level A~ (which is required) - -#+name: meta_markup_source_raw_doc_header_and_content_split -#+BEGIN_SRC d -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; -} -#+END_SRC - -*** source line array :array: - -#+name: meta_markup_source_raw_source_line_array -#+BEGIN_SRC d -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; -} -#+END_SRC - -*** source content raw line array :array: -- used for regular .sst files; master .ssm files and; .ssi inserts -- regex is passed for relevant enforce match - -**** read in file - -#+name: meta_markup_source_raw_read_in_file -#+BEGIN_SRC d -auto markupSourceReadIn(in string fn_src) { - static auto rgx = Rgx(); - enforce( - fn_src.match(rgx.src_pth_sst_or_ssm), - "not a dr markup filename: «" ~ - fn_src ~ "»" - ); - auto source_txt_str = readInMarkupSource(fn_src); - return source_txt_str; -} -#+END_SRC - -**** tuple (a) header, (b) body content, (c) file insert list & (d) image list? - -- header -- body content -- file insert list -- [image list?] - -#+name: meta_markup_source_raw_tuple_of_header_and_body -#+BEGIN_SRC d -auto markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) { - string[] file_insert_list = []; - string[] images_list = []; - char[][] hc = header0Content1(source_txt_str); - char[] header = hc[0]; - char[] source_txt = hc[1]; - auto source_line_arr = markupSourceLineArray(source_txt); - string header_type = ""; - if (header.match(rgx.yaml_config)) { - header_type = "yaml"; - } - auto t = tuple( - header, - source_line_arr, - header_type, - file_insert_list, - images_list - ); - return t; -} -#+END_SRC - -**** get insert source line array - -#+name: meta_markup_source_raw_get_insert_source_line_array -#+BEGIN_SRC d -final char[][] getInsertMarkupSourceContentRawLineArray( - in char[] fn_src_insert, - Regex!(char) rgx_file -) { - enforce( - fn_src_insert.match(rgx_file), - "not a dr markup filename: «" ~ - fn_src_insert ~ "»" - ); - auto source_txt_str = readInMarkupSource(fn_src_insert); - auto source_line_arr = markupSourceLineArray(source_txt_str); - return source_line_arr; -} -#+END_SRC - -** get markup source, master file & inserts :masterfile:inserts: -[[./spine.org][spine]] [[./][org/]] - -*** scan inserts (sub-document) source :scan_insert_src: -**** scan subdoc source - -#+name: meta_inserts_scan -#+BEGIN_SRC d -char[][] contents_insert; -int[string] type1 = flags_type_init; -auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); -auto markup_src_file_path = fn_pth_full.captures[1]; -#+END_SRC - -**** loop insert (sub-document) - -#+name: meta_inserts_scan_loop -#+BEGIN_SRC d -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 (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) { - writeln(line); - writeln(fn_src_insert); - writeln( - " length contents insert array: ", - markup_sourcesubfile_insert_content.length - ); - } - if (_opt_action.source || _opt_action.pod) { - _images ~= _extract_images(markup_sourcesubfile_insert_content); - } - auto ins = Inserts(); - /+ - - 1. load file - - 2. read lines - - 3. scan lines - - a. if filename insert, and insert filename - - repeat 1 - - b. else - - add line to new array; - - build image list, search for any image files to add to image list - +/ -} else { - type1["header_make"] = 0; - type1["header_meta"] = 0; - contents_insert ~= line; // images to extract for image list? - if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(line); - if (_image_linelist.length > 0) { - _images ~= _image_linelist; - } - } -} -#+END_SRC - -**** post loop - -#+name: meta_inserts_scan_post -#+BEGIN_SRC d -auto t = tuple( - contents_insert, - _images -); -return t; -#+END_SRC - -*** scan document source :scan_src: -**** scan doc source - -#+name: meta_master_doc_scan_for_insert_filenames -#+BEGIN_SRC d -char[][] contents; -int[string] type = flags_type_init; -auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); -auto markup_src_file_path = fn_pth_full.captures[1]; -char[][] contents_insert; -string[] _images =[]; -string[] insert_file_list =[]; -#+END_SRC - -**** include inserts: _loop master_ scan for inserts (insert documents) - -#+name: meta_master_doc_scan_for_insert_filenames_loop -#+BEGIN_SRC d -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 ~= fn_src_insert.to!string; - auto raw = MarkupRawUnit(); - /+ TODO +/ - auto markup_sourcefile_insert_content - = raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); - debug(insert_file) { - writeln(line); - writeln(fn_src_insert); - writeln( - " length contents insert array: ", - markup_sourcefile_insert_content.length - ); - } - auto ins = Inserts(); - auto contents_insert_tu = ins.scan_subdoc_source( - _opt_action, - markup_sourcefile_insert_content, - fn_src_insert.to!string - ); - contents ~= contents_insert_tu[0]; // images to extract for image list? - if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(contents_insert_tu[0]); - if (_image_linelist.length > 0) { - _images ~= _image_linelist; - } - } - /+ - - 1. load file - - 2. read lines - - 3. scan lines - - a. if filename insert, and insert filename - - repeat 1 - - b. else - - add line to new array; - - build image list, search for any image files to add to image list - +/ -} else { - contents ~= line; - if (_opt_action.source || _opt_action.pod) { - auto _image_linelist = _extract_images(line); - if (_image_linelist.length > 0) { - _images ~= _image_linelist; - } - } -} -#+END_SRC - -**** post loop - -#+name: meta_master_doc_scan_for_insert_filenames_post -#+BEGIN_SRC d -string[] images = []; -foreach(i; uniq(_images.sort())) { - images ~= i; -} -debug(insert_file) { - writeln(__LINE__); - writeln(contents.length); -} -auto t = tuple( - contents, - insert_file_list, - images -); -return t; -#+END_SRC - -* __END__ -- cgit v1.2.3