Add an option to completely remove <p> tags

Created on 15 March 2023, over 1 year ago
Updated 8 July 2024, 5 months ago

Problem/Motivation

I'm using a text field with Ckeditor5 to edit custom title fields. The content editor needs to add bold and italic tags, but not the heading level. I've created an input format with Ckeditor5 and only <strong> and <em> tags. On the field template I've hardcoded the desider heading level but the field value is always with enclosing <p>.

Proposed resolution

I've found this module and I've added an option to remove al <p> tags (and put <br/> when needed). I've created a small patch. Let me know if it could be added on the module.

Thank you.

✨ Feature request
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

🇮🇹Italy finex

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @finex
  • Status changed to Closed: works as designed over 1 year ago
  • 🇵🇱Poland Krzysztof DomaÅ„ski Poland

    For semantic reasons, deleting paragraphs is not recommended. A semantic element clearly describes its meaning to the browser.

    If you need to get rid of <p> tags add them to core filter Limit allowed HTML tag and correct faulty HTML.

  • Status changed to Closed: won't fix over 1 year ago
  • 🇬🇧United Kingdom iancawthorne

    If you need to get rid of

    tags add them to core filter Limit allowed HTML tag and correct faulty HTML.

    It is not possible to remove

    tags from the core filter Limit allowed HTML tags and correct faulty HTML in ckeditor 5.

    I have the same use case as the opening post where there is a heading that requires formatting with bold or italic, but the text format should not allow heading or paragraph tags. It looks like this patch does exactly as required.

    I would add a +1 for this ticket being re opened.

  • 🇦🇺Australia sime Melbourne

    It's not possible to limit <p> tags as that field is controlled now. This is my toolbar which has no reference to block level elements.

    [Bold][Italic][Link]
    

    This is the forced allowed tags for the above configuration.

    <br> <p> <strong> <em> <a href data-entity-type data-entity-uuid data-entity-substitution>
    
  • Status changed to Active over 1 year ago
  • 🇦🇺Australia sime Melbourne

    It's also kinda of a pain for local dev and this doesn't work with twig debug on.

      {{ content.field_html|render|replace({'<p>': '','</p>': ''})|raw }}
    
  • 🇦🇺Australia sime Melbourne

    This is probably easiest solution based on contrib (no D10 release at this point)
    https://www.drupal.org/project/customfilter →

  • 🇮🇹Italy finex

    I still think my initial patch it's the way. Just add a better description like "This option will not enclose the text with a

    element, please make sure that the template will enclose the content using an appropriate tag." :-)

  • Status changed to Closed: won't fix over 1 year ago
  • 🇦🇺Australia sime Melbourne

    I was confused and thought this was an issue in Drupal core, sorry about that - i wouldn't have reopened. For the record also has upstream attention.

    https://github.com/ckeditor/ckeditor5/issues/1537#issuecomment-1627542561

  • 🇮🇹Italy finex

    Thanks for suggesting the Custom Filter module (now it's also available on D10) but I still prefer this lightweight module. Even if it's a "won't fix" I've updated the patch :-)

Production build 0.71.5 2024