From 556fe84ef861f1a2df3ce421a137fcf284c3e2c3 Mon Sep 17 00:00:00 2001 From: ponkore Date: Mon, 11 Jan 2016 21:30:21 +0900 Subject: [PATCH] content-with-more-marker returns with correct tags `content-with-more-marker` returns a HTML string when the `content` conteins more marker (""). In many case, HTML tags in `content` is balanced. ex. ------------------------------
this post has more marker and more content.
------------------------------ But original code breaks the balance. ------------------------------
this post has more marker ------------------------------ Afer this patch applied, `tagsoup` read above text and `hiccup` re-render to HTML text with correct balanced tags. ------------------------------
this post has more marker
------------------------------ --- src/cryogen_core/compiler.clj | 5 ++++- test/cryogen_core/compiler_test.clj | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/cryogen_core/compiler_test.clj diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index ee1fe84..cccec50 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -251,7 +251,10 @@ [^String content] (let [index (.indexOf content "")] (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" diff --git a/test/cryogen_core/compiler_test.clj b/test/cryogen_core/compiler_test.clj new file mode 100644 index 0000000..e7e77ca --- /dev/null +++ b/test/cryogen_core/compiler_test.clj @@ -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 "
+
+ this post does not have more marker +
+
"))) + ; text with more marker, return text before more marker with closing tags. + (is (= (content-until-more-marker "
+
+ this post has more marker + +and more content. +
+
") + "
+ this post has more marker +
")))