cryogen

2021-08-30T14:01:34.017900Z

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

Jakub Holý (HolyJak) 2021-08-30T15:15:37.018600Z

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.

Jakub Holý (HolyJak) 2021-08-30T15:16:08.018800Z

Otherwise you'd need to do some post-processing of the html

2021-08-30T21:00:58.019Z

well, i figured out how to do it, but it’s ugly lol

2021-08-30T21:12:28.019200Z

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

👍 1