diff --git a/README.md b/README.md index c9fe49cd..29276a0f 100644 --- a/README.md +++ b/README.md @@ -314,23 +314,21 @@ parse('
', { ### htmlparser2 -The default [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-options) are: +Along with the default [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode), the parser also sets: -```js +```json { - decodeEntities: true, - lowerCaseAttributeNames: false + "lowerCaseAttributeNames": false } ``` Since [v0.12.0](https://github.com/remarkablemark/html-react-parser/tree/v0.12.0), the htmlparser2 options can be overridden. -The following example enables [`decodeEntities`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-decodeentities) and [`xmlMode`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode): +The following example enables [`xmlMode`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode) but disables [`lowerCaseAttributeNames`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-lowercaseattributenames): ```js parse('

', { htmlparser2: { - decodeEntities: true, xmlMode: true } }); diff --git a/index.js b/index.js index c66fbbdf..3929d5a5 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,7 @@ var domToReact = require('./lib/dom-to-react'); var attributesToProps = require('./lib/attributes-to-props'); var htmlToDOM = require('html-dom-parser'); -// decode HTML entities by default for `htmlparser2` -var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false }; +var domParserOptions = { lowerCaseAttributeNames: false }; /** * Converts HTML string to React elements. diff --git a/package.json b/package.json index 78608284..21a3a3ea 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "dom" ], "dependencies": { - "html-dom-parser": "0.5.0", + "html-dom-parser": "1.0.0", "react-property": "1.0.1", "style-to-js": "1.1.0" }, diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 658946d3..772788cd 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1,5 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`HTMLReactParser escapes tags inside of 1`] = ` +<title> + <em>text</em> + +`; + exports[`HTMLReactParser parses SVG 1`] = `


', comment: '', doctype: '', + title: '<em>text</em>', customElement: '' }; diff --git a/test/index.test.js b/test/index.test.js index 59f0ba5f..4ceb844c 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -75,6 +75,10 @@ describe('HTMLReactParser', () => { const reactElement = parse('' + encodedEntities + ''); expect(reactElement.props.children).toBe(decodedEntities); }); + + it('escapes tags inside of ', () => { + expect(parse(html.title)).toMatchSnapshot(); + }); }); describe('replace option', () => {