Skip to content

Commit

Permalink
fix: replace nbsp with space (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed May 4, 2023
1 parent 9ecce71 commit f093c74
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/utils/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ');
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/importers/fixtures/space.spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ <h1>Space sample</h1>
<p>A simple paragraph</p>
<p>A paragraph with a br inside.<br> This should be next line.</p>
<p>A paragraph with a br at the end.<br></p>
<p>A paragraph with a br at the end and &amp;nbsp; "&nbsp;".<br> &nbsp;</p>
<p>A paragraph followed by a br</p>
<br>
<p>A paragraph after the br</p>
&nbsp;
<p>&nbsp;</p>
<p>A paragraph after the nbsp;</p>
</body>
</html>
4 changes: 2 additions & 2 deletions test/importers/fixtures/space.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ This should be next line.

A paragraph with a br at the end.

A paragraph with a br at the end and \&nbsp; " ".

A paragraph followed by a br

\


A paragraph after the br



A paragraph after the nbsp;
5 changes: 5 additions & 0 deletions test/utils/DOMUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ describe('DOMUtils#reviewParagraphs tests', () => {
test('<p><video width="320" height="240" controls=""><source src="movie.mp4" type="video/mp4"></video></p>', '<p><video width="320" height="240" controls=""><source src="movie.mp4" type="video/mp4"></video></p>');
test('<p><iframe src="www.iframe.com"></iframe></p>', '<p><iframe src="www.iframe.com"></iframe></p>');
});

it('reviewParagraphs replaces &nbsp; with spaces', () => {
test('<p>usefull with space&nbsp;</p>', '<p>usefull with space </p>');
test('<p>&nbsp;more&nbsp;spaces&nbsp;<br> &nbsp;</p>', '<p> more spaces <br> </p>');
});
});

describe('DOMUtils#reviewHeadings tests', () => {
Expand Down

0 comments on commit f093c74

Please sign in to comment.