From ef4ccd3eb4884bb62991d25af1e8a512b50a4e8f Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Fri, 3 Dec 2021 10:20:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20UPGRADE:=20markdown-it-py?= =?UTF-8?q?=20v2,=20mdit-py-plugins=20v0.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/executablebooks/markdown-it-py/releases/tag/v2.0.0, and https://github.com/executablebooks/mdit-py-plugins/releases/tag/v0.3.0 closes #169 --- docs/api/parsers.md | 2 +- docs/api/reference.rst | 2 +- myst_parser/docutils_.py | 3 +-- myst_parser/docutils_renderer.py | 12 +++++++----- myst_parser/sphinx_parser.py | 3 +-- myst_parser/sphinx_renderer.py | 2 +- setup.cfg | 4 ++-- tests/test_commonmark/test_commonmark.py | 3 --- tests/test_renderers/fixtures/sphinx_roles.md | 16 ++++++++++++++++ tests/test_renderers/fixtures/syntax_elements.md | 9 +++++++++ 10 files changed, 39 insertions(+), 17 deletions(-) diff --git a/docs/api/parsers.md b/docs/api/parsers.md index 669839fe..581dc563 100644 --- a/docs/api/parsers.md +++ b/docs/api/parsers.md @@ -112,7 +112,7 @@ pprint(parser.get_active_rules()) {'block': ['front_matter', 'table', 'code', - 'math_block_eqno', + 'math_block_label', 'math_block', 'fence', 'myst_line_comment', diff --git a/docs/api/reference.rst b/docs/api/reference.rst index 431fdb73..9fde1952 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -36,7 +36,7 @@ Sphinx .. autoclass:: myst_parser.sphinx_renderer.SphinxRenderer :special-members: __output__ - :members: handle_cross_reference, render_math_block_eqno + :members: handle_cross_reference, render_math_block_label :undoc-members: :member-order: alphabetical :show-inheritance: diff --git a/myst_parser/docutils_.py b/myst_parser/docutils_.py index 1e9562c8..9c7c918e 100644 --- a/myst_parser/docutils_.py +++ b/myst_parser/docutils_.py @@ -8,7 +8,6 @@ from docutils import nodes from docutils.parsers.rst import Parser as RstParser from markdown_it.token import Token -from markdown_it.utils import AttrDict from myst_parser.main import MdParserConfig, default_parser @@ -47,7 +46,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None: config = MdParserConfig(renderer="docutils") parser = default_parser(config) parser.options["document"] = document - env = AttrDict() + env: dict = {} tokens = parser.parse(inputstring, env) if not tokens or tokens[0].type != "front_matter": # we always add front matter, so that we can merge it with global keys, diff --git a/myst_parser/docutils_renderer.py b/myst_parser/docutils_renderer.py index 43a964c1..e5b580fe 100644 --- a/myst_parser/docutils_renderer.py +++ b/myst_parser/docutils_renderer.py @@ -784,11 +784,13 @@ def render_table_row(self, token: SyntaxTreeNode) -> None: def render_math_inline(self, token: SyntaxTreeNode) -> None: content = token.content - if token.markup == "$$": - # available when dmath_double_inline is True - node = nodes.math_block(content, content, nowrap=False, number=None) - else: - node = nodes.math(content, content) + node = nodes.math(content, content) + self.add_line_and_source_path(node, token) + self.current_node.append(node) + + def render_math_inline_double(self, token: SyntaxTreeNode) -> None: + content = token.content + node = nodes.math_block(content, content, nowrap=False, number=None) self.add_line_and_source_path(node, token) self.current_node.append(node) diff --git a/myst_parser/sphinx_parser.py b/myst_parser/sphinx_parser.py index 334fc64d..86ee64fb 100644 --- a/myst_parser/sphinx_parser.py +++ b/myst_parser/sphinx_parser.py @@ -6,7 +6,6 @@ from docutils.core import publish_doctree from docutils.parsers.rst import Parser as RstParser from markdown_it.token import Token -from markdown_it.utils import AttrDict from sphinx.application import Sphinx from sphinx.io import SphinxStandaloneReader from sphinx.parsers import Parser as SphinxParser @@ -52,7 +51,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None: config = document.settings.env.myst_config parser = default_parser(config) parser.options["document"] = document - env = AttrDict() + env: dict = {} tokens = parser.parse(inputstring, env) if not tokens or tokens[0].type != "front_matter": # we always add front matter, so that we can merge it with global keys, diff --git a/myst_parser/sphinx_renderer.py b/myst_parser/sphinx_renderer.py index a7458c23..5bb385ba 100644 --- a/myst_parser/sphinx_renderer.py +++ b/myst_parser/sphinx_renderer.py @@ -122,7 +122,7 @@ def render_heading(self, token: SyntaxTreeNode) -> None: self.doc_env.myst_anchors = True # type: ignore[attr-defined] section["myst-anchor"] = doc_slug - def render_math_block_eqno(self, token: SyntaxTreeNode) -> None: + def render_math_block_label(self, token: SyntaxTreeNode) -> None: """Render math with referencable labels, e.g. ``$a=1$ (label)``.""" label = token.info content = token.content diff --git a/setup.cfg b/setup.cfg index 8a76a96b..4ba7b8f4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,8 +39,8 @@ packages = find: install_requires = docutils>=0.15,<0.18 jinja2 # required for substitutions, but let sphinx choose version - markdown-it-py>=1.0.0,<2.0.0 - mdit-py-plugins~=0.2.8 + markdown-it-py>=1.0.0,<3.0.0 + mdit-py-plugins~=0.3.0 pyyaml sphinx>=3.1,<5 python_requires = >=3.6 diff --git a/tests/test_commonmark/test_commonmark.py b/tests/test_commonmark/test_commonmark.py index 9ace5e89..63e0c89a 100644 --- a/tests/test_commonmark/test_commonmark.py +++ b/tests/test_commonmark/test_commonmark.py @@ -26,9 +26,6 @@ def test_commonmark(entry): pytest.skip( "Thematic breaks on the first line conflict with front matter syntax" ) - if entry["example"] == 599: # \n - # TODO awaiting upstream fix - pytest.skip("url backslash escaping") test_case = entry["markdown"] output = to_html(test_case) diff --git a/tests/test_renderers/fixtures/sphinx_roles.md b/tests/test_renderers/fixtures/sphinx_roles.md index 1f942fc0..6053220b 100644 --- a/tests/test_renderers/fixtures/sphinx_roles.md +++ b/tests/test_renderers/fixtures/sphinx_roles.md @@ -637,6 +637,22 @@ ref (`sphinx.roles.XRefRole`): a . +-------------------------------- +ref with line breaks (`sphinx.roles.XRefRole`): +. +{ref}`some +text +` +. + + + + + some text +. + -------------------------------- numref (`sphinx.roles.XRefRole`): . diff --git a/tests/test_renderers/fixtures/syntax_elements.md b/tests/test_renderers/fixtures/syntax_elements.md index b08b8365..d95c7744 100644 --- a/tests/test_renderers/fixtures/syntax_elements.md +++ b/tests/test_renderers/fixtures/syntax_elements.md @@ -368,6 +368,15 @@ Target: . +-------------------------- +Target with whitespace: +. +(target with space)= +. + + +. + -------------------------- Referencing: .