Skip to content

Fix: Converting a <pre> to blocks drops new lines#13606

Closed
jorgefilipecosta wants to merge 1 commit intomasterfrom
fix/converting-a-pre-to-blocks-drops-new-lines
Closed

Fix: Converting a <pre> to blocks drops new lines#13606
jorgefilipecosta wants to merge 1 commit intomasterfrom
fix/converting-a-pre-to-blocks-drops-new-lines

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

Description

Fixes: #12109

Previously wp.richText.create always replaced newline character with a space character.
This PR adds a flag that allows disabling this behavior: filterWhiteSpaceChars = false.
Normally browsers ignore newline chars inside HTML documents, but inside pre tag newlines are rendered as a newline.
This PR's fixes a bug wherein the editor newlines inside pre-block were not rendered.

How has this been tested?

I pasted the following block into Gutenberg:

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">line1
      line2
line3</pre>
<!-- /wp:preformatted -->

I verified newline and whitespaces were kept.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Jan 30, 2019
@gziolo gziolo requested a review from ellatrix February 5, 2019 16:14
@gziolo gziolo added this to the 5.1 (Gutenberg) milestone Feb 5, 2019
@ellatrix
Copy link
Copy Markdown
Member

ellatrix commented Feb 6, 2019

What's the difference between <pre>one<br>two</pre> and <pre>one\ntwo</pre>? Should we normalise to one of these?

@ellatrix
Copy link
Copy Markdown
Member

ellatrix commented Feb 6, 2019

When RichText inserts a line break, it will insert a <br> element. TinyMCE did the same. So I'm leaning towards using the element. But we can save it either way, maybe a unicode line break is easier to read.

So since there are two possible ways to write it, and only one that properly works with the rich text value, could we not replace line breaks with elements before feeding it to RichText?

@ellatrix ellatrix mentioned this pull request Feb 9, 2019
5 tasks
@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Closed in favor of #13799.

@aduth aduth deleted the fix/converting-a-pre-to-blocks-drops-new-lines branch March 26, 2019 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Converting a <pre> to blocks drops new lines

3 participants