diff --git a/src/utils/DOMUtils.js b/src/utils/DOMUtils.js index c790b06..b659b55 100644 --- a/src/utils/DOMUtils.js +++ b/src/utils/DOMUtils.js @@ -103,10 +103,12 @@ export default class DOMUtils { (tag.textContent === '' || tag.textContent === ' ' || tag.textContent === ' ' - || tag.textContent.charCodeAt(0) === 160) + || (tag.textContent.charCodeAt(0) === 160 && tag.textContent.length === 1)) && !tag.querySelector(DOMUtils.EMPTY_TAGS_TO_PRESERVE.join(',')) ) { tag.remove(); + } else { + tag.innerHTML = tag.innerHTML.replace(/ /gm, ' '); } } } diff --git a/test/importers/fixtures/space.spec.html b/test/importers/fixtures/space.spec.html index f1415d8..de75e29 100644 --- a/test/importers/fixtures/space.spec.html +++ b/test/importers/fixtures/space.spec.html @@ -4,10 +4,11 @@

Space sample

A simple paragraph

A paragraph with a br inside.
This should be next line.

A paragraph with a br at the end.

+

A paragraph with a br at the end and   " ".
 

A paragraph followed by a br


A paragraph after the br

-   +

 

A paragraph after the nbsp;

\ No newline at end of file diff --git a/test/importers/fixtures/space.spec.md b/test/importers/fixtures/space.spec.md index 1c959ee..49bc10d 100644 --- a/test/importers/fixtures/space.spec.md +++ b/test/importers/fixtures/space.spec.md @@ -7,6 +7,8 @@ This should be next line. A paragraph with a br at the end. +A paragraph with a br at the end and \  " ". + A paragraph followed by a br \ @@ -14,6 +16,4 @@ A paragraph followed by a br A paragraph after the br - - A paragraph after the nbsp; \ No newline at end of file diff --git a/test/utils/DOMUtils.spec.js b/test/utils/DOMUtils.spec.js index 1e81ea9..51eda16 100644 --- a/test/utils/DOMUtils.spec.js +++ b/test/utils/DOMUtils.spec.js @@ -95,6 +95,11 @@ describe('DOMUtils#reviewParagraphs tests', () => { test('

', '

'); test('

', '

'); }); + + it('reviewParagraphs replaces   with spaces', () => { + test('

usefull with space 

', '

usefull with space

'); + test('

 more spaces 
 

', '

more spaces

'); + }); }); describe('DOMUtils#reviewHeadings tests', () => {