From f4f2cbdbd1341b62195075288bb6e3dc8de43196 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 24 Nov 2011 15:30:19 +0100 Subject: Fix wikilink insertion. --- src/mulk/benki/wiki.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') 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" [] -- cgit v1.2.3