Bug #93302
closedPre-formatted text in RTE gets re-formatted when inside an ordered / unordered list
0%
Description
When a pre-formatted text (pre
element) gets entered into an RTE enabled field in the backend, the formatting might get destroyed during persistence depending on the context of the pre
element:
- The formatting stays in order as long as the
pre
element is a top-level element or a child of particular other elements - The formatting might get destroyed as soon as the
pre
element is a child of an ordered or unordered list (ol
/ul
) and potentially other elements as well
Due to the nature of the problem it's difficult / impossible to give a representative RTE value example that would survive the format mangling done by Forge ... Just imagine a pre-formatted code block inside a ul
> li
.
The reason for the problem is that only particular HTML elements are parsed recursively in RteHtmlParser::TS_transform_db
(TYPO3 10.4, taken from line 416 onwards):
// Traverse the blocks foreach ($blockSplit as $k => $v) { if ($k % 2) { // Inside block: // Init: $tag = $this->getFirstTag($v); $tagName = strtolower($this->getFirstTagName($v)); // Process based on the tag: switch ($tagName) { case 'blockquote': case 'dd': case 'div': case 'header': case 'section': case 'footer': case 'nav': case 'article': case 'aside': $blockSplit[$k] = $tag . $this->TS_transform_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</' . $tagName . '>'; break; case 'pre': break; default: // usually <hx> tags and <table> tags where no other block elements are within the tags // Eliminate true linebreaks inside block element tags $blockSplit[$k] = preg_replace('/[' . LF . ']+/', ' ', $blockSplit[$k]); } } else {
Right now, the default
case gets triggered for ordered and unordered lists, eliminating linebreaks within the tag content and thus effectively destroying the formatting of pre-formatted text (even though pre
elements are treated individually). It seems lists should be treated just like the other block level elements (i.e. parsed recursively). Adding ul
and ol
(and potentially other elements?) to the list of recursively transformed elements seems to solve the problem.
Updated by Georg Ringer over 2 years ago
- Related to Bug #97727: RteHtmlParser crashes with ill-formed HTML added
Updated by Riccardo De Contardi 7 months ago ยท Edited
- Status changed from New to Needs Feedback
Could we have an example of which "formatting" went lost?
I tried the following tests with TYPO3 10.4.37, 11.5.35, 12.4.14, 13.2.0-dev:
Test 1:¶
1) Create a "Text" CE
2) add on it three paragraph of text
<p>One</p> <p>Two</p> <p>Three</p>
3) select the first paragraph and convert it into a formatted text ( pre
tag )
4) select the third paragraph and convert it into a formatted text ( pre
tag )
5) Save it
6) select the first pre
and use the CKEditor button to convert it into an unordered list
7) select the third pre
and use the CKEditor button to convert it into an ordered list
8) Save it
Result¶
The pre
tag has been kept
I even tried with selecting some words inside the pre
texts and add some formatting like Bold, Italic, Underline (I just used the buttons of CKEditor) but the result is the same: everything seems kept
Test 2:¶
1) Create a "Text" CE
2) add on it three paragraph of text
<p>One <strong> some text in bold</strong> and <i> some text in italic</i></p> <p>Two</p> <p>Three <strong> some text in bold</strong> and <i> some text in italic</i></p>
3) select the first paragraph and convert it into an unordered list
4) select the third paragraph and convert it into an ordered list
5) Save it
6) select the first list and use the CKEditor button to convert it into a formatted text ( pre
tag )
7) select the third list and use the CKEditor button to convert it into a formatted text ( pre
tag )
8) Save it
Result¶
The pre
tag has been kept as well as the tags inside
Is a different test necessary?
Updated by Georg Ringer 5 months ago
- Status changed from Needs Feedback to Closed
I am closing the issue as ckeditor code changed a lot since version 10. feel free to reopen a new issue or contact me on slack if still valid on v12/v13