Skip to content

Commit

Permalink
[BUGFIX] Allow <figure> tag outside of paragraph tags
Browse files Browse the repository at this point in the history
<figure> is allowed in HTML5 outside of paragraphs,
thus it should also be configured like that out-of-the-box

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure

Since CKEditor5 is using <figure> around tables, and also
might add a <figcaption> both variants are now enabled by default.

Resolves: #99273
Releases: main, 11.5, 10.4
Change-Id: I9356cc13ccef764f475ba42cc47f43f7ecd624a1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76923
Tested-by: Frank Nägler <frank.naegler@typo3.com>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Frank Nägler <frank.naegler@typo3.com>
  • Loading branch information
bmack committed Dec 5, 2022
1 parent aa3ee0e commit 9f87b5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions typo3/sysext/core/Classes/Html/RteHtmlParser.php
Expand Up @@ -42,13 +42,13 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
* List of elements that are not wrapped into a "p" tag while doing the transformation.
* @var string
*/
protected $blockElementList = 'DIV,TABLE,BLOCKQUOTE,PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD,HEADER,SECTION,FOOTER,NAV,ARTICLE,ASIDE';
protected $blockElementList = 'DIV,TABLE,BLOCKQUOTE,PRE,UL,OL,H1,H2,H3,H4,H5,H6,ADDRESS,DL,DD,HEADER,SECTION,FOOTER,NAV,ARTICLE,ASIDE,FIGURE';

/**
* List of all tags that are allowed by default
* @var string
*/
protected $defaultAllowedTagsList = 'b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span,abbr,acronym,dfn';
protected $defaultAllowedTagsList = 'b,i,u,a,img,br,div,center,pre,figure,figcaption,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span,abbr,acronym,dfn';

/**
* Set to the TSconfig options coming from Page TSconfig
Expand Down Expand Up @@ -111,6 +111,8 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
'blockquote',
'div',
'footer',
'figure',
'figcaption',
'header',
'hr',
'nav',
Expand Down
13 changes: 12 additions & 1 deletion typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
Expand Up @@ -25,7 +25,7 @@ class RteHtmlParserTest extends UnitTestCase
{
protected bool $resetSingletonInstances = true;

protected array $procOptions = ['overruleMode' => 'default', 'allowTagsOutside' => 'hr,abbr'];
protected array $procOptions = ['overruleMode' => 'default', 'allowTagsOutside' => 'hr,abbr,figure'];

/**
* Data provider for hrTagCorrectlyTransformedOnWayToDataBase
Expand Down Expand Up @@ -743,4 +743,15 @@ public function allowTagsOutsidePreventsWrappingTaginPTag(): void
self::assertEquals('<abbr>Allowed outside of p-tag</abbr>', $subject->transformTextForRichTextEditor('<abbr>Allowed outside of p-tag</abbr>', $this->procOptions));
self::assertEquals('<p><span>Not allowed outside of p-tag</span></p>', $subject->transformTextForRichTextEditor('<span>Not allowed outside of p-tag</span>', $this->procOptions));
}

/**
* @test
*/
public function tableAndFigureApplyCorrectlyOutsideOfParagraphTags(): void
{
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$subject = new RteHtmlParser($eventDispatcher);
self::assertEquals('<figure class="table">' . CRLF . '<table>Allowed outside of p-tag</table>' . CRLF . '</figure>', $subject->transformTextForRichTextEditor('<figure class="table">' . CRLF . '<table>Allowed outside of p-tag</table>' . CRLF . '</figure>', $this->procOptions));
self::assertEquals('<figure class="table">' . CRLF . '<table>Allowed outside of p-tag</table>' . CRLF . '<figcaption>My Logo</figcaption></figure>', $subject->transformTextForRichTextEditor('<figure class="table">' . CRLF . '<table>Allowed outside of p-tag</table>' . CRLF . '<figcaption>My Logo</figcaption></figure>', $this->procOptions));
}
}
3 changes: 2 additions & 1 deletion typo3/sysext/rte_ckeditor/Configuration/RTE/Processing.yaml
Expand Up @@ -27,6 +27,7 @@ processing:
- dt
- em
- figure
- figcaption
- footer
- header
- h1
Expand Down Expand Up @@ -66,7 +67,7 @@ processing:
- var

## Tags that are allowed outside of paragraphs
allowTagsOutside: [address, article, aside, blockquote, figure, footer, header, hr, nav, section, div]
allowTagsOutside: [address, article, aside, blockquote, figure, figcaption, footer, header, hr, nav, section, div]

## allowed default attributes
allowAttributes: [class, id, title, dir, lang, xml:lang, itemscope, itemtype, itemprop]
Expand Down

0 comments on commit 9f87b5e

Please sign in to comment.