From e25f2db188e82c7aad22b6ddbb270f2dbf5b2aa9 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Tue, 28 May 2024 23:01:07 +1000 Subject: [PATCH] fix(word-counter): #761 count words using chars outside latin alphabet --- src/extensions/word-counter/client.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/word-counter/client.mjs b/src/extensions/word-counter/client.mjs index 33d639f..7074f96 100644 --- a/src/extensions/word-counter/client.mjs +++ b/src/extensions/word-counter/client.mjs @@ -43,8 +43,8 @@ export default async (api, db) => { const updateStats = debounce(() => { if (!document.contains($page)) $page = document.querySelector(page); if (!$page) return; - const text = $page.innerText, - words = text.split(/[^\w]+/).length, + const text = $page.innerText.trim(), + words = text.length ? text.split(/\s+/).length : 0, sentences = text.split(".").filter((s) => s.trim()).length, blocks = $page.querySelectorAll("[data-block-id]").length; $wordCount.setCount(words);