This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-30
Channels
- # adventofcode (4)
- # aleph (1)
- # announcements (6)
- # babashka (11)
- # beginners (63)
- # calva (73)
- # clj-kondo (9)
- # clj-on-windows (20)
- # cljdoc (8)
- # cljsrn (4)
- # clojure (48)
- # clojure-europe (20)
- # clojure-italy (1)
- # clojure-nl (11)
- # clojure-spec (11)
- # clojure-uk (3)
- # clojurescript (32)
- # cloverage (1)
- # conjure (1)
- # cryogen (5)
- # datomic (83)
- # fulcro (28)
- # graphql (23)
- # gratitude (4)
- # helix (15)
- # honeysql (4)
- # improve-getting-started (14)
- # introduce-yourself (3)
- # jackdaw (5)
- # kaocha (11)
- # leiningen (1)
- # malli (1)
- # meander (5)
- # off-topic (18)
- # pathom (17)
- # pedestal (6)
- # polylith (15)
- # practicalli (1)
- # quil (2)
- # reitit (4)
- # releases (6)
- # shadow-cljs (38)
- # sql (20)
- # testing (6)
- # timbre (5)
- # tools-deps (11)
- # vim (2)
now that i’ve gotten that set up, next question! and maybe this should go somewhere else, so please direct me if necessary. I’m looking to render all of my code snippets server-side using Pygments (with https://github.com/bfontaine/clygments), and can’t quite figure out how to hook into the rendering process to modify only the code blocks
You cannot, not via cryogen proper. Rendering markup to html is done by the markup plugin such as cryogen-asciidoctor. Look at what it allows (eg asciidoctor allows custom macros / extensions) or fork and adjust it.
Otherwise you'd need to do some post-processing of the html
well, i figured out how to do it, but it’s ugly lol
(defn transform-html
"Creates an enlive-snippet from `html-string` then removes
the newline nodes"
[html-string]
(->> (enlive/html-snippet html-string)
(walk/postwalk
(fn [node]
(if (seq? node)
(remove #(and (string? %) (re-matches #"\n\h*" %)) node)
node)))
(walk/postwalk
(fn [node]
(if (= "listingblock" (get-in node [:attrs :class]))
(let [pre (-> node :content first :content first)
n (first (:content pre))
lang (keyword (get-in n [:attrs :data-lang]))
content (-> (:content n)
(first)
(clygments/highlight lang :html))
n (list (assoc n :content (enlive/html-snippet content)))]
(assoc node :content (list (assoc pre :content n))))
node)))))
(alter-var-root
#'util/trimmed-html-snippet
(fn [_f] transform-html))
(defn transform-html
"Creates an enlive-snippet from `html-string` then removes
the newline nodes"
[html-string]
(->> (enlive/html-snippet html-string)
(walk/postwalk
(fn [node]
(if (seq? node)
(remove #(and (string? %) (re-matches #"\n\h*" %)) node)
node)))
(walk/postwalk
(fn [node]
(if (= "listingblock" (get-in node [:attrs :class]))
(let [pre (-> node :content first :content first)
n (first (:content pre))
lang (keyword (get-in n [:attrs :data-lang]))
content (-> (:content n)
(first)
(clygments/highlight lang :html))
n (list (assoc n :content (enlive/html-snippet content)))]
(assoc node :content (list (assoc pre :content n))))
node)))))
(alter-var-root
#'util/trimmed-html-snippet
(fn [_f] transform-html))