-
-
Notifications
You must be signed in to change notification settings - Fork 389
Open
Description
Markwon can parse and render inline latex like $$latex$$,but it can't work with $latex$;
by add another InlineProcessor,I found it can work well with both $$latext$$ and $latex$;code as follow:
- write a new JLatexMathInlineProcessor
class JLatexMathInlineProcessor2 : InlineProcessor() {
override fun specialCharacter(): Char {
return '$'
}
override fun parse(): Node? {
val latex = match(RE) ?: return null
val node = JLatexMathNode()
node.latex(latex.substring(1, latex.length - 1))
return node
}
companion object {
private val RE: Pattern = Pattern.compile( "(?<!\\\\)\\$((?:\\\\.|[^$\\\\])*)\\$(?!\\$)")
}
}- add it to the MarkwonInlineParserPlugin
val markwonInlineParserPlugin = MarkwonInlineParserPlugin.create().also {
it.factoryBuilder().addInlineProcessor(JLatexMathInlineProcessor2())
}- make sure markwon use that plugin
val MARKWON = Markwon.builder(parent.context)
.usePlugin(markwonInlineParserPlugin)
.usePlugin(JLatexMathPlugin.create(markwonView.textSize
) { builder -> builder.inlinesEnabled(true) })- it works
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
