Lots of improvements from running against real live tag soup
This commit is contained in:
parent
7bc60a0bbb
commit
81a7337eb3
|
@ -5,6 +5,7 @@
|
|||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||
:dependencies [[org.clojure/clojure "1.8.0"]
|
||||
[enlive "1.1.6"]]
|
||||
:plugins [[lein-codox "0.10.3"]]
|
||||
:plugins [[lein-codox "0.10.3"]
|
||||
[lein-release "1.0.5"]]
|
||||
:lein-release {:deploy-via :clojars}
|
||||
:signing {:gpg-key "Simon Brooke (Stultus in monte) <simon@journeyman.cc>"})
|
||||
|
|
|
@ -7,15 +7,18 @@
|
|||
(defn markdown-a
|
||||
"Process the anchor element `e` into markdown, using dispatcher `d`."
|
||||
[e d]
|
||||
(apply
|
||||
str
|
||||
(flatten
|
||||
(list
|
||||
(str
|
||||
"["
|
||||
(map #(process % d) (:content e))
|
||||
(s/trim (apply str (process (:content e) d)))
|
||||
"]("
|
||||
(-> e :attrs :href)
|
||||
")"))))
|
||||
")"))
|
||||
|
||||
(defn markdown-br
|
||||
"Process the line-break element `e`, so beloved of tag-soupers, into
|
||||
markdown"
|
||||
[e d]
|
||||
"\n\n")
|
||||
|
||||
(defn markdown-code
|
||||
"Process the code or samp `e` into markdown, using dispatcher `d`."
|
||||
|
@ -51,15 +54,12 @@
|
|||
"Process the header element `e` into markdown, with level `level`,
|
||||
using dispatcher `d`."
|
||||
[e d level]
|
||||
(apply
|
||||
str
|
||||
(flatten
|
||||
(list
|
||||
(str
|
||||
"\n"
|
||||
(take level (repeat "#"))
|
||||
(apply str (take level (repeat "#")))
|
||||
" "
|
||||
(map #(process % d) (:content e))
|
||||
"\n"))))
|
||||
(s/trim (apply str (process (:content e) d)))
|
||||
"\n"))
|
||||
|
||||
(defn markdown-h1
|
||||
"Process the header element `e` into markdown, with level 1, using
|
||||
|
@ -105,7 +105,7 @@
|
|||
(defn markdown-img
|
||||
"Process this image element `e` into markdown, using dispatcher `d`."
|
||||
[e d]
|
||||
(str " ")"))
|
||||
(str " ")"))
|
||||
|
||||
(defn markdown-ol
|
||||
"Process this ordered list element `e` into markdown, using dispatcher
|
||||
|
@ -120,10 +120,15 @@
|
|||
str
|
||||
(flatten
|
||||
(list "\n" (inc %2) ". " (process %1 d))))
|
||||
(:content e)
|
||||
(html/select e [:li])
|
||||
(range))))
|
||||
"\n\n"))
|
||||
|
||||
(defn markdown-omit
|
||||
"Don't process the element `e` into markdown, but return `nil`."
|
||||
[e d]
|
||||
nil)
|
||||
|
||||
(defn markdown-pre
|
||||
"Process the preformatted emphasis element `e` into markdown, using
|
||||
dispatcher `d`."
|
||||
|
@ -155,13 +160,14 @@
|
|||
str
|
||||
(flatten
|
||||
(list "\n* " (process % d))))
|
||||
(:content e))))
|
||||
(html/select e [:li]))))
|
||||
"\n\n"))
|
||||
|
||||
|
||||
(def markdown-dispatcher
|
||||
{:a markdown-a
|
||||
:b markdown-strong
|
||||
:br markdown-br
|
||||
:code markdown-code
|
||||
:body markdown-default
|
||||
:div markdown-div
|
||||
|
@ -179,8 +185,10 @@
|
|||
:p markdown-div
|
||||
:pre markdown-pre
|
||||
:samp markdown-code
|
||||
:script markdown-omit
|
||||
:span markdown-default
|
||||
:strong markdown-strong
|
||||
:style markdown-omit
|
||||
:ul markdown-ul
|
||||
})
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
(string? element) element
|
||||
(or (seq? element) (vector? element))
|
||||
(map #(process % dispatcher) element)))
|
||||
(doall (map #(process % dispatcher) element))))
|
||||
|
||||
(defn- transformer-dispatch
|
||||
[a _]
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
(deftest img-test
|
||||
(testing "Image tag."
|
||||
(let [expected ""
|
||||
(let [expected ""
|
||||
actual (process
|
||||
{:tag :img
|
||||
:attrs {:src "http://foo.bar/image.png"
|
||||
|
|
Loading…
Reference in a new issue