Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32 lines
817 B
Plaintext
32 lines
817 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 blocks, tree-wide (via the transform layer). For
|
|
;; renaming a term throughout a document. Immutable; case-sensitive.
|
|
;;
|
|
;; 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"))))
|
|
|
|
(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))))))
|