#87400CKEditor: assign correct CSS class to tags with entryHTMLparser_db
Description
I would like to assign CSS classes to tags in CKEditor (h1 should have the class .c-rte__h1, h2 should have .c-rte__h2 and so on). This can be done with fixAttrib:class:default: (see snippet below).
The problem occurs when switching between the paragraph style (e.g. from h1 to h2 -> see attached video). Only the tag gets updated, the class will stay the same ().
editor:
config:
stylesSet:
# Inline styles
- { name: 'Normal text', element: 'p', attributes: { 'class': 'c-rte__text' }}
- { name: 'Intro text', element: 'p', attributes: { 'class': 'c-rte__text c-rte__text--intro' }}
- { name: 'Small text', element: 'p', attributes: { 'class': 'c-rte__text c-rte__text--small' }}
format_tags: "p;h1;h2;h3;h4;h5"
processing:
# Set classes for RTE elements
entryHTMLparser_db:
tags:
br:
fixAttrib:
class:
default: c-rte__br
h1:
fixAttrib:
class:
default: u-h1 c-rte__h1
h2:
fixAttrib:
class:
default: u-h2 c-rte__h2
p:
fixAttrib:
class:
default: c-rte__text
…
(An alternative method would be fixAttrib:class:set, but it overrides the classes assigned with stlyesSet.)
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Related issues 2
Files 1
History 3
-
Benni Mack changed Related to #87314 <span data-processor="relativetime" data-value="2022-01-26T08:16:57+00:00" > 01/26/22, 08:16 </span>
-
Benni Mack changed Related to #92943 <span data-processor="relativetime" data-value="2022-01-26T08:22:48+00:00" > 01/26/22, 08:22 </span>
-
Georg Ringer commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-09-29T21:03:25+00:00" > 09/29/26, 21:03 </span>
The editor configuration and the RTE processing are independent.
when changing the format in CKEditor, the existing class attribute is kept, and fixAttrib.class.default only applies if the attribute is missing, as documented. Classes which depend on the tag only should not be stored in the content. Use CSS selectors like .c-rte h2 or add the classes in the frontend with lib.parseFunc_RTE. Closing as this works as designed.