From f5491b4b15d7542105bf74ebe59d5497a620545e Mon Sep 17 00:00:00 2001 From: Dustin Darcy Date: Thu, 27 Jul 2023 16:09:35 -0400 Subject: [PATCH] Swapping all spaces with global   (non-blocking spaces) causes issues with word-wrap. To solve this we now only have nbsp when we encounter spaces or a tab at the start of a line (to maintain indentation). A fiddle exists to test the regex at: https://jsfiddle.net/xtraeme/x34ao9jp/13/ --- .gitignore | 3 +++ scripts/export.js | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c87cd2f..04d3ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ node_modules/ .yarn/* .pnp.* +# Testing +private/ + # rust target/ diff --git a/scripts/export.js b/scripts/export.js index 587848e..30b2bba 100644 --- a/scripts/export.js +++ b/scripts/export.js @@ -168,7 +168,13 @@ async function exportInit() { if (replaceInUserInput) { const userInputBlocks = j.querySelectorAll(USER_INPUT_SELECTOR); userInputBlocks.forEach((block) => { - block.innerHTML = block.innerHTML.replace(/\n/g, '
').replace(/ /g, ' '); + + //For quicker testing use js fiddle: https://jsfiddle.net/xtraeme/x34ao9jp/13/ + block.innerHTML = block.innerHTML + .replace(/ |\u00A0/g, ' ') //Replace =C2=A0 (nbsp non-breaking space) with breaking-space + .replace(/\t/g, '    ') // Replace tab with 4 non-breaking spaces + .replace(/^ +/gm, function(match) { return ' '.repeat(match.length); }) //Add =C2=A0 + .replace(/\n/g, '
'); }); }