@@ -106,6 +106,8 @@ def output_latex_environment(self, m):
106
106
107
107
class MarkdownWithMath (mistune .Markdown ):
108
108
def __init__ (self , renderer , ** kwargs ):
109
+ kwargs ["parse_block_html" ] = True
110
+
109
111
if "inline" not in kwargs :
110
112
kwargs ["inline" ] = MathInlineLexer
111
113
if "block" not in kwargs :
@@ -115,6 +117,18 @@ def __init__(self, renderer, **kwargs):
115
117
def output_multiline_math (self ):
116
118
return self .inline (self .token ["text" ])
117
119
120
+ def output_open_html (self ):
121
+ # This makes mistune behave more like markedjs
122
+ # (markedjs behing used by Jupyter Notebook and JupyterLab)
123
+ MathInlineGrammar .linebreak = re .compile (r'^ *\n(?!\s*$)' )
124
+ MathInlineGrammar .text = re .compile (
125
+ r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| *\n|$)'
126
+ )
127
+ out = super ().output_open_html ()
128
+ MathInlineGrammar .linebreak = re .compile (r'^ {2,}\n(?!\s*$)' )
129
+ MathInlineGrammar .text = re .compile (r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| {2,}\n|$)' )
130
+ return out
131
+
118
132
119
133
class IPythonRenderer (mistune .Renderer ):
120
134
def block_code (self , code , lang ):
0 commit comments