defines a procedure used for looking up links by id in a document

This commit is contained in:
2025-09-04 15:09:50 -07:00
parent 724dc95086
commit e3590502a9

16
gmi.rkt
View File

@@ -3,6 +3,7 @@
(provide (contract-out
[render (-> document? void?)]
[parse (-> (listof string?) document?)]
[match-link (-> document? integer? (or/c string? #f))]
[struct document ((structure (listof (or/c text? link? pre?))))]))
;; a gemtext document is represented as a list of structs, a struct
@@ -147,3 +148,18 @@
[(link? line)
(printf "[~a] ~a\n" (link-ord line) (link-str line))]))
(document-structure document)))
(define (match-link document id)
(define (iter next-structure)
(cond
[(and (link? (car next-structure))
(= (link-ord (car next-structure)) id))
(link-url (car next-structure))]
[(empty? (cdr next-structure))
#f]
[else
(iter (cdr next-structure))]))
(iter (document-structure document)))