summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project.clj4
-rw-r--r--src/mulk/benki/wiki.clj20
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" []