Skip to content

Commit

Permalink
middle ground
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Sep 24, 2024
1 parent 00f48c2 commit c4785a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/nextjournal/markdown/impl/types.clj
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
(ns nextjournal.markdown.impl.types)
(ns nextjournal.markdown.impl.types
(:import [nextjournal.markdown.impl.types CustomNode]))

;; 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)

(defonce _
(definterface CustomNode
(getLiteral [])
(setLiteral [v])
(nodeType [])))

(defn ->InlineFormula [lit]
(let [state (atom lit)]
(proxy [org.commonmark.node.CustomNode nextjournal.markdown.impl.types.CustomNode] []
(proxy [org.commonmark.node.CustomNode CustomNode] []
(getLiteral [] @state)
(nodeType [] :inline-formula))))

(defn ->BlockFormula
([] (->BlockFormula nil))
([lit]
(let [state (atom lit)]
(proxy [org.commonmark.node.CustomBlock nextjournal.markdown.impl.types.CustomNode] []
(proxy [org.commonmark.node.CustomBlock CustomNode] []
(getLiteral [] @state)
(setLiteral [v] (do (reset! state v)
this))
(nodeType [] :block-formula)))))

(defn ->ToC []
(proxy [org.commonmark.node.CustomBlock nextjournal.markdown.impl.types.CustomNode] []
(proxy [org.commonmark.node.CustomBlock CustomNode] []
(nodeType [] :toc)))

(defn setLiteral [^CustomNode n lit]
Expand Down
12 changes: 12 additions & 0 deletions src/nextjournal/markdown/impl/types/CustomNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nextjournal.markdown.impl.types;

// rebuild with:
// javac src/nextjournal/markdown/impl/types/CustomNode.java

public interface CustomNode {

public Object setLiteral(Object v);
public Object getLiteral();
public Object nodeType();

}

0 comments on commit c4785a2

Please sign in to comment.