Skip to content

Commit

Permalink
⬆️ UPDATE: docutils v0.19, sphinx v5 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jul 24, 2023
1 parent fcab0cc commit 8832b52
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 111 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Expand Up @@ -21,7 +21,7 @@ keywords = ["restructuredtext","markdown", "myst"]

requires-python=">=3.7"
dependencies=[
"docutils>=0.15,<0.18",
"docutils>=0.16,<0.19",
"importlib_resources~=3.1;python_version<'3.9'",
"pyyaml",
"markdown-it-py~=1.0",
Expand All @@ -39,12 +39,13 @@ Documentation = "https://rst-to-myst.readthedocs.io"
rst2myst = "rst_to_myst.cli:main"

[project.optional-dependencies]
sphinx = ["sphinx>=3.2,<5"]
sphinx = ["sphinx>=4,<6"]
test = [
"pytest~=6.0",
"coverage",
"pytest-cov",
"pytest-regressions"
"pytest-regressions",
"pytest-param-files",
]
docs = [
"myst-parser",
Expand Down
24 changes: 0 additions & 24 deletions rst_to_myst/utils.py
@@ -1,30 +1,6 @@
from pathlib import Path

import yaml


def read_fixture_file(path):
text = Path(path).read_text(encoding="utf-8")
tests = []
section = 0
last_pos = 0
lines = text.splitlines(keepends=True)
for i in range(len(lines)):
if lines[i].rstrip() == ".":
if section == 0:
tests.append([i, lines[i - 1].strip()])
section = 1
elif section == 1:
tests[-1].append("".join(lines[last_pos + 1 : i]))
section = 2
elif section == 2:
tests[-1].append("".join(lines[last_pos + 1 : i]))
section = 0

last_pos = i
return tests


def represent_str(dumper, data):
# borrowed from http://stackoverflow.com/a/33300001
if len(data.splitlines()) > 1:
Expand Down
16 changes: 8 additions & 8 deletions tests/fixtures/ast.txt
Expand Up @@ -65,17 +65,17 @@ y `uri <a.org>`_ z
sub
r
s
<footnote_reference ids="id1" refid="id6">
<footnote_reference ids="footnote-reference-1" refid="footnote-1">
1

<footnote_reference auto="1" ids="id2" refid="id7">
<footnote_reference auto="1" ids="footnote-reference-2" refid="footnote-2">
2

<footnote_reference auto="*" ids="id3" refid="id8">
<footnote_reference auto="*" ids="footnote-reference-3" refid="footnote-3">
*
t
u
<citation_reference ids="id4" refname="cit2002">
<citation_reference ids="citation-reference-1" refname="cit2002">
CIT2002
v
w
Expand All @@ -86,14 +86,14 @@ y `uri <a.org>`_ z
<reference embedded="True" name="uri" refuri="a.org">
uri
z
<target anonymous="1" ids="id5" refuri="anonymous-target">
<footnote backrefs="id1" ids="id6" names="1">
<target anonymous="1" ids="target-1" refuri="anonymous-target">
<footnote backrefs="footnote-reference-1" ids="footnote-1" names="1">
<paragraph>
normal footnote
<footnote auto="1" backrefs="id2" ids="id7" names="2">
<footnote auto="1" backrefs="footnote-reference-2" ids="footnote-2" names="2">
<paragraph>
auto-number footnote.
<footnote auto="*" backrefs="id3" ids="id8">
<footnote auto="*" backrefs="footnote-reference-3" ids="footnote-3">
<paragraph>
auto-symbol footnote.
<citation ids="a" names="a">
Expand Down
13 changes: 6 additions & 7 deletions tests/fixtures/render.txt
Expand Up @@ -251,14 +251,14 @@ footnote:
.. [#] auto-number footnote.
.. [*] auto-symbol footnote.
.
[^id4] [^id5] [^id6]
[^footnote-1] [^footnote-2] [^footnote-3]

[^id4]: normal footnote
[^footnote-1]: normal footnote
next line

[^id5]: auto-number footnote.
[^footnote-2]: auto-number footnote.

[^id6]: auto-symbol footnote.
[^footnote-3]: auto-symbol footnote.
.

citation:
Expand Down Expand Up @@ -310,9 +310,9 @@ table, nested syntax:
.
| *A* | <http://a.net/> |
| --- | --------------- |
| `C` | [^id2] |
| `C` | [^footnote-1] |

[^id2]: footnote
[^footnote-1]: footnote
.

tables-grid:
Expand Down Expand Up @@ -427,7 +427,6 @@ next term
: Description `a` [a].
.


directive-eval-rst
.
.. unknown:: argument
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/render_extra.txt
Expand Up @@ -34,21 +34,21 @@ e `literal` f
g [reference] h
i [a phrase] j
k [text][ref] l
m [anonymous](id5) n
m [anonymous](target-1) n
o (inline target not supported) p
q {{ sub }} r
s [^1] [^id6] [^id7] t
s [^1] [^footnote-1] [^footnote-2] t
u [^cite_cit2002] v
w <http://a.net/> x
y [uri](a.org) z

(id5)=
(target-1)=

anonymous target paragraph

[^id6]: auto-number footnote.
[^footnote-1]: auto-number footnote.

[^id7]: auto-symbol footnote.
[^footnote-2]: auto-symbol footnote.
next line

new paragraph
Expand Down
71 changes: 22 additions & 49 deletions tests/test_fixtures.py
@@ -1,59 +1,32 @@
from pathlib import Path

import pytest
from pytest_param_files import ParamTestData

from rst_to_myst import rst_to_myst, to_docutils_ast
from rst_to_myst.utils import read_fixture_file

FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures")


@pytest.mark.parametrize(
"line,title,rst,expected",
read_fixture_file(FIXTURE_PATH / "ast.txt"),
ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "ast.txt")],
)
def test_ast(line, title, rst, expected):
document, warning_stream = to_docutils_ast(rst)
text = document.pformat()
try:
assert warning_stream.getvalue() == ""
assert text.rstrip() == expected.rstrip()
except AssertionError:
print(text)
raise


@pytest.mark.parametrize(
"line,title,rst,expected",
read_fixture_file(FIXTURE_PATH / "render.txt"),
ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "render.txt")],
)
def test_render(line, title, rst, expected):
output = rst_to_myst(rst)
try:
if "EXPECT_WARNING" not in title:
assert output.warning_stream.getvalue() == ""
else:
assert output.warning_stream.getvalue() != ""
assert output.text.rstrip() == expected.rstrip()
except AssertionError:
print(output.text)
raise


@pytest.mark.parametrize(
"line,title,rst,expected",
read_fixture_file(FIXTURE_PATH / "render_extra.txt"),
ids=[
f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "render_extra.txt")
],
)
def test_render_extra(line, title, rst, expected):
output = rst_to_myst(rst)
try:
@pytest.mark.param_file(FIXTURE_PATH / "ast.txt")
def test_ast(file_params: ParamTestData):
document, warning_stream = to_docutils_ast(file_params.content)
assert warning_stream.getvalue() == ""
file_params.assert_expected(document.pformat(), rstrip=True)


@pytest.mark.param_file(FIXTURE_PATH / "render.txt")
def test_render(file_params: ParamTestData):
output = rst_to_myst(file_params.content)
if "EXPECT_WARNING" not in file_params.title:
assert output.warning_stream.getvalue() == ""
assert output.text.rstrip() == expected.rstrip()
except AssertionError:
print(output.text)
raise
else:
assert output.warning_stream.getvalue() != ""
file_params.assert_expected(output.text, rstrip=True)


@pytest.mark.param_file(FIXTURE_PATH / "render_extra.txt")
def test_render_extra(file_params: ParamTestData):
output = rst_to_myst(file_params.content)
assert output.warning_stream.getvalue() == ""
file_params.assert_expected(output.text, rstrip=True)
4 changes: 2 additions & 2 deletions tests/test_texts/test_texts_directives_.md
Expand Up @@ -1687,7 +1687,7 @@ The following options are recognized:
```

The "class" directive sets the ["classes"] attribute value on its content
or on the first immediately following non-comment element [^id13]. For
or on the first immediately following non-comment element [^footnote-1]. For
details of the "classes" attribute, see [its entry](../doctree.html#classes) in [The Docutils
Document Tree][the docutils document tree].

Expand Down Expand Up @@ -1740,7 +1740,7 @@ The text above is parsed and transformed into this doctree fragment:
Second paragraph.
```

[^id13]: To set a "classes" attribute value on a block quote, the
[^footnote-1]: To set a "classes" attribute value on a block quote, the
"class" directive must be followed by an empty comment:

```
Expand Down
26 changes: 13 additions & 13 deletions tests/test_texts/test_texts_restructuredtext_.md
Expand Up @@ -485,14 +485,14 @@ matching "overlines" above the title. An underline/overline is a
single repeated punctuation character that begins in column 1 and
forms a line extending at least as far as the right edge of the title
text. Specifically, an underline/overline character may be any
non-alphanumeric printable 7-bit ASCII character [^id2]. When an
non-alphanumeric printable 7-bit ASCII character [^footnote-1]. When an
overline is used, the length and character used must match the
underline. Underline-only adornment styles are distinct from
overline-and-underline styles that use the same character. There may
be any number of levels of section titles, although some output
formats may have limits (HTML has 6 levels).

[^id2]: The following are all valid section title adornment
[^footnote-1]: The following are all valid section title adornment
characters:

```
Expand Down Expand Up @@ -966,20 +966,20 @@ arbitrary body elements.
##### RCS Keywords

[Bibliographic fields] recognized by the parser are normally checked
for RCS [^id6] keywords and cleaned up [^id7]. RCS keywords may be
for RCS [^footnote-2] keywords and cleaned up [^footnote-3]. RCS keywords may be
entered into source files as "\$keyword\$", and once stored under RCS or
CVS [^id8], they are expanded to "\$keyword: expansion text \$". For
CVS [^footnote-4], they are expanded to "\$keyword: expansion text \$". For
example, a "Status" field will be transformed to a "status" element:

```
:Status: $keyword: expansion text $
```

[^id6]: Revision Control System.
[^footnote-2]: Revision Control System.

[^id7]: RCS keyword processing can be turned off (unimplemented).
[^footnote-3]: RCS keyword processing can be turned off (unimplemented).

[^id8]: Concurrent Versions System. CVS uses the same keywords as RCS.
[^footnote-4]: Concurrent Versions System. CVS uses the same keywords as RCS.

Processed, the "status" element's text will become simply "expansion
text". The dollar sign delimiters and leading RCS keyword name are
Expand Down Expand Up @@ -1176,10 +1176,10 @@ Syntax diagram:

Quoted literal blocks are unindented contiguous blocks of text where
each line begins with the same non-alphanumeric printable 7-bit ASCII
character [^id10]. A blank line ends a quoted literal block. The
character [^footnote-5]. A blank line ends a quoted literal block. The
quoting characters are preserved in the processed document.

[^id10]: The following are all valid quoting characters:
[^footnote-5]: The following are all valid quoting characters:

```
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Expand Down Expand Up @@ -1743,7 +1743,7 @@ the number of footnotes. One symbol footnote cannot have multiple
references.

The standard Docutils system uses the following symbols for footnote
marks [^id12]:
marks [^footnote-6]:

- asterisk/star ("\*")
- dagger (HTML character entity "\&dagger;", Unicode U+02020)
Expand All @@ -1756,7 +1756,7 @@ marks [^id12]:
- diamond suit ("\&diams;"/U+02666)
- club suit ("\&clubs;"/U+02663)

[^id12]: This list was inspired by the list of symbols for "Note
[^footnote-6]: This list was inspired by the list of symbols for "Note
Reference Marks" in The Chicago Manual of Style, 14th edition,
section 12.51. "Parallels" ("||") were given in CMoS instead of
the pilcrow. The last four symbols (the card suits) were added
Expand Down Expand Up @@ -2308,7 +2308,7 @@ Images

The "[image]" directive has been implemented.

Styles [^id15]
Styles [^footnote-7]

: Substitution references may be used to associate inline text with
an externally defined presentation style:
Expand Down Expand Up @@ -2340,7 +2340,7 @@ Styles [^id15]
% .. style:: disclaimer
% All rights reversed. Reprint what you like.

[^id15]: There may be sufficient need for a "style" mechanism to
[^footnote-7]: There may be sufficient need for a "style" mechanism to
warrant simpler syntax such as an extension to the interpreted
text role syntax. The substitution mechanism is cumbersome for
simple text styling.
Expand Down

0 comments on commit 8832b52

Please sign in to comment.