Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot/exts/info/doc/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def convert_li(self, el: PageElement, text: str, convert_as_inline: bool) -> str
bullet = bullets[depth % len(bullets)]
return f"{bullet} {text}\n"

def convert_hn(self, _n: int, el: PageElement, text: str, convert_as_inline: bool) -> 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
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/info/doc/_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _get_truncated_description(

# Nothing needs to be truncated if the last element ends before the truncation index.
if truncate_index >= markdown_element_ends[-1]:
return result
return result.strip(string.whitespace)

# Determine the actual truncation index.
possible_truncation_indices = [cut for cut in markdown_element_ends if cut < truncate_index]
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deepdiff = "7.0.1"
emoji = "2.14.0"
feedparser = "6.0.11"
lxml = "5.3.0"
markdownify = "0.13.1"
markdownify = "0.14.1"
python-dateutil = "2.9.0.post0"
python-frontmatter = "1.1.0"
rapidfuzz = "3.10.1"
Expand Down
18 changes: 18 additions & 0 deletions tests/bot/exts/info/doc/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest import TestCase

from bs4 import BeautifulSoup

from bot.exts.info.doc import _parsing as parsing
from bot.exts.info.doc._markdown import DocMarkdownConverter

Expand Down Expand Up @@ -87,3 +89,19 @@ def _run_tests(self, test_cases: tuple[tuple[str, str], ...]):
with self.subTest(input_string=input_string):
d = DocMarkdownConverter(page_url="https://example.com")
self.assertEqual(d.convert(input_string), expected_output)


class MarkdownCreationTest(TestCase):
def test_surrounding_whitespace(self):
test_cases = (
("<p>Hello World</p>", "Hello World"),
("<p>Hello</p><p>World</p>", "Hello\n\nWorld"),
("<h1>Title</h1>", "**Title**")
)
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):
tags = BeautifulSoup(input_string, "html.parser")
self.assertEqual(parsing._create_markdown(None, tags, "https://example.com"), expected_output)
Loading