diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ca8473..f4342a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v2.0.0 ### Breaking Changes - ReactHtmlParser now decodes html entities by default +- html, head and body tags are no longer automatically converted to div tags ### Updates - Add React v16 as a peer dependency - Added options parameter to ReactHtmlParser function with `decodeEntities` option (default true) diff --git a/src/elementTypes/TagElementType.js b/src/elementTypes/TagElementType.js index 7db95d1..3004ca1 100644 --- a/src/elementTypes/TagElementType.js +++ b/src/elementTypes/TagElementType.js @@ -1,7 +1,6 @@ import React from 'react'; import ProcessNodes from '../utils/ProcessNodes'; import GeneratePropsFromAttributes from '../utils/GeneratePropsFromAttributes'; -import TransformTagName from '../utils/TransformTagName'; import VoidElements from '../dom/elements/VoidElements'; /** @@ -17,7 +16,7 @@ export default function TagElementType(node, key) { const props = GeneratePropsFromAttributes(node.attribs, key); // transform the tag name if needed - const tagName = TransformTagName(node.name); + const tagName = node.name; // If the node is not a void element and has children then process them let children = null; diff --git a/src/utils/TransformTagName.js b/src/utils/TransformTagName.js deleted file mode 100644 index ede016a..0000000 --- a/src/utils/TransformTagName.js +++ /dev/null @@ -1,20 +0,0 @@ -const TAGS_TO_TRANSFORM = { - 'html': 'div', - 'head': 'div', - 'body': 'div' -}; - -/** - * Transforms the specified tag name to another tag name if needed - * - * @param {String} tagName The name of the tag - * @returns {String} The transformed tag name or the original if it doesn't need to be transformed - */ -export default function TransformTagName(tagName) { - if (TAGS_TO_TRANSFORM.hasOwnProperty(tagName)) { - return TAGS_TO_TRANSFORM[tagName]; - } - else { - return tagName; - } -} diff --git a/test/integration/integration.spec.js b/test/integration/integration.spec.js index 301096b..1c829aa 100644 --- a/test/integration/integration.spec.js +++ b/test/integration/integration.spec.js @@ -68,18 +68,6 @@ describe('Integration tests: ', () => { test(`
test
`); }); - it('should transform a html tag to a div', () => { - test('test', '
test
'); - }); - - it('should transform a head tag to a div', () => { - test('test', '
test
'); - }); - - it('should transform a body tag to a div', () => { - test('test', '
test
'); - }); - it('should not allow nesting of void elements', () => { test('

test

', '

test

'); }); diff --git a/test/unit/utils/TransformTagName.spec.js b/test/unit/utils/TransformTagName.spec.js deleted file mode 100644 index 4d149a2..0000000 --- a/test/unit/utils/TransformTagName.spec.js +++ /dev/null @@ -1,14 +0,0 @@ -import TransformTagName from 'utils/TransformTagName'; - -describe('Testing `utils/TransformTagName`', () => { - - it('should transform the tag name if needed', () => { - expect(TransformTagName('html')).toBe('div'); - expect(TransformTagName('head')).toBe('div'); - expect(TransformTagName('body')).toBe('div'); - expect(TransformTagName('a')).toBe('a'); - expect(TransformTagName('div')).toBe('div'); - expect(TransformTagName('span')).toBe('span'); - }); - -});