Skip to content

Commit adbff12

Browse files
authored
Merge pull request #441 from CoCo-Japan-pan/check-brackets-in-url
remove brackets in embedded urls
2 parents c420326 + 3b8645d commit adbff12

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

onlinejudge_verify/languages/special_comments.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def list_doxygen_annotations(path: pathlib.Path) -> Dict[str, str]:
5353

5454
@functools.lru_cache(maxsize=None)
5555
def list_embedded_urls(path: pathlib.Path) -> List[str]:
56-
pattern = re.compile(r"""['"`]?https?://\S*""") # use a broad pattern. There are no needs to make match strict.
56+
pattern = re.compile(r"""['"`<\(]?https?://\S*""") # use a broad pattern. There are no needs to make match strict.
5757
with open(path, 'rb') as fh:
5858
content = fh.read().decode()
5959
urls = []
@@ -70,5 +70,17 @@ def list_embedded_urls(path: pathlib.Path) -> List[str]:
7070
# Remove quotes and trailing superfluous chars around the URL
7171
url = url[1:end_quote_pos]
7272
break
73+
# The URL may be written like `[atcoder](https://atcoder.jp/)` or `<https://atcoder.jp/>` in Markdown syntax.
74+
# In this case, we need to remove brackets around the URL.
75+
for (lbracket, rbracket) in (('<', '>'), ('(', ')')):
76+
if url.startswith(lbracket):
77+
end_bracket_pos = url.rfind(rbracket)
78+
if end_bracket_pos == 0:
79+
# Remove opening bracket from the URL like `<https://atcoder.jp/`
80+
url = url[1:]
81+
else:
82+
# Remove brackets and trailing superfluous chars around the URL
83+
url = url[1:end_bracket_pos]
84+
break
7385
urls.append(url)
7486
return sorted(set(urls))

0 commit comments

Comments
 (0)