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:
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 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.
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.
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.
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.
Maybe removeParagraphTags can solve this issue
or
Hi Guys
What about RemoveFirstParagraphTag method? Did you try it?
Thanks,
Alex
Alex, where would we add this?
Hi Blackhawk
In place where do you want to render content from RTE
/Alex
Thanks everyone, I will check the methods out.
To get around it quickly, I just inserted the fields without
tags surrounding it.
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
is working on a reply...