Files
rose-ash/lib/content/find-replace.sx
giles 92c0c853a9
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
content: find-replace covers callout text + 2 tests (752/752)
fr-has-text? now treats callout as text-bearing, matching asText/stats/
summary. content/find-replace previously skipped callout bodies silently.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 11:10:25 +00:00

35 lines
913 B
Plaintext

;; content-on-sx — global find/replace across text-bearing blocks.
;;
;; Replaces every occurrence of `from` with `to` in the `text` field of
;; text / heading / code / quote / callout blocks, tree-wide (via the transform
;; layer). For renaming a term throughout a document. Immutable; case-sensitive.
;; (Same text-bearing set asText/stats/summary treat as content.)
;;
;; Requires (loaded by harness): block.sx, transform.sx (content/map-blocks).
(define
fr-in?
(fn
(x xs)
(cond
((= (len xs) 0) false)
((= (first xs) x) true)
(else (fr-in? x (rest xs))))))
(define
fr-has-text?
(fn
(b)
(fr-in? (blk-type b) (list "text" "heading" "code" "quote" "callout"))))
(define
content/find-replace
(fn
(doc from to)
(content/map-blocks
doc
fr-has-text?
(fn
(b)
(blk-set b "text" (replace (str (blk-get b "text")) from to))))))