summaryrefslogtreecommitdiff
path: root/src/clarktown/parsers/ordered_list_block.clj
blob: 4dfaf3827e376744e6cdceb0f0646a4823bdbf01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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))))))