~subsetpark/bagatto

ref: ab40776ba07d326fa8d4e978511843a8ca38bd54 bagatto/src/multimarkdown.janet -rw-r--r-- 558 bytes
ab40776b — Zach Smith Emit pattern name on empty pattern 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(import sh)

(defn- metadata-keys [md] (->> (sh/$< echo ,(string md) | multimarkdown -m --) (string/trim) (string/split "\n")))
(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)))