Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(notes): strip wrapping quotes from generated titles (#1640)

Henry Suac5b089875a5
diff --git a/src/utils/generateTitle.ts b/src/utils/generateTitle.ts
index 4dafebb5e..70b45f12b 100644
--- a/src/utils/generateTitle.ts
+++ b/src/utils/generateTitle.ts
@@ -1,6 +1,7 @@
import reasoningService from "../services/ReasoningService";
import type { ReasoningConfig } from "../services/BaseReasoningService";
import { getSettings } from "../stores/settingsStore";
+import { sanitizeGeneratedTitle } from "./sanitizeGeneratedTitle";
const TITLE_SYSTEM_PROMPT =
"Generate a concise 3-8 word title for these notes. Return ONLY the title text, nothing else — no quotes, no prefix, no explanation.";
@@ -18,8 +19,7 @@ export async function generateNoteTitle(
disableThinking: getSettings().noteFormattingDisableThinking,
...config,
});
- const cleaned = raw.trim().replace(/^["']|["']$/g, "");
- return cleaned.length > 0 && cleaned.length < 100 ? cleaned : "";
+ return sanitizeGeneratedTitle(raw);
} catch {
return "";
}
diff --git a/src/utils/sanitizeGeneratedTitle.ts b/src/utils/sanitizeGeneratedTitle.ts
new file mode 100644
index 000000000..d5bc2c1fb
--- /dev/null
+++ b/src/utils/sanitizeGeneratedTitle.ts
@@ -0,0 +1,50 @@
+// Quote marks models wrap generated titles in despite the prompt: ASCII,
+// typographic (curly, German low-9), guillemets, and CJK title brackets.
+// prettier-ignore
+const WRAPPING_QUOTES = new Set([
+ '"', "'", "“", "”", "‘", "’", "„", "‚", "«", "»", "「", "」", "『", "』", "《", "》",
+]);
+
+// Apostrophe-shaped marks are never stripped one-sided: at a single end they
+// are usually part of the word (Workin’, ’Tis the Season), not a wrapper.
+const APOSTROPHES = new Set(["'", "‘", "’"]);
+
+const hasQuoteBesides = (text: string, index: number): boolean => {
+ for (let i = 0; i < text.length; i += 1) {
+ if (i !== index && WRAPPING_QUOTES.has(text[i])) return true;
+ }
+ return false;
+};
+
+// Peel wrapping quotes the model added despite the prompt. Only matched
+// wrappers (a quote at BOTH ends) are peeled, so a title that merely contains
+// a quoted phrase at one end — Feedback on “Project X” — stays intact.
+export function sanitizeGeneratedTitle(raw: string): string {
+ let cleaned = raw.trim();
+ while (
+ cleaned.length >= 2 &&
+ WRAPPING_QUOTES.has(cleaned[0]) &&
+ WRAPPING_QUOTES.has(cleaned[cleaned.length - 1])
+ ) {
+ cleaned = cleaned.slice(1, -1).trim();
+ }
+
+ // An unterminated wrapper ("Weekly standup) leaves a quote at exactly one
+ // end with no counterpart anywhere else in the string; strip it.
+ if (cleaned.length > 1) {
+ const first = cleaned[0];
+ const last = cleaned[cleaned.length - 1];
+ if (WRAPPING_QUOTES.has(first) && !APOSTROPHES.has(first) && !hasQuoteBesides(cleaned, 0)) {
+ cleaned = cleaned.slice(1).trim();
+ } else if (
+ WRAPPING_QUOTES.has(last) &&
+ !APOSTROPHES.has(last) &&
+ !hasQuoteBesides(cleaned, cleaned.length - 1)
+ ) {
+ cleaned = cleaned.slice(0, -1).trim();
+ }
+ }
+
+ if (cleaned.length === 1 && WRAPPING_QUOTES.has(cleaned)) return "";
+ return cleaned.length > 0 && cleaned.length < 100 ? cleaned : "";
+}
diff --git a/test/utils/sanitizeGeneratedTitle.test.js b/test/utils/sanitizeGeneratedTitle.test.js
new file mode 100644
index 000000000..224ed53c0
--- /dev/null
+++ b/test/utils/sanitizeGeneratedTitle.test.js
@@ -0,0 +1,62 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const load = () => import("../../src/utils/sanitizeGeneratedTitle.ts");
+
+test("strips wrapping ASCII quotes", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle('"Weekly standup"'), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle("'Weekly standup'"), "Weekly standup");
+});
+
+test("strips wrapping typographic quotes", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle("“Weekly standup”"), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle("‘Weekly standup’"), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle("«Weekly standup»"), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle("„Wochenmeeting“"), "Wochenmeeting");
+ assert.equal(sanitizeGeneratedTitle("「週次ミーティング」"), "週次ミーティング");
+ assert.equal(sanitizeGeneratedTitle("《周会纪要》"), "周会纪要");
+});
+
+test("peels stacked wrappers left by mixed quote styles", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle('"“Weekly standup”"'), "Weekly standup");
+});
+
+test("keeps inner apostrophes and elisions", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle("Don't stop meeting"), "Don't stop meeting");
+ assert.equal(sanitizeGeneratedTitle("'Don't stop meeting'"), "Don't stop meeting");
+ assert.equal(sanitizeGeneratedTitle("Workin’"), "Workin’");
+ assert.equal(sanitizeGeneratedTitle("’Tis the Season"), "’Tis the Season");
+});
+
+test("keeps a quoted phrase at one end intact", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle("Feedback on “Project X”"), "Feedback on “Project X”");
+ assert.equal(sanitizeGeneratedTitle("“Q3” Planning Notes"), "“Q3” Planning Notes");
+ assert.equal(sanitizeGeneratedTitle("Discussing «Le Projet»"), "Discussing «Le Projet»");
+});
+
+test("strips an unterminated wrapper with no counterpart", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle('"Weekly standup'), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle('Weekly standup"'), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle("«Réunion"), "Réunion");
+});
+
+test("trims whitespace around wrapping quotes", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle(' "Weekly standup" '), "Weekly standup");
+ assert.equal(sanitizeGeneratedTitle('" Weekly standup "'), "Weekly standup");
+});
+
+test("rejects empty or overlong titles after stripping", async () => {
+ const { sanitizeGeneratedTitle } = await load();
+ assert.equal(sanitizeGeneratedTitle(""), "");
+ assert.equal(sanitizeGeneratedTitle('""'), "");
+ assert.equal(sanitizeGeneratedTitle('"'), "");
+ assert.equal(sanitizeGeneratedTitle("a".repeat(100)), "");
+ assert.equal(sanitizeGeneratedTitle("short"), "short");
+});