content-with-more-marker returns with correct tags
`content-with-more-marker` returns a HTML string when the `content` conteins more marker ("<!--more-->"). In many case, HTML tags in `content` is balanced. ex. ------------------------------ <div id='post'> <div class='post-content'> this post has more marker <!--more--> and more content. </div> </div> ------------------------------ But original code breaks the balance. ------------------------------ <div id='post'> <div class='post-content'> this post has more marker ------------------------------ Afer this patch applied, `tagsoup` read above text and `hiccup` re-render to HTML text with correct balanced tags. ------------------------------ <div id='post'> <div class='post-content'> this post has more marker </div></div> ------------------------------
This commit is contained in:
parent
13c445ff17
commit
556fe84ef8
2 changed files with 27 additions and 1 deletions
|
@ -251,7 +251,10 @@
|
||||||
[^String content]
|
[^String content]
|
||||||
(let [index (.indexOf content "<!--more-->")]
|
(let [index (.indexOf content "<!--more-->")]
|
||||||
(if (pos? index)
|
(if (pos? index)
|
||||||
(subs content 0 index))))
|
(let [s (subs content 0 index)]
|
||||||
|
(->> ((tagsoup/parse-string s) 2)
|
||||||
|
(drop 2)
|
||||||
|
hiccup/html)))))
|
||||||
|
|
||||||
(defn create-preview
|
(defn create-preview
|
||||||
"Creates a single post preview"
|
"Creates a single post preview"
|
||||||
|
|
23
test/cryogen_core/compiler_test.clj
Normal file
23
test/cryogen_core/compiler_test.clj
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
(ns cryogen-core.compiler-test
|
||||||
|
(:require [clojure.test :refer :all]
|
||||||
|
[cryogen-core.compiler :refer :all]))
|
||||||
|
|
||||||
|
; Test that the content-until-more-marker return nil or correct html text.
|
||||||
|
(deftest test-content-until-more-marker
|
||||||
|
; text without more marker, return nil
|
||||||
|
(is (nil? (content-until-more-marker "<div id=\"post\">
|
||||||
|
<div class=\"post-content\">
|
||||||
|
this post does not have more marker
|
||||||
|
</div>
|
||||||
|
</div>")))
|
||||||
|
; text with more marker, return text before more marker with closing tags.
|
||||||
|
(is (= (content-until-more-marker "<div id='post'>
|
||||||
|
<div class='post-content'>
|
||||||
|
this post has more marker
|
||||||
|
<!--more-->
|
||||||
|
and more content.
|
||||||
|
</div>
|
||||||
|
</div>")
|
||||||
|
"<div id=\"post\"><div class=\"post-content\">
|
||||||
|
this post has more marker
|
||||||
|
</div></div>")))
|
Loading…
Reference in a new issue