It's not creating tags outside the parent, that's simply how the browser interprets incorrect HTML. The inspector always display the DOM tree created by the browser, not the HTML source. Looks like your redactor field includes a <p>
tag in its value, but you're also wrapping that in a <p>
tag in your template. This results in output like this (which you can check using right click -> View Page Source
in your browser):
<p class="section__description padding-left">
<p>
Lorem Ipsum …
</p>
</p>
But that isn't valid HTML, because a <p>
tag can't contain other <p>
tags. Browsers try to fix broken HTML, so the first paragraph is automatically closed before the second one opens. This is why you see multiple paragraphs in the inspector.
To fix this, you have to options:
- If you want the editors to be able to enter multiple paragraphs in the redactor field, use a
<div>
(or another element that can contain<p>
tags) as the wrapper instead of a<p>
. - If you really only want to allow a single paragraph in the redactor field, you can switch to inline mode
switch to inline mode1. This way, the redactor output won't be wrapped in<p>
tags so you can safely use the<p>
tag in your template. Sidenote, this setting is quite unreliable, you may want to usestriptags
with a whitelist of allowed inline tags to ensure the output doesn't include superfluous<p>
tags.
1 Inline mode is broken, see this issue for details. Instead, set enterKey: false
to prevent editors from adding new paragraphs or breakline: true
to make the enter
key add <br>
tags instead of starting a new paragraph. Remove all block formatting options with the buttons
setting. Then you can use the striptags
filter in the output template to only allow inline tags and remove the <p>
tag if necessary. If this sounds tedious, see my answer here regarding alternative WYSIWYG editors.