2014-12-29 16:15:48 +00:00
|
|
|
(ns cryogen-core.markup
|
2017-01-16 07:37:19 +00:00
|
|
|
(:require [clojure.string :as s]))
|
2015-01-15 01:49:51 +00:00
|
|
|
|
|
|
|
(defonce markup-registry (atom []))
|
2014-12-29 16:15:48 +00:00
|
|
|
|
|
|
|
(defprotocol Markup
|
2014-12-30 12:31:46 +00:00
|
|
|
"A markup engine comprising a dir(ectory) containing markup files,
|
|
|
|
an ext(ension) for finding markup file names, and a render-fn that returns
|
|
|
|
a fn with the signature [java.io.Reader config] -> String (HTML)."
|
2014-12-29 16:15:48 +00:00
|
|
|
(dir [this])
|
|
|
|
(ext [this])
|
|
|
|
(render-fn [this]))
|
|
|
|
|
2015-01-15 01:49:51 +00:00
|
|
|
(defn rewrite-hrefs
|
2014-12-30 12:31:46 +00:00
|
|
|
"Injects the blog prefix in front of any local links
|
2016-01-08 23:51:40 +00:00
|
|
|
ex. <img src='/img/cryogen.png'/> becomes <img src='/blog/img/cryogen.png'/>"
|
2015-01-09 12:11:38 +00:00
|
|
|
[blog-prefix text]
|
2016-01-10 14:40:19 +00:00
|
|
|
(if (s/blank? blog-prefix)
|
|
|
|
text
|
2017-01-16 07:37:19 +00:00
|
|
|
(s/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/"))))
|
2015-01-09 12:11:38 +00:00
|
|
|
|
2014-12-30 12:31:46 +00:00
|
|
|
(defn markups
|
|
|
|
"Return a vector of Markup implementations. This is the primary entry point
|
|
|
|
for a client of this ns. This vector should be used to iterate over supported
|
|
|
|
Markups."
|
|
|
|
[]
|
2015-01-15 01:49:51 +00:00
|
|
|
@markup-registry)
|
2016-05-24 05:20:36 +00:00
|
|
|
|
|
|
|
(defn register-markup
|
|
|
|
"Add a Markup implementation to the registry."
|
|
|
|
[mu]
|
|
|
|
(swap! markup-registry conj mu))
|
|
|
|
|
|
|
|
(defn clear-registry
|
|
|
|
"Reset the Markup registry."
|
|
|
|
[]
|
|
|
|
(reset! markup-registry []))
|