Answer the question
In order to leave comments, you need to log in
How to do reverse operation in highlight.js or other similar library?
Hello. I use the highlight.js library for syntax highlighting. There is such a code
<div id="container">
<h1>Hello World!!</h1>
</div>
<button id="edit">Edit</button>
<button id="done">Done</button>
var container = document.getElementById('container'),
edit = document.getElementById('edit'),
done = document.getElementById('done');
edit.addEventListener('click', function () {
var code = container.innerHTML,
$pre = document.createElement('pre'),
$code = document.createElement('code');
container.setAttribute('contenteditable', true);
container.removeChild(container.childNodes[1]);
container.appendChild($pre);
$pre.appendChild($code);
$code.innerHTML = code.replace(/<|>/g,function(s){return s==="<"?"<":">"}).replace( /<(\/?script)>/g ,"<$1>");
hljs.highlightBlock($code);
}, false);
done.addEventListener('click', function () {
// ОБРАТНАЯ ОПЕРАЦИЯ
}, false);
<h1>Hello World</h1>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question