Merge pull request #60 from ponkore/better-support-for-preview

content-with-more-marker returns with correct html closing tags
This commit is contained in:
Dmitri Sotnikov 2016-01-11 10:09:33 -05:00
commit 8ab65e0297
2 changed files with 27 additions and 1 deletions

View file

@ -251,7 +251,10 @@
[^String content]
(let [index (.indexOf content "<!--more-->")]
(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
"Creates a single post preview"

View 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>")))