taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.12k stars 112 forks source link

Update unchanged attributes, By `setAttribute` #240

Closed ykawakamy closed 1 year ago

ykawakamy commented 1 year ago

When calling setAttribute, even unchanged attributes are escaped. I would like to keep the original strings when editing the HTML source.

Example:

root = HTMLParser.parse("<div unchanged='[\npreserve newline\n]'></div>");
div = root.firstChild
console.log(div.toString())
// output: 
//   <div unchanged='[
//   preserve newline
//   ]'></div>

div.setAttribute("append","newAttribute");
console.log(div.toString())
// output: 
//   <div unchanged="[\\npreserve newline\\n]" append="newAttribute"></div>'
// expected: 
//   <div unchanged='[
//   preserve newline
//   ]' append="newAttribute"></div>'
taoqf commented 1 year ago

Thank you.