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 /src | |
parent | 8d20fa59204301da2102d8d09d00d20a10ccbfc2 (diff) |
Fix wikilink insertion.
Diffstat (limited to 'src')
-rw-r--r-- | src/mulk/benki/wiki.clj | 20 |
1 files changed, 13 insertions, 7 deletions
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" [] |