|
163 | 163 |
|
164 | 164 | (def viewer-opts-normalization |
165 | 165 | "Normalizes ns for viewer opts keywords `:nextjournal.clerk/x` => `:nextjournal/x`" |
166 | | - (into {} |
| 166 | + (into {:nextjournal/opts :nextjournal/render-opts} |
167 | 167 | (map (juxt #(keyword "nextjournal.clerk" (name %)) |
168 | 168 | #(keyword "nextjournal" (name %)))) |
169 | 169 | (conj parser/block-settings :viewer :viewers))) |
|
179 | 179 | {:width width :css-class css-class})))) |
180 | 180 | opts) |
181 | 181 |
|
182 | | -(defn normalize-viewer-opts [opts] |
183 | | - (throw-when-viewer-opts-invalid (set/rename-keys opts viewer-opts-normalization))) |
| 182 | +(defn normalize-viewer-opts [viewer-opts] |
| 183 | + (throw-when-viewer-opts-invalid (set/rename-keys viewer-opts viewer-opts-normalization))) |
184 | 184 |
|
185 | 185 | (defn normalize-viewer [viewer] |
186 | 186 | (cond (keyword? viewer) viewer |
|
330 | 330 | (with-viewer (keyword "nextjournal.markdown" (name type)) wrapped-value))) |
331 | 331 |
|
332 | 332 | (defn into-markup [markup] |
333 | | - (fn [{:as wrapped-value :nextjournal/keys [viewers opts]}] |
| 333 | + (fn [{:as wrapped-value :nextjournal/keys [viewers render-opts]}] |
334 | 334 | (-> (with-viewer {:name `markdown-node-viewer :render-fn 'identity} wrapped-value) |
335 | 335 | mark-presented |
336 | 336 | (update :nextjournal/value |
337 | 337 | (fn [{:as node :keys [text content] ::keys [doc]}] |
338 | | - (into (cond-> markup (fn? markup) (apply [(merge opts node)])) |
| 338 | + (into (cond-> markup (fn? markup) (apply [(merge render-opts node)])) |
339 | 339 | (cond text [text] |
340 | 340 | content (mapv #(-> (ensure-wrapped-with-viewers viewers (assoc % ::doc doc)) |
341 | 341 | (with-md-viewer) |
|
507 | 507 | opts-from-block |
508 | 508 | (ensure-wrapped-with-viewers (or viewers (get-viewers *ns*)) value)) |
509 | 509 | presented-result (-> (present to-present) |
510 | | - (update :nextjournal/opts |
| 510 | + (update :nextjournal/render-opts |
511 | 511 | (fn [{:as opts existing-id :id}] |
512 | 512 | (cond-> opts |
513 | 513 | auto-expand-results? (assoc :auto-expand-results? auto-expand-results?) |
|
574 | 574 |
|
575 | 575 | (defn md-image->viewer [doc block-id idx {:keys [attrs]}] |
576 | 576 | (with-viewer `html-viewer |
577 | | - #?(:clj {:nextjournal/opts {:id (processed-block-id block-id [idx])} |
| 577 | + #?(:clj {:nextjournal/render-opts {:id (processed-block-id block-id [idx])} |
578 | 578 | :nextjournal/width (try (image-width (read-image (:src attrs))) |
579 | 579 | (catch Throwable _ :prose))}) |
580 | 580 | [:div.flex.flex-col.items-center.not-prose.mb-4 |
|
598 | 598 | (mapcat (fn [fragment] |
599 | 599 | (if (= :image (:type (first fragment))) |
600 | 600 | (map #(md-image->viewer doc id (swap! !idx inc) %) fragment) |
601 | | - [(with-viewer `markdown-viewer {:nextjournal/opts {:id (processed-block-id id [(swap! !idx inc)])}} |
| 601 | + [(with-viewer `markdown-viewer {:nextjournal/render-opts {:id (processed-block-id id [(swap! !idx inc)])}} |
602 | 602 | (process-sidenotes {:type :doc |
603 | 603 | :content (vec fragment) |
604 | 604 | ::doc doc} doc))])) |
|
610 | 610 | (cond-> [] |
611 | 611 | code? |
612 | 612 | (conj (with-viewer (if fold? `folded-code-block-viewer `code-block-viewer) |
613 | | - {:nextjournal/opts (assoc (select-keys cell [:loc]) |
614 | | - :id (processed-block-id (str id "-code")))} |
| 613 | + {:nextjournal/render-opts (assoc (select-keys cell [:loc]) |
| 614 | + :id (processed-block-id (str id "-code")))} |
615 | 615 | (dissoc cell :result))) |
616 | 616 | (or result? eval?) |
617 | 617 | (conj (cond-> (ensure-wrapped (-> cell (assoc ::doc doc) (set/rename-keys {:result ::result}))) |
|
719 | 719 | :transform-fn (update-val #(with-viewer `html-viewer |
720 | 720 | [:div.code-viewer.code-listing |
721 | 721 | (with-viewer `code-viewer |
722 | | - {:nextjournal/opts {:language (:language % "clojure")}} |
| 722 | + {:nextjournal/render-opts {:language (:language % "clojure")}} |
723 | 723 | (str/trim-newline (md.transform/->text %)))]))} |
724 | 724 |
|
725 | 725 | ;; marks |
|
886 | 886 | {:name `mathjax-viewer :render-fn 'nextjournal.clerk.render/render-mathjax :transform-fn mark-presented}) |
887 | 887 |
|
888 | 888 | (defn ->opts [wrapped-value] |
889 | | - (select-keys wrapped-value [:nextjournal/budget :nextjournal/css-class :nextjournal/width :nextjournal/opts |
| 889 | + (select-keys wrapped-value [:nextjournal/budget :nextjournal/css-class :nextjournal/width :nextjournal/render-opts |
890 | 890 | :nextjournal/render-evaluator |
891 | 891 | :!budget :store!-wrapped-value :present-elision-fn :path :offset])) |
892 | 892 |
|
|
935 | 935 | {:name `code-viewer |
936 | 936 | :render-fn 'nextjournal.clerk.render/render-code |
937 | 937 | :transform-fn (comp mark-presented |
938 | | - #(update-in % [:nextjournal/opts :language] (fn [lang] (or lang "clojure"))) |
| 938 | + #(update-in % [:nextjournal/render-opts :language] (fn [lang] (or lang "clojure"))) |
939 | 939 | (update-val (fn [v] (if (string? v) v (str/trim (with-out-str (pprint/pprint v)))))))}) |
940 | 940 |
|
941 | 941 | (def reagent-viewer |
|
995 | 995 | (-> wrapped-value |
996 | 996 | (assoc :nextjournal/viewer `table-markup-viewer) |
997 | 997 | (update :nextjournal/width #(or % :wide)) |
998 | | - (update :nextjournal/opts merge {:num-cols (count (or head (first rows))) |
999 | | - :number-col? (into #{} |
1000 | | - (comp (map-indexed vector) |
1001 | | - (keep #(when (number? (second %)) (first %)))) |
1002 | | - (not-empty (first rows)))}) |
| 998 | + (update :nextjournal/render-opts merge {:num-cols (count (or head (first rows))) |
| 999 | + :number-col? (into #{} |
| 1000 | + (comp (map-indexed vector) |
| 1001 | + (keep #(when (number? (second %)) (first %)))) |
| 1002 | + (not-empty (first rows)))}) |
1003 | 1003 | (assoc :nextjournal/value (cond->> [] |
1004 | 1004 | (seq rows) (cons (with-viewer `table-body-viewer (merge (-> applied-viewer |
1005 | 1005 | (select-keys [:page-size]) |
|
0 commit comments