diff --git a/src/nextjournal/markdown/impl.clj b/src/nextjournal/markdown/impl.clj index 670d51a..e718fa8 100644 --- a/src/nextjournal/markdown/impl.clj +++ b/src/nextjournal/markdown/impl.clj @@ -211,6 +211,18 @@ z/up (z/edit assoc :type :todo-list) z/down z/rightmost)) +(def clazzes (atom #{})) + +(comment + @clazzes + ) + +(def ^:private visitChildren-meth + ;; cached reflection only happens once + (delay (let [meth (.getDeclaredMethod AbstractVisitor "visitChildren" (into-array [Node]))] + (.setAccessible meth true) + meth))) + (defn node->data [{:as ctx-in :keys [footnotes]} ^Node node] (assert (:type ctx-in) ":type must be set on initial doc") (assert (:content ctx-in) ":content must be set on initial doc") @@ -249,10 +261,12 @@ ;; else branch nodes (if (get-method open-node (class node)) - (with-tight-list node - (swap! !ctx open-node node) - (proxy-super visitChildren node) - (swap! !ctx close-node node)) + (do + (swap! clazzes conj (class node)) + (with-tight-list node + (swap! !ctx open-node node) + (.invoke ^java.lang.reflect.Method @visitChildren-meth this (into-array Object [node])) + (swap! !ctx close-node node))) (prn ::not-implemented node)))))) (let [{:as ctx-out :keys [doc title toc footnotes] ::keys [label->footnote-ref]} (deref !ctx)] diff --git a/src/nextjournal/markdown/impl/types.clj b/src/nextjournal/markdown/impl/types.clj index df3ab70..6f9f4de 100644 --- a/src/nextjournal/markdown/impl/types.clj +++ b/src/nextjournal/markdown/impl/types.clj @@ -1,14 +1,18 @@ -(ns nextjournal.markdown.impl.types - (:import [nextjournal.markdown.impl.types CustomNode])) +(ns nextjournal.markdown.impl.types) ;; See also ;; https://github.com/noties/Markwon/blob/master/markwon-ext-latex/src/main/java/io/noties/markwon/ext/latex/JLatexMathBlockParser.java (set! *warn-on-reflection* true) +(definterface CustomNode + (getLiteral []) + (setLiteral [v]) + (nodeType [])) + (defn ->InlineFormula [lit] (let [state (atom lit)] - (proxy [org.commonmark.node.CustomNode CustomNode] [] + (proxy [org.commonmark.node.CustomNode nextjournal.markdown.impl.types.CustomNode] [] (getLiteral [] @state) (nodeType [] :inline-formula)))) @@ -16,14 +20,14 @@ ([] (->BlockFormula nil)) ([lit] (let [state (atom lit)] - (proxy [org.commonmark.node.CustomBlock CustomNode] [] + (proxy [org.commonmark.node.CustomBlock nextjournal.markdown.impl.types.CustomNode] [] (getLiteral [] @state) (setLiteral [v] (do (reset! state v) this)) (nodeType [] :block-formula))))) (defn ->ToC [] - (proxy [org.commonmark.node.CustomBlock CustomNode] [] + (proxy [org.commonmark.node.CustomBlock nextjournal.markdown.impl.types.CustomNode] [] (nodeType [] :toc))) (defn setLiteral [^CustomNode n lit]