问题
I used contenteditable div to paste and replace all html tags with <br>
tag. But the pasted html start with <html><body><!--StartFragment-->
and end with <!--EndFragment--></body></html>
.
When i try to replace pasted html with <br>
tag, it inserts three <br>
tags at start position. So the pasted content start and end with three line breaks unnecessarily.
How to remove those unwanted tags on paste..?
Javascript code used to get pasted html content:
$(document).on('paste','#div-id',function(e){
e.preventDefault();
var pastedData = e.originalEvent.clipboardData.getData('text/html');
});
Note: Used regex to replace all tags with break tag(except <img>
and <br>
tag)
var replacedData = pastedData.replace(/\<(?!img|br).*?\>/g,"<br>");
来源:https://stackoverflow.com/questions/43649792/how-to-get-only-html-code-without-startfragment-on-paste-in-contenteditab