~subsetpark/bagatto

ref: 3820976c0cbb3214fb194f811dc8c3fdb2ab9ffd bagatto/src/multimarkdown.janet -rw-r--r-- 624 bytes
3820976c — Zach Smith Filter out empty strings in mmarkdown attributes 5 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)))