Skip to content

Commit

Permalink
⬆️ UPGRADE: markdown-it-py v2, mdit-py-plugins v0.3 (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Dec 3, 2021
1 parent a28e9b7 commit 43d5c66
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/api/parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion docs/api/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions myst_parser/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions myst_parser/docutils_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions myst_parser/sphinx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/sphinx_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/test_commonmark/test_commonmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: # <http://example.com/\\[\\>\n
# TODO awaiting upstream fix
pytest.skip("url backslash escaping")
test_case = entry["markdown"]
output = to_html(test_case)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_renderers/fixtures/sphinx_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,22 @@ ref (`sphinx.roles.XRefRole`):
a
.

--------------------------------
ref with line breaks (`sphinx.roles.XRefRole`):
.
{ref}`some
text
<and
a
custom reference>`
.
<document source="notset">
<paragraph>
<pending_xref refdoc="mock_docname" refdomain="std" refexplicit="True" reftarget="and a custom reference" reftype="ref" refwarn="True">
<inline classes="xref std std-ref">
some text
.

--------------------------------
numref (`sphinx.roles.XRefRole`):
.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_renderers/fixtures/syntax_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ Target:
<target ids="target" names="target">
.
--------------------------
Target with whitespace:
.
(target with space)=
.
<document source="notset">
<target ids="target-with-space" names="target\ with\ space">
.
--------------------------
Referencing:
.
Expand Down

0 comments on commit 43d5c66

Please sign in to comment.