From 2fff07e6d75592af0df443de16661041458f0647 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 19 Aug 2025 17:12:18 -0400 Subject: [PATCH] fix: preserve sentence structure across newlines Instead of stripping out the newlines characters, leading to mangled content when rendering full contents, provide a space instead. Fixes #186 Signed-off-by: Mike Fiedler --- mkdocs_rss_plugin/plugin.py | 7 ++++--- tests/test_build.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index a169ad4..515f69d 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -432,7 +432,8 @@ def on_post_build(self, config: config_options.Config) -> None: prev_char = "" for char in template.render(feed=asdict(self.feed_created)): if char == "\n": - continue + # convert new lines to spaces to preserve sentence structure + char = " " if char == " " and prev_char == " ": prev_char = char continue @@ -442,8 +443,8 @@ def on_post_build(self, config: config_options.Config) -> None: with out_feed_updated.open(mode="w", encoding="UTF8") as fifeed_updated: for char in template.render(feed=asdict(self.feed_updated)): if char == "\n": - prev_char = char - continue + # convert new lines to spaces to preserve sentence structure + char = " " if char == " " and prev_char == " ": prev_char = char continue diff --git a/tests/test_build.py b/tests/test_build.py index 7f07e47..451d796 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -405,6 +405,12 @@ def test_simple_build_item_length_unlimited(self): 150, f"Failed item title: {feed_item.title}", ) + # check sentences split across multiple lines retain spacing + if feed_item.title in ["My first blog post", "A second post"]: + self.assertIn( + "Pellentesque nec maximus ex.", + feed_item.summary, + ) def test_simple_build_item_delimiter(self): with tempfile.TemporaryDirectory() as tmpdirname: