@@ -106,6 +106,8 @@ def output_latex_environment(self, m):
106106
107107class MarkdownWithMath (mistune .Markdown ):
108108 def __init__ (self , renderer , ** kwargs ):
109+ kwargs ["parse_block_html" ] = True
110+
109111 if "inline" not in kwargs :
110112 kwargs ["inline" ] = MathInlineLexer
111113 if "block" not in kwargs :
@@ -115,6 +117,18 @@ def __init__(self, renderer, **kwargs):
115117 def output_multiline_math (self ):
116118 return self .inline (self .token ["text" ])
117119
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+
118132
119133class IPythonRenderer (mistune .Renderer ):
120134 def block_code (self , code , lang ):
0 commit comments