From 7e779ac15b8d62d8351b278c218a089637975bdd Mon Sep 17 00:00:00 2001 From: Hendrik Polczynski Date: Sun, 26 Mar 2023 13:01:30 +0200 Subject: [PATCH 1/3] add reproduction tests --- tests/integration/docs/index.md | 8 +++++++- tests/integration/docs/nested/page1.md | 6 ++++++ tests/integration/mkdocs.yml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/integration/docs/index.md b/tests/integration/docs/index.md index 70b1f6f..4d302a6 100644 --- a/tests/integration/docs/index.md +++ b/tests/integration/docs/index.md @@ -74,4 +74,10 @@ This work is based on the [mkdocs-markdownextradata-plugin](https://github.com/r ## GitHub Action ![GitHub Action](https://github.com/manuzhang/mkdocs-htmlproofer-plugin/actions/workflows/ci.yml/badge.svg){ #github-action } -[GitHub Action](#github-action) \ No newline at end of file +[GitHub Action](#github-action) + +## Image Link absolute/relative + +![test](assets/hello-world.drawio.svg) + +![test](/assets/hello-world.drawio.svg) diff --git a/tests/integration/docs/nested/page1.md b/tests/integration/docs/nested/page1.md index ba26388..c96b242 100644 --- a/tests/integration/docs/nested/page1.md +++ b/tests/integration/docs/nested/page1.md @@ -23,3 +23,9 @@ or to a nested page But allows valid anchors such as [Main Page](../index.md#mkdocs-htmlproofer-plugin) and [Table of Contents](../index.md#table-of-contents). + +## Image Link absolute/relative + +![test](../assets/hello-world.drawio.svg) + +![test](/assets/hello-world.drawio.svg) diff --git a/tests/integration/mkdocs.yml b/tests/integration/mkdocs.yml index bb7a878..f79ce65 100644 --- a/tests/integration/mkdocs.yml +++ b/tests/integration/mkdocs.yml @@ -6,7 +6,7 @@ markdown_extensions: - attr_list plugins: - htmlproofer: - raise_error: True + raise_error_after_finish: True raise_error_excludes: 504: ['*'] 404: ['https://www.mkdocs.org/user-guide/plugin', From 1e90bc9e0348b811a8bda4ab937144e59520dae8 Mon Sep 17 00:00:00 2001 From: Hendrik Polczynski Date: Sun, 26 Mar 2023 13:13:04 +0200 Subject: [PATCH 2/3] implement fix for root paths --- htmlproofer/plugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htmlproofer/plugin.py b/htmlproofer/plugin.py index 87ae85c..af9eefc 100644 --- a/htmlproofer/plugin.py +++ b/htmlproofer/plugin.py @@ -160,8 +160,12 @@ def find_target_markdown(url: str, src_path: str, files: Dict[str, File]) -> Opt def find_source_file(url: str, src_path: str, files: Dict[str, File]) -> Optional[File]: """From a built URL, find the original file from the project that built it.""" - # Handle relative links by concatenating the source dir with the destination path - search_path = os.path.normpath(str(pathlib.Path(src_path).parent / pathlib.Path(url))) + if len(url) > 1 and url[0] == '/': + # Convert root/site paths + search_path = os.path.normpath(url[1:]) + else: + # Handle relative links by concatenating the source dir with the destination path + search_path = os.path.normpath(str(pathlib.Path(src_path).parent / pathlib.Path(url))) try: return files[search_path] From ea5e5a25e03b401a59f99c101524b465906073fd Mon Sep 17 00:00:00 2001 From: Hendrik Polczynski Date: Sun, 26 Mar 2023 13:20:12 +0200 Subject: [PATCH 3/3] add unit test cases for root paths --- tests/unit/test_plugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 39aacc3..b93f3da 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -189,6 +189,7 @@ def test_get_url_status__non_markdown_page(plugin): ])} assert plugin.get_url_status('drawing.svg', 'index.md', set(), files, False) == 0 + assert plugin.get_url_status('/drawing.svg', 'index.md', set(), files, False) == 0 assert plugin.get_url_status('not-existing.svg', 'index.md', set(), files, False) == 404 @@ -214,3 +215,5 @@ def test_get_url_status__local_page_nested(plugin): assert plugin.get_url_status('foo/bar/nested.html#nested-one', 'index.md', set(), files, False) == 0 assert plugin.get_url_status('foo/baz/nested.html#nested-two', 'index.md', set(), files, False) == 0 + + assert plugin.get_url_status('/index.html', 'foo/baz/sibling.md', set(), files, False) == 0