Skip to content

Commit

Permalink
tools: External markdowns are treated as internal links (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeallthethingz authored Nov 14, 2024
1 parent 6a6bfeb commit c9eaf7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/github_readme_sync/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def check_links(path):
errors = []

for match in md_link_matches:
if match[1].startswith(("http://", "https://", "mailto:")):
continue
path_to_check = os.path.join(current_dir, match[1].split("#")[0])
path_to_check = os.path.normpath(path_to_check)
if any(placeholder in match[1] for placeholder in IGNORE_DOCS):
Expand Down
17 changes: 17 additions & 0 deletions tools/github_readme_sync/tests/hierarchy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile
import threading
import unittest
from pathlib import Path

from tools.github_readme_sync.hierarchy import (
CATEGORY_PREFIX,
Expand All @@ -21,6 +22,7 @@
INDENTATION_UNIT,
check_external,
check_hierarchy_file,
check_links,
create_hierarchy_file,
extract_links,
)
Expand Down Expand Up @@ -233,6 +235,21 @@ def extract(input_string, expected_output):
["https://a.com/quotes"],
)

def test_check_links_ignores_external(self):
"""Test that check_links ignores external links (http/https/mailto)."""
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
f.write("""
[External Link](https://example.com/page.md)
[Another External](http://test.com/doc.md)
[Email Link](mailto:[email protected])
""")
temp_path = f.name

try:
self.assertEqual(check_links(temp_path), [])
finally:
Path(temp_path).unlink()


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

0 comments on commit c9eaf7c

Please sign in to comment.