Good afternoon. What happens that I want to get a text string with HTML tags, but the summernote interprets them and shows the rich text, and what I want is to show the text with tags, but I have not succeeded:
var content = '<b>Content</b> and <b>tags</b> and <i>HTML</i>';
//I have tried this:
$('#summernote').summernote('code',content);
$('#summernote').val(content);
But the result is this: Content and tags and HTML
What I want is to copy and paste a text that contains HTML tags, but I do not want the summernote to interpret those tags. What I want, is that the user can see the tags when pasting that text without activating the mode 'code view'
var content = '<b>Content</b> and <b>tags</b> and <i>HTML</i>';
//Initialize the summernote
$('#summernote').summernote({
height: 200
});
$('#summernote').summernote('code',content);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.js"></script>
<div id="summernote">
</div>
Good day, I have managed to resolve the issue.
My goal was that at the moment of pasting content with HTML from an external source (word), the Summernote would not interpret the labels and if it would show me a string showing me the tags.
Something like this:
"Text with HTML and hide tags" ==> "<p>Text with <b>HTML</b> and <i>hide</i> tags</p><br>"
The solution was:
Get the content that was copied and pasted
let contentPasted = $('#summernote').summernote('code');
Replace the symbols (< and >) with (& lt; and & gt;)
let finalContent = contentPasted.replace(/>/g,'>').replace(/</g,'<')
And with this, it was enough for the HTML code not to be interpreted: