This commit is contained in:
taoqf 2020-03-09 14:59:11 +08:00
parent 667f09d923
commit b05eb5c127
3 changed files with 23 additions and 4 deletions

View file

@ -1,4 +1,3 @@
import { decode } from 'he';
import Node from './node';
import NodeType from './type';
@ -19,7 +18,7 @@ export default class CommentNode extends Node {
* @return {string} text content
*/
get text() {
return decode(this.rawText);
return this.rawText;
}
toString() {

View file

@ -1,4 +1,3 @@
import { decode } from 'he';
import NodeType from './type';
import Node from './node';
@ -23,7 +22,7 @@ export default class TextNode extends Node {
* @return {string} text content
*/
get text() {
return decode(this.rawText);
return this.rawText;
}
/**

View file

@ -526,6 +526,27 @@ describe('HTML Parser', function () {
root.firstChild.getAttribute('alt').should.eql('«Sogno');
root.firstChild.rawAttributes.alt.should.eql('«Sogno');
});
it('shoud not decode text', function () {
// https://github.com/taoqf/node-html-parser/issues/33
const root = parseHTML(`<html>
<body>
<div id='source'>
&lt;p&gt;
This content should be enclosed within an escaped p tag&lt;br /&gt;
&lt;/p&gt;
</div>
</body>
</html>`)
root.toString().should.eql(`<html>
<body>
<div id='source'>
&lt;p&gt;
This content should be enclosed within an escaped p tag&lt;br /&gt;
&lt;/p&gt;
</div>
</body>
</html>`);
});
});
describe('#insertAdjacentHTML() should parse and insert childrens', function () {