diff options
| author | 2021-01-10 03:32:54 +0100 | |
|---|---|---|
| committer | 2021-01-10 06:16:10 +0100 | |
| commit | 5df60dd2ad10aec1c0368ed357562338e89a1250 (patch) | |
| tree | 0482622f8ee49cb129bd2de50dde748386c2271e | |
| parent | Set exception on future (diff) | |
Bump markdownify to 0.6.1-0.6.*
The 0.6 release brought a new parameter that has to be included in all
tag handling methods
| -rw-r--r-- | Pipfile | 2 | ||||
| -rw-r--r-- | bot/exts/info/doc/_markdown.py | 21 | ||||
| -rw-r--r-- | bot/exts/info/doc/_parsing.py | 2 |
3 files changed, 15 insertions, 10 deletions
@@ -18,7 +18,7 @@ deepdiff = "~=4.0" feedparser = "~=5.2" fuzzywuzzy = "~=0.17" lxml = "~=4.4" -markdownify = "~=0.4" +markdownify = "~=0.6.1" more_itertools = "~=8.2" python-dateutil = "~=2.8" pyyaml = "~=5.1" diff --git a/bot/exts/info/doc/_markdown.py b/bot/exts/info/doc/_markdown.py index ba35a84c4..1b7d8232b 100644 --- a/bot/exts/info/doc/_markdown.py +++ b/bot/exts/info/doc/_markdown.py @@ -11,7 +11,7 @@ class DocMarkdownConverter(MarkdownConverter): super().__init__(**options) self.page_url = page_url - def convert_li(self, el: PageElement, text: str) -> str: + def convert_li(self, el: PageElement, text: str, convert_as_inline: bool) -> str: """Fix markdownify's erroneous indexing in ol tags.""" parent = el.parent if parent is not None and parent.name == "ol": @@ -27,27 +27,32 @@ class DocMarkdownConverter(MarkdownConverter): bullet = bullets[depth % len(bullets)] return f"{bullet} {text}\n" - def convert_hn(self, _n: int, el: PageElement, text: str) -> str: + def convert_hn(self, _n: int, el: PageElement, text: str, convert_as_inline: bool) -> str: """Convert h tags to bold text with ** instead of adding #.""" + if convert_as_inline: + return text return f"**{text}**\n\n" - def convert_code(self, el: PageElement, text: str) -> str: + def convert_code(self, el: PageElement, text: str, convert_as_inline: bool) -> str: """Undo `markdownify`s underscore escaping.""" return f"`{text}`".replace("\\", "") - def convert_pre(self, el: PageElement, text: str) -> str: + def convert_pre(self, el: PageElement, text: str, convert_as_inline: bool) -> str: """Wrap any codeblocks in `py` for syntax highlighting.""" code = "".join(el.strings) return f"```py\n{code}```" - def convert_a(self, el: PageElement, text: str) -> str: + def convert_a(self, el: PageElement, text: str, convert_as_inline: bool) -> str: """Resolve relative URLs to `self.page_url`.""" el["href"] = urljoin(self.page_url, el["href"]) - return super().convert_a(el, text) + return super().convert_a(el, text, convert_as_inline) - def convert_p(self, el: PageElement, text: str) -> str: + def convert_p(self, el: PageElement, text: str, convert_as_inline: bool) -> str: """Include only one newline instead of two when the parent is a li tag.""" + if convert_as_inline: + return text + parent = el.parent if parent is not None and parent.name == "li": return f"{text}\n" - return super().convert_p(el, text) + return super().convert_p(el, text, convert_as_inline) diff --git a/bot/exts/info/doc/_parsing.py b/bot/exts/info/doc/_parsing.py index 032fe3404..46ae33b92 100644 --- a/bot/exts/info/doc/_parsing.py +++ b/bot/exts/info/doc/_parsing.py @@ -259,7 +259,7 @@ def _get_truncated_description( if rendered_length + element_length < max_length: if is_tag: - element_markdown = markdown_converter.process_tag(element) + element_markdown = markdown_converter.process_tag(element, convert_as_inline=False) else: element_markdown = markdown_converter.process_text(element) |