Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Bobi 211 posts 583 karma points
    Apr 15, 2017 @ 21:45

    How to prevent <p> tags from being created automatically in richText editor


    I've been noticing that when you add content to a richText editor,

    tags are automatically created. Is there a way to prevent this?

    I ask because I've nested the umbraco content fields within their correctly styled

    tags in the code already, so that only content is added in the content editor, and users do not have to worry about correctly styling the content they add to the richText editor.

    For example, I pre-styled the umbraco content fields below:

    <h4 class="myClass">@Umbraco.Field("textString2")</h4> <p class="myClass">@Umbraco.Field("richText2")</p>

    Any suggestions? Also, any advice regarding best practice for this topic? I imagine it will be quicker to remove the

    tags in the richText editors, than to remove them from every page of code (which will be quite tedious and take a very long time). Also, I imagine that best practice would be to prevent users from having to worry about styling paragraphs, etc., since that should already be done in the html5 code.

    I've noticed that my code contains double

    tags for every umbraco field added.

  • Nicholas Westby 1725 posts 5649 karma points c-trib
    Apr 16, 2017 @ 03:32
    Nicholas Westby

    I ran into this problem on a recent project too. I opted to simply remove the paragraph tags. I also created a regex to validate the input so users are unable to enter more than one paragraph, and I added descriptions to those properties instructing users to enter only a single line of text.

    Another option, probably much more involved, would be to create a custom property editor that uses a plugin (maybe not tinyMce) that has an option to allow for text to be entered without a surrounding paragraph.

    If somebody has other approaches, I'd also be curious to hear them.

  • Yakov Lebski 155 posts 682 karma points
    Apr 16, 2017 @ 04:27
    Yakov Lebski

    Maybe removeParagraphTags can solve this issue



  • Alex Skrypnyk 4637 posts 16596 karma points MVP 2x admin
    Apr 18, 2017 @ 15:55
    Alex Skrypnyk

    Hi Guys

    What about RemoveFirstParagraphTag method? Did you try it?




  • blackhawk 313 posts 1364 karma points
    Feb 12, 2018 @ 19:14

    Alex, where would we add this?

  • Alex Skrypnyk 4637 posts 16596 karma points MVP 2x admin
    Feb 13, 2018 @ 08:55
    Alex Skrypnyk

    Hi Blackhawk

    In place where do you want to render content from RTE


  • Bobi 211 posts 583 karma points
    Apr 21, 2017 @ 16:48

    Thanks everyone, I will check the methods out.

    To get around it quickly, I just inserted the fields without

    tags surrounding it.

  • Nigel Wilson 851 posts 1822 karma points
    Feb 12, 2018 @ 20:50
    Nigel Wilson

    Hey all

    From the "dark ages" is this post...

    Near the end of the tinyMceConfig.config file you can amend the validElements and change "#p" to "-p" which from memory did help prevent empty paragraphs being added by default.

    Not sure it totally answers / solves the issue, but thought I'd mention it.



Please Sign in or register to post replies

Write your reply to: