Bug #104520
openRteHtmlParser does not allow custom attribute configuration for <span> tags as children of a <p> tag
100%
Description
We were wondering, why it is impossible to add custom attributes to <span> tags. It turns out, that the "allowedAttribs" definition is hard-coded only for <span> tags in RteHtmlParser.php! This issue was reported already 9 years ago but closed.
Wouldn't it makes much more sense to apply the YAML configuration processing.allowAttributes of Processing.yaml here as well, so we are able to customize it, like for any other tags?
Use-Case:
In CKEditor we want to add an editor-plugin for ToolTips which can be placed on whole headlines, paragraphs, but also on single words:
<h1>Hello <span data-tooltip-content="This works!" data-tooltip-position="auto">world</span></h1>
<p data-tooltip-content="This works!" data-tooltip-position="top">Hello world</p>
<p>Hello <span data-tooltip-content="Why is this not working?">world</span></p>
If we append these data-attributes to processing.allowAttributes, it works perfectly well for the <h1> and the <p> tag. But everything is stripped away from the <span> if <p> is the parent tag ! The header has a <span> as child to mark only one word, and here its working. So this should work on <p> as well, but it isn't.
Is there a reason for it or is this just a left-over behavior of old times? Our current (ugly) workaround is the usage of a composer-patch.
Background:
The JavaScript to init the tooltip uses the data-attribute like tooltip('[data-tooltip-content]', {}); with some default options, which can be overwritten by the data-attribute (see e.g. "data-tooltip-position" in the above example)
Updated by Garvin Hicking 4 months ago
- Category set to RTE (rtehtmlarea + ckeditor)
- Status changed from New to Needs Feedback
Would you maybe like to share the patch as a gerrit patch to allow the community to vote on the implementation?
Note though this will very likely nit be included to v11, but might get into v12, and could definitely get into v13.
Personally I assume this is more an oversight and not a conscious decission to prevent in span tags.
Updated by Garvin Hicking 4 months ago
- Related to Bug #66401: span.allowedAttribs not taken into account added
Updated by Bastian Stargazer 4 months ago · Edited
Garvin Hicking wrote in #note-1:
Would you maybe like to share the patch as a gerrit patch to allow the community to vote on the implementation?
I've never wrote a Gerrit patch, but I could try. As solution, I would just change this one line to minimize possible side-effects, but that should be OK right? At least I tested it and it works like expected:
$keepTags['span'] = [
- 'allowedAttribs' => 'id,class,style,title,lang,xml:lang,dir,itemscope,itemtype,itemprop',
+ 'allowedAttribs' => implode(',', array_unique($this->procOptions['allowAttributes.'] ?? [])),
'fixAttrib' => [
'class' => [
'removeIfFalse' => 1,
],
],
'rmTagIfNoAttrib' => 1,
];
Updated by Gerrit Code Review 4 months ago
- Status changed from Needs Feedback to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85498
Updated by Gerrit Code Review 3 months ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85498
Updated by Gerrit Code Review 3 months ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85498
Updated by Gerrit Code Review 3 months ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85498
Updated by Gerrit Code Review 3 months ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85498
Updated by Garvin Hicking 3 months ago
BTW, note the following syntax should be able to do the trick even before the patch:
YAML:
processing: HTMLparser_db: tags: span: rmTagIfNoAttrib: 0 allowedAttribs: 'class,data-tooltip-content'
TSconfig:
RTE.default.proc.HTMLparser_db.tags.span { rmTagIfNoAttrib = 0 allowedAttribs = class,data-tooltip-content }
Aligning the default attributes for p and span though makes sense. :)
Updated by Gerrit Code Review 3 months ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/85462
Updated by Bastian Stargazer 3 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset cb5f8bb4f513c74dccfb7490bbd50f865ca50e04.
Updated by Garvin Hicking 3 months ago
- Related to Bug #104622: ckeditor font-size is removed after saving in V 12.4.18 added
Updated by Oliver Hader 3 months ago
- Status changed from Resolved to New
The previous patches have been reverted for TYPO3 v12 (v12.4.18 → v12.4.19) and v13 (during v13.3-dev)
→ see reverts https://review.typo3.org/q/Ib63cc4733944ad98830ee269baf13f1b15076ef5