From da575bf8a80cc2900bd5984718485cdacca0f527 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 7 Sep 2026 22:30:03 -0400 Subject: ocda: clean heading text used for navigation heading text used for navigation is normalised, and | escaped (assisted by Claude-Code) --- src/sisudoc/ocda/abstraction/ssp.d | 49 +++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/sisudoc/ocda/abstraction/ssp.d') 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 +/ -- cgit v1.2.3