~subsetpark/bagatto

ref: 22683bebdf00ea054405e41739fc0ef5fdeb7666 bagatto/src/multimarkdown.janet -rw-r--r-- 624 bytes
22683beb — Zach Smith Demand pool management: wait for all threads to exit before main thread exits 10 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
(import sh)

(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)))

(defn metadata [md]
  (let [keys (metadata-keys md)]
    (table ;(mapcat |[$0 (metadata-value md $0)] keys))))

(defn snippet
  [md &opt smart]
  (default smart true)

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