diff --git a/src/processNodes.js b/src/processNodes.js index ba414ac..b5bd43e 100644 --- a/src/processNodes.js +++ b/src/processNodes.js @@ -1,4 +1,3 @@ -import isEmptyTextNode from './utils/isEmptyTextNode'; import convertNodeToElement from './convertNodeToElement'; /** @@ -11,7 +10,6 @@ import convertNodeToElement from './convertNodeToElement'; export default function processNodes(nodes, transform) { return nodes - .filter(node => !isEmptyTextNode(node)) .map((node, index) => { // return the result of the transform function if applicable diff --git a/src/utils/isEmptyTextNode.js b/src/utils/isEmptyTextNode.js deleted file mode 100644 index 27b8f48..0000000 --- a/src/utils/isEmptyTextNode.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Tests a htmlparser2 node and returns whether is it a text node at the start and end of the line containing only - * white space. This allows these node types to be excluded from the rendering because they are unnecessary. - * - * @param {Object} node The element object as created by htmlparser2 - * @returns {boolean} Whether the node is an empty text node - */ -export default function isEmptyTextNode(node) { - return node.type === 'text' && /\r?\n/.test(node.data) && node.data.trim() === ''; -} diff --git a/test/integration/integration.spec.js b/test/integration/integration.spec.js index b9d1930..ce804c0 100644 --- a/test/integration/integration.spec.js +++ b/test/integration/integration.spec.js @@ -193,4 +193,10 @@ describe('Integration tests: ', () => { expect(htmlparser2).toBeDefined(); }); + it('should preserve whitespace with new lines between nodes', () => { + test( + 'there should be\n a space', + 'there should be\n a space' + ); + }); }); diff --git a/test/unit/processNodes.spec.js b/test/unit/processNodes.spec.js index a9131c0..d8b2d0b 100644 --- a/test/unit/processNodes.spec.js +++ b/test/unit/processNodes.spec.js @@ -1,34 +1,16 @@ -const isEmptyTextNode = jasmine.createSpy('isEmptyTextNode'); const convertNodeToElement = jasmine.createSpy('convertNodeToElement'); const processNodes = require('inject!processNodes')({ - './utils/isEmptyTextNode': isEmptyTextNode, './convertNodeToElement': convertNodeToElement }).default; describe('Testing `processNodes`', () => { beforeEach(() => { - isEmptyTextNode.calls.reset(); - isEmptyTextNode.and.returnValue(false); convertNodeToElement.calls.reset(); convertNodeToElement.and.callFake(node => node); }); - it('should filter out empty text nodes', () => { - - isEmptyTextNode.and.callFake(node => node !== 'node2'); - - const nodes = [ - 'node1', - 'node2', - 'node3' - ]; - - expect(processNodes(nodes)).toEqual(['node2']); - - }); - it('should return the response from the transform function if it is not undefined', () => { const nodes = [ 'node1', diff --git a/test/unit/utils/isEmptyTextNode.spec.js b/test/unit/utils/isEmptyTextNode.spec.js deleted file mode 100644 index 30f74bc..0000000 --- a/test/unit/utils/isEmptyTextNode.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import isEmptyTextNode from 'utils/isEmptyTextNode'; - -describe('Testing `utils/isEmptyTextNode`', () => { - - it('should return true for text nodes that contain a line break', () => { - - const nodes = [ - { type: 'text', data:'\n' }, - { type: 'text', data:' \n' }, - { type: 'text', data:'\n ' }, - { type: 'text', data:' \n ' }, - { type: 'text', data:'\r\n' }, - { type: 'text', data:' \r\n' }, - { type: 'text', data:'\r\n ' }, - { type: 'text', data:' \r\n ' } - ]; - - nodes.forEach(node => { - expect(isEmptyTextNode(node)).toBe(true); - }); - - }); - - it('should return false for text nodes not containing a line break', () => { - expect(isEmptyTextNode({ type:'text', data: '' })).toBe(false); - }); - - it('should return false for non text nodes', () => { - expect(isEmptyTextNode({ type:'tag' })).toBe(false); - }); - -});