Skip to content

Commit

Permalink
Remove surrounding whitespace from doc description markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
wookie184 committed Dec 30, 2024
1 parent fdcf913 commit 0a31206
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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
17 changes: 17 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,18 @@ 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"),
)
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)

0 comments on commit 0a31206

Please sign in to comment.