From b8c35610c39b670ab0086f3dd6710527e494f698 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:10:12 +0200 Subject: [PATCH] fix: Prevent extra leading space in paragraphs in line wrap modes (#473) --- docs/users/changelog.md | 1 + src/mdformat/renderer/_context.py | 2 +- tests/data/wrap_width_50.md | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/users/changelog.md b/docs/users/changelog.md index afc7b28..f636be2 100644 --- a/docs/users/changelog.md +++ b/docs/users/changelog.md @@ -11,6 +11,7 @@ Note that there is currently no guarantee for a stable Markdown formatting style - Fixed - Incorrect line wrap on lines right after a hard break. Thank you, [MDW](https://github.com/mdeweerd), for the issue. + - Adding an extra leading space to paragraphs that start with space in line wrap modes. - Added - Plugin interface: `mdformat.plugins.ParserExtensionInterface.add_cli_argument_group`. With this plugins can now read CLI arguments merged with values from `.mdformat.toml`. diff --git a/src/mdformat/renderer/_context.py b/src/mdformat/renderer/_context.py index 89140b1..df67993 100644 --- a/src/mdformat/renderer/_context.py +++ b/src/mdformat/renderer/_context.py @@ -346,7 +346,7 @@ def _wrap(text: str, *, width: int | Literal["no"]) -> str: ) wrapped = wrapper.fill(text) wrapped = _recover_preserve_chars(wrapped, replacements) - return " " + wrapped if text.startswith(" ") else wrapped + return wrapped def _prepare_wrap(text: str) -> tuple[str, str]: diff --git a/tests/data/wrap_width_50.md b/tests/data/wrap_width_50.md index a75a155..eceede9 100644 --- a/tests/data/wrap_width_50.md +++ b/tests/data/wrap_width_50.md @@ -180,3 +180,11 @@ sssssssssssssssssssssssssssssssssssss backslash bar"> ipsum dolor sit amet, consectetur adip elitismisun. . + + +Starts with encoded space +. + * * * +. + * * \* +.