aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2025-10-14 09:02:41 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2025-10-14 10:54:55 -0400
commit7864505c3d3030c7a32d0eee360528d0d504f747 (patch)
treed5fd182a02fdc3a4c44526661bddab508ff60629
parentabstraction metainfo, provide endnote parent ocn (diff)
text output, improve various (including no-ocn)HEADmain
- revisit links (fix later)
-rw-r--r--flake.lock6
-rw-r--r--org/default_regex.org1
-rw-r--r--org/out_text.org65
-rw-r--r--org/spine.org4
-rw-r--r--src/sisudoc/io_out/rgx.d1
-rw-r--r--src/sisudoc/io_out/text.d65
-rw-r--r--src/sisudoc/meta/rgx.d1
-rwxr-xr-xsrc/sisudoc/spine.d4
8 files changed, 72 insertions, 75 deletions
diff --git a/flake.lock b/flake.lock
index 62540c3..0754bc8 100644
--- a/flake.lock
+++ b/flake.lock
@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
- "lastModified": 1760256791,
- "narHash": "sha256-uTpzDHRASEDeFUuToWSQ46Re8beXyG9dx4W36FQa0/c=",
+ "lastModified": 1760349414,
+ "narHash": "sha256-W4Ri1ZwYuNcBzqQQa7NnWfrv0wHMo7rduTWjIeU9dZk=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "832e3b6db48508ae436c2c7bfc0cf914eac6938e",
+ "rev": "c12c63cd6c5eb34c7b4c3076c6a99e00fcab86ec",
"type": "github"
},
"original": {
diff --git a/org/default_regex.org b/org/default_regex.org
index 1470c76..1c0ca2f 100644
--- a/org/default_regex.org
+++ b/org/default_regex.org
@@ -634,6 +634,7 @@ static inline_link_hash = ctRegex!(`┥(?P<text>.+?)┝
static inline_link_seg_and_hash = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>(?P<seg>[^/#├]*)#(?P<hash>.+?))├`, "mg");
static inline_link_clean = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
static inline_link_toc_to_backmatter = ctRegex!(`┤#(?P<link>endnotes|bibliography|bookindex|glossary|blurb)├`, "mg");
+static find_bookindex_ocn_link_and_comma = ctRegex!(`[, ]*┥.+?┝┤#?\S+?├`, "mg");
static url = ctRegex!(`https?://`, "mg");
static uri = ctRegex!(`(?:https?|git)://`, "mg");
static uri_identify_components = ctRegex!(`(?P<type>(?:https?|git)://)(?P<path>\S+?/)(?P<file>[^/]+)$`, "mg");
diff --git a/org/out_text.org b/org/out_text.org
index 7a990a1..02d6294 100644
--- a/org/out_text.org
+++ b/org/out_text.org
@@ -212,8 +212,7 @@ template munge() {
string newlines = "\n\n";
template special_characters_and_font_face() {
string code(string _txt){
- _txt = _txt
- .replaceAll(rgx.nbsp_char, " ");
+ _txt = _txt.replaceAll(rgx.nbsp_char, " ");
return _txt;
}
string general(string _txt) {
@@ -235,21 +234,16 @@ template munge() {
return _txt;
}
string links_and_images(string _txt){
- if (_txt.matchFirst(rgx.inline_link)) {
+ if (_txt.match(rgx.inline_link)) {
foreach (m; _txt.matchAll(rgx.inline_link)) {
- if (m.captures[3] == "0") {
- _txt = _txt
- .replaceFirst(rgx.inline_link, (m.captures[1]));
- } else {
- _txt = _txt
- .replaceFirst(rgx.inline_link, (m.captures[1] ~ " ≫" ~ m.captures[3]));
- }
+ _txt = (m.captures[3] == "0")
+ ? _txt.replaceFirst(rgx.inline_link, (m.captures[1]))
+ : _txt.replaceFirst(rgx.inline_link, (m.captures[1] ~ " ≫" ~ m.captures[3]));
}
}
if (_txt.matchFirst(rgx.inline_image)) {
foreach (m; _txt.matchAll(rgx.inline_image)) {
- _txt = _txt
- .replaceFirst(rgx.inline_image, (m.captures[3]));
+ _txt = _txt.replaceFirst(rgx.inline_image, (m.captures[3]));
}
}
return _txt;
@@ -260,28 +254,22 @@ template munge() {
string _notes;
string _ocn;
string general_munge;
- if (obj.metainfo.ocn == 0 || doc_matters.opt.action.ocn_off) {
- _ocn = "";
- } else {
- _ocn = "「" ~ obj.metainfo.ocn.to!string ~ "」" ~ newline;
- }
+ _ocn = (obj.metainfo.ocn == 0 || doc_matters.opt.action.ocn_off)
+ ? "" : "「" ~ obj.metainfo.ocn.to!string ~ "」" ~ newline;
if (_txt.matchFirst(rgx.inline_notes_al_gen)) {
foreach (m; _txt.matchAll(rgx.inline_notes_al_regular_number_note)) {
- _notes ~= newlines ~ m["num"] ~ ". " ~ m["note"];
+ _notes ~= newlines ~ m["num"] ~ ". "
+ ~ special_characters_and_font_face!().general(m["note"].replaceAll(rgx.inline_link, ("$1")));
}
}
_txt = _txt.replaceAll(rgx.inline_notes_al_regular_number_note, "[$1]");
- if (obj.metainfo.is_a == "code") {
- _txt = special_characters_and_font_face!().code(_txt);
- } else {
- _txt = special_characters_and_font_face!().general(_txt);
- }
+ _txt = (obj.metainfo.is_a == "code")
+ ? special_characters_and_font_face!().code(_txt)
+ : special_characters_and_font_face!().general(_txt);
_txt = special_characters_and_font_face!().links_and_images(_txt);
- if (obj.metainfo.is_a == "heading") {
- general_munge = newline ~ _txt ~ _notes ~ newline ~ _ocn ~ newline;
- } else {
- general_munge = _txt ~ _notes ~ newline ~ _ocn ~ newline;
- }
+ general_munge = (obj.metainfo.is_a == "heading")
+ ? newline ~ _txt ~ _notes ~ newline ~ _ocn ~ newline
+ : _txt ~ _notes ~ newline ~ _ocn ~ newline;
return general_munge;
}
string toc(O,M)(O obj, M doc_matters) {
@@ -310,7 +298,9 @@ template munge() {
default:
break;
}
- _txt = _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1 ≫ $3"));
+ _txt = (doc_matters.opt.action.ocn_off)
+ ? _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1"))
+ : _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1 ≫ $3"));
return _txt ~ newline;
}
string heading(O,M)(O obj, M doc_matters) {
@@ -454,19 +444,24 @@ template munge() {
string _ocn;
_ocn = "「" ~ obj.metainfo.ocn.to!string ~ "」";
string _txt = obj.text;
+ string _parent_ocn;
_txt = _txt
- .replaceAll(rgx.inline_link, ("$1")) // consider
- .replaceFirst(rgx.inline_superscript, ("$1"));
- _txt = special_characters_and_font_face!().general(_txt) ~ " ≫" ~ obj.metainfo.parent_ocn.to!string;
+ .replaceAll(rgx.inline_link, ("$1")) // consider
+ .replaceFirst(rgx.inline_superscript, ("$1"));
+ _parent_ocn = (obj.metainfo.parent_ocn == 0 || doc_matters.opt.action.ocn_off)
+ ? "" : " ≫" ~ obj.metainfo.parent_ocn.to!string;
+ _txt = special_characters_and_font_face!().general(_txt) ~ _parent_ocn;
return _txt ~ newlines;
}
string bookindex(O,M)(O obj, M doc_matters) {
// puts(obj.metainfo.is_a);
// return obj.metainfo.is_a;
string _txt = obj.text;
- _txt = _txt
- .replaceAll(rgx.inline_link, ("≫$1"))
- .replaceAll(regex("\\s*\\\\"), "");
+ _txt = (doc_matters.opt.action.ocn_off)
+ ? _txt.replaceAll(rgx.find_bookindex_ocn_link_and_comma, "")
+ .replaceAll(regex("\\s*\\\\"), "")
+ : _txt.replaceAll(rgx.inline_link, ("≫$1"))
+ .replaceAll(regex("\\s*\\\\"), "");
_txt = special_characters_and_font_face!().general(_txt);
return _txt ~ newlines;
}
diff --git a/org/spine.org b/org/spine.org
index 8f0af14..9971dc2 100644
--- a/org/spine.org
+++ b/org/spine.org
@@ -321,6 +321,7 @@ bool[string] opts = [
"light" : false,
"manifest" : false,
"hide-ocn" : false,
+ "no-ocn" : false,
"ocn-off" : false,
"odf" : false,
"odt" : false,
@@ -444,6 +445,7 @@ auto helpInfo = getopt(args,
"latex-header-sty", "latex document header sty files", &opts["latex-header-sty"],
"light", "default light theme", &opts["light"],
"manifest", "process manifest output", &opts["manifest"],
+ "no-ocn", "object cite numbers", &opts["no-ocn"],
"ocn-off", "object cite numbers", &opts["ocn-off"],
"odf", "open document format text (--odt)", &opts["odf"],
"odt", "open document format text", &opts["odt"],
@@ -675,7 +677,7 @@ struct OptActions {
return opts["hide-ocn"];
}
@trusted bool ocn_off() {
- return opts["ocn-off"];
+ return ((opts["ocn-off"]) || (opts["no-ocn"])) ? true : false;
}
@trusted bool pod() {
return opts["pod"];
diff --git a/src/sisudoc/io_out/rgx.d b/src/sisudoc/io_out/rgx.d
index 1327854..f54deda 100644
--- a/src/sisudoc/io_out/rgx.d
+++ b/src/sisudoc/io_out/rgx.d
@@ -110,6 +110,7 @@ static template spineRgxOut() {
static inline_link_seg_and_hash = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>(?P<seg>[^/#├]*)#(?P<hash>.+?))├`, "mg");
static inline_link_clean = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
static inline_link_toc_to_backmatter = ctRegex!(`┤#(?P<link>endnotes|bibliography|bookindex|glossary|blurb)├`, "mg");
+ static find_bookindex_ocn_link_and_comma = ctRegex!(`[, ]*┥.+?┝┤#?\S+?├`, "mg");
static url = ctRegex!(`https?://`, "mg");
static uri = ctRegex!(`(?:https?|git)://`, "mg");
static uri_identify_components = ctRegex!(`(?P<type>(?:https?|git)://)(?P<path>\S+?/)(?P<file>[^/]+)$`, "mg");
diff --git a/src/sisudoc/io_out/text.d b/src/sisudoc/io_out/text.d
index ce37310..9401bae 100644
--- a/src/sisudoc/io_out/text.d
+++ b/src/sisudoc/io_out/text.d
@@ -66,8 +66,7 @@ template outputText() {
string newlines = "\n\n";
template special_characters_and_font_face() {
string code(string _txt){
- _txt = _txt
- .replaceAll(rgx.nbsp_char, " ");
+ _txt = _txt.replaceAll(rgx.nbsp_char, " ");
return _txt;
}
string general(string _txt) {
@@ -89,21 +88,16 @@ template outputText() {
return _txt;
}
string links_and_images(string _txt){
- if (_txt.matchFirst(rgx.inline_link)) {
+ if (_txt.match(rgx.inline_link)) {
foreach (m; _txt.matchAll(rgx.inline_link)) {
- if (m.captures[3] == "0") {
- _txt = _txt
- .replaceFirst(rgx.inline_link, (m.captures[1]));
- } else {
- _txt = _txt
- .replaceFirst(rgx.inline_link, (m.captures[1] ~ " ≫" ~ m.captures[3]));
- }
+ _txt = (m.captures[3] == "0")
+ ? _txt.replaceFirst(rgx.inline_link, (m.captures[1]))
+ : _txt.replaceFirst(rgx.inline_link, (m.captures[1] ~ " ≫" ~ m.captures[3]));
}
}
if (_txt.matchFirst(rgx.inline_image)) {
foreach (m; _txt.matchAll(rgx.inline_image)) {
- _txt = _txt
- .replaceFirst(rgx.inline_image, (m.captures[3]));
+ _txt = _txt.replaceFirst(rgx.inline_image, (m.captures[3]));
}
}
return _txt;
@@ -114,28 +108,22 @@ template outputText() {
string _notes;
string _ocn;
string general_munge;
- if (obj.metainfo.ocn == 0 || doc_matters.opt.action.ocn_off) {
- _ocn = "";
- } else {
- _ocn = "「" ~ obj.metainfo.ocn.to!string ~ "」" ~ newline;
- }
+ _ocn = (obj.metainfo.ocn == 0 || doc_matters.opt.action.ocn_off)
+ ? "" : "「" ~ obj.metainfo.ocn.to!string ~ "」" ~ newline;
if (_txt.matchFirst(rgx.inline_notes_al_gen)) {
foreach (m; _txt.matchAll(rgx.inline_notes_al_regular_number_note)) {
- _notes ~= newlines ~ m["num"] ~ ". " ~ m["note"];
+ _notes ~= newlines ~ m["num"] ~ ". "
+ ~ special_characters_and_font_face!().general(m["note"].replaceAll(rgx.inline_link, ("$1")));
}
}
_txt = _txt.replaceAll(rgx.inline_notes_al_regular_number_note, "[$1]");
- if (obj.metainfo.is_a == "code") {
- _txt = special_characters_and_font_face!().code(_txt);
- } else {
- _txt = special_characters_and_font_face!().general(_txt);
- }
+ _txt = (obj.metainfo.is_a == "code")
+ ? special_characters_and_font_face!().code(_txt)
+ : special_characters_and_font_face!().general(_txt);
_txt = special_characters_and_font_face!().links_and_images(_txt);
- if (obj.metainfo.is_a == "heading") {
- general_munge = newline ~ _txt ~ _notes ~ newline ~ _ocn ~ newline;
- } else {
- general_munge = _txt ~ _notes ~ newline ~ _ocn ~ newline;
- }
+ general_munge = (obj.metainfo.is_a == "heading")
+ ? newline ~ _txt ~ _notes ~ newline ~ _ocn ~ newline
+ : _txt ~ _notes ~ newline ~ _ocn ~ newline;
return general_munge;
}
string toc(O,M)(O obj, M doc_matters) {
@@ -164,7 +152,9 @@ template outputText() {
default:
break;
}
- _txt = _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1 ≫ $3"));
+ _txt = (doc_matters.opt.action.ocn_off)
+ ? _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1"))
+ : _txt.replaceAll(rgx.inline_link, (_spaces ~ "$1 ≫ $3"));
return _txt ~ newline;
}
string heading(O,M)(O obj, M doc_matters) {
@@ -308,19 +298,24 @@ template outputText() {
string _ocn;
_ocn = "「" ~ obj.metainfo.ocn.to!string ~ "」";
string _txt = obj.text;
+ string _parent_ocn;
_txt = _txt
- .replaceAll(rgx.inline_link, ("$1")) // consider
- .replaceFirst(rgx.inline_superscript, ("$1"));
- _txt = special_characters_and_font_face!().general(_txt) ~ " ≫" ~ obj.metainfo.parent_ocn.to!string;
+ .replaceAll(rgx.inline_link, ("$1")) // consider
+ .replaceFirst(rgx.inline_superscript, ("$1"));
+ _parent_ocn = (obj.metainfo.parent_ocn == 0 || doc_matters.opt.action.ocn_off)
+ ? "" : " ≫" ~ obj.metainfo.parent_ocn.to!string;
+ _txt = special_characters_and_font_face!().general(_txt) ~ _parent_ocn;
return _txt ~ newlines;
}
string bookindex(O,M)(O obj, M doc_matters) {
// puts(obj.metainfo.is_a);
// return obj.metainfo.is_a;
string _txt = obj.text;
- _txt = _txt
- .replaceAll(rgx.inline_link, ("≫$1"))
- .replaceAll(regex("\\s*\\\\"), "");
+ _txt = (doc_matters.opt.action.ocn_off)
+ ? _txt.replaceAll(rgx.find_bookindex_ocn_link_and_comma, "")
+ .replaceAll(regex("\\s*\\\\"), "")
+ : _txt.replaceAll(rgx.inline_link, ("≫$1"))
+ .replaceAll(regex("\\s*\\\\"), "");
_txt = special_characters_and_font_face!().general(_txt);
return _txt ~ newlines;
}
diff --git a/src/sisudoc/meta/rgx.d b/src/sisudoc/meta/rgx.d
index da48658..86ca40c 100644
--- a/src/sisudoc/meta/rgx.d
+++ b/src/sisudoc/meta/rgx.d
@@ -251,6 +251,7 @@ static template spineRgxIn() {
static inline_link_seg_and_hash = ctRegex!(`┥(?P<text>.+?)┝┤(?P<link>(?P<seg>[^/#├]*)#(?P<hash>.+?))├`, "mg");
static inline_link_clean = ctRegex!(`┤(?:.+?)├|[┥┝]`, "mg");
static inline_link_toc_to_backmatter = ctRegex!(`┤#(?P<link>endnotes|bibliography|bookindex|glossary|blurb)├`, "mg");
+ static find_bookindex_ocn_link_and_comma = ctRegex!(`[, ]*┥.+?┝┤#?\S+?├`, "mg");
static url = ctRegex!(`https?://`, "mg");
static uri = ctRegex!(`(?:https?|git)://`, "mg");
static uri_identify_components = ctRegex!(`(?P<type>(?:https?|git)://)(?P<path>\S+?/)(?P<file>[^/]+)$`, "mg");
diff --git a/src/sisudoc/spine.d b/src/sisudoc/spine.d
index 82138f7..f53fc09 100755
--- a/src/sisudoc/spine.d
+++ b/src/sisudoc/spine.d
@@ -154,6 +154,7 @@ string program_name = "spine";
"light" : false,
"manifest" : false,
"hide-ocn" : false,
+ "no-ocn" : false,
"ocn-off" : false,
"odf" : false,
"odt" : false,
@@ -263,6 +264,7 @@ string program_name = "spine";
"latex-header-sty", "latex document header sty files", &opts["latex-header-sty"],
"light", "default light theme", &opts["light"],
"manifest", "process manifest output", &opts["manifest"],
+ "no-ocn", "object cite numbers", &opts["no-ocn"],
"ocn-off", "object cite numbers", &opts["ocn-off"],
"odf", "open document format text (--odt)", &opts["odf"],
"odt", "open document format text", &opts["odt"],
@@ -487,7 +489,7 @@ string program_name = "spine";
return opts["hide-ocn"];
}
@trusted bool ocn_off() {
- return opts["ocn-off"];
+ return ((opts["ocn-off"]) || (opts["no-ocn"])) ? true : false;
}
@trusted bool pod() {
return opts["pod"];