{:title "EDN Frontmatter Example"
:published #inst "2018-03-08"}
This is the edn frontmatter example
(ns demo | |
(:import | |
(org.commonmark.parser Parser) | |
(org.commonmark.renderer.html HtmlRenderer))) | |
(def parser (.build (Parser/builder))) | |
(def renderer (.build (HtmlRenderer/builder))) | |
(defn -main [input] | |
(->> (slurp input) | |
(.parse parser) | |
(.render renderer) | |
(println))) |
(ns demo2 | |
(:require | |
[clojure.edn :as edn] | |
[clojure.pprint :refer [pprint]]) | |
(:import | |
(org.commonmark.parser Parser) | |
(org.commonmark.node FencedCodeBlock) | |
(org.commonmark.renderer.html HtmlRenderer))) | |
(defn extract-meta! [doc] | |
(let [node (.getFirstChild doc)] | |
(when (and (instance? FencedCodeBlock node) | |
(= (.getInfo node) "clojure")) | |
(.unlink node) | |
(edn/read-string (.getLiteral node))))) | |
(def parser (.build (Parser/builder))) | |
(def renderer (.build (HtmlRenderer/builder))) | |
(defn -main [input] | |
(let [doc (.parse parser (slurp input)) | |
meta (extract-meta! doc) | |
html (.render renderer doc)] | |
(pprint (assoc meta :html html)))) |
{:paths ["."] | |
:deps {org.clojure/clojure {:mvn/version "1.9.0"} | |
com.atlassian.commonmark/commonmark {:mvn/version "0.11.0"}}} |
Runnable examples from https://mrmcc3.github.io/blog/posts/commonmark-in-clojure/
Basic markdown processing
EDN front matter trick