This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-01
Channels
- # announcements (3)
- # aws (1)
- # babashka (56)
- # beginners (42)
- # calva (9)
- # cider (6)
- # circleci (5)
- # clj-kondo (17)
- # cljs-experience (1)
- # cljsjs (2)
- # clojure (106)
- # clojure-australia (1)
- # clojure-europe (36)
- # clojure-germany (5)
- # clojure-italy (13)
- # clojure-nl (14)
- # clojure-spec (19)
- # clojure-uk (27)
- # clojurescript (27)
- # cursive (20)
- # datomic (24)
- # events (2)
- # fulcro (11)
- # graalvm (1)
- # jobs (6)
- # lsp (6)
- # malli (5)
- # meander (36)
- # membrane (17)
- # nbb (4)
- # nextjournal (86)
- # off-topic (18)
- # pathom (3)
- # polylith (5)
- # portal (14)
- # rdf (5)
- # re-frame (5)
- # releases (6)
- # remote-jobs (3)
- # reveal (2)
- # ring (6)
- # shadow-cljs (171)
- # tools-deps (61)
- # vim (10)
- # xtdb (6)
@U9EQP1K0X worked on that and we decided to not show it yet as we want to add more styling. Not sure if it's already possible to show it.
and (possibly asked that before): how to hide result? Having comment
block with ^{:nextjournal.clerk/visibility #{:hide}}
, the block is hidden but result nil
is visible.
Need to also set ^{:nextjournal.clerk/viewer :hide-result}
. See https://github.com/nextjournal/clerk/pull/59
you might also have seen https://github.com/nextjournal/clerk/pull/24
I wanted to +1 the approach suggested in https://clojurians.slack.com/archives/C01GH5EN7JA/p1638997812197500 that resulted in https://github.com/nextjournal/clerk/pull/24. The use case I have is wanting to show code in a notebook but
1. Not show the result
2. Not complicate the code I want people to read with having to do (clerk/hide-result (the-code-I-actually-want-to-show))
I like having the ^{::clerk/visibility :hide}
metadata because I can control what code I do not want the reader to have to see. I would also like to have a ^{::clerk/visibility :hide-result}
option as that would let me show the reader the code, without the result (which may be distracting) and without having to distract from the code with (clerk/hide-result...
That being said, Clerk is awesome and I really appreciate everyone’s work on it! I used to be a huge user of Python and Jupyter notebooks but using Clojure more now, I greatly prefer the Clojure REPL development experience while still being able to do literate programming with Clerk.
@U0D6MPESW did you see that ^{::clerk/viewer :hide-result}
is supported as of https://github.com/nextjournal/clerk/pull/59? Controlling both result and code cell visibility with a single keyword leads to a combinatorial state explosion that I think is better avoided.
Thanks @mkvlr, I had not seen that updated but just updated the version of clerk I was using and my .clj file and it works great!
Is there a configuration that can hide the ^{…}
metadata annotation? For example, I want to talk about this bit of code but would like to hide the metadata used by Clerk. It is in my .clj and gets rendered as
^{::clerk/viewer :hide-result}
(def scratch-db-uri "asami:")
First one: when I make custom viewer, how can I use external functions in :render-fn
?
(defn make-color-div
[c]
(clerk/html [:div {:style {:background-color "#aaaaaa"}} c]))
(clerk/set-viewers! [{:name :color :render-fn `make-color-div}])
while (clerk/set-viewers! [{:name :color :render-fn '#(v/html [:div {:style {:background-color "#aaaaaa"}} %])}])
works
asking because you can extend the environment and hence what namespaces you can use in :render-fn
but that means you also have to do your own ClojureScript compilation
this adds some complexity, which may or may not be a problem for you. If you already have a cljs pipeline on this project it’s pretty simple
in that case you should be able to define a viewer with only a :transform-fn
and return hiccup tagged with clerk/html
(ns transform
(:require [nextjournal.clerk :as clerk]))
(clerk/set-viewers! [{:pred vector? :transform-fn clerk/html}])
[:h1 "Hi Hiccup 👋"]
:transform-fn
can of course be more complex, but should call clerk/html
eventually if you want to render hiccup
Ok. Following notebook hangs everything, eats all CPU, firefox claims that page is slow (and eats tons of memory). Any idea what happens?
^{:nextjournal.clerk/visibility :hide-ns}
(ns notebooks.color
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.config :as config]
[clojure2d.color :as c]))
(defn color-spans [c]
(let [c (:nextjournal/value c)
str-color (if (< (c/luma c) 128.0) "white" "black")
n (c/format-hex c)]
[:span {:style (str "background-color:" n ";color:" str-color ";")} (str "[" n "] " c)]))
(clerk/set-viewers! [{:name :color :render-fn (quote v/html)
:transform-fn color-spans}])
(color-spans {:nextjournal/value :red})
;; => [:span {:style "background-color:#ff0000;color:white;"} "[#ff0000] :red"]
#_(swap! config/!resource->url assoc "/css/viewer.css" "../docs/static/static.css")
;; # Color
(clerk/with-viewer :color 11)
;; ## Sub
^{::clerk/viewer :color}
(+ 1 2)
^{:nextjournal.clerk/visibility :hide
:nextjournal.clerk/viewer :hide-result}
(comment
(require '[nextjournal.clerk :as clerk])
(clerk/serve! {:browse? true :watch-paths ["notebooks"]})
(clerk/show! "notebooks/color.clj")
(clerk/halt!))
^{:nextjournal.clerk/visibility :hide-ns}
(ns ^:nextjournal.clerk/no-cache notebooks.color
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as v]
[clojure2d.color :as c]))
(defn color-spans [c]
(let [c (v/value c)
str-color (if (< (c/luma c) 128.0) "white" "black")
hex (c/format-hex c)]
(v/html [:span {:style {:background-color hex :color str-color}}
(str "[" hex "] " c)])))
(clerk/set-viewers! [{:name :color :pred #{:red 3 11} :transform-fn color-spans}])
:red
;; # Color
11
;; ## Sub
(+ 1 2)
#_(clerk/serve! {})
above works indeed, thanks for a hiccup hint. However, selecting viewer with metadata or using with-viewer
produces unusable viewer
Ok, eventually I decided not to use custom viewer at all. Just created a function which returns html view. No need to use meta tags etc.
re working from a concrete impl, I meant pretty much doing what you did above: start with a let statement and get the hiccup to render for concrete values, only then move things into a viewer. But you’re right that for your use case the viewers aren’t needed as you don’t seem to require the recursive nature of viewers.
So far so good 🙂 I'm trying to prepare better doc for clojure2d.color namespace and above attempt was crucial to make it happen.
It hangs here (after interrupting in repl):
1. Unhandled java.lang.InterruptedException
(No message)
Object.java: -2 java.lang.Object/wait
Object.java: 338 java.lang.Object/wait
ProcessImpl.java: 434 java.lang.ProcessImpl/waitFor
shell.clj: 127 clojure.java.shell/sh
browse.clj: 74 clojure.java.browse/browse-url
browse.clj: 66 clojure.java.browse/browse-url
clerk.clj: 306 nextjournal.clerk/serve!
clerk.clj: 284 nextjournal.clerk/serve!
REPL: 34 notebooks.color/eval30547
@mkvlr regarding this issue. I think it might be connected to my setup which is WSL2 on Windows 11 with wslg (xserver). I tried to change browsers and google-chrome
hangs everything during serve!
while firefox
hangs during show!
strange, we’re not doing more https://github.com/nextjournal/clerk/blob/main/src/nextjournal/clerk.clj#L306
ah ok, so you can’t load http://localhost:7777 in chrome?
I can, but I can't (clojure.java.browse/browse-url "
with google-chrome
as a default browser
Looks like this bug may be related to https://clojure.atlassian.net/browse/CLJ-2493
It's not deterministic on my setup, sometimes I can continue, sometimes I can't clerk/halt!
helps or not. Anyway, currently at the stage where color-spans
is called but nothing happens, ie. resulting div is empty:
I replicated here
https://scicloj.github.io/scicloj.ml-tutorials/userguide-models_clerk.html#/src/scicloj/ml/models_clerk.clj
one of my userguides for
Large part of it is "generated", now using clerk functions.
It has as well quite some vega plots and other images.
Most was rather easy to do, Clerk is getting really good. 👍
Overall three issues:
1. cannot control overall output width: https://github.com/nextjournal/clerk/issues/68
2. Non deterministic cach behavoiur if vars are defined multiple times: https://github.com/nextjournal/clerk/issues/66
3. A real TOC is missing. I used a workaround. Should come soon.
4. Cannot render verbatim text with newlines: https://github.com/nextjournal/clerk/issues/69
Great job overall !
Great to hear! On your issues: 1. controlling width was possible, see https://github.com/nextjournal/clerk/issues/68#issuecomment-1027683555 & https://github.com/nextjournal/clerk/blob/ec07ed2701fb82ecac94c786a1310d7e324cab18/notebooks/controlling_width.clj. 2. hope to get around to that next week 3. also coming soon:tm: 4. https://github.com/nextjournal/clerk/issues/69#issuecomment-1027687431
for 1): But this cannot be applied to all cells in one go, but needed to be done for each code expression, correct ? So I look for a way to set the default output width.
correct. What you want to set the default to? Currently the table viewer defaults to :wide
while most other cells default to :prose
. Wide large images default to :full
, others to :wide
. So there’s not a single default and I’m unsure there should be as e.g. all images will no look good in :full
.
Hmm . Not sure. I just know that I use "wide" or "full" often to show wide / full polts and tables. And combining this with the code in the normal ,, narrow style", looks ugly.