From 41429764c34dcbf96e29ae768497a288a3a84f1f Mon Sep 17 00:00:00 2001 From: martinRenou Date: Wed, 20 Apr 2022 16:23:47 +0200 Subject: [PATCH 1/2] Match markedjs behavior for parsing HTML linebreaks --- nbconvert/filters/markdown_mistune.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 382a53882..739d56010 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,18 @@ 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]+?(?=[\\ Date: Wed, 20 Apr 2022 14:24:29 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nbconvert/filters/markdown_mistune.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 739d56010..c197adf17 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -120,13 +120,11 @@ def output_multiline_math(self): 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]+?(?=[\\