aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-06-22 14:46:44 +0100
committerGravatar GitHub <[email protected]>2022-06-22 14:46:44 +0100
commit538f984ea84e2fefdec47e8b81bec4e2d03118a1 (patch)
tree40b1f41954a3ce528572c65776faabd4045430e7
parentFix help embed views (diff)
parentMerge pull request #2199 from Numerlor/doc-description-headerlink (diff)
Merge branch 'main' into fix_return_button
-rw-r--r--bot/exts/info/doc/_html.py19
-rw-r--r--bot/exts/info/doc/_parsing.py5
2 files changed, 19 insertions, 5 deletions
diff --git a/bot/exts/info/doc/_html.py b/bot/exts/info/doc/_html.py
index c101ec250..497246375 100644
--- a/bot/exts/info/doc/_html.py
+++ b/bot/exts/info/doc/_html.py
@@ -1,4 +1,3 @@
-import re
from functools import partial
from typing import Callable, Container, Iterable, List, Union
@@ -11,7 +10,6 @@ from . import MAX_SIGNATURE_AMOUNT
log = get_logger(__name__)
-_UNWANTED_SIGNATURE_SYMBOLS_RE = re.compile(r"\[source]|\\\\|ΒΆ")
_SEARCH_END_TAG_ATTRS = (
"data",
"function",
@@ -129,12 +127,23 @@ def get_signatures(start_signature: PageElement) -> List[str]:
start_signature,
*_find_next_siblings_until_tag(start_signature, ("dd",), limit=2),
)[-MAX_SIGNATURE_AMOUNT:]:
- for tag in element.find_all("a", class_="headerlink", recursive=False):
+ for tag in element.find_all(_filter_signature_links, recursive=False):
tag.decompose()
- signature = _UNWANTED_SIGNATURE_SYMBOLS_RE.sub("", element.text)
-
+ signature = element.text
if signature:
signatures.append(signature)
return signatures
+
+
+def _filter_signature_links(tag: Tag) -> bool:
+ """Return True if `tag` is a headerlink, or a link to source code; False otherwise."""
+ if tag.name == "a":
+ if "headerlink" in tag.get("class", ()):
+ return True
+
+ if tag.find(class_="viewcode-link"):
+ return True
+
+ return False
diff --git a/bot/exts/info/doc/_parsing.py b/bot/exts/info/doc/_parsing.py
index 8ce9ea3a1..b37aadc01 100644
--- a/bot/exts/info/doc/_parsing.py
+++ b/bot/exts/info/doc/_parsing.py
@@ -256,4 +256,9 @@ def get_symbol_markdown(soup: BeautifulSoup, symbol_data: DocItem) -> Optional[s
signature = get_signatures(symbol_heading)
description = get_dd_description(symbol_heading)
+ for description_element in description:
+ if isinstance(description_element, Tag):
+ for tag in description_element.find_all("a", class_="headerlink"):
+ tag.decompose()
+
return _create_markdown(signature, description, symbol_data.url).strip()