Replace tagsoup dependency with enlive

Tagsoup depends on an old version of clojure.data.xml, which doesn't
compile with clojure 1.9.0-alpha12. Enlive seems more actively
maintained and used.
This commit is contained in:
Aleksander Madland Stapnes 2017-01-15 05:30:25 -03:00
parent 9c7c935d66
commit dbd5caaf1f
3 changed files with 18 additions and 17 deletions

View file

@ -14,6 +14,6 @@
[selmer "1.10.3"] [selmer "1.10.3"]
[pandect "0.6.1"] [pandect "0.6.1"]
[hawk "0.2.11"] [hawk "0.2.11"]
[clj-tagsoup "0.3.0" :exclusions [org.clojure/clojure]]] [enlive "1.1.6"]]
:deploy-repositories [["snapshots" :clojars] :deploy-repositories [["snapshots" :clojars]
["releases" :clojars]]) ["releases" :clojars]])

View file

@ -5,8 +5,7 @@
[clojure.java.io :refer [copy file reader writer]] [clojure.java.io :refer [copy file reader writer]]
[clojure.string :as s] [clojure.string :as s]
[text-decoration.core :refer :all] [text-decoration.core :refer :all]
[pl.danieljanus.tagsoup :as tagsoup] [net.cgrand.enlive-html :as enlive]
[hiccup.core :as hiccup]
[cryogen-core.toc :refer [generate-toc]] [cryogen-core.toc :refer [generate-toc]]
[cryogen-core.sass :as sass] [cryogen-core.sass :as sass]
[cryogen-core.markup :as m] [cryogen-core.markup :as m]
@ -295,23 +294,24 @@
:uri uri}))))) :uri uri})))))
(defn content-until-more-marker (defn content-until-more-marker
[^String content] "Returns the content until the <!--more--> special comment,
(let [index (.indexOf content "<!--more-->")] closing any unclosed tags. Returns nil if there's no such comment."
(if (pos? index) [content]
(let [s (subs content 0 index)] (when-let [index (s/index-of content "<!--more-->")]
(->> ((tagsoup/parse-string s) 2) (->> (subs content 0 index)
(drop 2) enlive/html-snippet
hiccup/html))))) enlive/emit*
(apply str))))
(defn create-preview (defn create-preview
"Creates a single post preview" "Creates a single post preview"
[blocks-per-preview post] [blocks-per-preview post]
(merge post (update post :content
{:content (or (content-until-more-marker (:content post)) #(or (content-until-more-marker %)
(->> ((tagsoup/parse-string (:content post)) 2) (->> (enlive/html-snippet %)
(drop 2) (take blocks-per-preview)
(take blocks-per-preview) enlive/emit*
hiccup/html))})) (apply str)))))
(defn create-previews (defn create-previews
"Returns a sequence of vectors, each containing a set of post previews" "Returns a sequence of vectors, each containing a set of post previews"

View file

@ -22,7 +22,8 @@
and more content. and more content.
</div> </div>
</div>") </div>")
"<div id=\"post\"><div class=\"post-content\"> "<div id=\"post\">
<div class=\"post-content\">
this post has more marker this post has more marker
</div></div>"))) </div></div>")))