From 4fa6647b9c87be3cf08de515698b24d73c0f42b8 Mon Sep 17 00:00:00 2001 From: FortPile <50821025+Coadon@users.noreply.github.com> Date: Mon, 27 Nov 2023 21:16:27 +0800 Subject: [PATCH] fix(funbox): fix Wikipedia funbox sometimes producing double spaces (FortPile) (#4814) * fix: prepone non-ascii characters removal * also replacing fancy symbols --------- Co-authored-by: Miodec --- frontend/src/ts/test/wikipedia.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/ts/test/wikipedia.ts b/frontend/src/ts/test/wikipedia.ts index 68fd21c05..391d9ba85 100644 --- a/frontend/src/ts/test/wikipedia.ts +++ b/frontend/src/ts/test/wikipedia.ts @@ -106,16 +106,20 @@ export async function getSection(language: string): Promise
{ // Remove invisible characters sectionText = sectionText.replace(/[\u200B-\u200D\uFEFF]/g, ""); + // replace any fancy symbols + sectionText = Misc.cleanTypographySymbols(sectionText); + + // Remove non-ascii characters for English articles + if (urlTLD === "en") { + sectionText = sectionText.replace(/[^\x20-\x7E]+/g, ""); + } + // Convert all whitespace to space sectionText = sectionText.replace(/\s+/g, " "); // Removing whitespace before and after text sectionText = sectionText.trim(); - if (urlTLD === "en") { - sectionText = sectionText.replace(/[^\x20-\x7E]+/g, ""); - } - const words = sectionText.split(" "); const section = new Section(