summaryrefslogtreecommitdiff
path: root/jakob/utils/sxml.scm
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2026-02-13 16:36:33 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2026-02-13 16:36:33 -0500
commit8fa54d5ac98d95016f0c3eaa9fbc4f042294705d (patch)
treec8bfac4a9c3321f9b01acbb339dfeacac28e42e8 /jakob/utils/sxml.scm
parent9df8cb9cfa56f694ae10cfc0b9e9fd4427cc3c72 (diff)
Various site updates
Diffstat (limited to 'jakob/utils/sxml.scm')
-rw-r--r--jakob/utils/sxml.scm40
1 files changed, 39 insertions, 1 deletions
diff --git a/jakob/utils/sxml.scm b/jakob/utils/sxml.scm
index 0fc34d2..5ab08a9 100644
--- a/jakob/utils/sxml.scm
+++ b/jakob/utils/sxml.scm
@@ -23,7 +23,8 @@
script
sanitize-subtree
- rewrite-absolute-urls-as-relative))
+ rewrite-absolute-urls-as-relative
+ flatten-section-headings))
;;;
@@ -89,3 +90,40 @@ sanitize the resultant subtree."
((xs ...)
(map rewrite-absolute-urls-as-relative xs))
(elem elem)))
+
+(define (flatten-section-headings tree)
+ """Flattens extraneous sections output by Org-mode
+
+This function traverses a SXML tree and removes the outermost `<div>`
+elements that represent Org-mode section headings.
+
+Args:
+ tree: A SXML tree.
+
+Returns:
+ A SXML tree with the outermost Org section heading `<div>` elements
+removed and their contents flattened.
+ """
+ (define (flatten-section-headings-inner tree)
+ (define (is-org-section form)
+ (match form
+ ((or ('div ('@ ('id id) ('class _))
+ rest ...)
+ ('div ('@ ('id id))
+ rest ...)
+ ('div ('@ ('role "doc-footnote") ('class id))
+ rest ...))
+ (or (string=? "footpara" id)
+ (string-prefix? "text-footnotes" id)
+ (string-prefix? "outline-container-org" id)
+ (string-prefix? "text-org" id)))
+ (_ #f)))
+ (match tree
+ ((? is-org-section
+ ('div ('@ _ ...)
+ rest ...))
+ (append-map flatten-section-headings-inner rest))
+ ((xs ...)
+ (list (append-map flatten-section-headings-inner xs)))
+ (elem (list elem))))
+ (first (flatten-section-headings-inner tree)))