Skip to content

Commit

Permalink
Bump markdownify from 0.6.1 to 0.11.6 (#2429)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: wookie184 <[email protected]>
  • Loading branch information
dependabot[bot] and wookie184 authored Mar 7, 2023
1 parent e770530 commit bf8f8f4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
12 changes: 10 additions & 2 deletions bot/exts/info/doc/_markdown.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -56,3 +60,7 @@ def convert_p(self, el: PageElement, text: str, convert_as_inline: bool) -> str:
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 ""
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions tests/bot/exts/info/doc/test_parsing.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -64,3 +65,25 @@ def _run_tests(self, test_cases):
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)

0 comments on commit bf8f8f4

Please sign in to comment.