diff options
Diffstat (limited to 'src/clarktown/parsers/ordered_list_block.clj')
| -rw-r--r-- | src/clarktown/parsers/ordered_list_block.clj | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/clarktown/parsers/ordered_list_block.clj b/src/clarktown/parsers/ordered_list_block.clj new file mode 100644 index 0000000..4dfaf38 --- /dev/null +++ b/src/clarktown/parsers/ordered_list_block.clj @@ -0,0 +1,25 @@ +(ns clarktown.parsers.ordered-list-block + (:require + [clojure.string :as string] + [clarktown.parser :as parser])) + + +(defn is? + "Determines whether we're dealing with a list block or not." + [block] + (re-matches #"(?s)^\d\..*$" (string/trim block))) + + +(defn render + "Renders the ordered list block" + [block parsers] + (loop [result "" + items (string/split-lines block)] + (if (empty? items) + (str "<ol>" result "</ol>") + (let [value (-> (first items) + (string/replace-first #"\d\." "") + string/trim + (parser/parse parsers))] + (recur (str result "<li>" value "</li>") + (drop 1 items)))))) |
