Skip to content

Fix newline handling in inline HTML elements on import - #3231

Open
caddydove wants to merge 1 commit into
anyproto:developfrom
caddydove:fix/3114-html-inline-newlines
Open

Fix newline handling in inline HTML elements on import#3231
caddydove wants to merge 1 commit into
anyproto:developfrom
caddydove:fix/3114-html-inline-newlines

Conversation

@caddydove

Copy link
Copy Markdown

What this PR does

Fixes #3114.

When importing HTML, newlines used only to pretty-print the source (inside <strong>, <a>, paragraph text, etc.) leaked into the imported content as unwanted line breaks — e.g. <strong>000\n111\n222</strong> became three separate blocks instead of one "000 111 222".

Changes

  • Before converting HTML to markdown, collapse interior whitespace runs in text nodes to a single space, mirroring HTML's inline whitespace collapsing.
  • Whitespace is preserved inside pre/textarea/script/style where it is significant.
  • Leading/trailing whitespace of text nodes is preserved so newlines that separate sibling inline elements still break them into distinct items (keeps the existing List with spans with new line items behavior).
  • Updated the Link testdata expectation that was encoding the buggy behavior (interior newlines in paragraph text), and added regression tests for the reported cases.

Test plan

  • go test ./core/block/import/markdown/anymark/ -count=1
  • go test ./core/block/import/... -count=1
  • go vet ./core/block/import/markdown/anymark/

HTML used for pretty-printing (newlines inside <strong>, <a>, paragraph
text, etc.) leaked into imported content as unwanted line breaks, turning
'000\n111\n222' into separate blocks instead of '000 111 222'.

Before converting HTML to markdown, collapse interior whitespace runs in
text nodes to a single space (except in pre/textarea/script/style where
whitespace is significant). Leading/trailing whitespace is preserved so
newlines separating sibling inline elements still break them into distinct
items (e.g. pasted '1. One\n2. Two' list-like spans).

Fixes anyproto#3114
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.

Broken newline handling in inline HTML elements

1 participant