From e3590502a97922309d801dfcef3bf5a670c952dd Mon Sep 17 00:00:00 2001 From: w6vvn Date: Thu, 4 Sep 2025 15:09:50 -0700 Subject: [PATCH] defines a procedure used for looking up links by id in a document --- gmi.rkt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gmi.rkt b/gmi.rkt index 919c5f8..198eb17 100644 --- a/gmi.rkt +++ b/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)))