Skip to content

Commit

Permalink
Merge branch 'main' into fix-586
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed Dec 7, 2023
2 parents eb89e0b + 6dab22c commit 7627691
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ Changes can be:

* 💫 Support using Markdown syntax in `clerk/caption` text

* 💫 Redesign examples viewer to be more readable and in a way that doesn't force `display: flex` onto contents.

* 🛠 Bump depdendencies

* `com.taoensso/nippy` to `3.4.0-beta1`
* `io.github.nextjournal/markdown` to `0.5.146`

* 🐜 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`.

* 🐞 Fix caching behaviour of `clerk/image` and support overriding image-viewer by name

* 🐞 Fix `unquote` in experimental cljs Clerk editor, fixes [#576](https://github.com/nextjournal/clerk/issues/576) @sritchie
Expand Down
24 changes: 12 additions & 12 deletions src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[flatland.ordered.map :refer [ordered-map]]
#?@(:clj [[babashka.fs :as fs]
[clojure.repl :refer [demunge]]
[clojure.tools.reader :as tools.reader]
[editscript.edit]
[nextjournal.clerk.config :as config]
[nextjournal.clerk.analyzer :as analyzer]]
Expand Down Expand Up @@ -361,7 +362,7 @@

#?(:clj (defn roundtrippable? [x]
(try
(= x (-> x str read-string))
(= x (-> x str tools.reader/read-string))
(catch Exception _e false))))

#?(:clj
Expand All @@ -375,7 +376,7 @@
#?(:clj
(defmethod print-method clojure.lang.Symbol [o w]
(if (or (roundtrippable? o)
(= (name o) "?@")) ;; splicing reader conditional, see issue #338
(= (name o) "?@")) ;; splicing reader conditional, see issue #338
(print-simple o w)
(.write w (pr-str (->viewer-eval (if-let [ns (namespace o)]
(list 'symbol ns (name o))
Expand Down Expand Up @@ -1110,7 +1111,7 @@

#?(:clj
(defn edn-roundtrippable? [x]
(= x (-> x ->edn read-string))))
(= x (-> x ->edn tools.reader/read-string))))

#?(:clj
(defn throw-if-sync-var-is-invalid [var]
Expand Down Expand Up @@ -1858,19 +1859,18 @@
(-> wrapped-value
mark-preserve-keys
(assoc :nextjournal/viewer {:render-fn '(fn [{:keys [form val]} opts]
[:div.flex.flex-wrap
{:class "py-[7px]"}
[:div [:div.bg-slate-100.px-2.rounded
(nextjournal.clerk.render/inspect-presented opts form)]]
[:div.flex.mt-1
[:div.mx-2.font-sans.text-xs.text-slate-500 {:class "mt-[2px]"} ""]
[:div.mb-3.last:mb-0
[:div.bg-slate-100.dark:bg-slate-800.px-4.py-2.border-l-2.border-slate-200.dark:border-slate-700
(nextjournal.clerk.render/inspect-presented opts form)]
[:div.pt-2.px-4.border-l-2.border-transparent
(nextjournal.clerk.render/inspect-presented opts val)]])})
(update-in [:nextjournal/value :form] code)))})

(def examples-viewer
{:transform-fn (update-val (fn [examples]
(mapv (partial with-viewer example-viewer) examples)))
:render-fn '(fn [examples opts]
(into [:div.border-l-2.border-slate-300.pl-4
[:div.uppercase.tracking-wider.text-xs.font-sans.text-slate-500.mt-4.mb-2 "Examples"]]
(nextjournal.clerk.render/inspect-children opts) examples))})
[:div
[:div.uppercase.tracking-wider.text-xs.font-sans.font-bold.text-slate-500.dark:text-white.mb-2.mt-3 "Examples"]
(into [:div]
(nextjournal.clerk.render/inspect-children opts) examples)])})
6 changes: 6 additions & 0 deletions test/nextjournal/clerk/viewer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@
(is (= "#viewer-eval (symbol \"~\")"
(pr-str (symbol "~")))))

(testing "symbols and keywords with two slashes readable by `read-string` but not `tools.reader/read-string` print as viewer-eval"
(is (= "#viewer-eval (symbol \"foo\" \"bar/baz\")"
(pr-str (read-string "foo/bar/baz"))))
(is (= "#viewer-eval (keyword \"foo\" \"bar/baz\")"
(pr-str (read-string ":foo/bar/baz")))))

(testing "splicing reader conditional prints normally (issue #338)"
(is (= "?@" (pr-str (symbol "?@")))))

Expand Down

0 comments on commit 7627691

Please sign in to comment.