summaryrefslogtreecommitdiffhomepage
path: root/gleam/src
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-09-26 00:50:16 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-10-02 21:38:29 -0400
commit8fd585f659c5dfc7c822cb8b7d66d2c5f9e901a1 (patch)
treeda7d5e19a865627108e01f0a758a953c674cd94b /gleam/src
parenta third input form: the abstraction out of a pod archive (diff)
two fields the model was missing, found by writing an html writer
anchor_tags and heading_lev_anchor. Both are in the specification's property table and neither was read, so they went to the unknown counts and a writer over the library had no way to emit a link target. The cost was visible the moment an html writer existed: 154 of its internal links pointed at nothing, because a note reference points at the endnote's anchor and the endnote's anchor is an anchor_tag. heading_lev_anchor is the name a document's own cross references use, 1,854 of them in the reference collection. The .ssp carries them as repeated .anchor_tag and as .heading_lev_anchor; the database as the object_anchors child table and the heading_lev_anchor column. Both loaders read both now, the dump reports them, and the four-way agreement still holds: 36 of 36 each way. One thing to watch when adding a column to the database query: the read is by position, so a column inserted in the middle shifts every one after it. Adding heading_lev_anchor after segment_html_is broke all 36 documents until it moved to the end of the select. (assisted by Claude-Code)
Diffstat (limited to 'gleam/src')
-rw-r--r--gleam/src/ocda/dump.gleam6
-rw-r--r--gleam/src/ocda/load_db.gleam28
-rw-r--r--gleam/src/ocda/load_ssp.gleam8
-rw-r--r--gleam/src/ocda/model.gleam4
4 files changed, 44 insertions, 2 deletions
diff --git a/gleam/src/ocda/dump.gleam b/gleam/src/ocda/dump.gleam
index 1ab37a6..2b05751 100644
--- a/gleam/src/ocda/dump.gleam
+++ b/gleam/src/ocda/dump.gleam
@@ -165,6 +165,7 @@ fn object(
|> kv("segment_prev", obj.segment_prev)
|> kv("segment_next", obj.segment_next)
|> kv("anchor", obj.anchor)
+ |> kv("heading_lev_anchor", obj.heading_lev_anchor)
|> kn("table_cols", obj.table_cols)
|> kv("table_widths", obj.table_widths)
|> kv("table_aligns", obj.table_aligns)
@@ -174,6 +175,7 @@ fn object(
|> kv("heading_ancestors_text", obj.heading_ancestors_text)
|> kv("sha256", obj.sha256)
|> links(obj)
+ |> anchor_tags(obj)
|> images(obj)
|> text(obj)
}
@@ -182,6 +184,10 @@ fn links(acc: List(String), obj: Object) -> List(String) {
list.fold(obj.stow_link, acc, fn(lines, url) { kv(lines, "stow_link", url) })
}
+fn anchor_tags(acc: List(String), obj: Object) -> List(String) {
+ list.fold(obj.anchor_tags, acc, fn(lines, a) { kv(lines, "anchor_tag", a) })
+}
+
fn images(acc: List(String), obj: Object) -> List(String) {
list.fold(obj.images, acc, fn(lines, img) {
// the name last, because a filename may hold a space where none of the
diff --git a/gleam/src/ocda/load_db.gleam b/gleam/src/ocda/load_db.gleam
index bcd65d8..e919615 100644
--- a/gleam/src/ocda/load_db.gleam
+++ b/gleam/src/ocda/load_db.gleam
@@ -242,6 +242,7 @@ fn objects(
use sha256 <- decode.field(34, decode.string)
use text <- decode.field(35, decode.string)
use id <- decode.field(36, decode.int)
+ use hla <- decode.field(37, decode.string)
decode.success(#(
id,
Object(
@@ -259,6 +260,7 @@ fn objects(
segment_html_is: segment_html_is,
table_aligns: json_words(table_aligns),
stow_link: [],
+ anchor_tags: [],
parent_ocn: parent,
last_descendant_ocn: last_descendant,
children: json_ints(children),
@@ -277,6 +279,7 @@ fn objects(
segment_prev: segment_prev,
segment_next: segment_next,
anchor: anchor,
+ heading_lev_anchor: hla,
table_cols: table_cols,
table_widths: json_words(table_widths),
table_header: table_header != 0,
@@ -303,7 +306,12 @@ fn objects(
// the four repeatable properties of the text form are child tables
// here, one query each
let object =
- Object(..object, images: images(conn, id), stow_link: links(conn, id))
+ Object(
+ ..object,
+ images: images(conn, id),
+ stow_link: links(conn, id),
+ anchor_tags: anchors(conn, id),
+ )
case model.is_section(object.section) {
False -> acc
True ->
@@ -337,7 +345,7 @@ fn object_sql(doc_id: Int) -> String {
coalesce(table_aligns,''), coalesce(table_header,0),
coalesce(code_linenumbers,0),
coalesce(heading_ancestors_text,''), coalesce(sha256,''),
- coalesce(text,''), id
+ coalesce(text,''), id, coalesce(heading_lev_anchor,'')
from objects where doc_id = " <> int.to_string(doc_id) <> "
order by case section
when 'head' then 1 when 'toc' then 2 when 'body' then 3
@@ -393,6 +401,22 @@ fn links(conn: sqlight.Connection, object_id: Int) -> List(String) {
|> result.unwrap([])
}
+fn anchors(conn: sqlight.Connection, object_id: Int) -> List(String) {
+ let d = {
+ use anchor <- decode.field(0, decode.string)
+ decode.success(anchor)
+ }
+ sqlight.query(
+ "select anchor from object_anchors where object_id = "
+ <> int.to_string(object_id)
+ <> " order by seq",
+ on: conn,
+ with: [],
+ expecting: d,
+ )
+ |> result.unwrap([])
+}
+
fn one(conn: sqlight.Connection, sql: String) -> String {
let d = {
use v <- decode.field(0, decode.string)
diff --git a/gleam/src/ocda/load_ssp.gleam b/gleam/src/ocda/load_ssp.gleam
index 6dcc38a..83af6e2 100644
--- a/gleam/src/ocda/load_ssp.gleam
+++ b/gleam/src/ocda/load_ssp.gleam
@@ -267,6 +267,10 @@ fn apply_property(
Object(..object, stow_link: list.append(object.stow_link, [value])),
True,
)
+ "anchor_tag" -> #(
+ Object(..object, anchor_tags: list.append(object.anchor_tags, [value])),
+ True,
+ )
"parent" -> #(Object(..object, parent_ocn: parse_int(value)), True)
"last_descendant" -> #(
Object(..object, last_descendant_ocn: parse_int(value)),
@@ -295,6 +299,10 @@ fn apply_property(
"segment_prev" -> #(Object(..object, segment_prev: value), True)
"segment_next" -> #(Object(..object, segment_next: value), True)
"anchor" -> #(Object(..object, anchor: value), True)
+ "heading_lev_anchor" -> #(
+ Object(..object, heading_lev_anchor: value),
+ True,
+ )
"table_cols" -> #(Object(..object, table_cols: parse_int(value)), True)
"table_widths" -> #(Object(..object, table_widths: value), True)
"table_header" -> #(Object(..object, table_header: value == "true"), True)
diff --git a/gleam/src/ocda/model.gleam b/gleam/src/ocda/model.gleam
index 20d7fba..a45cf6e 100644
--- a/gleam/src/ocda/model.gleam
+++ b/gleam/src/ocda/model.gleam
@@ -87,6 +87,7 @@ pub type Object {
segment_html_is: String,
table_aligns: String,
stow_link: List(String),
+ anchor_tags: List(String),
parent_ocn: Int,
last_descendant_ocn: Int,
children: List(Int),
@@ -105,6 +106,7 @@ pub type Object {
segment_prev: String,
segment_next: String,
anchor: String,
+ heading_lev_anchor: String,
table_cols: Int,
table_widths: String,
table_header: Bool,
@@ -130,6 +132,7 @@ pub fn new_object() -> Object {
segment_html_is: "",
table_aligns: "",
stow_link: [],
+ anchor_tags: [],
parent_ocn: 0,
last_descendant_ocn: 0,
children: [],
@@ -148,6 +151,7 @@ pub fn new_object() -> Object {
segment_prev: "",
segment_next: "",
anchor: "",
+ heading_lev_anchor: "",
table_cols: 0,
table_widths: "",
table_header: False,