fix(word-counter): count words using chars outside latin alphabet

This commit is contained in:
dragonwocky 2024-05-28 23:01:07 +10:00
parent ec738cd03f
commit e25f2db188
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8

View File

@ -43,8 +43,8 @@ export default async (api, db) => {
const updateStats = debounce(() => { const updateStats = debounce(() => {
if (!document.contains($page)) $page = document.querySelector(page); if (!document.contains($page)) $page = document.querySelector(page);
if (!$page) return; if (!$page) return;
const text = $page.innerText, const text = $page.innerText.trim(),
words = text.split(/[^\w]+/).length, words = text.length ? text.split(/\s+/).length : 0,
sentences = text.split(".").filter((s) => s.trim()).length, sentences = text.split(".").filter((s) => s.trim()).length,
blocks = $page.querySelectorAll("[data-block-id]").length; blocks = $page.querySelectorAll("[data-block-id]").length;
$wordCount.setCount(words); $wordCount.setCount(words);