diff options
| -rw-r--r-- | webmentions_ssg/tasks/mentions.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/webmentions_ssg/tasks/mentions.py b/webmentions_ssg/tasks/mentions.py index 42dd0b6..687ba38 100644 --- a/webmentions_ssg/tasks/mentions.py +++ b/webmentions_ssg/tasks/mentions.py @@ -12,22 +12,18 @@ from bs4 import BeautifulSoup IRI_PATTERN = rfc3987.get_compiled_pattern("IRI") TRAILING_IRI_PUNCTUATION = ".,;:!?" -HTML_URL_ATTRIBUTES = { - "href": {"a", "area", "link"}, - "src": { - "audio", - "embed", - "iframe", - "img", - 'input[type="image" i]', - "script", - "audio source", - "video source", - "track", - "video", - }, - "cite": {"blockquote", "del", "ins", "q"}, -} +HTML_URL_ATTRIBUTES = ( + ("a[href], area[href], link[href]", "href"), + ( + ( + "audio[src], embed[src], iframe[src], img[src], " + 'input[type="image" i][src], script[src], ' + "audio source[src], video source[src], track[src], video[src]" + ), + "src", + ), + ("blockquote[cite], del[cite], ins[cite], q[cite]", "cite"), +) def html_mentions_target(body: bytes, source_url: str, target_url: str) -> bool: @@ -49,11 +45,7 @@ def html_mentions_target(body: bytes, source_url: str, target_url: str) -> bool: ): base_url = urljoin(source_url, base_href.strip()) - for attribute, selectors in HTML_URL_ATTRIBUTES.items(): - selector = ", ".join( - [f"{selector_string}[{attribute}]" for selector_string in selectors] - ) - + for selector, attribute in HTML_URL_ATTRIBUTES: for element in document.select(selector): if not isinstance(reference := element.get(attribute), str): continue |
