Join strings into one string

This commit is contained in:
Lassi Kortela 2024-11-08 22:56:15 +02:00
parent 0a1fda4a08
commit 1a86155662
1 changed files with 11 additions and 4 deletions

View File

@ -10,6 +10,13 @@
(cons (car list) new-list)) (cons (car list) new-list))
(cdr list))))) (cdr list)))))
(define (join-strings-into-one-string list)
(let loop ((result "") (tail list))
(cond ((null? tail) result)
((string? (car tail)) (loop (string-append result (car tail))
(cdr tail)))
(else (error "Expected all strings" list)))))
(define (vector-refs vec . indexes) (define (vector-refs vec . indexes)
(let loop ((obj vec) (indexes indexes)) (let loop ((obj vec) (indexes indexes))
(if (null? indexes) obj (if (null? indexes) obj
@ -40,7 +47,7 @@
((equal? type "Code") ((equal? type "Code")
`(code ,@(convert-many (cdr (contents-list))))) `(code ,@(convert-many (cdr (contents-list)))))
((equal? type "CodeBlock") ((equal? type "CodeBlock")
`(pre (@ (data-syntax ,@(join-adjacent-strings `(pre (@ (data-syntax ,(join-strings-into-one-string
(vector->list (vector->list
(vector-refs (contents) 0 1))))) (vector-refs (contents) 0 1)))))
,@(convert-many (cdr (contents-list))))) ,@(convert-many (cdr (contents-list)))))
@ -62,7 +69,7 @@
,(join-strings-into-one-string ,(join-strings-into-one-string
(vector->list (vector-ref (contents) 1))))))) (vector->list (vector-ref (contents) 1)))))))
((equal? type "Link") ((equal? type "Link")
`(a (@ (href ,(join-adjacent-strings `(a (@ (href ,(join-strings-into-one-string
(vector->list (vector-ref (contents) 2))))) (vector->list (vector-ref (contents) 2)))))
,@(convert-many (vector->list (vector-ref (contents) 1))))) ,@(convert-many (vector->list (vector-ref (contents) 1)))))
((equal? type "Plain") ((equal? type "Plain")