thexerteproject / xerteonlinetoolkits

Xerte Online Toolkits
www.xerte.org.uk
Apache License 2.0
62 stars 61 forks source link

Single line wysiwyg editor (with the button toolbar) adds new lines #1261

Closed torinfo closed 8 months ago

torinfo commented 8 months ago

From Deltion

When we try to center the (in this case) title of a flashcard by changing the HTML using the <> Code button in the toolbar by adding for example <center><p>Title</p></center>, or <p style="text-align:center;">Title</p> and you leave the title and come back later again, a new line has been inserted before and after the title (actually <p>&nbsp</p> has been inserted before and after the title.

Cause: This is cuased by the fact that Xerte tries to get rid of the surrounding <p> tags that the CkEditor is adding. It does that by searching for <p> and replace it by nothing. In the case of <center> the first tag is not <p> and nothing gets replaced. In the second instance the <p> tag is not found because it has an attribute. When reentering the editor, the <p> tag is added without any check. This causes code like <p><center><p>Title</p></center></p> or <p><p style="..>Title</p></p>. CkEditor doesn't like that and 'corrects' the code resulting in the <p>&nbsp;</p>.

I do not have an easy solution for the <center> case, but the <p with an attribute is easily solved by only adding <p> if no <p tag can be found. Partial solution.