aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2020-07-20 03:57:27 +0200
committerGravatar Numerlor <[email protected]>2020-07-20 14:55:15 +0200
commit9f78dbafc3bc532bbfb5ffa0ef110fdeb0c3e8a5 (patch)
tree549456f1bba8398ed1e19db3470de100157e7149
parentAdd function for finding tags until a matching tag (diff)
Simplify module parsing method.
Instead of returning None and multiple values, the method now only returns the string of the description. Previously the parsing returned None and quit when appropriate tags for shortening the description were not found, but the new implementation simply defaults to the provided start tag if a better alternative is not found.
-rw-r--r--bot/cogs/doc/parsing.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/bot/cogs/doc/parsing.py b/bot/cogs/doc/parsing.py
index 5e5a5be66..368feeb68 100644
--- a/bot/cogs/doc/parsing.py
+++ b/bot/cogs/doc/parsing.py
@@ -59,17 +59,18 @@ find_next_siblings_until_tag = partial(find_elements_until_tag, func=BeautifulSo
find_previous_siblings_until_tag = partial(find_elements_until_tag, func=BeautifulSoup.find_previous_siblings)
-def parse_module_symbol(heading: PageElement) -> Optional[Tuple[None, str]]:
- """Get page content from the headerlink up to a table or a tag with its class in `SEARCH_END_TAG_ATTRS`."""
- start_tag = heading.find("a", attrs={"class": "headerlink"})
- if start_tag is None:
- return None
+def get_module_description(start_element: PageElement) -> Optional[str]:
+ """
+ Get page content to a table or a tag with its class in `SEARCH_END_TAG_ATTRS`.
- description = find_all_children_until_tag(start_tag, _match_end_tag)
- if description is None:
- return None
+ A headerlink a tag is attempted to be found to skip repeating the module name in the description,
+ if it's found it's used as the tag to search from instead of the `start_element`.
+ """
+ header = start_element.find("a", attrs={"class": "headerlink"})
+ start_tag = header.parent if header is not None else start_element
+ description = "".join(str(tag) for tag in find_next_siblings_until_tag(start_tag, _match_end_tag))
- return None, description
+ return description
def parse_symbol(heading: PageElement, html: str) -> Tuple[List[str], str]: