1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00

Swapping all spaces with global &nbsp (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/
This commit is contained in:
Dustin Darcy 2023-07-27 16:09:35 -04:00
parent 66a0dafbc6
commit f5491b4b15
2 changed files with 10 additions and 1 deletions

3
.gitignore vendored
View File

@ -4,6 +4,9 @@ node_modules/
.yarn/* .yarn/*
.pnp.* .pnp.*
# Testing
private/
# rust # rust
target/ target/

8
scripts/export.js vendored
View File

@ -168,7 +168,13 @@ async function exportInit() {
if (replaceInUserInput) { if (replaceInUserInput) {
const userInputBlocks = j.querySelectorAll(USER_INPUT_SELECTOR); const userInputBlocks = j.querySelectorAll(USER_INPUT_SELECTOR);
userInputBlocks.forEach((block) => { userInputBlocks.forEach((block) => {
block.innerHTML = block.innerHTML.replace(/\n/g, '<br/>').replace(/ /g, '&nbsp;');
//For quicker testing use js fiddle: https://jsfiddle.net/xtraeme/x34ao9jp/13/
block.innerHTML = block.innerHTML
.replace(/&nbsp;|\u00A0/g, ' ') //Replace =C2=A0 (nbsp non-breaking space) with breaking-space
.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') // Replace tab with 4 non-breaking spaces
.replace(/^ +/gm, function(match) { return '&nbsp;'.repeat(match.length); }) //Add =C2=A0
.replace(/\n/g, '<br/>');
}); });
} }