Fork me on GitHub
#nextjournal
<
2022-02-03
>
grahamcarlyle12:02:23

Hello, I am generating a static version of a notebook by calling clerk/build-static-app!, and was hoping to be able to use the :git/url :git/sha params to generate the nice link back to the git repo of the source, but the url it generates doesn't work if my code (deps.edn) isn't at the root of the git repo. I'm wondering if i'm missing a way of doing this, or whether a new option such as :git/root would be necessary to support my use case?

genmeblog13:02:49

How do you generate this url? 'build-static-app' generates a html file. Why not just use absolute url?

mkvlr13:02:53

not supported yet. So you'd want a equivalent of :deps/root?

mkvlr13:02:36

or :git/root, makes sense. Issue and optionally PR welcome

grahamcarlyle13:02:31

I've created an issue and PR for this, sorry for the delay in doing this https://github.com/nextjournal/clerk/issues/99

genmeblog20:02:17

The idea. Currently every form is treated separately and result is rendered directly under the code, form after form. Is there a way to make a block of forms, rendered them in one piece and results in another under as a one block?

genmeblog20:02:45

Now it's like:

genmeblog20:02:17

(some-form 1 2 3)
;; result
(another-form 1 2 3)
;; result

genmeblog20:02:47

What about this?

(some-form 1 2 3)
(another-form 1 2 3)
;; first result
;; second result

mkvlr08:02:32

do you have an example where that would be desired?

genmeblog08:02:52

For example here:

genmeblog08:02:38

I think block of code lines + block of results would be better here. It can be my personal feeling though

genmeblog08:02:30

Here are some examples from other docs:

genmeblog08:02:56

Thinking aloud: I think it's a matter of more compact view and/or ability to overwrite certain styles.

genmeblog10:02:13

also something like in RMarkdown:

genmeblog10:02:11

Similarly in Jupyter:

mkvlr10:02:25

in the jupyter example it’s showing stdout & err (which we don’t yet show in Clerk)

mkvlr10:02:35

you can do this today:

(clerk/with-viewers
  [{:pred vector? :render-fn '#(v/html (into [:div.flex.flex-col] (v/inspect-children %2) %1))}
   {:pred #(and (string? %)
                (re-matches
                 (re-pattern
                  (str "(?i)"
                       "(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|"
                       "(rgb|hsl)a?\\((-?\\d+%?[,\\s]+){2,3}\\s*[\\d\\.]+%?\\))")) %))
    :render-fn '#(v/html [:div
                          [:div.inline-block.rounded-sm.shadow.ml-2
                           {:style {:width 16
                                    :height 16
                                    :border "1px solid rgba(0,0,0,.2)"
                                    :background-color %}}]
                          [:span.font-mono.text-xs.ml-2 %]])}]
  ["#571845"
   "rgb(144,12,62)"
   "rgba(199,0,57,1.0)"
   "hsl(11,100%,60%)"
   "hsla(46, 97%, 48%, 1.000)"])

mkvlr10:02:18

(return a vector and modify the vector viewer to render elements vertically)

genmeblog10:02:23

mhm... (with jupyter, I wanted to show that several froms can be combined to get forms block + results block, instead of interleaved view)

genmeblog10:02:30

I know that vector is possible but requires smart dispatching code.

genmeblog10:02:11

It's a feature request from my side 🙂

mkvlr10:02:07

what do you mean by smart dispatching code?

genmeblog10:02:13

I mean I have to write another function for seqence of colors/palettes/gradients. Or add some logic to my viewer function (🎨)

mkvlr10:02:18

I don’t yet see how we can automatically do it… We need some way to signal that it should render multiple results?

genmeblog11:02:04

Maybe double newline can be an indicator to render a block?

(code 1)
(code 2)

(code 3)

(code 4)
(code 5)

genmeblog11:02:17

this could be rendered as 3 blocks

genmeblog11:02:11

Anyway, that's just an idea. I'm aware that's a breaking change request but maybe there can be an option to set by user to choose the method of block vs line-by-line rendering.

mkvlr11:02:08

still would like to understand a bit better what you don’t like about the vector option?

genmeblog11:02:39

I'm not saying I don't like 🙂 I need to write a piece of code which will render it properly. That's all.

genmeblog11:02:40

Oh, it works now almost ok (need to get rid of [] at the beginning)

mkvlr11:02:04

yes, that’s what I mean

mkvlr11:02:24

(clerk/set-viewers! [{:pred vector?
                      :render-fn '#(v/html (into [:div.flex.flex-col] (v/inspect-children %2) %1))}])

mkvlr11:02:25

another possibility would be for us to add this as a default named viewer to Clerk, then it would be selectable via metadata like this

(clerk/set-viewers! [{:name :flex-col
                      :render-fn '#(v/html (into [:div.flex.flex-col] (v/inspect-children %2) %1))}])

^{::clerk/viewer :flex-col}
[:one
 :two
 :three]

genmeblog11:02:10

So another minor issue: is there a way to get rid of meta tag?

mkvlr11:02:54

yes, been talking to @U07SQTAEM about this and we want this as an option as well.

genmeblog11:02:20

Great! Thank you for taking your time for that.

mkvlr11:02:37

I’m a bit concerned about adding it too soon though because then it’s no longer obvious how to do some of those things. @U4FSZE57V maybe we find a elegant way to unhide it on demand.

genmeblog11:02:50

What about making such switches/options as a meta for namespace?

genmeblog11:02:19

Like global no-cache?

genmeblog11:02:35

(ns {^:nextjournal.clerk/options #{:no-cache :hide-tags :some-other-option}} notebooks.color)

mkvlr11:02:11

yeah, possible. (Btw think we also want to move those options out from the namespace to the form ^:nextjournal.clerk/no-cache (ns notebooks.color notebooks.color) )

genmeblog11:02:18

that's even better

jackrusher15:02:22

We've been thinking about this too, @U1EP3BZ3Q. But our approach with Clerk is the opposite of "move fast and break things", where we really want to make sure that everything fits together well to give the most power with the least API surface. 🙂

genmeblog19:02:17

Ha! I'm the last person who expect moving fast and breaking things 🙂 Just sharing my observations and conclusions, which are subjective for sure but may be helpful (I hope).

jackrusher12:02:18

I just meant that we're listening and trying to meet everyone's concerns, even if it seems like we're a bit slow shipping a solution or we don't take someone's pull request as is. 🙂