diff --git a/md_dead_link_check/preprocess.py b/md_dead_link_check/preprocess.py index 608361a..13b3be1 100644 --- a/md_dead_link_check/preprocess.py +++ b/md_dead_link_check/preprocess.py @@ -10,7 +10,8 @@ RE_HEADER = r"^[#]{1,6}\s*(.*)" RE_LINK = r"[!]{0,1}\[[^\]!]*\]\((([^\s)]+)(?:\s*(.*?))?)\)" -RE_HTML_A_TAG_ID = r".*?<\/a>" +RE_HTML_A_TAG_ID = r".*?<\/a>" +RE_HTML_A_TAG_HREF = r".*?<\/a>" RE_SUB = r"[$`][^`]+?[$`]" @@ -102,9 +103,13 @@ def process_md_file(path: Path, root_dir: Path) -> MarkdownInfo: # Detect id under a tag matches = re.findall(RE_HTML_A_TAG_ID, line) - if matches: - for id in matches: - fragments.append(id) + for id in matches: + fragments.append(id) + + # Detect links under a tag + matches = re.findall(RE_HTML_A_TAG_HREF, line) + for link in matches: + links.append(LinkInfo(link, path, line_num)) return MarkdownInfo(path=path, fragments=fragments, links=links) diff --git a/tests/test_md_files/a.md b/tests/test_md_files/a.md index 751e675..9151886 100644 --- a/tests/test_md_files/a.md +++ b/tests/test_md_files/a.md @@ -26,7 +26,7 @@ Some text [github](https://github.com/AlexanderDokuchaev) [b](./b.md) [d.a](b.md) `[A+B](A)` -[d.a](./d/a.md) +d.ad.a [d.a](/tests/test_md_files/d/a.md "tag") ### Header with `quotes` and $math$ diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py index 4962adb..a9b0d63 100644 --- a/tests/test_preprocess.py +++ b/tests/test_preprocess.py @@ -73,6 +73,11 @@ def test_process_md_file(): location=Path("tests/test_md_files/a.md"), line_num=29, ), + LinkInfo( + link="./d/a.md", + location=Path("tests/test_md_files/a.md"), + line_num=29, + ), LinkInfo( link="/tests/test_md_files/d/a.md", location=Path("tests/test_md_files/a.md"),