3 [clojure.string :as str]
4 [clojure.walk :as walk]
5 [gemtext.core :as gemtext]))
8 "Given a string representing a gemtext document, parse it into an
9 hiccup-like data structure."
14 (gemtext/unparse thing))
16 (defn maybe-patch-link [[type attrs body :as t]]
17 (cond (not= type :a) t
19 (re-matches #".*\.(jpg|jpeg|png|gif)" (:href attrs))
20 (let [{:keys [href]} attrs]
27 (re-matches #".*\.gmi" (:href attrs))
28 [:p.link [:a {:href (str/replace (:href attrs)
34 [:p.link [:a {:href (:href attrs)}
37 (defn not-empty-ps [[type body :as t]]
42 (defn id-from-title [title]
44 (str/replace #" +" "-")
47 (defn fix-headlines-id [[type body :as t]]
49 :h1 [:h1 {:id (id-from-title body)} body]
50 :h2 [:h2 {:id (id-from-title body)} body]
51 :h3 [:h3 {:id (id-from-title body)} body]
55 (->> (gemtext/to-hiccup doc)
57 (map maybe-patch-link)
58 (map fix-headlines-id)))
61 (to-hiccup [[:link "http://f.com" "hello"]])