diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 382a53882..c197adf17 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -106,6 +106,8 @@ def output_latex_environment(self, m): class MarkdownWithMath(mistune.Markdown): def __init__(self, renderer, **kwargs): + kwargs["parse_block_html"] = True + if "inline" not in kwargs: kwargs["inline"] = MathInlineLexer if "block" not in kwargs: @@ -115,6 +117,16 @@ def __init__(self, renderer, **kwargs): def output_multiline_math(self): return self.inline(self.token["text"]) + def output_open_html(self): + # This makes mistune behave more like markedjs + # (markedjs behing used by Jupyter Notebook and JupyterLab) + MathInlineGrammar.linebreak = re.compile(r"^ *\n(?!\s*$)") + MathInlineGrammar.text = re.compile(r"^[\s\S]+?(?=[\\