From 68b82be9593e8c8ddbf22f55688c670bccd8d264 Mon Sep 17 00:00:00 2001 From: Adam Tankanow Date: Mon, 29 Dec 2014 11:15:48 -0500 Subject: [PATCH] add markup ns to abstract markdown vs asciidoc --- src/cryogen_core/markup.clj | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/cryogen_core/markup.clj diff --git a/src/cryogen_core/markup.clj b/src/cryogen_core/markup.clj new file mode 100644 index 0000000..f769ce8 --- /dev/null +++ b/src/cryogen_core/markup.clj @@ -0,0 +1,37 @@ +(ns cryogen-core.markup + (:require [markdown.core :refer [md-to-html-string]] + [clojure.string :as s]) + (:import org.asciidoctor.Asciidoctor$Factory + java.util.Collections)) + +(defprotocol Markup + (dir [this]) + (ext [this]) + (render-fn [this])) + +(defn- markdown [] + (reify Markup + (dir [this] "md") + (ext [this] ".md") + (render-fn [this] + (fn [rdr] + (md-to-html-string + (->> (java.io.BufferedReader. rdr) + (line-seq) + (s/join "\n")) + :heading-anchors true))))) + +(defn- asciidoc [] + (reify Markup + (dir [this] "asc") + (ext [this] ".asc") + (render-fn [this] + (fn [rdr] + (.convert (Asciidoctor$Factory/create) + (->> (java.io.BufferedReader. rdr) + (line-seq) + (s/join "\n")) + (Collections/emptyMap)))))) + +(defn markups [] + [(markdown) (asciidoc)])