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

Overridable Markdown node Viewers #62

Closed
wants to merge 34 commits into from
Closed

Overridable Markdown node Viewers #62

wants to merge 34 commits into from

Conversation

zampino
Copy link
Collaborator

@zampino zampino commented Jan 27, 2022

This set of changes (partially 1) fits markdown rendering into the viewers API framework, in doing so we achieve:

  • each markdown node (:heading, :paragraph, :monospace, etc) gets assigned an individual viewer and as such its appearance is completely customisable by the user via set-viewers! function. Check the markdown viewers notebook.
  • markdown viewers might depend on other viewers. For instance the formula viewer now is implemented on top of the :latex viewer: changing the latter will affect all formulas inserted in markdown fragments. Check the mathjax example.

It is debatable if this is sufficient or if we want to move viewer selection on the clojure side as per latest trend.

  • fix safari issues with Error: MathJax retry

Notes

1: Markdown blocks are not described but passed to the client wrapped in with-viewer format. The client is still responsible for looking up the right viewer for each markdown node.

this is needed for switching inline or display rendering of formulas
markdown formulas pick up whatever latex viewer is currently configured 
in the notebook.
(incorporate upstream changes from viewer.css)
by restoring same same markup
this allows to change the subject of viewers to be markdown nodes as
they should
@zampino zampino force-pushed the described-markdown branch from b1b010e to 9fda473 Compare January 31, 2022 11:51
@zampino
Copy link
Collaborator Author

zampino commented Jan 31, 2022

Trying to do viewer selection on the clojure side but it's not looking good. Starting with just a few nodes with a recursive describe step done via :transform-fn (which doesn't get passed describe opts) and unwrapping via value fn:

(def describe-children (map (comp value #(describe % {:viewers default-markdown-viewers}))))

(def default-markdown-viewers
  [{:name :nextjournal.markdown/formula
    :fetch-fn (fn [_ {:keys [text]}] text)
    :render-fn (quote v/katex-viewer)}

   {:name :nextjournal.markdown/text
    :fetch-fn (fn [_ {:keys [text]}] text)}

   {:name :nextjournal.markdown/paragraph
    :fetch-fn fetch-all
    :transform-fn (fn [{:nextjournal/keys [value]}]
                    (into [:p] describe-children (:content value)))}

   {:name :nextjournal.markdown/heading
    :fetch-fn fetch-all
    :transform-fn (fn [{:nextjournal/keys [value]}]
                    (let [{:keys [heading-level content]} value]
                      (into [(keyword (str \h heading-level))]
                            describe-children
                            content)))}])

(def default-viewers
  [{:name :nextjournal.markdown/doc
    :render-fn 'v/html
    :transform-fn (fn [wrapped-value]                       ;; FIXME: transform-fn doesn't take options
                    (-> wrapped-value
                        (update :nextjournal/value (fn [{:keys [content]}]
                                                     (into [:<>]
                                                           describe-children
                                                           content)))))
    :fetch-fn fetch-all}
...

and this looks kind of ok

(-> (nextjournal.markdown/parse "# Hello
some paragraph $\\phi$.
  ")
      nextjournal.clerk.view/md->viewer
      describe)
;; => 
{:path [],
 :nextjournal/value [:<> [:h1 "Hello"] [:p "some paragraph " "\\phi" "."]],
 :nextjournal/viewer {:name :nextjournal.markdown/doc, :render-fn #viewer-fnv/html}}

but I cannot easily get a grasp on the formula node :render-fn to have it use the latex viewer. We'd also have to check that this approach is still open for user-facing overrides.

@zampino
Copy link
Collaborator Author

zampino commented Feb 21, 2022

or if we want to move viewer selection on the clojure side

This is actually relying on "client-side viewer registration" which is being dropped with https://github.com/nextjournal/clerk/compare/drop-eval-viewer. The current approach won't make sense any longer, so we'll need to go for an actual server-side description.

@zampino
Copy link
Collaborator Author

zampino commented Mar 24, 2022

Superseded by #122.

@zampino zampino closed this Mar 24, 2022
@mk mk deleted the described-markdown branch August 26, 2022 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant