aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/ocda/abstraction/ssp.d
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-09-07 22:30:03 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-09-09 17:45:07 -0400
commitda575bf8a80cc2900bd5984718485cdacca0f527 (patch)
treecaf36b04621a87d6f063914bd2a62340a11d401c /src/sisudoc/ocda/abstraction/ssp.d
parentocda: the eight slot arrays are fixed length (diff)
ocda: clean heading text used for navigation
heading text used for navigation is normalised, and | escaped (assisted by Claude-Code)
Diffstat (limited to 'src/sisudoc/ocda/abstraction/ssp.d')
-rw-r--r--src/sisudoc/ocda/abstraction/ssp.d49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/sisudoc/ocda/abstraction/ssp.d b/src/sisudoc/ocda/abstraction/ssp.d
index 181e785..6aa55c2 100644
--- a/src/sisudoc/ocda/abstraction/ssp.d
+++ b/src/sisudoc/ocda/abstraction/ssp.d
@@ -50,6 +50,48 @@
module sisudoc.ocda.abstraction.ssp;
@safe:
/+ ↓ write document abstraction as human-readable .ssp text file +/
+/+ ↓ escaping for values that are folded onto one line
+
+ a .ssp property value runs to the end of its line, and
+ .heading_ancestors_text joins its eight slots with "|", so a slot that
+ itself contains "|", a backslash or a line break has to be escaped or
+ the value cannot be read back. the pair here is the whole of the rule,
+ used by the writer and by the reader.
++/
+template sspEscape() {
+ import std.array : replace;
+ string sspEscapeValue(string _s) {
+ return _s
+ .replace("\\", "\\\\")
+ .replace("|", "\\|")
+ .replace("\n", "\\n")
+ .replace("\r", "\\r");
+ }
+ string[] sspUnescapeSplit(string _s) {
+ string[] _out;
+ string _cur;
+ bool _esc;
+ foreach (c; _s) {
+ if (_esc) {
+ switch (c) {
+ case 'n': _cur ~= '\n'; break;
+ case 'r': _cur ~= '\r'; break;
+ default: _cur ~= c; break; // covers \\ and \|
+ }
+ _esc = false;
+ } else if (c == '\\') {
+ _esc = true;
+ } else if (c == '|') {
+ _out ~= _cur;
+ _cur = "";
+ } else {
+ _cur ~= c;
+ }
+ }
+ _out ~= _cur;
+ return _out;
+ }
+}
/+ ↓ one object record: the single definition of what an object looks
like in a .ssp file. the writer emits with it, and the reader is
checked against it by round trip, so the two cannot drift
@@ -60,6 +102,7 @@ template sspObjectRecord() {
import std.stdio;
import std.string;
import std.array;
+ mixin sspEscape;
string[] sspObjectRecord(O)(O obj, string section, bool _vox = false) {
string[] output;
/+ ↓ object declaration line. a heading carries its identifier here,
@@ -328,7 +371,11 @@ template sspObjectRecord() {
if (h.length > 0) { has_hat = true; break; }
}
if (has_hat) {
- output ~= ".heading_ancestors_text: " ~ obj.tags.heading_ancestors_text.join("|");
+ string[] _hat;
+ foreach (h; obj.tags.heading_ancestors_text) {
+ _hat ~= sspEscapeValue(h.to!string);
+ }
+ output ~= ".heading_ancestors_text: " ~ _hat.join("|");
}
}
/+ ↓ lev4 subtoc +/