Skip to content

Commit 24ca23e

Browse files
committed
Merge branch 'main' into sci-async-3
# Conflicts: # render/deps.edn # src/nextjournal/clerk/sci_env.cljs
2 parents 2871aa1 + a70fc41 commit 24ca23e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1956
-923
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
;; always force unix line endings to make hashing consistent
22
* text eol=lf
33
*.png binary
4+
*.db binary

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
clojure -J-Dclojure.main.report=stderr -X:demo:nextjournal/clerk :git/sha '"${{ github.sha }}"' :git/url '"https://github.com/nextjournal/clerk"' :paths '["book.clj" "CHANGELOG.md" "editor.clj"]'
149149
150150
- name: 🏗 Build Clerk Static App with default Notebooks
151-
run: clojure -J-Dclojure.main.report=stderr -X:demo:nextjournal/clerk :git/sha '"${{ github.sha }}"' :git/url '"https://github.com/nextjournal/clerk"' :bundle true
151+
run: clojure -J-Dclojure.main.report=stderr -X:demo:nextjournal/clerk :package :single-file
152152

153153
- name: 📠 Copy book & static build to bucket under SHA
154154
run: |

CHANGELOG.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,75 @@ Changes can be:
88

99
## Unreleased
1010

11+
...
12+
13+
## 0.16.1016 (2024-06-05)
14+
15+
* 🥡 The whole cell context (e.g. its form, code text etc.) is now passed to viewer functions along with the wrapped result. In addition, a new cell-viewer has been added to possibly transform a cell's properties prior to presentation. This can be used, for instance, to alter a cell's visibility programmatically ([#575](https://github.com/nextjournal/clerk/issues/575)).
16+
17+
* 🪬 Allow viewer predicate functions to opt into recieving more context (the form with metadata, code text, etc) by providing putting the predicate function as value in a map with a `:wrapped` key, e.g. `{:pred {:wrapped (fn [x] ,,,)} ,,,}`. This makes Clerk's form metadata viewer selection extensible.
18+
19+
* 💬 Add `clerk/comment` that behaves like `clojure.core/comment` outside of Clerk but shows the results like regular top-level forms in Clerk.
20+
21+
* 💫 Allow to disable welcome page in `serve!` by specifying `:paths` or `:paths-fn`.
22+
23+
* 💫 Support using Markdown syntax in `clerk/caption` text
24+
25+
* 💫 Support toggling auto-expansion of results in tap viewer
26+
27+
* 💫 Redesign examples viewer to be more readable and in a way that doesn't force `display: flex` onto contents.
28+
29+
* 💫 Introduce client-side routing for static builds to make page transitions smoother by default. In addition, the option `:bundle?` for `clerk/build!` is now deprecated in favour of setting a new option `:package` to `:single-file` (the default for it being `:directory`).
30+
31+
* 💫 Introduce a toc viewer for allowing customization of the table of contents
32+
33+
* 🛠 Bump depdendencies
34+
35+
* `com.taoensso/nippy` to `3.4.2`
36+
* `http-kit/http-kit` to `3.8.0`
37+
* `io.github.nextjournal/markdown` to `0.5.146`
38+
* `hiccup/hiccup` to `2.0.0-RC3`
39+
40+
* 🐜 Fix blank screen caused by react unmounting when an exception occurs during `clerk/show!`, fixes [#586](https://github.com/nextjournal/clerk/issues/586) @elken
41+
42+
* 🐜 Fix browser crashing when file watcher is used with `:show-filter-fn` option in notebooks with exceptions, fixes [#616](https://github.com/nextjournal/clerk/issues/616).
43+
44+
* 🐜 Make edn transmission resilient to symbols and keywords containing multiple slashes like `foo/bar/baz`. Those can be read by `read-string` but not in ClojureScript which is based on `tools.reader`.
45+
46+
* 🐞 Fix `:nextjournal.clerk/page-size` option throwing when set on string values, fixes [#584][https://github.com/nextjournal/clerk/issues/584]
47+
48+
* 🐞 Fix caching behaviour of `clerk/image` and support overriding image-viewer by name
49+
50+
* 🐞 Fix tap viewer keeping open/collapsed state [#543](https://github.com/nextjournal/clerk/issues/543) @teodorlu
51+
52+
* 🐞 Fix `serve!` `:browse` option for default host & port
53+
54+
* 🐞 Fix `unquote` in experimental cljs Clerk editor, fixes [#576](https://github.com/nextjournal/clerk/issues/576) @sritchie
55+
56+
* 🐞 Fix `row` and `col` viewers not showing a first map argument, fixes [#567](https://github.com/nextjournal/clerk/issues/567) @teodorlu
57+
58+
* 🐞 Fix long sidenotes overlapping with subsequent content, fixes [#564](https://github.com/nextjournal/clerk/issues/564) @hlship
59+
60+
* 🐞 Fix image embedding regression in static build introduced in 424bf35040a266f71d00d8a581ba7cdfcfcd4a75
61+
62+
* 🐞 Swallow git errors in shell-out-str instead of printing them to stdout/err
63+
64+
* 🐞 Fix an issue in fragments which showed definitions as vars instead of their values
65+
66+
* 🐞 Fix blank page when notebook contains latex errors in prose [#571](https://github.com/nextjournal/clerk/issues/571) @titonbarua and [#603](https://github.com/nextjournal/clerk/issues/603) @teodorlu
67+
68+
* 🐞 Fix displaying images when expanding elided data [#612](https://github.com/nextjournal/clerk/issues/612) @a1exsh
69+
70+
* 🐞 Elide end-location metadata from forms which otherwise crashes `honey.sql/format` [#646](https://github.com/nextjournal/clerk/issues/646) @borkdude
71+
72+
## 0.15.957 (2023-09-28)
73+
74+
* 🔌 Offline support
75+
76+
Support working fully offline by adding a ServiceWorker to intercept and cache network requests to remote assets in the browser. It works for Clerk's js bundle, its tailwind css script, fonts and as well as javascript dynamically loaded using d3-require like Clerk's Vega and Plotly viewers.
77+
78+
To use it, you need to open Clerk in the browser when online to populate the cache. Viewers that are dynamically loaded (e.g. Vega or Plotly) need to be used once while offline to be cached. We're considering loading them on worker init in a follow up.
79+
1180
* 👁️ Improve viewer customization
1281

1382
* Simplify customization of number of rows displayed for table viewer using viewer-opts, e.g. `(clerk/table {::clerk/page-size 7})`. Pass `{::clerk/page-size nil}` to display elisions. Can also be passed a form metadata. Fixes [#406](https://github.com/nextjournal/clerk/issues/406).
@@ -47,6 +116,8 @@ Changes can be:
47116

48117
* 💫 Assign `:name` to every viewer in `default-viewers`
49118

119+
* 🐜 Ensure `var->location` returns a string path location fixing `Cannot open <#object[sun.nio.fs.UnixPath ,,,> as an InputStream` errors
120+
50121
* 🐞 Don't run existing files through `fs/glob`, fixes [#504](https://github.com/nextjournal/clerk/issues/504). Also improves performance of homepage.
51122

52123
* 🐞 Show correct non-var return value for deflike form, fixes [#499](https://github.com/nextjournal/clerk/issues/499)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To use Clerk in your project, you'll need Java 11+ and [`clojure`](https://cloju
4646
following dependency to your `deps.edn`:
4747

4848
```edn
49-
{:deps {io.github.nextjournal/clerk {:mvn/version "0.14.919"}}}
49+
{:deps {io.github.nextjournal/clerk {:mvn/version "0.16.1016"}}}
5050
```
5151

5252
Require and start Clerk as part of your system start, e.g. in `user.clj`:

bb.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{:min-bb-version "0.9.159"
22
:paths ["bb"]
33
:deps {io.github.nextjournal/dejavu {:git/sha "4980e0cc18c9b09fb220874ace94ba6b57a749ca"}
4-
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}}
4+
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}}
55
:tasks
66
{:requires
77
([tasks :as t]

book.clj

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
;; To use Clerk in your project, add the following dependency to your `deps.edn`:
6161

6262
;; ```edn
63-
;; {:deps {io.github.nextjournal/clerk {:mvn/version "0.14.919"}}}
63+
;; {:deps {io.github.nextjournal/clerk {:mvn/version "0.16.1016"}}}
6464
;; ```
6565

6666
;; Require and start Clerk as part of your system start, e.g. in `user.clj`:
@@ -299,32 +299,47 @@ int main() {
299299

300300
;; ### 🏞 Images
301301

302-
;; Clerk now has built-in support for the
303-
;; `java.awt.image.BufferedImage` class, which is the native image
304-
;; format of the JVM.
305-
;;
306-
;; When combined with `javax.imageio.ImageIO/read`, one can easily
307-
;; load images in a variety of formats from a `java.io.File`, an
308-
;; `java.io.InputStream`, or any resource that a `java.net.URL` can
309-
;; address.
302+
;; Clerk offers the `clerk/image` viewer to create a buffered image
303+
;; from a string or anything `javax.imageio.ImageIO/read` can take
304+
;; (URL, File or InputStream).
310305
;;
311306
;; For example, we can fetch a photo of De zaaier, Vincent van Gogh's
312307
;; famous painting of a farmer sowing a field from Wiki Commons like
313308
;; this:
314309

315-
(ImageIO/read (URL. "https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/The_Sower.jpg/1510px-The_Sower.jpg"))
310+
(clerk/image "https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/The_Sower.jpg/1510px-The_Sower.jpg")
316311

317312
;; We've put some effort into making the default image rendering
318313
;; pleasing. The viewer uses the dimensions and aspect ratio of each
319314
;; image to guess the best way to display it in classic DWIM
320315
;; fashion. For example, an image larger than 900px wide with an
321316
;; aspect ratio larger then two will be displayed full width:
322317

323-
(ImageIO/read (URL. "https://images.unsplash.com/photo-1532879311112-62b7188d28ce?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8"))
318+
(clerk/image "https://images.unsplash.com/photo-1532879311112-62b7188d28ce?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8")
324319

325320
;; On the other hand, smaller images are centered and shown using their intrinsic dimensions:
326321

327-
(ImageIO/read (URL. "https://nextjournal.com/data/QmSJ6eu6kUFeWrqXyYaiWRgJxAVQt2ivaoNWc1dtTEADCf?filename=thermo.png&content-type=image/png"))
322+
(clerk/image "https://nextjournal.com/data/QmSJ6eu6kUFeWrqXyYaiWRgJxAVQt2ivaoNWc1dtTEADCf?filename=thermo.png&content-type=image/png")
323+
324+
;; You can use `clerk/image` together with `clerk/caption` which will render a simple caption under the image:
325+
326+
(clerk/caption
327+
"Implements of the Paper Printing Industry"
328+
(clerk/image "https://nextjournal.com/data/QmX99isUndwqBz7nj8fdG7UoDakNDSH1TZcvY2Y6NUTe6o?filename=image.gif&content-type=image/gif"))
329+
330+
;; Captions aren't limited to images and work together with any arbitrary content that you provide, e.g. a table:
331+
332+
^{::clerk/visibility {:code :fold}}
333+
(clerk/caption
334+
"Modern Symmetrical Unary(7) in [Solresol](https://wiki.xxiivv.com/site/solresol.html)"
335+
(clerk/table {:head ["Solfège" "French IPA" "English IPA" "Meaning"]
336+
:rows [["Do" "/do/" "/doʊ/" "no"]
337+
["Re" "/ʁɛ/" "/ɹeɪ/" "and, also"]
338+
["Mi" "/mi/" "/miː/" "or"]
339+
["Fa" "/fa/" "/fɑː/" "at, to"]
340+
["Sol" "/sɔl/" "/soʊl/" "but, if"]
341+
["La" "/la/" "/lɑː/" "the, then"]
342+
["Si" "/si/" "/siː/" "yes"]]}))
328343

329344
;; ### 📒 Markdown
330345

@@ -363,13 +378,15 @@ int main() {
363378
;; nice captions:
364379

365380
(defn caption [text]
366-
(clerk/html [:span.text-slate-500.text-xs.text-center.font-sans text]))
381+
(clerk/html [:figcaption.text-center.mt-1 text]))
367382

368383
(clerk/row
369384
(clerk/col image-1 (caption "Figure 1: Decorative A"))
370385
(clerk/col image-2 (caption "Figure 2: Decorative B"))
371386
(clerk/col image-3 (caption "Figure 3: Decorative C")))
372387

388+
;; Note: the caption example is _exactly_ how `clerk/caption` is implemented in Clerk.
389+
373390
;; **Alternative notations**
374391
;;
375392
;; By default, `row` and `col` operate on `& rest` so you can pass any
@@ -531,7 +548,7 @@ v/default-viewers
531548

532549
;; #### ⚙️ Transform
533550

534-
;; When writing your own viewer, the first extension point you should reach for is `:tranform-fn`.
551+
;; When writing your own viewer, the first extension point you should reach for is `:transform-fn`.
535552

536553
#_ "exercise: wrap this in `v/present` and call it at the REPL"
537554
(v/with-viewer {:transform-fn v/inspect-wrapped-values}

build.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
:connection "scm:git:git://github.com/nextjournal/clerk.git"
3333
:developerConnection "scm:git:ssh://[email protected]/nextjournal/clerk.git"
3434
:tag (str "v" version)}
35-
:src-dirs ["src"]})
35+
:src-dirs ["src"]
36+
:pom-data
37+
[[:licenses
38+
[:license
39+
[:name "ISC License"]
40+
[:url "https://opensource.org/license/isc-license-txt"]]]]})
3641
(b/copy-dir {:src-dirs ["src" "resources"]
3742
:target-dir class-dir
3843
:replace {}})

deps.edn

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
org.clojure/tools.analyzer {:mvn/version "1.1.0"}
55
org.clojure/tools.analyzer.jvm {:mvn/version "1.1.0"}
66
babashka/fs {:mvn/version "0.2.14"}
7-
borkdude/edamame {:mvn/version "1.0.16"}
7+
borkdude/edamame {:mvn/version "1.4.24"}
88
weavejester/dependency {:mvn/version "0.2.1"}
99
com.nextjournal/beholder {:mvn/version "1.0.2"}
1010
org.flatland/ordered {:mvn/version "1.15.11"}
1111

12-
io.github.nextjournal/markdown {:mvn/version "0.5.144"}
12+
io.github.nextjournal/markdown {:mvn/version "0.5.148"}
1313
babashka/process {:mvn/version "0.4.16"}
1414
io.github.nextjournal/dejavu {:git/sha "4980e0cc18c9b09fb220874ace94ba6b57a749ca"}
1515

16-
com.taoensso/nippy {:mvn/version "3.2.0"}
16+
com.taoensso/nippy {:mvn/version "3.4.2"}
1717

1818
mvxcvi/multiformats {:mvn/version "0.3.107"}
1919
com.pngencoder/pngencoder {:mvn/version "0.13.1"}
2020

21-
http-kit/http-kit {:mvn/version "2.6.0"}
22-
hiccup/hiccup {:mvn/version "2.0.0-alpha2"}
21+
http-kit/http-kit {:mvn/version "2.8.0"}
22+
hiccup/hiccup {:mvn/version "2.0.0-RC3"}
2323

2424
rewrite-clj/rewrite-clj {:mvn/version "1.1.45"}
2525

@@ -35,23 +35,31 @@
3535
:jvm-opts ["-Dclojure.main.report=stdout"]
3636
:nextjournal.clerk/aliases [:demo]}
3737

38+
3839
:sci {:extra-deps {io.github.nextjournal/clerk.render {:local/root "render"}}}
3940

40-
:dev {:extra-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha3"} ;; for `:as-alias` & `add-lib` support but only in dev
41+
:dev {:extra-deps {org.clojure/clojure {:mvn/version "1.12.0-beta1"} ;; for `:as-alias` & `add-lib` support but only in dev
4142
arrowic/arrowic {:mvn/version "0.1.1"}
4243
binaryage/devtools {:mvn/version "1.0.3"}
43-
cider/cider-nrepl {:mvn/version "0.29.0"}
44+
cider/cider-nrepl {:mvn/version "0.49.0"}
45+
nrepl/nrepl {:mvn/version "1.2.0"}
4446
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.0.3"}
45-
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}
47+
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}
4648
org.slf4j/slf4j-nop {:mvn/version "2.0.7"}
47-
org.babashka/cli {:mvn/version "0.5.40"}}
49+
org.babashka/cli {:mvn/version "0.5.40"}
50+
io.github.babashka/sci.nrepl {:git/sha "75f379c685bbd58c3e23f531339eb144e104937d"}}
4851
:extra-paths ["dev" "notebooks"]
4952
:jvm-opts ["-Dclerk.resource_manifest={\"/js/viewer.js\" \"/js/viewer.js\"}"
53+
"-Dclerk.render_repl={}"
5054
"-Dpolyglot.engine.WarnInterpreterOnly=false" "-XX:-OmitStackTraceInFastThrow"
5155
"-Djdk.attach.allowAttachSelf"]
5256
:main-opts ["-m" "shadow.cljs.devtools.cli"]
5357
:exec-fn nextjournal.clerk.dev-launcher/start}
5458

59+
:profile {:exec-fn user/profile
60+
:exec-args {:phase :analysis}
61+
:jvm-opts ["-Dclojure.main.report=stdout"]}
62+
5563
:test {:extra-deps {nubank/matcher-combinators {:mvn/version "3.5.1"}
5664
org.clojure/test.check {:mvn/version "1.1.1"}
5765
lambdaisland/kaocha {:mvn/version "1.66.1034"}
@@ -66,16 +74,21 @@
6674
:demo {:extra-deps {com.github.seancorfield/next.jdbc {:mvn/version "1.2.659"}
6775
io.github.applied-science/shapes {:git/sha "da44031cf79a649932cb502f17388db23f2b8ace"}
6876
org.xerial/sqlite-jdbc {:mvn/version "3.34.0"}
77+
com.github.seancorfield/honeysql {:mvn/version "2.6.1126"}
6978
org.clojure/data.csv {:mvn/version "1.0.0"}
7079
hickory/hickory {:mvn/version "0.7.1"}
7180
sicmutils/sicmutils {:mvn/version "0.20.0" :exclusions [org.babashka/sci]}
7281
io.github.mentat-collective/emmy {:git/sha "b98fef51d80d3edcff3100562b929f9980ff34d7"
7382
:exclusions [org.babashka/sci]}
7483
io.github.nextjournal/clerk-slideshow {:git/sha "11a83fea564da04b9d17734f2031a4921d917893"}}}
7584

85+
:nextjournal/garden {:exec-fn nextjournal.clerk/serve!
86+
:exec-args {:index "book.clj"}
87+
:nextjournal.garden/aliases [:demo]}
88+
7689
:build {:deps {io.github.nextjournal/clerk {:local/root "."}
77-
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}
78-
io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"}
90+
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}
91+
io.github.clojure/tools.build {:git/tag "v0.10.3" :git/sha "15ead66"}
7992
io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}}
8093
:extra-paths ["bb" "src" "resources"] ;; for loading lookup-url in build
8194
:ns-default build}

dev/user.clj

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
(ns user
2-
(:require [clojure.string :as str]
3-
[nextjournal.clerk :as clerk]))
2+
(:require [clj-async-profiler.core :as prof]
3+
[clojure.java.io :as io]
4+
[nextjournal.clerk :as clerk]
5+
[nextjournal.clerk.analyzer :as analyzer]
6+
[nextjournal.clerk.eval :as eval]
7+
[nextjournal.clerk.parser :as parser]))
48

59
(comment
610
;; start without file watcher & open browser
@@ -43,4 +47,40 @@
4347

4448
(do (require 'kaocha.repl)
4549
(kaocha.repl/run :unit))
46-
)
50+
51+
(do
52+
(clerk/clear-cache!)
53+
(reset! analyzer/!file->analysis-cache {})
54+
(prof/profile
55+
(-> (parser/parse-file {:doc? true} "book.clj")
56+
analyzer/build-graph
57+
analyzer/hash))
58+
nil)
59+
(prof/serve-ui 8080))
60+
61+
(defmacro with-ex-data [sym body do-block]
62+
`(try ~body
63+
(catch Exception e#
64+
(let [~sym (ex-data e#)]
65+
~do-block))))
66+
67+
(defmulti profile :phase)
68+
69+
(defmethod profile :analysis [_opts]
70+
(let [test-docs [(parser/parse-file {:doc? true} (io/resource "clojure/core.clj"))
71+
(parser/parse-file {:doc? true} (io/resource "nextjournal/clerk/analyzer.clj"))
72+
(parser/parse-file {:doc? true} (io/resource "nextjournal/clerk.clj"))
73+
#_ more?]
74+
times 5]
75+
(let [{:keys [time-ms]}
76+
(eval/time-ms
77+
(dotimes [_i times]
78+
(doseq [doc (shuffle test-docs)]
79+
(-> (analyzer/build-graph doc) analyzer/hash))
80+
(prn :done/pass _i)))
81+
mean (/ time-ms (* times (count test-docs)))]
82+
(println (format "Elapsed mean time: %f msec" mean)))))
83+
84+
;; clj -X:dev:profile :phase :analysis
85+
;; Elapsed mean time: ~1700 msec (iMac i9, main)
86+
;; Elapsed mean time: ~1670 msec (iMac i9, analyzer-improvements)

garden.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:project "book-of-clerk"}

0 commit comments

Comments
 (0)