Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pasteHTML auto add unused <p><br></p> #3370

Closed
wzhonggo opened this issue Aug 21, 2019 · 33 comments
Closed

pasteHTML auto add unused <p><br></p> #3370

wzhonggo opened this issue Aug 21, 2019 · 33 comments

Comments

@wzhonggo
Copy link

Before submitting an issue, please make sure to search for already open issues, and add to that. This way we can track issues more easily. Thank you, and Thanks for using Summernote.

Description of your Issue or Request:

I want to paste html , but it add many <p><br></p>.

steps to reproduce (Add more if necessary):

  1. go to https://summernote.org/

  2. in chrome console exec $('#summernote').summernote('pasteHTML', '<p>1</p>');

  3. in code view <p><br></p><p>1</p><p><br></p> , why has <p><br></p>. Is it has solution not add <p><br></p> when call pasteHTML method

What is your Operating System, Browser and Version and Summernote Version you are using:

This can help find and resolve any issues.

  1. Operating System: Windows 10

  2. Browser and Version: Chrome 76.0.3809.100

  3. Summernote Version: 0.8.12

  4. Bootstrap Version or Lite: bootstrap3

screenshot of issue

Add screenshot which shows your issue(if needed).
image

You can make gif from Recordit.

If you can make the issue using jsfiddle(https://jsfiddle.net/), We can save time to reproduce the problem.

@DiemenDesign
Copy link
Member

DiemenDesign commented Sep 19, 2019

Ok, firstly, what you are referring to as "Chrome Console", is not a Console where you can execute commands, it is a source code editor. When you paste things like you are doing, the Summernote API tries to sanitize the input and uses it's best guess, what you are seeing is that guess.

@seltix5
Copy link

seltix5 commented Nov 11, 2019

i'm having the same problem.
example here : https://codepen.io/seltix/pen/qBByJKo

@easylogic
Copy link
Member

#3495

@Budsy
Copy link

Budsy commented Nov 28, 2019

This is an annoying behavior. If I load in HTML content, then simply save it, it wraps the content in <p><br></p> tags. Repeating loading using htmlPaste and saving with no actions using the editor keeps adding additional tags at the beginning and ending, creating a bigger and bigger file, and basically corrupted content. Has this been addressed? (Using Edge browser and latest build from today). I checked with Chrome and it does the same thing.

@DiemenDesign
Copy link
Member

Latest build available? or you built the project and used the resulting files from the dist/ folder?

@seltix5
Copy link

seltix5 commented Nov 28, 2019

In my exam le it was with last build available provided by you in another issue.

@Budsy
Copy link

Budsy commented Nov 29, 2019

This was the Bootstrap version that I took from the dist/ folder in the archive.

@Budsy
Copy link

Budsy commented Nov 30, 2019

The workaround for this is to avoid using pasteHTML for loading content. So, when I want to load new content from the server, I first reset and destroy the existing summernote object. Then load the div with the content, then reinitialize a new summernote editor object. This technique works well to leave the content untouched upon loading.

@venomoustoad
Copy link

@Budsy Could you elaborate in code what you did?

@venomoustoad
Copy link

Alright, just implemented the workaround based on Budsy's comment using jquery to insert myHTML (a html string). pasteHTML remains broken. Replaces existing summernote with new replica summernote.

<div  id = "summernote_container">
        <div id="summernote" class="summernote">
            <span></span>
        </div>
</div>
<script>
$('#summernote_container').html('<div id="summernote" class="summernote"><span>'+myHTML+'</span></div>');
</script>

@Budsy
Copy link

Budsy commented Dec 7, 2019

I do my content loading with jQuery ajax. Basically, the workaround is to avoid pasteHtml and simply instantiate a new summernote object and load html into the summernote object's content div:

                             $.ajax({
				type: "GET",
				dataType: "html",
				data: { "filePath": fPath }, // fPath tells the handler what content file to fetch.
				url: "/PathToGetHandlerToSendFileContentsAsHtml",
				cache: false,
				success: function (result) {
					$('.summernote').summernote('reset');  // may not be required.
					$('.summernote').summernote('destroy');
					$('.summernote').html(result);
					$('.summernote').summernote();
				},
				error: function (jqXHR, textStatus, errorThrown) {
					alert('There was an error loading the contents file.' + errorThrown);
				}
			});

@sigurdne
Copy link

pasteHTML works if you set the isNotSplitEdgePoint in the function splitPoint()

//         isNotSplitEdgePoint: isInline
           isNotSplitEdgePoint : true

But I don't know what else it will break...

@easylogic
Copy link
Member

v0.8.14 is released. please use it.

@sigurdne
Copy link

This one is still a problem in v0.8.14

The isNotSplitEdgePoint : true fixed it for my use

@kotmatpockuh
Copy link

Still reproducible.

@DiemenDesign DiemenDesign reopened this Mar 29, 2020
@DiemenDesign
Copy link
Member

DiemenDesign commented Mar 29, 2020

@easylogic This is still an ongoing issue, I just tried with a curent built from source, and with isNotSplitEdgePoint:true,, the editor when pasting HTML using $("#summernote").summernote('pasteHTML',data); is still adding unwanted <p><br></p> elements to the start and end of every paragraph, which creates an unwanted space before and after each paragraph. I've been looking through the source, and have yet to find a way to stop this being added without breaking things and getting errors.

@dreammonkey
Copy link

same here, using 0.8.16

@dlynam
Copy link

dlynam commented May 12, 2020

Same issue for me in 0.8.16 as well. Also tried downgrading to 0.8.14 and using isNotSplitEdgePoint : true but it puts the first node last when pasting.

@davidwaf
Copy link

davidwaf commented Jun 7, 2020

Am using 0.8.18 an experiencing same issue.

@Sitheps
Copy link

Sitheps commented Jul 9, 2020

v. 0.8.18 Has any progress been made as to a solution for this very problematic bug?

@daveapsgithub
Copy link

Out of about 6 HTML Editors, I choose to evaluate summernote first. I slammed straight into this bug. I tried several workarounds. This is the sort of problem that you would expect to see in an alpha release; not something that appears somewhat mature. So I jumped over to https://quilljs.com/ and go it working and integrated in no time at all.

@gensablin
Copy link

gensablin commented Sep 12, 2020

Hi, I played around with this <p><br></p> thing and looks like found the solution.
I used summernote-lite and at line 2129 removed emptyPara: "<p>".concat(blankHTML, "</p>"),
And in summernote-lite.min removed emptyPara:"<p>".concat(j,"</p>"),
So editor stopped adding this paragraph.

@DiemenDesign
Copy link
Member

A PR would be most welcome.

@gensablin
Copy link

A PR would be most welcome.

It seems that this topic has been of interest to some people for a long time. Can I post this somewhere so it's easy to find? Please tell me where it is better to do it.

@DiemenDesign
Copy link
Member

I am going to assume you don't have git installed or know how to use it. If you want to post here the functions that you changed I can make the changes, test, and do the PR.

However, if you do know how to clone the repo, make the changes to the file in src/, and do a PR, I'd be more than happy to test the changes and approve the changes as long as the changes don't break other things. If you plan on doing the PR, I urge you to build locally and test as well before doing the PR.

@gensablin
Copy link

gensablin commented Sep 14, 2020 via email

@gensablin
Copy link

Oops! It looks like the removal of this emptyPara: "<p>".concat(blankHTML, "</p>"), is affecting summernote('reset');. It stopped working. I decided to change it carefully back, but without <p>, like this emptyPara: "".concat(blankHTML, ""), and reset started working again. In summernote-lite.min - emptyPara:"".concat(j,""),. It seems summernote('reset');. using this blankHTML.

@DiemenDesign
Copy link
Member

DiemenDesign commented Dec 5, 2020

This has been added to the Projects List, you can check the progress here https://github.com/summernote/summernote/projects/3
You can continue to discuss this issue here, but this is marked as closed to make it easier to manage new issues, thank you.

@neil-viralmd
Copy link

For me, it worked with just this code:

$("#summernote").summernote("destroy");
$("#summernote").html( htmlString );
$("#summernote").summernote();

@elementalpete
Copy link

The method suggested by a few including neil-viralmd and Budsy didn't work for me, but I got it to work this way:

$("#summernote").summernote("code", htmlString);

@FahaoTang
Copy link

This issue is also bothering me and the latest release still has this issue. The card in projects has been opened for years. Is there intention to fix it?

@nikollaih
Copy link

pasteHTML works if you set the isNotSplitEdgePoint in the function splitPoint()

//         isNotSplitEdgePoint: isInline
           isNotSplitEdgePoint : true

But I don't know what else it will break...

@sigurdne It works, thanks

@adamjpeterson
Copy link

Any updates here? The solutions I'm seeing are for replacing the entire div and not related to the original question of pasting html (pasteHTML) at the cursor position. A paragraph and break are still being added. Any help would be greatly appreciated!

pandamouse pushed a commit to pandamouse/summernote that referenced this issue Jun 30, 2022
- don't add paragraph if inserting nodes that are not isInline
pandamouse pushed a commit to pandamouse/summernote that referenced this issue Jun 30, 2022
- update solution to only affect pasteHTML
- add doNotInsertPara boolean in insertNode parameter. If true then remove added empty paragraph otherwise only remove the added paragraph if the inserted node is a paragraph (as per original code)
- pasteHTML to set doNotInsertPara if the node to be inserted is not an isInline node
- revert test change on insertHorizontalRule and insertTable
pandamouse pushed a commit to pandamouse/summernote that referenced this issue Jun 30, 2022
- update solution to only affect pasteHTML
- add doNotInsertPara boolean in insertNode parameter. If true then remove added empty paragraph otherwise only remove the added paragraph if the inserted node is a paragraph (as per original code)
- pasteHTML to set doNotInsertPara if the node to be inserted is not an isInline node
- revert test change on insertHorizontalRule and insertTable
DiemenDesign added a commit that referenced this issue Sep 11, 2022
pasteHTML auto add unused <p><br></p> #3370
@DiemenDesign DiemenDesign moved this from To do to PR made, Waiting for testing and Approval. in Bugs Feb 1, 2024
@DiemenDesign DiemenDesign moved this from PR made, Waiting for testing and Approval. to Done in Bugs Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests