From 85fc3f59f537f260691dc5d0dfcd98daa5c4de7a Mon Sep 17 00:00:00 2001 From: sudo-Harshk Date: Mon, 1 Dec 2025 18:21:38 +0530 Subject: [PATCH] fix(stats): implement regex for sentences, lists, and tables --- frontend/app.js | 12 ++++++++++++ frontend/index.html | 18 ++++++++++++++++++ plugins/note_stats.py | 25 ++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/frontend/app.js b/frontend/app.js index 2aa75da..e560858 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -2962,6 +2962,15 @@ function noteApp() { // Paragraph count const paragraphs = content.split('\n\n').filter(p => p.trim()).length; + // Sentences: punctuation [.!?]+ followed by space or end-of-string + const sentences = (content.match(/[.!?]+(?:\s|$)/g) || []).length; + + // List items: lines starting with -, *, + or a number (e.g. 1., 10.), excluding tasks [-] + const listItems = (content.match(/^\s*(?:[-*+]|\d+\.)\s+(?!\[)/gm) || []).length; + + // Tables: separator rows containing both '|' and '---' + const tables = (content.match(/^(?=.*\|)(?=.*---).*$/gm) || []).length; + // Link count const linkMatches = content.match(/\[([^\]]+)\]\(([^\)]+)\)/g) || []; const links = linkMatches.length; @@ -2990,11 +2999,14 @@ function noteApp() { this.noteStats = { words, + sentences, characters: chars, total_characters: totalChars, reading_time_minutes: readingTime, lines, paragraphs, + list_items: listItems, + tables, links, internal_links: internalLinks, external_links: links - internalLinks, diff --git a/frontend/index.html b/frontend/index.html index bf35062..14cedc8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1567,6 +1567,24 @@
+ +
+
Sentences
+
+
+ + +
+
Lists
+
+
+ + +
+
Tables
+
+
+