Copied to clipboard

Flag this post as spam?

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


  • Bobi 346 posts 950 karma points
    Apr 15, 2017 @ 21:45
    Bobi
    1

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

    Hi,

    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 2054 posts 7100 karma points c-trib
    Apr 16, 2017 @ 03:32
    Nicholas Westby
    1

    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 554 posts 2118 karma points
    Apr 16, 2017 @ 04:27
    Yakov Lebski
    1

    Maybe removeParagraphTags can solve this issue

      @Umbraco.Field("pageText",removeParagraphTags:true)
    

    or

      @Umbraco.StripHtml("<html>","p")
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Apr 18, 2017 @ 15:55
    Alex Skrypnyk
    2

    Hi Guys

    What about RemoveFirstParagraphTag method? Did you try it?

    @umbraco.library.RemoveFirstParagraphTag(Umbraco.Field("richText2"))
    

    Thanks,

    Alex

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

    Alex, where would we add this?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 13, 2018 @ 08:55
    Alex Skrypnyk
    0

    Hi Blackhawk

    In place where do you want to render content from RTE

    /Alex

  • Bobi 346 posts 950 karma points
    Apr 21, 2017 @ 16:48
    Bobi
    0

    Thanks everyone, I will check the methods out.

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

    tags surrounding it.

  • Nigel Wilson 944 posts 2076 karma points
    Feb 12, 2018 @ 20:50
    Nigel Wilson
    0

    Hey all

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

    https://our.umbraco.org/forum/using/ui-questions/17096-Remove-empty-paragraph-tags-in-tinymce

    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.

    Cheers

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft