This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-19
Channels
- # announcements (5)
- # babashka (49)
- # beginners (11)
- # biff (5)
- # calva (123)
- # clerk (9)
- # cljdoc (5)
- # cljs-dev (9)
- # clojure (62)
- # clojure-europe (32)
- # clojure-nl (1)
- # clojure-norway (54)
- # clojure-uk (3)
- # clojurescript (30)
- # community-development (5)
- # cursive (9)
- # devops (5)
- # events (1)
- # fulcro (35)
- # graalvm (10)
- # gratitude (3)
- # hyperfiddle (9)
- # jobs (3)
- # keechma (1)
- # lsp (10)
- # malli (14)
- # off-topic (42)
- # overtone (1)
- # releases (3)
- # shadow-cljs (66)
- # squint (153)
- # xtdb (19)
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"?
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
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 documents