Skip to content

fix: _clean_content newline condensation bug#107

Open
Jah-yee wants to merge 1 commit intolsdefine:mainfrom
Jah-yee:main
Open

fix: _clean_content newline condensation bug#107
Jah-yee wants to merge 1 commit intolsdefine:mainfrom
Jah-yee:main

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 18, 2026

Bug Fix

In `_clean_content`, the condition `'\\n' in p\' was checking for a 3-character sequence (backslash, backslash, n) in the patterns. However, the third pattern `r'(\r?\n){3,}'` only contains the 2-character sequence (backslash, n).

Result: All patterns were being replaced with `''` (empty string), destroying paragraph spacing.

Fix: Change `'\\n'\' to `'\n'\' so the condition correctly identifies the newline-collapse pattern and replaces it with `'\n\n'` instead.

Testing

The fix was verified by checking that the condition now correctly evaluates:

  • `'\n' in r'(\r?\n){3,}'\' = True ✓
  • Previously: `'\\n' in r'(\r?\n){3,}'\' = False ✗

Related

Closes #87
Signed-off-by: Jah-yee

Changed '\\\\n' to '\\n' in the condition check.

The bug: '\\\\n' (3-char \\n) never matched the pattern
r'(\\r?\\n){3,}' which only contains the 2-char sequence
backslash+n. This caused all patterns to be replaced with ''
(empty string) instead of correctly condensing newlines.

Fix: use '\\n' (2-char backslash+n) so the condition
correctly identifies the newline-collapse pattern.

Closes lsdefine#87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: _clean_content deletes excess newlines instead of condensing them

1 participant