Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meta-viewer for metadata-based viewer assignment #502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@
(def mathjax-viewer
{:name `mathjax-viewer :render-fn 'nextjournal.clerk.render/render-mathjax :transform-fn mark-presented})

(def meta-viewer
Copy link
Collaborator Author

@sritchie sritchie May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to add examples to the book, @mk .

Here's one:

image

{:name `meta-viewer
:pred (comp (some-fn fn? map?) :nextjournal.clerk/viewer meta)
:transform-fn
(update-val
(fn [v]
(let [viewer (-> v meta :nextjournal.clerk/viewer)]
(if (fn? viewer)
(viewer v)
(with-viewer viewer v)))))})

(defn ->opts [wrapped-value]
(select-keys wrapped-value [:nextjournal/budget :nextjournal/css-class :nextjournal/width :nextjournal/opts
:nextjournal/render-evaluator
Expand Down Expand Up @@ -1193,6 +1204,7 @@
elision-viewer
katex-viewer
mathjax-viewer
meta-viewer
html-viewer
plotly-viewer
vega-lite-viewer
Expand Down