Skip to content

fix(editor): preserve leading newlines in plain text editor#8787

Open
omnizs38 wants to merge 1 commit into
nextcloud:mainfrom
omnizs38:fix/preserve-plaintext-leading-newlines
Open

fix(editor): preserve leading newlines in plain text editor#8787
omnizs38 wants to merge 1 commit into
nextcloud:mainfrom
omnizs38:fix/preserve-plaintext-leading-newlines

Conversation

@omnizs38

Copy link
Copy Markdown

📝 Summary

  • Resolves: N/A

This PR fixes an issue where the plain text editor stripped leading newlines and trailing whitespace on empty first lines of plain text documents.

When setting or updating the content of the plain text editor, the raw content is escaped and wrapped inside HTML <pre>...</pre> tags. By standard HTML rules, DOMParser strips a single leading newline character inside <pre> tags. Prepending a newline (\n) to <pre> content ensures that DOMParser strips only our prepended newline, leaving the document's original leading newlines and whitespace intact.

This change also re-enables the previously skipped CommonMark plain text tests 97 and 117, which now pass successfully.

🖼️ Screenshots

🏚️ Before 🏡 After
N/A (No visual changes) N/A (No visual changes)

🚧 TODO

  • None

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

Signed-off-by: omnizs38 <omnizs@proton.me>
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.

1 participant