feat(announcements): honour the line breaks an author actually typed - #30
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The surprise
An author writes this in the composer's Body:
and the reader gets one line: "Test Test Test Test Test TestTestTestTestTest".
That is markdown behaving exactly as specified — a single newline is a soft break, rendered as a space; only a blank line or two trailing spaces break a line. It is a reasonable rule for a document format and the wrong one for the field this text is typed into. The Body is a plain textarea with no hint that it is markdown at all, the moderator note the server splices into an approval announcement is typed the same way, and nothing anywhere tells an author that the Enter they just pressed will be discarded.
The fix
remark-breaks, so a newline is the line break the author typed. This is the same resolution comment fields everywhere use, GitHub's included.It rewrites text nodes only, so fenced code blocks keep their newlines verbatim — there is a test for that, since a
<br>injected into a code block would change the code itself. Blank lines still start paragraphs.Nothing changes server-side: sphere-api's
deriveSummaryalready collapses whitespace when it takes the body's first paragraph for the bell popover, so the row reads the same as before.Tests
Three new tests in
Markdown.test.tsx. The first was verified to fail againstmain; the other two pin behaviour this must not break:<br>;<p>s;<br>and keepsnpm install\nnpm run buildintact.vitest run— 183 passed (24 files).npm run buildclean.