From c5e7965fec017d2a51ae42ddd781d472fc89bff8 Mon Sep 17 00:00:00 2001 From: Asko Nomm Date: Sun, 10 Apr 2022 18:24:19 +0200 Subject: Close #11: Support dash unordered lists --- resources/test/core.md | 5 +++++ resources/test/core_result.html | 2 ++ src/clarktown/parsers/list_block.clj | 14 +++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/resources/test/core.md b/resources/test/core.md index 619ab5e..afc972a 100644 --- a/resources/test/core.md +++ b/resources/test/core.md @@ -52,6 +52,11 @@ function markdownToHTML(markdown) { } ``` +- Test 123 +- Test 223 + - Test 334 + 1. Test test + This is ___bold italic text___ and ***this is also***. *What about italic text that **has bold text***? ## Hi there, world! diff --git a/resources/test/core_result.html b/resources/test/core_result.html index 59ca907..aaad44a 100644 --- a/resources/test/core_result.html +++ b/resources/test/core_result.html @@ -44,6 +44,8 @@ function markdownToHTML(markdown) { return parsedBlocks.join(""); } + +

This is bold italic text and this is also. What about italic text that has bold text?

Hi there, world!

diff --git a/src/clarktown/parsers/list_block.clj b/src/clarktown/parsers/list_block.clj index 437f780..52f955f 100644 --- a/src/clarktown/parsers/list_block.clj +++ b/src/clarktown/parsers/list_block.clj @@ -7,7 +7,7 @@ "Determines whether we're dealing with a list block or not." [block] (->> (string/trim block) - (re-matches #"(?s)^(\d\.\s|\*{1}\s).*$"))) + (re-matches #"(?s)^(\d\.\s|\*{1}\s|\-{1}\s).*$"))) (defn string->indent-n @@ -97,13 +97,21 @@ (loop [result "" inner-items items] (if (empty? inner-items) - (if (string/starts-with? (:value (first items)) "*") + (if (or (string/starts-with? (:value (first items)) "*") + (string/starts-with? (:value (first items)) "-")) (str "") (str "
    " result "
")) (let [inner-item (first inner-items) - value (if (string/starts-with? (:value inner-item) "*") + value (cond + ; * unordered list + (string/starts-with? (:value inner-item) "*") (-> (string/replace-first (:value inner-item) "*" "") string/trim) + ; - unordered list + (string/starts-with? (:value inner-item) "-") + (-> (string/replace-first (:value inner-item) "-" "") + string/trim) + :else (-> (string/replace-first (:value inner-item) #"\d\." "") string/trim))] (recur (if (:items inner-item) -- cgit v1.2.3