Skip to content

Commit d0c3974

Browse files
committed
Ignore absolute links in Markdown.
Fixes mkdocs#1621.
1 parent 8fbaae6 commit d0c3974

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mkdocs/structure/pages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def run(self, root):
214214
def path_to_url(self, url):
215215
scheme, netloc, path, params, query, fragment = urlparse(url)
216216

217-
if scheme or netloc or not path or AMP_SUBSTITUTE in url or '.' not in os.path.split(path)[-1]:
217+
if (scheme or netloc or not path or url.startswith('/')
218+
or AMP_SUBSTITUTE in url or '.' not in os.path.split(path)[-1]):
218219
# Ignore URLs unless they are a relative link to a source file.
219220
# AMP_SUBSTITUTE is used internally by Markdown only for email.
220221
# No '.' in the last part of a path indicates path does not point to a file.

mkdocs/tests/structure/page_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,13 @@ def test_external_link(self):
772772
'<p><a href="http://example.com/index.md">external link</a></p>'
773773
)
774774

775+
@mock.patch('io.open', mock.mock_open(read_data='[absolute link](/path/to/file.md)'))
776+
def test_absolute_link(self):
777+
self.assertEqual(
778+
self.get_rendered_result(['index.md']),
779+
'<p><a href="/path/to/file.md">absolute link</a></p>'
780+
)
781+
775782
@mock.patch('io.open', mock.mock_open(read_data='<mail@example.com>'))
776783
def test_email_link(self):
777784
self.assertEqual(

0 commit comments

Comments
 (0)