reverse document and preformatted structures at end of parsing of each so that the document structure is in logical order

This commit is contained in:
2025-09-01 20:41:22 -07:00
parent 75d833949c
commit 4a08e57d3f

View File

@@ -26,7 +26,8 @@
(define (iter document lines state)
;; when there are no more lines, we have finished parsing.
(if (empty? lines)
document
;; consing inherently makes everything backwards
(reverse document)
;; otherwise, we have a state machine to traverse.
(cond
@@ -35,7 +36,13 @@
(or (empty? (cdr lines))
(string-prefix? (car lines) "```")))
(iter document
;; also hard to follow. at this point:
;; 1. the car of the document is necessarily a preformatted block
;; and the contents of that block are backwards
;; 2. take those contents, reverse them, append them to the
;; cdr of the document
(iter (cons (preformatted (reverse (preformatted-str (car document))))
document)
(cdr lines)
'normal)]