We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const { parse } = require('node-html-parser') var insrc = `\ <html> <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> <div id="e" title='"world"' color="red">expected</div> <div id="a" title='"world"' onClick='alert("hello")' color="red">actual</div> </html> `; var root = parse(insrc); root.querySelectorAll('#e').forEach(node => { node.setAttribute('onClick', "alert('hello')"); }) root.querySelectorAll('#a').forEach(node => { //node.setAttribute('title', '"replaced"'); node.removeAttribute('color'); // FIXME }) console.log(root.toString());
result
<html> <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> <div id="e" title=""world"" color="red" onClick="alert('hello')">expected</div> <div id="a" title="\"world\"" onClick="alert(\"hello\")">actual</div> </html>
title="\"world\"" is invalid html
title="\"world\""
should be either title='"world"' (pretty, minimal diff) or title=""world"" (ugly, invasive)
title='"world"'
title=""world""
The text was updated successfully, but these errors were encountered:
similar problem: newlines in attribute values are escaped as \n but should be
\n
failing test
diff --git a/test/tests/html.js b/test/tests/html.js index 3bcf636..8d85725 100644 --- a/test/tests/html.js +++ b/test/tests/html.js @@ -391,6 +391,13 @@ describe('HTML Parser', function () { p.getAttribute('c').should.eql('undefined'); p.toString().should.eql('<p a="12" b="null" c="undefined"></p>'); }); + it('should escape newlines to html entities', function () { + const root = parseHTML('<p></p>'); + const p = root.firstChild; + p.setAttribute('a', '1\n2'); + p.getAttribute('a').should.eql('1\n2'); + p.toString().should.eql('<p a="1 2"></p>'); + }); it('should throw type Error', function () { const root = parseHTML('<p a=12 b=13 c=14></p>'); const p = root.firstChild;
Sorry, something went wrong.
this happens when using setAttributes also
setAttributes
6f6c824
No branches or pull requests
result
title="\"world\""
is invalid htmlshould be either
title='"world"'
(pretty, minimal diff)or
title=""world""
(ugly, invasive)The text was updated successfully, but these errors were encountered: