File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 698
698
(let [re-eval (fn [{:keys [form]}] (viewer/->viewer-fn form))]
699
699
(w/postwalk (fn [x] (cond-> x (viewer/viewer-fn? x) re-eval)) doc)))
700
700
701
+ (defn replace-viewer-fns [doc]
702
+ (w/postwalk-replace (:hash->viewer doc) (dissoc doc :hash->viewer )))
703
+
701
704
(defn ^:export set-state! [{:as state :keys [doc]}]
702
705
(when (contains? state :doc )
703
706
(when (exists? js/window)
704
707
; ; TODO: can we restore the scroll position when navigating back?
705
708
(.scrollTo js/window #js {:top 0 }))
706
- (reset! !doc doc))
709
+ (reset! !doc ( replace-viewer-fns doc) ))
707
710
; ; (when (and error (contains? @!doc :status))
708
711
; ; (swap! !doc dissoc :status))
709
712
(when (remount? doc)
Original file line number Diff line number Diff line change 1
1
(ns nextjournal.clerk.view
2
- (:require [nextjournal.clerk.viewer :as v ]
3
- [hiccup.page :as hiccup ]
2
+ (:require [clojure.java.io :as io ]
3
+ [clojure.set :as set ]
4
4
[clojure.string :as str]
5
- [clojure.java.io :as io])
5
+ [clojure.walk :as walk]
6
+ [hiccup.page :as hiccup]
7
+ [nextjournal.clerk.viewer :as v])
6
8
(:import (java.net URI)))
7
9
10
+ (defn ^:private extract-hash->viewer [presentation]
11
+ (into {}
12
+ (map (juxt :hash identity))
13
+ (keep :nextjournal/viewer (tree-seq (some-fn map? vector?) #(cond-> % (map? %) vals) presentation))))
14
+
8
15
(defn doc->viewer
9
16
([doc] (doc->viewer {} doc))
10
17
([opts {:as doc :keys [ns file]}]
11
18
(binding [*ns* ns ]
12
- (-> (merge doc opts) v/notebook v/present))))
19
+ (let [presentation (-> (merge doc opts) v/notebook v/present)
20
+ hash->viewer (extract-hash->viewer presentation)]
21
+ (assoc (walk/postwalk-replace (set/map-invert hash->viewer) presentation)
22
+ :hash->viewer hash->viewer)))))
13
23
14
24
#_(doc->viewer (nextjournal.clerk/eval-file " notebooks/hello.clj" ))
15
25
#_(nextjournal.clerk/show! " notebooks/test.clj" )
You can’t perform that action at this time.
0 commit comments