Opened 8 years ago
Closed 7 years ago
#37066 closed defect (bug) (fixed)
Two paragraphs will merge if the later starts with <br>
Reported by: | rellect | Owned by: | azaozz |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | minor | Version: | 4.5.2 |
Component: | TinyMCE | Keywords: | has-patch |
Focuses: | administration | Cc: |
Description
Reproduce:
Write a new post and do the following:
- Write few words
- Shift + Enter (to break line)
- Write few words
So now you'll have something like that:
First line.. Second line..
Now, between the first and the second line, click enter. You will get this
First line.. Second line..
You will also see the space between the two lines in the editor.
Now save or switch to html mode
Expected:
Two paragraphs, and space between the two lines.
Current Result:
One paragraph, no space between the two lines.
Attachments (3)
Change History (15)
#3
in reply to:
↑ 1
@
8 years ago
Replying to iseulde:
Thanks for the ticket. Could you give more detailed steps to reproduce?
Now, between the first and the second line, click enter.
Where is the cursor? On the first or second line?
Could you give the expected and actual HTML result?
Cursor is at the end of the first line, then pressing enter.
The result looks like this
Then switching to Text mode, it removes the spaces between the lines:
#4
@
8 years ago
- Summary changed from Paragraph after break line isn't maintained when saving to Enter after a break line being removed when switching to editor text mode
#5
@
8 years ago
- Keywords needs-patch added; reporter-feedback removed
- Milestone changed from Awaiting Review to Future Release
- Severity changed from normal to minor
Confirmed. It's a (minor) bug in pre_wpautip()
. Exact HTML:
<p>111</p> <p><br>222</p>
Note that
<p>111<br></p> <p>222</p>
works as expected.
#7
follow-up:
↓ 9
@
8 years ago
- Keywords has-patch added; needs-patch removed
The problem was with the following regex (in editor.js):
html = html.replace( /\s*<br ?\/?>\s*/gi, '\n' );
At this point of the code, all <p> tags are already replaced with \n
And the above regex strips all whitespaces before and after the <br>s, which also removed the break lines separating the paragraphs.
The fix I've included in the patch is:
html = html.replace( /\s*?(\n)?\s*<br ?\/?>\s*/gi, '$1\n' );
Specificaly \s*?(\n)?\s*
- this will look for one new line within the whitespace, and append it back to the string.
#8
@
8 years ago
- Summary changed from Enter after a break line being removed when switching to editor text mode to Two paragraphs will merge if the later starts with <br>
#9
in reply to:
↑ 7
;
follow-up:
↓ 10
@
8 years ago
Replying to rellect:
37066.patch looks good. Thinking that 37066.2.patch would probably be slightly better as less backtracking in the regex (the logic is identical, just uses a callback instead of more complex regex).
#10
in reply to:
↑ 9
@
8 years ago
Replying to azaozz:
Replying to rellect:
37066.patch looks good. Thinking that 37066.2.patch would probably be slightly better as less backtracking in the regex (the logic is identical, just uses a callback instead of more complex regex).
Agreed, looks better. Added 37066.3 to correct a typo in the relevant comment.
Thanks for the ticket. Could you give more detailed steps to reproduce?
Where is the cursor? On the first or second line?
Could you give the expected and actual HTML result?