~subsetpark/bagatto

bagatto/src/multimarkdown.janet -rw-r--r-- 705 bytes
4fc04b3a — Zach Smith Add render some 2 months ago
                                                                                
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
26
27
28
29
30
31
32
33
34
(import sh)
(import /src/env)

(defn- metadata-keys
  [md]
  (->> (sh/$< echo ,(string md) |multimarkdown -m --)
       (string/trim)
       (string/split "\n")
       (filter (complement empty?))))

(defn- metadata-value
  [md key]
  (->> (sh/$< echo ,(string md) |multimarkdown -e ,key --)
       (string/trim)))

(env/defrequire
  "multimarkdown"
  metadata
  [md]
  (let [keys (metadata-keys md)]
    (table ;(mapcat |[$0 (metadata-value md $0)] keys))))


(env/defrequire
  "multimarkdown"
  snippet
  [md &opt smart]
  (default smart true)

  (->>
    (if smart
      (sh/$< echo ,(string md) |multimarkdown -s --)
      (sh/$< echo ,(string md) |multimarkdown --nosmart -s --))
    (string/trim)))