Created
March 2, 2023 22:13
-
-
Save harrygallagher4/783d1e1fbdca840c9dec16742285cae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (get-renderers render-element render-elements) | |
`((#:document . | |
,(λ (doc) | |
`(article | |
,@(render-elements (document-body doc)) | |
,@(render-element `(footnotes '() ,@(document-footnotes doc)))))) | |
(#:fallback . ,(λ (tag att els children) `(,tag ,att ,@(children)))) | |
(link . | |
,(λ (att els children) | |
(match-let ((`((dest ,dest) (title ,title)) att)) | |
`(a ((href ,dest) ,@(if title `((title ,title)) '())) ,@(children))))) | |
(image . | |
,(λ (att els children) | |
(match-let ((`((src ,src) (title ,title) (desc ,desc)) att)) | |
`(img ((src ,src) | |
,@(if desc `((alt ,desc)) '()) | |
,@(if title `((title ,title)) '())))))) | |
(footnote-reference . | |
,(λ (att els children) | |
(match-let ((`((label ,label) (defn-num ,defn-num) (ref-num ,ref-num)) att)) | |
`(sup (a ((href ,(~a "#" (fn-def-anchor label))) | |
(id ,(fn-ref-anchor label ref-num))) | |
,(number->string defn-num)))))) | |
(footnote-definition . | |
,(λ (att els children*) | |
(match-let ((`((label ,label) (ref-count ,ref-count)) attrs) | |
(backrefs (make-backrefs ref-count)) | |
(children (children*))) | |
`(li ((id ,(fn-def-anchor label))) | |
,@(match children | |
((list blocks ... (list 'p inline ...)) | |
`(,@blocks (p ,@inline ,@backrefs))) | |
(_ (append children backrefs))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment