fix: keep whitespaces and newlines in pre and textareas

This commit is contained in:
Hubert SABLONNIÈRE 2015-07-29 15:03:15 +02:00
parent f4fc886b5e
commit fae14c92c3
3 changed files with 52 additions and 6 deletions

View File

@ -255,12 +255,10 @@ function main() {
inliner.removeComments($(':root')[0], $);
// collapse the white space
if (inliner.options.collapseWhitespace) {
// TODO put white space helper back in
$('pre').html(function tidyPre(i, html) {
return html.replace(/\n/g, '~~nl~~');
});
$('textarea').val(function tidyTextarea(i, v) {
return v.replace(/\n/g, '~~nl~~').replace(/\s/g, '~~s~~');
$('pre, textarea').each(function () {
$(this).html($(this).html()
.replace(/\n/g, '~~nl~~')
.replace(/\s/g, '~~s~~'));
});
html = $.html()

View File

@ -0,0 +1,15 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>html whitespaces</title> </head> <body> <div><code>// projector page window.addEventListener(&apos;storage&apos;, function (event) { if (event.key === &apos;currentSlide&apos;) { goToSlide(event.newValue); } });</code></div> <pre><code>// projector page
window.addEventListener(&apos;storage&apos;, function (event) {
if (event.key === &apos;currentSlide&apos;) {
goToSlide(event.newValue);
}
});</code></pre> <textarea><code>// projector page
window.addEventListener(&apos;storage&apos;, function (event) {
if (event.key === &apos;currentSlide&apos;) {
goToSlide(event.newValue);
}
});</code></textarea> </body> </html>

33
test/fixtures/html-whitespaces.src.html vendored Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>html whitespaces</title>
</head>
<body>
<div><code>// projector page
window.addEventListener('storage', function (event) {
if (event.key === 'currentSlide') {
goToSlide(event.newValue);
}
});</code></div>
<pre><code>// projector page
window.addEventListener('storage', function (event) {
if (event.key === 'currentSlide') {
goToSlide(event.newValue);
}
});</code></pre>
<textarea><code>// projector page
window.addEventListener('storage', function (event) {
if (event.key === 'currentSlide') {
goToSlide(event.newValue);
}
});</code></textarea>
</body>
</html>