clerk

mathpunk 2024-05-28T18:30:38.483819Z

I'd like to view some Mermaid diagrams. I am perhaps not understanding what's going on in https://github.clerk.garden/nextjournal/book-of-clerk/commit/b4c03cfb272f516a287c51133dd2dc0a71f274f0/#loading-libraries because I pasted that code in, restarted Clerk in case some dependency needed to be downloaded, and get

mathpunk 2024-05-28T18:31:23.787079Z

> Note that this library isn't bundled with Clerk but we use a component based on https://github.com/d3/d3-require to load it at runtime. If this implies I'm supposed to do something other than the code shown, I don't know what the implication is.

mkvlr 2024-05-28T19:33:27.884059Z

and nextjournal.clerk.render/with-d3-require doesnโ€™t work either?

mathpunk 2024-05-28T20:11:39.766989Z

that's right

mathpunk 2024-05-28T20:12:32.570869Z

mathpunk 2024-05-28T20:14:02.819189Z

My editor autocomplete agrees that it's never heard of this...

mathpunk 2024-05-28T20:14:08.474269Z

Maybe I have an older Clerk version

mathpunk 2024-05-28T20:15:16.884309Z

oh hello, I'm many versions behind.... I am now remembering that I used the version from a blog post to ensure that what I got is what she got

mathpunk 2024-05-28T20:15:21.596179Z

I bet I'm about to fix this now~

mkvlr 2024-05-28T20:16:47.804689Z

copied this from the book of clerk and it works fine (Iโ€™m on the latest main)

(ns notebooks.viewers.mermaid
  (:require [nextjournal.clerk :as clerk]))

(def mermaid-viewer
  {:transform-fn clerk/mark-presented
   :render-fn '(fn [value]
                 (when value
                   [nextjournal.clerk.render/with-d3-require {:package ["mermaid@8.14/dist/mermaid.js"]}
                    (fn [mermaid]
                      [:div {:ref (fn [el] (when el
                                             (.render mermaid (str (gensym)) value #(set! (.-innerHTML el) %))))}])]))})

;; We can then use  the above viewer using `with-viewer`.
(clerk/with-viewer mermaid-viewer
  "stateDiagram-v2
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]")

mathpunk 2024-05-28T20:17:18.706369Z

Yeah I had an outdated version

๐Ÿ‘ 1
mkvlr 2024-05-28T20:17:22.132879Z

cool

mathpunk 2024-05-28T20:17:31.614699Z

D'oh! Thanks for the sanity check

mathpunk 2024-05-28T20:17:49.873549Z

(also, wow, what a beautiful new 7777 home page! ๐Ÿ˜ )

๐Ÿ™Œ 2