Skip to content

Commit c9d0e7c

Browse files
authored
fix: preserve sentence structure across newlines (#378)
Instead of stripping out the newlines characters, leading to mangled content when rendering full contents, provide a space instead. Fixes #186
2 parents 376a32c + 2fff07e commit c9d0e7c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

mkdocs_rss_plugin/plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ def on_post_build(self, config: config_options.Config) -> None:
432432
prev_char = ""
433433
for char in template.render(feed=asdict(self.feed_created)):
434434
if char == "\n":
435-
continue
435+
# convert new lines to spaces to preserve sentence structure
436+
char = " "
436437
if char == " " and prev_char == " ":
437438
prev_char = char
438439
continue
@@ -442,8 +443,8 @@ def on_post_build(self, config: config_options.Config) -> None:
442443
with out_feed_updated.open(mode="w", encoding="UTF8") as fifeed_updated:
443444
for char in template.render(feed=asdict(self.feed_updated)):
444445
if char == "\n":
445-
prev_char = char
446-
continue
446+
# convert new lines to spaces to preserve sentence structure
447+
char = " "
447448
if char == " " and prev_char == " ":
448449
prev_char = char
449450
continue

tests/test_build.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ def test_simple_build_item_length_unlimited(self):
405405
150,
406406
f"Failed item title: {feed_item.title}",
407407
)
408+
# check sentences split across multiple lines retain spacing
409+
if feed_item.title in ["My first blog post", "A second post"]:
410+
self.assertIn(
411+
"Pellentesque nec maximus ex.",
412+
feed_item.summary,
413+
)
408414

409415
def test_simple_build_item_delimiter(self):
410416
with tempfile.TemporaryDirectory() as tmpdirname:

0 commit comments

Comments
 (0)