clerk

Ruben Sevaldson 2024-03-19T14:54:35.748109Z

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"?

Ruben Sevaldson 2024-03-24T17:49:53.682389Z

Thanks a lot! Will try this out

Ruben Sevaldson 2024-03-24T17:53:54.175329Z

> 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 documents

teodorlu 2024-03-24T18:41:44.114279Z

Yeah, good point. Hiccup is probably a bit more compact.

teodorlu 2024-03-20T21:15:31.512659Z

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

teodorlu 2024-03-20T21:20:49.573089Z

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"}` )

teodorlu 2024-03-20T21:26:12.671239Z

> • 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!

teodorlu 2024-03-20T21:27:37.763389Z

Relevant Clerk docs: https://book.clerk.vision/#elisions

teodorlu 2024-03-20T21:39:12.262109Z

People who know Clerk better than I may be able to give you better answers!