Skip to content

Commit

Permalink
DOM: stripHTML: preserve leading and trailing space
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 13, 2021
1 parent 7aa0a40 commit c87dae7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/dom/src/dom/strip-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* @return {string} The text content with any html removed.
*/
export default function stripHTML( html ) {
const document = new window.DOMParser().parseFromString(
html,
'text/html'
);
return document.body.textContent || '';
const doc = document.implementation.createHTMLDocument( '' );
doc.body.innerHTML = html;
return doc.body.textContent || '';
}

0 comments on commit c87dae7

Please sign in to comment.