summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsko Nomm <asko@bien.ee>2022-04-10 18:24:19 +0200
committerAsko Nomm <asko@bien.ee>2022-04-10 18:24:19 +0200
commitc5e7965fec017d2a51ae42ddd781d472fc89bff8 (patch)
tree69c50b9f4e575eaa6995337135373eb352b931a9
parent187bfeaeb559e8d17f63aef46deb1b2c28ee9829 (diff)
Close #11: Support dash unordered lists
-rw-r--r--resources/test/core.md5
-rw-r--r--resources/test/core_result.html2
-rw-r--r--src/clarktown/parsers/list_block.clj14
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("");
}</code></pre>
+<ul><li>Test 123</li><li>Test 223<ul><li>Test 334<ol><li>Test test</li></ol></li></ul></li></ul>
+
<p>This is <em><strong>bold italic text</strong></em> and <em><strong>this is also</strong></em>. <em>What about italic text that <strong>has bold text</strong></em>?</p>
<h2>Hi there, world!</h2>
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 "<ul>" result "</ul>")
(str "<ol>" result "</ol>"))
(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)