Skip to content

Commit 0a31206

Browse files
committed
Remove surrounding whitespace from doc description markdown
1 parent fdcf913 commit 0a31206

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

bot/exts/info/doc/_parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _get_truncated_description(
186186

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

191191
# Determine the actual truncation index.
192192
possible_truncation_indices = [cut for cut in markdown_element_ends if cut < truncate_index]

tests/bot/exts/info/doc/test_parsing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest import TestCase
22

3+
from bs4 import BeautifulSoup
4+
35
from bot.exts.info.doc import _parsing as parsing
46
from bot.exts.info.doc._markdown import DocMarkdownConverter
57

@@ -87,3 +89,18 @@ def _run_tests(self, test_cases: tuple[tuple[str, str], ...]):
8789
with self.subTest(input_string=input_string):
8890
d = DocMarkdownConverter(page_url="https://example.com")
8991
self.assertEqual(d.convert(input_string), expected_output)
92+
93+
94+
class MarkdownCreationTest(TestCase):
95+
def test_surrounding_whitespace(self):
96+
test_cases = (
97+
("<p>Hello World</p>", "Hello World"),
98+
("<p>Hello</p><p>World</p>", "Hello\n\nWorld"),
99+
)
100+
self._run_tests(test_cases)
101+
102+
def _run_tests(self, test_cases: tuple[tuple[str, str], ...]):
103+
for input_string, expected_output in test_cases:
104+
with self.subTest(input_string=input_string):
105+
tags = BeautifulSoup(input_string, "html.parser")
106+
self.assertEqual(parsing._create_markdown(None, tags, "https://example.com"), expected_output)

0 commit comments

Comments
 (0)