how to stop Jodit from wrapping elements in <p> when inserting HTML

301 views Asked by At

How to reproduce:

  1. in javascript console, set html to asdf. My code is something like: editor.setEditorValue('asdf')
  2. toggle into source mode
  3. I see <p>asdf</p>. I expect to see only asdf.

Attempted solutions

  1. Configure enter: 'br'

This does actually work, solves the problem. But introduces a new problem, which is I want the HTML to be <p></p> when the user creates a new paragraph.

  1. Configure enter: 'br' with enterBlock: 'p'

doesn't change anything from #1.

1

There are 1 answers

0
Friendly Genius On

I think I solved it. Maybe someone can help me verify.

I initialized editor with enter: 'br'. This prevents the editor from adding 'p' to every non-p wrapped element.

Then when I set the HTML of the editor, I make sure to edit the options editor.options.enter = 'p' so that new blocks are paragraphs.

Weirdly, when I set the HTML again (even with enter = 'p'), Jodit respects the HTML and doesn't add extra paragraph tags to elements without a wrapper