aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-03-07 21:00:53 +0000
committerGravatar GitHub <[email protected]>2023-03-07 21:00:53 +0000
commitbf8f8f4c1f9522a942c88ca69a2d48427d2bbc28 (patch)
treec03a110d3bbf650e09e67ed4b483dda343ebd591
parentBump SebastiaanZ/github-status-embed-for-discord from 0.2.1 to 0.3.0 (#2448) (diff)
Bump markdownify from 0.6.1 to 0.11.6 (#2429)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: wookie184 <[email protected]>
-rw-r--r--bot/exts/info/doc/_markdown.py12
-rw-r--r--poetry.lock12
-rw-r--r--pyproject.toml6
-rw-r--r--tests/bot/exts/info/doc/test_parsing.py23
4 files changed, 40 insertions, 13 deletions
diff --git a/bot/exts/info/doc/_markdown.py b/bot/exts/info/doc/_markdown.py
index 1b7d8232b..315adda66 100644
--- a/bot/exts/info/doc/_markdown.py
+++ b/bot/exts/info/doc/_markdown.py
@@ -1,10 +1,14 @@
+import re
from urllib.parse import urljoin
+import markdownify
from bs4.element import PageElement
-from markdownify import MarkdownConverter
+# See https://github.com/matthewwithanm/python-markdownify/issues/31
+markdownify.whitespace_re = re.compile(r"[\r\n\s\t ]+")
-class DocMarkdownConverter(MarkdownConverter):
+
+class DocMarkdownConverter(markdownify.MarkdownConverter):
"""Subclass markdownify's MarkdownCoverter to provide custom conversion methods."""
def __init__(self, *, page_url: str, **options):
@@ -56,3 +60,7 @@ class DocMarkdownConverter(MarkdownConverter):
if parent is not None and parent.name == "li":
return f"{text}\n"
return super().convert_p(el, text, convert_as_inline)
+
+ def convert_hr(self, el: PageElement, text: str, convert_as_inline: bool) -> str:
+ """Ignore `hr` tag."""
+ return ""
diff --git a/poetry.lock b/poetry.lock
index 8a718ab82..de777c828 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1041,19 +1041,19 @@ source = ["Cython (>=0.29.7)"]
[[package]]
name = "markdownify"
-version = "0.6.1"
+version = "0.11.6"
description = "Convert HTML to markdown."
category = "main"
optional = false
python-versions = "*"
files = [
- {file = "markdownify-0.6.1-py3-none-any.whl", hash = "sha256:7489fd5c601536996a376c4afbcd1dd034db7690af807120681461e82fbc0acc"},
- {file = "markdownify-0.6.1.tar.gz", hash = "sha256:31d7c13ac2ada8bfc7535a25fee6622ca720e1b5f2d4a9cbc429d167c21f886d"},
+ {file = "markdownify-0.11.6-py3-none-any.whl", hash = "sha256:ba35fe289d5e9073bcd7d2cad629278fe25f1a93741fcdc0bfb4f009076d8324"},
+ {file = "markdownify-0.11.6.tar.gz", hash = "sha256:009b240e0c9f4c8eaf1d085625dcd4011e12f0f8cec55dedf9ea6f7655e49bfe"},
]
[package.dependencies]
-beautifulsoup4 = "*"
-six = "*"
+beautifulsoup4 = ">=4.9,<5"
+six = ">=1.15,<2"
[[package]]
name = "mccabe"
@@ -2317,4 +2317,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "3.10.*"
-content-hash = "68bfdf2115a5242df097155a2660a1c0276cf25b4785bdb761580bd35b77383c"
+content-hash = "4b3549e9e47535d1fea6015a0f7ebf056a42e4d27e766583ccd8b59ebe8297d6"
diff --git a/pyproject.toml b/pyproject.toml
index 71981e8d0..11e99ecbe 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -22,11 +22,7 @@ deepdiff = "6.2.1"
emoji = "2.2.0"
feedparser = "6.0.10"
lxml = "4.9.1"
-
-# Must be kept on this version unless doc command output is fixed
-# See https://github.com/python-discord/bot/pull/2156
-markdownify = "0.6.1"
-
+markdownify = "0.11.6"
more-itertools = "9.0.0"
python-dateutil = "2.8.2"
python-frontmatter = "1.0.0"
diff --git a/tests/bot/exts/info/doc/test_parsing.py b/tests/bot/exts/info/doc/test_parsing.py
index 1663d8491..d2105a53c 100644
--- a/tests/bot/exts/info/doc/test_parsing.py
+++ b/tests/bot/exts/info/doc/test_parsing.py
@@ -1,6 +1,7 @@
from unittest import TestCase
from bot.exts.info.doc import _parsing as parsing
+from bot.exts.info.doc._markdown import DocMarkdownConverter
class SignatureSplitter(TestCase):
@@ -64,3 +65,25 @@ class SignatureSplitter(TestCase):
for input_string, expected_output in test_cases:
with self.subTest(input_string=input_string):
self.assertEqual(list(parsing._split_parameters(input_string)), expected_output)
+
+
+class MarkdownConverterTest(TestCase):
+ def test_hr_removed(self):
+ test_cases = (
+ ('<hr class="docutils"/>', ""),
+ ("<hr>", ""),
+ )
+ self._run_tests(test_cases)
+
+ def test_whitespace_removed(self):
+ test_cases = (
+ ("lines\nof\ntext", "lines of text"),
+ ("lines\n\nof\n\ntext", "lines of text"),
+ )
+ self._run_tests(test_cases)
+
+ def _run_tests(self, test_cases: tuple[tuple[str, str], ...]):
+ for input_string, expected_output in test_cases:
+ with self.subTest(input_string=input_string):
+ d = DocMarkdownConverter(page_url="https://example.com")
+ self.assertEqual(d.convert(input_string), expected_output)