Skip to content

Commit c9eaf7c

Browse files
tools: External markdowns are treated as internal links (#12)
1 parent 6a6bfeb commit c9eaf7c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tools/github_readme_sync/hierarchy.py

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ def check_links(path):
149149
errors = []
150150

151151
for match in md_link_matches:
152+
if match[1].startswith(("http://", "https://", "mailto:")):
153+
continue
152154
path_to_check = os.path.join(current_dir, match[1].split("#")[0])
153155
path_to_check = os.path.normpath(path_to_check)
154156
if any(placeholder in match[1] for placeholder in IGNORE_DOCS):

tools/github_readme_sync/tests/hierarchy_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import tempfile
1414
import threading
1515
import unittest
16+
from pathlib import Path
1617

1718
from tools.github_readme_sync.hierarchy import (
1819
CATEGORY_PREFIX,
@@ -21,6 +22,7 @@
2122
INDENTATION_UNIT,
2223
check_external,
2324
check_hierarchy_file,
25+
check_links,
2426
create_hierarchy_file,
2527
extract_links,
2628
)
@@ -233,6 +235,21 @@ def extract(input_string, expected_output):
233235
["https://a.com/quotes"],
234236
)
235237

238+
def test_check_links_ignores_external(self):
239+
"""Test that check_links ignores external links (http/https/mailto)."""
240+
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
241+
f.write("""
242+
[External Link](https://example.com/page.md)
243+
[Another External](http://test.com/doc.md)
244+
[Email Link](mailto:[email protected])
245+
""")
246+
temp_path = f.name
247+
248+
try:
249+
self.assertEqual(check_links(temp_path), [])
250+
finally:
251+
Path(temp_path).unlink()
252+
236253

237254
if __name__ == "__main__":
238255
unittest.main()

0 commit comments

Comments
 (0)