defines a procedure used for looking up links by id in a document
This commit is contained in:
16
gmi.rkt
16
gmi.rkt
@@ -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)))
|
||||
|
Reference in New Issue
Block a user