From 97547298502f0c6078cf52466b0ade8a8122b7db Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 20 Jan 2016 09:59:47 +0100 Subject: [PATCH] [!!!][TASK] RTE transformations: Allow div sections by default Treat DIV as block elements by default (= remove "preserveDIVSections"). The info is now stored within "blockElementList". KeepTags "font" and "allowedFontColors" is now treated like any other tag and attribute values. Thus, the TSconfig options within RTE.default.proc - allowedFontColors - preserveDIVSections have no effect anymore. Resolves: #72837 Releases: master Change-Id: I81daf95737058076fbf6bda763a39a7c02f7b732 Reviewed-on: https://review.typo3.org/46103 Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Tested-by: Andreas Fernandez <typo3@scripting-base.de> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> --- .../core/Classes/Html/RteHtmlParser.php | 41 ++++--------------- ...ByDefaultAndRemoveFont-specificParsing.rst | 34 +++++++++++++++ .../Tests/Unit/Html/RteHtmlParserTest.php | 1 - .../PageTSconfig/Proc/pageTSConfig.txt | 3 -- 4 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-72837-RTETransformationsAllowDivSectionsByDefaultAndRemoveFont-specificParsing.rst diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php index 31841d32730d..01d34bbe1578 100644 --- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php +++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php @@ -25,12 +25,13 @@ use TYPO3\CMS\Frontend\Service\TypoLinkCodecService; /** * Class for parsing HTML for the Rich Text Editor. (also called transformations) */ -class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser +class RteHtmlParser extends HtmlParser { /** + * List of elements that are not wrapped into a "p" tag while doing the transformation. * @var string */ - public $blockElementList = 'PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD,HEADER,SECTION,FOOTER,NAV,ARTICLE,ASIDE'; + public $blockElementList = 'DIV,TABLE,BLOCKQUOTE,PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD,HEADER,SECTION,FOOTER,NAV,ARTICLE,ASIDE'; /** * Set this to the pid of the record manipulated by the class. @@ -799,7 +800,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser return $value; } // Split the content from RTE by the occurrence of these blocks: - $blockSplit = $this->splitIntoBlock('TABLE,BLOCKQUOTE,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList, $value); + $blockSplit = $this->splitIntoBlock($this->blockElementList, $value); $cc = 0; $aC = count($blockSplit); // Avoid superfluous linebreaks by transform_db after ending headListTag @@ -902,8 +903,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser public function TS_transform_rte($value) { // Split the content from database by the occurrence of the block elements - $blockElementList = 'TABLE,BLOCKQUOTE,' . ($this->procOptions['preserveDIVSections'] ? 'DIV,' : '') . $this->blockElementList; - $blockSplit = $this->splitIntoBlock($blockElementList, $value); + $blockSplit = $this->splitIntoBlock($this->blockElementList, $value); // Traverse the blocks foreach ($blockSplit as $k => $v) { if ($k % 2) { @@ -931,7 +931,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser $nextFTN = $this->getFirstTagName($blockSplit[$k + 1]); $onlyLineBreaks = (preg_match('/^[ ]*' . LF . '+[ ]*$/', $blockSplit[$k]) == 1); // If the line is followed by a block or is the last line: - if (GeneralUtility::inList($blockElementList, $nextFTN) || !isset($blockSplit[$k + 1])) { + if (GeneralUtility::inList($this->blockElementList, $nextFTN) || !isset($blockSplit[$k + 1])) { // If the line contains more than just linebreaks, reduce the number of trailing linebreaks by 1 if (!$onlyLineBreaks) { $blockSplit[$k] = preg_replace('/(' . LF . '*)' . LF . '[ ]*$/', '$1', $blockSplit[$k]); @@ -1046,42 +1046,17 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser } // Setting up span tags if they are allowed: if (isset($keepTags['span'])) { - $classes = array_merge(array(''), $this->allowedClasses); $keepTags['span'] = array( 'allowedAttribs' => 'id,class,style,title,lang,xml:lang,dir,itemscope,itemtype,itemprop', 'fixAttrib' => array( 'class' => array( - 'list' => $classes, 'removeIfFalse' => 1 ) ), 'rmTagIfNoAttrib' => 1 ); - if (!$this->procOptions['allowedClasses']) { - unset($keepTags['span']['fixAttrib']['class']['list']); - } - } - // Setting up font tags if they are allowed: - if (isset($keepTags['font'])) { - $colors = array_merge(array(''), GeneralUtility::trimExplode(',', $this->procOptions['allowedFontColors'], true)); - $keepTags['font'] = array( - 'allowedAttribs' => 'face,color,size', - 'fixAttrib' => array( - 'face' => array( - 'removeIfFalse' => 1 - ), - 'color' => array( - 'removeIfFalse' => 1, - 'list' => $colors - ), - 'size' => array( - 'removeIfFalse' => 1 - ) - ), - 'rmTagIfNoAttrib' => 1 - ); - if (!$this->procOptions['allowedFontColors']) { - unset($keepTags['font']['fixAttrib']['color']['list']); + if (!empty($this->allowedClasses)) { + $keepTags['span']['fixAttrib']['class']['list'] = $this->allowedClasses; } } // Setting further options, getting them from the processiong options: diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-72837-RTETransformationsAllowDivSectionsByDefaultAndRemoveFont-specificParsing.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72837-RTETransformationsAllowDivSectionsByDefaultAndRemoveFont-specificParsing.rst new file mode 100644 index 000000000000..d939cd03f544 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-72837-RTETransformationsAllowDivSectionsByDefaultAndRemoveFont-specificParsing.rst @@ -0,0 +1,34 @@ +====================================================================================================== +Breaking: #72837 - RTE transformations: Allow div sections by default and remove font-specific parsing +====================================================================================================== + +Description +=========== + +The TSconfig ``RTE.default.proc`` options ``preserveDIVSections`` and ``allowedFontColors`` for transforming data between the Rich +Text Editor and the database were removed. + +The ``preserveDIVSections`` option is now built-in by default "always on", and DIV tags are always treated as block elements. + +Special handling for ``<font>`` tags is done via the regular tag processing options like any other tag. + + +Impact +====== + +Setting the TSconfig option ``RTE.default.proc.preserveDIVSections = 0`` or ``RTE.default.proc.allowedFontColors`` will have no effect anymore. + + +Affected Installations +====================== + +Any installation using custom TSconfig configurations for the RTE and using ``RTE.default.proc.preserveDIVSections`` set to 0 or ``RTE.default.proc.allowedFontColors`` to any value. + + +Migration +========= + +If DIV HTML elements should not treated like block elements, the RTE option ``RTE.proc.blockElementList`` can be manually +customized to not include DIV elements. + +If the option ``allowedFontColors`` is still needed, the existing functionality can be achieved by using the ``keepTags`` functionality to sort out correct values for a property. \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php b/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php index 778214332774..d018fee4e1ae 100644 --- a/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php +++ b/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php @@ -29,7 +29,6 @@ class RteHtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $this->subject = new \TYPO3\CMS\Core\Html\RteHtmlParser(); $this->subject->procOptions = array( 'dontConvBRtoParagraph' => '1', - 'preserveDIVSections' => '1', 'allowTagsOutside' => 'hr, address', 'disableUnifyLineBreaks' => '0', 'overruleMode' => 'ts_css' diff --git a/typo3/sysext/rtehtmlarea/Configuration/PageTSconfig/Proc/pageTSConfig.txt b/typo3/sysext/rtehtmlarea/Configuration/PageTSconfig/Proc/pageTSConfig.txt index a16fec00e10f..2ee5bde67e36 100644 --- a/typo3/sysext/rtehtmlarea/Configuration/PageTSconfig/Proc/pageTSConfig.txt +++ b/typo3/sysext/rtehtmlarea/Configuration/PageTSconfig/Proc/pageTSConfig.txt @@ -19,9 +19,6 @@ RTE.default.proc { ## br tags in the content are assumed to be intentional. dontConvBRtoParagraph = 1 - ## PRESERVE DIV SECTIONS - DO NOT REMAP TO P - preserveDIVSections = 1 - ## TAGS ALLOWED OUTSIDE P & DIV allowTagsOutside = address, article, aside, blockquote, footer, header, hr, nav, section -- GitLab