Issue Bug Closed

#102356Add example for configuring headings with classes into the docs

Chris Müller 11/09/23, 10:32 updated 12/02/25, 14:37

Description

Given the following RTE configuration:

editor:
  config:
    heading:
      options:
        - { model: 'paragraph', title: 'Paragraph' }
        - { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'h2' }
        - { model: 'heading3', view: 'h3', title: 'Heading 3', class: 'h3' }
        - { model: 'heading4', view: 'h4', title: 'Heading 4', class: 'h4' }

I would expect that when selecting a heading (e.g. “heading2”) the defined class (e.g. “h2”) is attached to the HTML alement. But this is not the case (neither in RTE directly nor in frontend).

According to the CKeditor documentation this should be done like in the example above:
https://ckeditor.com/docs/ckeditor5/latest/features/headings.html#configuring-toolbar-buttons

Reviews 3

History 912

  1. Sébastien Delcroix commented <span data-processor="relativetime" data-value="2024-10-08T22:17:23+00:00" > 10/08/24, 22:17 </span>

    The value of the option class defined for a heading is only added to the headings dropdown menu of the editor, according to the documentation : https://ckeditor.com/docs/ckeditor5/latest/api/module_heading_headingconfig-HeadingConfig.html#member-options

    If you want to add a class to your headings for frontend rendering, you need to add it to the view.classes option, as explained here : https://ckeditor.com/docs/ckeditor5/latest/features/headings.html#configuring-custom-heading-elements

    For instance :

    heading:
          options:
            - { model: 'heading2', view: { name: 'h2', classes: 'h2' }, title: 'Heading 2' }
            - { model: 'heading3', view: { name: 'h3', classes: 'h3' }, title: 'Heading 3' }

    Tested and approved on 12.4.21. Issue can be closed ;)

  2. Chris Müller changed subject Classes defined for headings are not considered Add example for configuring headings with classes into the docs <span data-processor="relativetime" data-value="2024-11-19T11:24:34+00:00" > 11/19/24, 11:24 </span>

  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2024-11-19T13:32:58+00:00" > 11/19/24, 13:32 </span>

    @krueml That sounds like a good idea, would you like to create a patch?

  4. Gerrit Code Review pushed patch set 1 for main to change 87241 status Accepted Under Review <span data-processor="relativetime" data-value="2024-11-26T18:40:15+00:00" > 11/26/24, 18:40 </span>

  5. Chris Müller commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2024-11-27T17:45:10+00:00" > 11/27/24, 17:45 </span>

    Applied in changeset commit:41fc2bcb0f1c9d1642ebe7fe924be33b041908be.