Skip to content

Commit

Permalink
Detect links with brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDokuchaev committed Jun 25, 2024
1 parent 252157c commit f6d1791
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion md_dead_link_check/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from git import Repo

RE_HEADER = r"^[#]{1,6}\s*(.*)"
RE_LINK = r"([!]{0,1})\[([^\]!]*)\]\(([^\s)]+)(?:\s*(.*?))?\)"
RE_LINK = r"([!]{0,1})\[([^\]!]*)\]\(([^()\s]+(?:\([^()\s]*\))*)\s*(.*?)\)"
RE_HTML_A_TAG_ID = r"<\w+\s+(?:[^>]*?\s+)?id=([\"'])(.*?)\1"
RE_HTML_A_TAG_HREF = r"<\w+\s+(?:[^>]*?\s+)?href=([\"'])(.*?)\1"
RE_SUB = r"[$`][^`]+?[$`]"
Expand Down
23 changes: 22 additions & 1 deletion tests/test_link_cheker.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_fails():
# Output message depends on proxy settings
ret[1].err_msg = None
ret[1].warn_msg = None

ret[7].err_msg = None
ret[7].warn_msg = None
ref = [
StatusInfo(
link_info=LinkInfo(
Expand Down Expand Up @@ -91,6 +92,15 @@ def test_fails():
err_msg="Unknown error",
warn_msg=None,
),
StatusInfo(
link_info=LinkInfo(
link="https://example.com/(bracket)",
location=Path("tests/test_md_files/fail.md"),
line_num=19,
),
err_msg=None,
warn_msg=None,
),
]
assert ret == ref

Expand Down Expand Up @@ -126,6 +136,8 @@ def test_exclude_links(exclude_links):
# Output message depends on proxy settings
ret[0].err_msg = None
ret[0].warn_msg = None
ret[4].err_msg = None
ret[4].warn_msg = None

ref = [
StatusInfo(
Expand Down Expand Up @@ -162,5 +174,14 @@ def test_exclude_links(exclude_links):
err_msg="Unknown error",
warn_msg=None,
),
StatusInfo(
link_info=LinkInfo(
link="https://example.com/(bracket)",
location=Path("tests/test_md_files/fail.md"),
line_num=19,
),
err_msg=None,
warn_msg=None,
),
]
assert ret == ref
2 changes: 2 additions & 0 deletions tests/test_md_files/fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
[1](not_exist_dir)

[1](error://urls/)

[1](https://example.com/(bracket))

0 comments on commit f6d1791

Please sign in to comment.