refactor rewrite-hrefs into 2 functions

- (1) can be reused by the asciidoc processing, it simply does the text
  replace
- (2) is a transformer using (1) for use in markdown.core
This commit is contained in:
Adam Tankanow 2015-01-09 07:11:38 -05:00
parent 21d825d0cd
commit 1cff8eadf2

View file

@ -17,9 +17,14 @@
"Injects the blog prefix in front of any local links "Injects the blog prefix in front of any local links
ex. <img src='/img/cryogen.png'/> becomes <img src='/blog/img/cryogen.png'/>" ex. <img src='/img/cryogen.png'/> becomes <img src='/blog/img/cryogen.png'/>"
[blog-prefix text]
(clojure.string/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/")))
(defn- rewrite-hrefs-transformer
"A :replacement-transformer for use in markdown.core that will inject the
given blog prefix in front of local links."
[{:keys [blog-prefix]} text state] [{:keys [blog-prefix]} text state]
[(clojure.string/replace text #"href=.?/|src=.?/" #(str (subs % 0 (dec (count %))) blog-prefix "/")) [(rewrite-hrefs blog-prefix text) state])
state])
(defn- markdown (defn- markdown
"Returns a Markdown (https://daringfireball.net/projects/markdown/) "Returns a Markdown (https://daringfireball.net/projects/markdown/)