Why does lightning-input-rich-text add a paragraph tag automatically to the text?

I am using a LWC lightning-input-rich-text that is populated from a custom field value when my LWC loads. This component is used to Send an email where body of email will be the text( value ) in this input rich text. When I send the email I get additional paragraph for each line break present in the text. Could not find this behavior anywhere in documentation, this one says that <p> tag is added for text enclosed in <div> or <p> tags , but my rich text does not have any of this, and this behavior is observed wherever there is a line break.

Is this a bug? Is there any workaround for this? I tried replacing all <p> and </p> tags with blanks but this will also remove the required

tags that were explicitly added in rich text originally.

Resulting Email:

enter image description here

Answers 1

  • As per case resolution from Salesforce, this is expected behaviour. Here is the gist of SF explanation:

    The WYSIWYG nature of how our rich text editor displays content only applies to the Lightning Experience. If the output of our rich text editors is viewed in non-Lightning contexts (such as in an e-mail), there will be visual inconsistencies. We have created a user story to update the rich text edit doc with the above content, soon the doc will also be updated with this content.

    So the most feasible workaround at this point of time is replacing <p><br></p> with blank.

    Ex : body.replaceAll('<p><br></p>',''); //'body' is the value in input rich text

Related Questions