Hi 🙂 I am a beginner with Clojure and clerk and have a couple of questions: • Is there an easy way to pretty print xml and/or html in clerk? • Is there a way to tell clerk to print a string in its entirety, without having to click "... more"?
Thanks a lot! Will try this out
> For both HTML and XML I’d probably convert to Clojure data structures first, then use the built-in viewers. Agreed, but I find the representation is a bit less concise than the raw XML? For example:
(xml/parse (java.io.ByteArrayInputStream. (.getBytes "<person><name>Ruben</name></person>")))
Becomes
{:tag :person,
:attrs nil,
:content [{:tag :name, :attrs nil, :content ["Ruben"]}]}
I think it can become a bit much when dealing with large XML documentsYeah, good point. Hiccup is probably a bit more compact.
Hi 🙂
> Is there an easy way to pretty print xml and/or html in clerk?
For both HTML and XML I’d probably convert to Clojure data structures first, then use the built-in viewers.
If you really want to view XML/HTML as text, it appears that xml is supported in fenced code blocks, and those can be produced programmatically.
Something like this:
(defn view-xml [xml-str]
(clerk/md (str "xml\n" xml-str "\n\n")))
(view-xml "Ruben ")reading the book https://book.clerk.vision/#code hinted towards using clerk/code with options. That didn’t seem to give me syntax highlighting, so I may be doing something wrong. (`io.github.nextjournal/clerk {:mvn/version "0.15.957"}` )
> • Is there a way to tell clerk to print a string in its entirety, without having to click “... more”? I’ve used this to view big tables:
(require '[nextjournal.clerk :as clerk]
'[nextjournal.clerk.viewer :as v])
(defn big-table [x]
(v/with-viewer (dissoc v/table-viewer :page-size)
x))
(big-table (repeatedly 200 (fn [] {:x (rand)})))
I’m guessing that something similar can be done for a string viewer, eg
(defn big-string [x]
(v/with-viewer (dissoc v/string-viewer :page-size)
x))
, but I haven’t tried!Relevant Clerk docs: https://book.clerk.vision/#elisions
People who know Clerk better than I may be able to give you better answers!