(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 "

")) (local render-grammar {:Header (fn render-header [{: contents : size}] (let [header-type (tostring size) header (.. "h" header-type) contents-render (render-contents contents)] (.. "<" header ">\n" contents-render "\n"))) :List (fn render-list [{: elements}] (var list-str "\n")) (set depth (- depth 1)) (_G.pp (.. "depth: " depth))) (set list-str (.. list-str "\n")) ; Close the first one list-str) :Quote (fn render-quote [{: contents}] (let [contents-render (render-contents contents)] (.. "
\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 "

    \n") (each [_ element (ipairs elements)] (let [contents-render (render-contents element.contents)] (set rendered (.. rendered "
  1. \n")) (set rendered (.. rendered contents-render "
  2. \n")) (set rendered (.. rendered "Back\n")) (set count (+ count 1)))) (.. rendered "
\n"))}) (fn render [blocks grammar] (var rendered "") (var metadata {}) (each [_ section (ipairs blocks)] (each [_ block (ipairs section)] (let [rule-set (. grammar (. block :type))] (if (. block :is-metadata) (set metadata (rule-set block metadata)) ; Handle metadata, TODO this doesn't handle sections for metadata semantics (set rendered (.. rendered (rule-set block)))))) ;(_G.pp rendered))) ; Write to the rendered string (set rendered (.. rendered "\n\n"))) ; TODO Section "rendering" ; Should each section be returned seperately? ; Then we can add metadata to it easily. ; Final section (values rendered metadata)) {: render : render-grammar}