Copy text from a heavily formatted MS Word document into a CKEditor field, and most of the tags and attributes are removed upon saving the content element. This is what I want, but some attributes still remain.
One example from a MS Word document containing a table with background colors, customized padding etc. leads to this in TYPO3:
<td style="background-color:yellow;border-bottom:1.0pt solid windowtext;border-left-style:none;border-right:1.0pt solid windowtext;border-top-style:none;height:31.2pt;padding:0cm;width:73.65pt;">
I want the whole style attribute (maybe keep the width) gone in TYPO3, but my config seems to be ignored:
editor:
config:
htmlSupport:
allow:
- { name: 'p', attributes: false, classes: false, styles: false }
- { name: 'span', attributes: ['title','lang', 'dir'], classes: false, styles: false }
- { name: 'abbr', attributes: ['title'], classes: false, styles: false }
- { name: 'table', attributes: false, classes: true, styles: false }
- { name: 'th', attributes: ['scope'], classes: true, styles: { 'width': true } }
- { name: 'td', attributes: ['width'], classes: true, styles: { 'width': true } }
Style attributes are removed from <p>
tags, but not from <td>
. The "remove format" button doesn't remove the styles, either. Neither does this:
...
- { name: 'td', attributes: ['width'], classes: true, styles: false }
Any idea how to do this in TYPO3 12? Maybe with additional TypoScript?
You can achieve this in your custom RTE yaml configuration.
Take this as an example:
processing:
entryHTMLparser_db:
tags:
table:
allowedAttribs: "none"
tbody:
allowedAttribs: "none"
tr:
allowedAttribs: "none"
td:
allowedAttribs: "none"
keepNonMatchedTags: true
The parser allows you to strip certain attributes from tags. See the official documentation: https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Functions/Htmlparser.html#htmlparser
After saving the record, the styles are removed before they are written in the database.