Skip to content

Commit

Permalink
馃悰 FIX: Ordered list starting number (#483)
Browse files Browse the repository at this point in the history
Propagate the starting number of ordered lists to the docutils AST.
  • Loading branch information
chrisjsewell committed Dec 31, 2021
1 parent 60e3601 commit feff225
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 13 deletions.
6 changes: 3 additions & 3 deletions myst_parser/docutils_renderer.py
Expand Up @@ -377,9 +377,9 @@ def render_bullet_list(self, token: SyntaxTreeNode) -> None:
self.render_children(token)

def render_ordered_list(self, token: SyntaxTreeNode) -> None:
list_node = nodes.enumerated_list()
list_node["enumtype"] = "arabic"
list_node["suffix"] = "."
list_node = nodes.enumerated_list(enumtype="arabic", prefix="", suffix=".")
if "start" in token.attrs: # starting number
list_node["start"] = token.attrs["start"]
self.add_line_and_source_path(list_node, token)
with self.current_node_context(list_node, append=True):
self.render_children(token)
Expand Down
20 changes: 17 additions & 3 deletions tests/test_renderers/fixtures/docutil_syntax_elements.md
Expand Up @@ -257,13 +257,27 @@ Nested Bullets
Enumerated List:
.
1. *foo*

para

10. starting
11. enumerator
.
<document source="notset">
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
<emphasis>
foo
<paragraph>
para
<enumerated_list enumtype="arabic" prefix="" start="10" suffix=".">
<list_item>
<paragraph>
starting
<list_item>
<paragraph>
enumerator
.

--------------------------
Expand All @@ -274,14 +288,14 @@ Nested Enumrated List:
1. c
.
<document source="notset">
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
a
<list_item>
<paragraph>
b
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
c
Expand Down
20 changes: 17 additions & 3 deletions tests/test_renderers/fixtures/sphinx_syntax_elements.md
Expand Up @@ -257,13 +257,27 @@ Nested Bullets
Enumerated List:
.
1. *foo*

para

10. starting
11. enumerator
.
<document source="notset">
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
<emphasis>
foo
<paragraph>
para
<enumerated_list enumtype="arabic" prefix="" start="10" suffix=".">
<list_item>
<paragraph>
starting
<list_item>
<paragraph>
enumerator
.

--------------------------
Expand All @@ -274,14 +288,14 @@ Nested Enumrated List:
1. c
.
<document source="notset">
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
a
<list_item>
<paragraph>
b
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
c
Expand Down
3 changes: 3 additions & 0 deletions tests/test_sphinx/conftest.py
Expand Up @@ -78,6 +78,9 @@ def read(
# only regress the inner body, since other sections are non-deterministic
soup = BeautifulSoup(content, "html.parser")
doc_div = soup.findAll("div", {"class": "documentwrapper"})[0]
# pygments 2.11.0 introduces a whitespace tag
for pygment_whitespace in doc_div.select("pre > span.w"):
pygment_whitespace.replace_with(pygment_whitespace.text)
text = doc_div.prettify()
for find, rep in (replace or {}).items():
text = text.replace(find, rep)
Expand Down
Expand Up @@ -24,7 +24,7 @@
texte 5 en
<strong>
gras
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
texte 6 en
Expand Down
Expand Up @@ -24,7 +24,7 @@
texte 5 en
<strong>
gras
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
texte 6 en
Expand Down
Expand Up @@ -24,7 +24,7 @@
texte 5 en
<strong>
gras
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
texte 6 en
Expand Down
Expand Up @@ -24,7 +24,7 @@
texte 5 en
<strong>
gras
<enumerated_list enumtype="arabic" suffix=".">
<enumerated_list enumtype="arabic" prefix="" suffix=".">
<list_item>
<paragraph>
texte 6 en
Expand Down

0 comments on commit feff225

Please sign in to comment.