From 9541170cb69f75d73595415f581d4a0f4e44be02 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sun, 9 Jan 2022 19:38:22 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20linkify=20link=20rend?= =?UTF-8?q?ering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linkify links should always be treated as external links --- myst_parser/docutils_renderer.py | 10 ++++++---- tests/test_renderers/fixtures/myst-config.txt | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/myst_parser/docutils_renderer.py b/myst_parser/docutils_renderer.py index eba7718b..5ac476d9 100644 --- a/myst_parser/docutils_renderer.py +++ b/myst_parser/docutils_renderer.py @@ -677,7 +677,7 @@ def render_link(self, token: SyntaxTreeNode) -> None: or any scheme if `myst_url_schemes` is None. - Otherwise, forward to `render_internal_link` """ - if token.markup == "autolink": + if token.info == "auto": # handles both autolink and linkify return self.render_autolink(token) if self.md_config.all_links_external: @@ -733,10 +733,12 @@ def render_internal_link(self, token: SyntaxTreeNode) -> None: self.render_children(token) def render_autolink(self, token: SyntaxTreeNode) -> None: - refuri = target = escapeHtml(token.attrGet("href") or "") # type: ignore[arg-type] - ref_node = nodes.reference(target, target, refuri=refuri) + refuri = escapeHtml(token.attrGet("href") or "") # type: ignore[arg-type] + ref_node = nodes.reference() + ref_node["refuri"] = refuri self.add_line_and_source_path(ref_node, token) - self.current_node.append(ref_node) + with self.current_node_context(ref_node, append=True): + self.render_children(token) def render_html_inline(self, token: SyntaxTreeNode) -> None: self.render_html_block(token) diff --git a/tests/test_renderers/fixtures/myst-config.txt b/tests/test_renderers/fixtures/myst-config.txt index ef4a81f6..b482a401 100644 --- a/tests/test_renderers/fixtures/myst-config.txt +++ b/tests/test_renderers/fixtures/myst-config.txt @@ -24,3 +24,13 @@ title: "The title *nested syntax*" Other header . + +[linkify] --myst-enable-extensions=linkify +. +www.example.com +. +<document source="<string>"> + <paragraph> + <reference refuri="http://www.example.com"> + www.example.com +. From 2f0cfb75d9967540706eea2f90b10f8ba72e23b0 Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Mon, 10 Jan 2022 00:17:55 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=AA=20TESTS:=20Update=20pytest-par?= =?UTF-8?q?am-files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- tests/test_html/test_html_to_nodes.py | 3 +-- tests/test_html/test_parse_html.py | 6 +++--- tests/test_renderers/test_error_reporting.py | 4 ++-- .../test_renderers/test_fixtures_docutils.py | 7 +++---- tests/test_renderers/test_fixtures_sphinx.py | 19 +++++++++---------- .../test_renderers/test_include_directive.py | 5 ++--- tests/test_renderers/test_myst_config.py | 4 ++-- 8 files changed, 23 insertions(+), 27 deletions(-) diff --git a/setup.cfg b/setup.cfg index e48e4080..92d22a71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -79,7 +79,7 @@ testing = pytest>=6,<7 pytest-cov pytest-regressions - pytest-param-files~=0.2.2 + pytest-param-files~=0.3.3 [flake8] max-line-length = 100 diff --git a/tests/test_html/test_html_to_nodes.py b/tests/test_html/test_html_to_nodes.py index c43d0a1c..9774a32f 100644 --- a/tests/test_html/test_html_to_nodes.py +++ b/tests/test_html/test_html_to_nodes.py @@ -3,7 +3,6 @@ import pytest from docutils import nodes -from pytest_param_files import with_parameters from myst_parser.html_to_nodes import html_to_nodes from myst_parser.main import MdParserConfig @@ -29,7 +28,7 @@ def _run_directive(name: str, first_line: str, content: str, position: int): ) -@with_parameters(FIXTURE_PATH / "html_to_nodes.md") +@pytest.mark.param_file(FIXTURE_PATH / "html_to_nodes.md") def test_html_to_nodes(file_params, mock_renderer): output = nodes.container() output += html_to_nodes(file_params.content, line_number=0, renderer=mock_renderer) diff --git a/tests/test_html/test_parse_html.py b/tests/test_html/test_parse_html.py index a9775414..5b765887 100644 --- a/tests/test_html/test_parse_html.py +++ b/tests/test_html/test_parse_html.py @@ -1,13 +1,13 @@ from pathlib import Path -from pytest_param_files import with_parameters +import pytest from myst_parser.parse_html import tokenize_html FIXTURE_PATH = Path(__file__).parent -@with_parameters(FIXTURE_PATH / "html_ast.md") +@pytest.mark.param_file(FIXTURE_PATH / "html_ast.md") def test_html_ast(file_params): tokens = "\n".join( repr(t) for t in tokenize_html(file_params.content).walk(include_self=True) @@ -15,7 +15,7 @@ def test_html_ast(file_params): file_params.assert_expected(tokens, rstrip=True) -@with_parameters(FIXTURE_PATH / "html_round_trip.md") +@pytest.mark.param_file(FIXTURE_PATH / "html_round_trip.md") def test_html_round_trip(file_params): ast = tokenize_html(file_params.content) file_params.assert_expected(str(ast), rstrip=True) diff --git a/tests/test_renderers/test_error_reporting.py b/tests/test_renderers/test_error_reporting.py index e6cfa6f0..72327fdb 100644 --- a/tests/test_renderers/test_error_reporting.py +++ b/tests/test_renderers/test_error_reporting.py @@ -2,15 +2,15 @@ from io import StringIO from pathlib import Path +import pytest from docutils.core import publish_doctree -from pytest_param_files import with_parameters from myst_parser.docutils_ import Parser FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@with_parameters(FIXTURE_PATH / "reporter_warnings.md") +@pytest.mark.param_file(FIXTURE_PATH / "reporter_warnings.md") def test_basic(file_params): """Test basic functionality.""" report_stream = StringIO() diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py index d9482e81..96b5a29d 100644 --- a/tests/test_renderers/test_fixtures_docutils.py +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -5,7 +5,6 @@ from pathlib import Path import pytest -from pytest_param_files import with_parameters from myst_parser.docutils_renderer import DocutilsRenderer, make_document from myst_parser.main import MdParserConfig, create_md_parser @@ -13,7 +12,7 @@ FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@with_parameters(FIXTURE_PATH / "docutil_syntax_elements.md") +@pytest.mark.param_file(FIXTURE_PATH / "docutil_syntax_elements.md") def test_syntax_elements(file_params): parser = create_md_parser( MdParserConfig(highlight_code_blocks=False), DocutilsRenderer @@ -25,7 +24,7 @@ def test_syntax_elements(file_params): file_params.assert_expected(outcome, rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "docutil_roles.md") +@pytest.mark.param_file(FIXTURE_PATH / "docutil_roles.md") def test_docutils_roles(file_params): """Test output of docutils roles.""" parser = create_md_parser(MdParserConfig(), DocutilsRenderer) @@ -34,7 +33,7 @@ def test_docutils_roles(file_params): file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "docutil_directives.md") +@pytest.mark.param_file(FIXTURE_PATH / "docutil_directives.md") def test_docutils_directives(file_params): """Test output of docutils directives.""" if "SKIP" in file_params.description: # line-block directive not yet supported diff --git a/tests/test_renderers/test_fixtures_sphinx.py b/tests/test_renderers/test_fixtures_sphinx.py index 69d0c87b..9a09d12e 100644 --- a/tests/test_renderers/test_fixtures_sphinx.py +++ b/tests/test_renderers/test_fixtures_sphinx.py @@ -7,7 +7,6 @@ import pytest import sphinx -from pytest_param_files import with_parameters from myst_parser.main import MdParserConfig, to_docutils from myst_parser.sphinx_renderer import SphinxRenderer, mock_sphinx_env @@ -20,25 +19,25 @@ def test_minimal_sphinx(): assert app.config["author"] == "bob geldof" -@with_parameters(FIXTURE_PATH / "sphinx_syntax_elements.md") +@pytest.mark.param_file(FIXTURE_PATH / "sphinx_syntax_elements.md") def test_syntax_elements(file_params): document = to_docutils(file_params.content, in_sphinx_env=True) file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "tables.md") +@pytest.mark.param_file(FIXTURE_PATH / "tables.md") def test_tables(file_params): document = to_docutils(file_params.content, in_sphinx_env=True) file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "directive_options.md") +@pytest.mark.param_file(FIXTURE_PATH / "directive_options.md") def test_directive_options(file_params): document = to_docutils(file_params.content) file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "sphinx_directives.md") +@pytest.mark.param_file(FIXTURE_PATH / "sphinx_directives.md") def test_sphinx_directives(file_params): # TODO fix skipped directives # TODO test domain directives @@ -52,7 +51,7 @@ def test_sphinx_directives(file_params): file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "sphinx_roles.md") +@pytest.mark.param_file(FIXTURE_PATH / "sphinx_roles.md") def test_sphinx_roles(file_params): if file_params.title.startswith("SKIP"): pytest.skip(file_params.title) @@ -65,7 +64,7 @@ def test_sphinx_roles(file_params): file_params.assert_expected(actual, rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "amsmath.md") +@pytest.mark.param_file(FIXTURE_PATH / "amsmath.md") def test_amsmath(file_params, monkeypatch): monkeypatch.setattr(SphinxRenderer, "_random_label", lambda self: "mock-uuid") document = to_docutils( @@ -76,7 +75,7 @@ def test_amsmath(file_params, monkeypatch): file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "containers.md") +@pytest.mark.param_file(FIXTURE_PATH / "containers.md") def test_containers(file_params, monkeypatch): monkeypatch.setattr(SphinxRenderer, "_random_label", lambda self: "mock-uuid") document = to_docutils( @@ -87,13 +86,13 @@ def test_containers(file_params, monkeypatch): file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "eval_rst.md") +@pytest.mark.param_file(FIXTURE_PATH / "eval_rst.md") def test_evalrst_elements(file_params): document = to_docutils(file_params.content, in_sphinx_env=True) file_params.assert_expected(document.pformat(), rstrip_lines=True) -@with_parameters(FIXTURE_PATH / "definition_lists.md") +@pytest.mark.param_file(FIXTURE_PATH / "definition_lists.md") def test_definition_lists(file_params): document = to_docutils( file_params.content, diff --git a/tests/test_renderers/test_include_directive.py b/tests/test_renderers/test_include_directive.py index 908afb8b..20e1a9d6 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -2,7 +2,6 @@ from pathlib import Path import pytest -from pytest_param_files import with_parameters from myst_parser.docutils_renderer import make_document from myst_parser.main import to_docutils @@ -10,7 +9,7 @@ FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@with_parameters(FIXTURE_PATH / "mock_include.md") +@pytest.mark.param_file(FIXTURE_PATH / "mock_include.md") def test_render(file_params, tmp_path): tmp_path.joinpath("other.md").write_text("a\nb\nc") tmp_path.joinpath("fmatter.md").write_text("---\na: 1\n---\nb") @@ -22,7 +21,7 @@ def test_render(file_params, tmp_path): file_params.assert_expected(output, rstrip=True) -@with_parameters(FIXTURE_PATH / "mock_include_errors.md") +@pytest.mark.param_file(FIXTURE_PATH / "mock_include_errors.md") def test_errors(file_params, tmp_path): if file_params.title.startswith("Non-existent path") and os.name == "nt": pytest.skip("tmp_path not converted correctly on Windows") diff --git a/tests/test_renderers/test_myst_config.py b/tests/test_renderers/test_myst_config.py index 24af9afc..fee43de3 100644 --- a/tests/test_renderers/test_myst_config.py +++ b/tests/test_renderers/test_myst_config.py @@ -3,15 +3,15 @@ from io import StringIO from pathlib import Path +import pytest from docutils.core import Publisher, publish_doctree -from pytest_param_files import with_parameters from myst_parser.docutils_ import Parser FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@with_parameters(FIXTURE_PATH / "myst-config.txt") +@pytest.mark.param_file(FIXTURE_PATH / "myst-config.txt") def test_cmdline(file_params): """The description is parsed as a docutils commandline""" pub = Publisher(parser=Parser()) From fa058f627300896f64d5f0c9ba532559dd9fa88f Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Mon, 10 Jan 2022 00:38:20 +0100 Subject: [PATCH 3/3] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7cd01786..70237f27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,7 +84,7 @@ jobs: run: | python -m pip install --upgrade pip pip install . - pip install pytest~=6.2 pytest-param-files~=0.2.2 docutils==${{ matrix.docutils-version }} + pip install pytest~=6.2 pytest-param-files~=0.3.3 docutils==${{ matrix.docutils-version }} - name: ensure sphinx is not installed run: | python -c "\