diff --git a/pyproject.toml b/pyproject.toml index 3ed2640..582a4da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mkdocs-include-markdown-plugin" -version = "7.1.3" +version = "7.1.4" description = "Mkdocs Markdown includer plugin." readme = "README.md" license = "Apache-2.0" diff --git a/src/mkdocs_include_markdown_plugin/process.py b/src/mkdocs_include_markdown_plugin/process.py index 3c47550..9908cf6 100644 --- a/src/mkdocs_include_markdown_plugin/process.py +++ b/src/mkdocs_include_markdown_plugin/process.py @@ -315,6 +315,10 @@ def rewrite_url(url: str) -> str: except IndexError: # pragma: no cover pass + # ensure that links to the same file are not rewritten + if new_path == '.': + new_path = '' + return urlunparse((scheme, netloc, new_path, params, query, fragment)) def found_href(m: re.Match[str], url_group_index: int = -1) -> str: diff --git a/tests/test_unit/test_include.py b/tests/test_unit/test_include.py index 2c1bf13..54a49e1 100644 --- a/tests/test_unit/test_include.py +++ b/tests/test_unit/test_include.py @@ -353,7 +353,6 @@ [], id='rstrip-windows-trailing-newlines', ), - ), ) def test_include( diff --git a/tests/test_unit/test_include_markdown.py b/tests/test_unit/test_include_markdown.py index e4afbe6..3d874d6 100644 --- a/tests/test_unit/test_include_markdown.py +++ b/tests/test_unit/test_include_markdown.py @@ -729,6 +729,33 @@ [], id='include-code-block-to-list-item (#123)', ), + + # Internal anchor in included file properly rewritten + pytest.param( + '''# Header + +{% include-markdown "{filepath}" %}''', + '''# First level heading + +Example data + +## Second level heading + +Link to [second level heading](#second-level-heading). +''', + '''# Header + +# First level heading + +Example data + +## Second level heading + +Link to [second level heading](#second-level-heading). +''', + [], + id='internal-anchor', + ), ), ) def test_include_markdown(