fix: preserve whitespace (#51)

No longer normalizing whitespace in html
pull/52/head
Adam Pash 8 years ago committed by GitHub
parent 15656cb3e1
commit 64c0fad2fd

@ -51,7 +51,7 @@ const Resource = {
throw new Error('Content does not appear to be text.'); throw new Error('Content does not appear to be text.');
} }
let $ = cheerio.load(content, { normalizeWhitespace: true }); let $ = cheerio.load(content);
if ($.root().children().length === 0) { if ($.root().children().length === 0) {
throw new Error('No children, likely a bad parse.'); throw new Error('No children, likely a bad parse.');

@ -84,17 +84,9 @@ $.cleanup = () => {
}; };
$.load = (html, opts = {}, returnHtml = false) => { $.load = (html, opts = {}, returnHtml = false) => {
const { normalizeWhitespace } = opts;
if (!html) { if (!html) {
html = $.cloneHtml(); html = $.cloneHtml();
} else { } else {
if (normalizeWhitespace) {
if (typeof html === 'string') {
html = html.replace(/[\s\n\r]+/g, ' ');
}
}
html = $('<container />').html(html); html = $('<container />').html(html);
} }

Loading…
Cancel
Save