(local fennel (require :fennel)) (fn _G.pp [x] (print (fennel.view x))) (var footnote-counter 1) (fn render-contents [contents] (var rendered "
")
(each [_ line (ipairs contents)]
(_G.pp line)
(match (. line :type)
"raw-text" (set rendered (.. rendered line.text "\n"))
"Italics" (set rendered (.. rendered "" line.text "\n"))
"Bold" (set rendered (.. rendered "" line.text "\n"))
"Strikethrough" (set rendered (.. rendered "" line.text "\n"))
"Monospace" (set rendered (.. rendered "" line.text "
\n"))
"Link" (set rendered (.. rendered "" line.title "\n"))
"Footnote-Link" (do
(set rendered (.. rendered "\n[" (tostring footnote-counter) "]\n\n"))
(set footnote-counter (+ footnote-counter 1)))))
(.. rendered "
\n" contents-render "\n"))) :Paragraph (fn render-paragraph [{: contents}] (render-contents contents)) ; Contents render handles the
tag?
:Image (fn render-image [{: link : contents}]
(.. "")) ; TODO this fucks up the alt tag
; Tags are a type of metadata
:Tag (fn metadata-tag [{: tags} metadata]
(if (= metadata.tags nil)
(tset metadata "tags" [tags])
(table.insert metadata.tags tags))
metadata)
:Metadata (fn metadata [{: key : val} metadata]
(if (= metadata.key nil)
(tset metadata key [val])
(table.insert metadata.key val))
metadata)
; Not sure what to do about code either
; Need to look into pygments or whatever see how that works
; Or find some sort of minimal js solution?
; Not really sure
:Code (fn code [{: codehint : contents}]
(.. "\n" contents "
\n"))
; Each footnote gets an incremental ID
; the contents parser will link to the appropriate footnote
; Don't forget to link to the ref (back link)
; See seirdy's footnotes for an example
; https://seirdy.one/meta/site-design/#fn:1
:Footnote (fn footnotes [{: elements}]
(var count 1)
(var rendered "