Project

General

Profile

Actions

Bug #93302

open

Pre-formatted text in RTE gets re-formatted when inside an ordered / unordered list

Added by Joschi Kuphal over 3 years ago. Updated about 2 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
RTE (rtehtmlarea + ckeditor)
Target version:
Start date:
2021-01-17
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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.


Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #97727: RteHtmlParser crashes with ill-formed HTMLNeeds Feedback2022-06-02

Actions
Actions #1

Updated by Georg Ringer about 2 years ago

  • Related to Bug #97727: RteHtmlParser crashes with ill-formed HTML added
Actions #2

Updated by Riccardo De Contardi about 2 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?

Actions

Also available in: Atom PDF