summernote: Pressing enter creates duplicate
tag
Pressing enter after any text in the editor creates duplicate <p>
tags.
The reason this is a problem for me is that I’m assigning an id to each <p>
tag as an anchor for same page navigation. Is there anyway to have summernote just create a blank <p>
tag rather then create a duplicate?
Thanks!
steps to reproduce
- Enter any text in Summernote Editor and press Enter
- Click on Code View and add an id to the
<p>
tag element - Close Code View and Press Enter after the text
- Enter new text
- Check code view and you will see that it duplicated the tag with the id.
browser version and os version and summernote version
What is your browser and OS?
Google Chrome 68.0.3440.106 Windows 10 Professional
What is your summernote version? 0.8.10, This happens on the summernote site examples as well.
screenshot of issue
Add screenshot which shows your issue(if needed). You can make gif from Recordit.
Recorded issue: http://recordit.co/hMBuVdPQrp
If you can make the issue using jsfiddle(https://jsfiddle.net/), We can save time to reproduce the problem.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 19 (6 by maintainers)
It’s not that it won’t be fixed, no one has come up with a solution as yet, or hasn’t had time to sit down and pull the function apart and nut out a solution, even though this has been an ongoing problem. We are open to PR’s to fix this, and other issues of course, if anyone has a solution. I, myself, have a lot of Farm stuff to be working on, and other projects that are more urgent at this time, if I get some time I’ll certainly look into this some more.
Forgive me if this is not the way to do things, however just to give someone a bit of a heads up, so this can be fixed eventually. It seems that after some digging it’s related to the “insertParagraph” function in /src/js/base/editing/Typing.js. This line (88 currently)
nextPara = dom.splitTree(splitRoot, rng.getStartPoint());
Seems to copy the current paragraph (since it’s usually wrapped in an
<p>
tag) including any child tags and strips all the body, and adds it within a new<p>
tag. That seems to cause a lot of issues for everyone, because id tags and everything is copied as well. Possibly stripping everything but style and class should help. I’m too unfamiliar with the code to add a PR, but maybe this helps someone.Honestly, I would have thought this would have been fixed by now.
From what I can tell the editor is checking to see what the previous tag is, and copies it and it’s content rather than just checking what it is and placing the tag and copying the same attributes except for
id
as they need to be unique per element would be a better idea. I think we should also have an options switch, as there are times where textual content doesn’t need to be placed inside elements. I’m also of the mind, that as a lot of people use Summernote for email creation, that we need an option that allows the use of the type of markup that email uses, between HTML5 that browsers use.