forked from nextjournal/clerk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiding_clerk_metadata.clj
66 lines (52 loc) · 1.72 KB
/
hiding_clerk_metadata.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;; # 👻 Hiding Clerk Metadata
(ns hiding-clerk-metadata
{:nextjournal.clerk/toc true}
(:require [nextjournal.clerk :as clerk]))
;; All metadata on forms in the `nextjournal.clerk` namespace should be hidden from the user, while all other keys should be displayed.
^clojure.lang.PersistentHashMap
^{::clerk/visibility {:result :hide} :please "keep me"}
{:a 'nice-map} ;; should keep comments here
;; map metadata with all-clerk keys should just not be displayed
^{::clerk/visibility {:result :show} ::clerk/width :wide ::clerk/no-cache true}
(clerk/html
[:h4
(apply str (repeat 10 "♦︎"))
[:span.mx-5 (rand-int 1000)]
(apply str (repeat 10 "♦︎"))])
;; simple truthy meta like `^::clerk/no-cache` should be removed
^::clerk/no-cache
(rand-int 100) ;; should keep comments here
;; ## Clerk metadata on Vars
;; Should also be hidden
(def ^::clerk/no-cache ^:private random-thing (rand-int 1000)) ;; should keep comments here
(defonce ^{::clerk/no-cache true :doc "this should stay"} once-random-thing (rand-int 1000))
^::clerk/sync
(defonce ^::clerk/no-cache sync-me (atom nil))
;; ## Whitespace
;; All whitespace and comments in-between annotations should be preserved:
^{:some/key 123 :and 'this ::clerk/no-cache true}
;; this should be kept
'some-symbol
^::clerk/no-cache
;; this form is not cached
{}
^ :foo
^ {:this :weird :map 'is
::clerk/visibility {:result :hide}
:is :all
:kept
123} ;; should keep comments here
'foo
;; ## Unevals
;; Unevals in between meta expressions should also be kept
^:private #_ keep-me {}
^::clerk/no-cache #_ keep-me {}
;; ## Unreadable forms
;; meta with e.g. unbalanced maps should throw as expected
;;
;; ^{:a 1 :c}
;; 'what
#_
(comment
^{:a 1 :c}
'what)