From 96e4bf2e98a27a2bd06d55284be2e96c3df3c86d Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Mon, 2 Oct 2023 13:23:12 +1100 Subject: [PATCH] Replace nbsp with regular sp when extracting text The nbsp are used by the browser to stop HTML white space collapsing from applying, but we don't want them in the plain text version. --- source/range/Contents.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/range/Contents.ts b/source/range/Contents.ts index c55d775..abb948d 100644 --- a/source/range/Contents.ts +++ b/source/range/Contents.ts @@ -53,6 +53,9 @@ const getTextContentsOfRange = (range: Range) => { } node = walker.nextNode(); } + // Replace nbsp with regular space; + // eslint-disable-next-line no-irregular-whitespace + textContent = textContent.replace(/ /g, ' '); return textContent; };