diff --git a/classes/nextjournal/markdown/parser2/types$fn__1950.class b/classes/nextjournal/markdown/parser2/types$fn__1950.class new file mode 100644 index 0000000..09a5ef5 Binary files /dev/null and b/classes/nextjournal/markdown/parser2/types$fn__1950.class differ diff --git a/classes/nextjournal/markdown/parser2/types$footnote_ref_getLabel.class b/classes/nextjournal/markdown/parser2/types$footnote_ref_getLabel.class new file mode 100644 index 0000000..091bce4 Binary files /dev/null and b/classes/nextjournal/markdown/parser2/types$footnote_ref_getLabel.class differ diff --git a/classes/nextjournal/markdown/parser2/types$footnote_ref_init.class b/classes/nextjournal/markdown/parser2/types$footnote_ref_init.class new file mode 100644 index 0000000..284028c Binary files /dev/null and b/classes/nextjournal/markdown/parser2/types$footnote_ref_init.class differ diff --git a/classes/nextjournal/markdown/parser2/types$loading__6798__auto____1948.class b/classes/nextjournal/markdown/parser2/types$loading__6798__auto____1948.class new file mode 100644 index 0000000..1d9a01d Binary files /dev/null and b/classes/nextjournal/markdown/parser2/types$loading__6798__auto____1948.class differ diff --git a/classes/nextjournal/markdown/parser2/types/Footnote.class b/classes/nextjournal/markdown/parser2/types/Footnote.class index b734c9a..8665511 100644 Binary files a/classes/nextjournal/markdown/parser2/types/Footnote.class and b/classes/nextjournal/markdown/parser2/types/Footnote.class differ diff --git a/classes/nextjournal/markdown/parser2/types/FootnoteRef.class b/classes/nextjournal/markdown/parser2/types/FootnoteRef.class new file mode 100644 index 0000000..79461aa Binary files /dev/null and b/classes/nextjournal/markdown/parser2/types/FootnoteRef.class differ diff --git a/classes/nextjournal/markdown/parser2/types/InlineFormula.class b/classes/nextjournal/markdown/parser2/types/InlineFormula.class index 3edab3f..1a209be 100644 Binary files a/classes/nextjournal/markdown/parser2/types/InlineFormula.class and b/classes/nextjournal/markdown/parser2/types/InlineFormula.class differ diff --git a/classes/nextjournal/markdown/parser2/types__init.class b/classes/nextjournal/markdown/parser2/types__init.class index f2d183f..63af632 100644 Binary files a/classes/nextjournal/markdown/parser2/types__init.class and b/classes/nextjournal/markdown/parser2/types__init.class differ diff --git a/src/nextjournal/markdown/parser2.clj b/src/nextjournal/markdown/parser2.clj index aaa9b83..e90427f 100644 --- a/src/nextjournal/markdown/parser2.clj +++ b/src/nextjournal/markdown/parser2.clj @@ -219,7 +219,6 @@ And what. [^note1]: the _what_ - * and new text[^endnote] at the end. * the * hell^[that warm place] @@ -230,6 +229,4 @@ And what. ;; inline footnotes (might be handled via a delimited processor) (md/parse "some text with^[ and not without] a footnote") - (parse "some text with^[ and not without] a footnote") - (parse "some text with $and not -without$ a footnote")) + (parse "some text with^[ and not without] a footnote")) diff --git a/src/nextjournal/markdown/parser2/footnotes.clj b/src/nextjournal/markdown/parser2/footnotes.clj index 3844838..7eecfe0 100644 --- a/src/nextjournal/markdown/parser2/footnotes.clj +++ b/src/nextjournal/markdown/parser2/footnotes.clj @@ -1,8 +1,11 @@ (ns nextjournal.markdown.parser2.footnotes - (:require [nextjournal.markdown.parser2.types]) - (:import (nextjournal.markdown.parser2.types Footnote) - (org.commonmark.parser Parser$ParserExtension Parser$Builder SourceLine) - (org.commonmark.parser.block AbstractBlockParser BlockContinue BlockParserFactory BlockStart ParserState BlockParser))) + (:require [clojure.string :as str] + [nextjournal.markdown.parser2.types]) + (:import (nextjournal.markdown.parser2.types Footnote FootnoteRef) + (org.commonmark.node Text Node Nodes) + (org.commonmark.parser Parser$ParserExtension Parser$Builder PostProcessor SourceLine) + (org.commonmark.parser.block AbstractBlockParser BlockContinue BlockParserFactory BlockStart ParserState BlockParser) + (org.commonmark.parser.delimiter DelimiterProcessor))) (def footnote-id-regex (re-pattern "\\[\\^\\s*(.*)\\s*\\]")) (def footnote-def-regex (re-pattern "^\\[\\^\\s*(.*)\\s*\\]:")) @@ -23,32 +26,32 @@ (BlockContinue/atIndex non-space))))))) (comment - (nextjournal.markdown.parser2/parse "what the + (nextjournal.markdown.parser2/parse "init [^label] end -[^what]: * what _the_ heck -* the +[^label]: * this is nice _and_ nice + * and so so +")) -what a what")) +(defn block-parser-factory [] + (proxy [Object BlockParserFactory] [] + (tryStart [^ParserState state _matchedBlockParser] + (if (<= 4 (.getIndent state)) + (BlockStart/none) + (let [^SourceLine line (.getLine state) + line-content (.getContent line) + next-non-space (.getNextNonSpaceIndex state) + candidate-content (subs line-content next-non-space) + m (re-matcher footnote-def-regex candidate-content)] + (if (re-find m) + (let [block-index (+ next-non-space (.end m)) + label (subs line-content (+ next-non-space 2) + (+ next-non-space (- (.end m) 2))) + ^BlockParser bp (block-parser label)] + (.atIndex (BlockStart/of (into-array [bp])) + block-index)) + (BlockStart/none))))))) (defn extension [] (proxy [Object Parser$ParserExtension] [] (extend [^Parser$Builder pb] - (.customBlockParserFactory - pb (proxy [Object BlockParserFactory] [] - (tryStart [^ParserState state _matchedBlockParser] - (if (<= 4 (.getIndent state)) - (BlockStart/none) - (let [^SourceLine line (.getLine state) - line-content (.getContent line) - next-non-space (.getNextNonSpaceIndex state) - candidate-content (subs line-content next-non-space) - m (re-matcher footnote-def-regex candidate-content)] - (if (re-find m) - (let [block-index (+ next-non-space (.end m)) - label (subs line-content (+ next-non-space 2) - (+ next-non-space (- (.end m) 2))) - ^BlockParser bp (block-parser label)] - (println :match label (.start m) (.end m)) - (.atIndex (BlockStart/of (into-array [bp])) - block-index)) - (BlockStart/none)))))))))) + (.customBlockParserFactory pb (block-parser-factory))))) diff --git a/src/nextjournal/markdown/parser2/types.clj b/src/nextjournal/markdown/parser2/types.clj index 71d01cf..3fda76d 100644 --- a/src/nextjournal/markdown/parser2/types.clj +++ b/src/nextjournal/markdown/parser2/types.clj @@ -30,7 +30,17 @@ (defn footnote-init [label] [[] (ref {:label label})]) (defn footnote-getLabel [this] (:label @(.state this))) -(comment - (compile 'nextjournal.markdown.parser2.types) +(gen-class + :name nextjournal.markdown.parser2.types.FootnoteRef + :extends org.commonmark.node.CustomNode + :constructors {[String] []} + :init init + :state state + :methods [[getLabel [] String]] + :prefix "footnote-ref-") - ) +(defn footnote-ref-init [label] [[] (ref {:label label})]) +(defn footnote-ref-getLabel [this] (:label @(.state this))) + +(comment + (compile 'nextjournal.markdown.parser2.types))