Issue Bug Closed

#87400CKEditor: assign correct CSS class to tags with entryHTMLparser_db

Benedikt Imminger 01/11/19, 11:07 updated 09/29/26, 21:03

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.

Files 1

History 3

  1. Georg Ringer commented and changed status New Closed <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.