diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-11-24 15:30:19 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-11-24 15:30:19 +0100 |
commit | f4f2cbdbd1341b62195075288bb6e3dc8de43196 (patch) | |
tree | 29feac9f8ae71a03c49b7aef89652ff1c57b447a | |
parent | 8d20fa59204301da2102d8d09d00d20a10ccbfc2 (diff) |
Fix wikilink insertion.
-rw-r--r-- | project.clj | 4 | ||||
-rw-r--r-- | src/mulk/benki/wiki.clj | 20 |
2 files changed, 16 insertions, 8 deletions
diff --git a/project.clj b/project.clj index 9a077b2..61e86b1 100644 --- a/project.clj +++ b/project.clj @@ -53,7 +53,9 @@ ;; Additional libraries ;;[clj-oauth2 "0.0.1"] ;;[org.clojars.zef/jopenid "1.05"] - [org.openid4java/openid4java-consumer "0.9.6" :type "pom"]] + [org.openid4java/openid4java-consumer "0.9.6" :type "pom"] + [org.jsoup/jsoup "1.6.1"] + ] :dev-dependencies [;;[swank-clojure "1.3.2"] [swank-clojure "1.4.0-SNAPSHOT"] ;;[ring-serve "0.1.1"] diff --git a/src/mulk/benki/wiki.clj b/src/mulk/benki/wiki.clj index b55b7e8..a5dfcb5 100644 --- a/src/mulk/benki/wiki.clj +++ b/src/mulk/benki/wiki.clj @@ -27,17 +27,23 @@ (defn- wikilinkify [tag-soup] - (let [doc (org.jsoup.Jsoup/parse tag-soup) - leaf-nodes (filter #(empty? (.children %)) - (.select doc "*"))] - (doseq [node leaf-nodes] - (.html node (html-insert-wikilinks (.html node)))) + (let [doc (org.jsoup.Jsoup/parse tag-soup) ] + (doseq [node (into [] (.select doc "*")) + subnode (into [] (.childNodes node))] + (when (instance? org.jsoup.nodes.TextNode subnode) + (println subnode) + (let [new-node (org.jsoup.nodes.Element. + (org.jsoup.parser.Tag/valueOf "span") + "")] + (.html new-node (html-insert-wikilinks (.html node))) + (.replaceWith subnode new-node) + (.unwrap new-node)))) (-> doc (.select "body") (.html)))) (defn- unwikilinkify [tag-soup] (let [doc (org.jsoup.Jsoup/parse tag-soup)] - (-> doc (.select ".benkilink") (.remove)) - (-> doc (.select "body") (.html)))) + (doseq [node (-> doc (.select ".benkilink") (.unwrap))]) + (-> doc (.select "body") (.html)))) (defpage "/wiki" [] |