I was looking for a better way to format my Clojure/EDN outputs in Clerk, I ended up building this function, but I was wondering if there is a better way to do it.
I basically just rewrote the nextjournal.clerk.viewer/code-viewer to use zprint instead of pprint. This way it aligns all the sequences in a nice justified manner.
(def zprint-code-viewer
{:name `zprint-code-viewer
:render-fn 'nextjournal.clerk.render/render-code
:transform-fn (comp v/mark-presented
#(update-in % [:nextjournal/render-opts :language] (fn [lang] (or lang "clojure")))
(clerk/update-val (fn [v] (str/trim (with-out-str (z/zprint v {:map {:comma? true :indent 0 :justify? true}}))))))})
This is the output with regular code-viewer:
{0 [0 0 0 0 0 0 0 0],
-128 [1 0 0 0 0 0 0 0],
127 [0 1 1 1 1 1 1 1],
2 [0 0 0 0 0 0 1 0],
32 [0 0 1 0 0 0 0 0],
40 [0 0 1 0 1 0 0 0],
-84 [1 0 1 0 1 1 0 0]}
This is the output with zprint-code-viewer:
{-128 [1 0 0 0 0 0 0 0],
-84 [1 0 1 0 1 1 0 0],
0 [0 0 0 0 0 0 0 0],
2 [0 0 0 0 0 0 1 0],
32 [0 0 1 0 0 0 0 0],
40 [0 0 1 0 1 0 0 0],
127 [0 1 1 1 1 1 1 1]}that’s the way. Alternatively you could import nextjournal.clerk.viewer and modify just the code-viewers transform-fn (using assoc) and add it using add-viewers!