🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(ai): unwrap a whole description that also quotes a value
davbio534da957e56e
diff --git a/src/core/capture/ai/__tests__/text.test.ts b/src/core/capture/ai/__tests__/text.test.tsindex 65503a8..fde7198 100644--- a/src/core/capture/ai/__tests__/text.test.ts+++ b/src/core/capture/ai/__tests__/text.test.ts@@ -22,6 +22,24 @@ describe('unwrapQuotes', () => {expect(unwrapQuotes('"Admin" in der Liste "Role"')).toBe('"Admin" in der Liste "Role"');});+ it('unwraps a whole description that also quotes a value', () => {+ expect(unwrapQuotes('"Select "Admin" from the Role dropdown"')).toBe('Select "Admin" from the Role dropdown');+ expect(unwrapQuotes('"在 Role 下拉菜单中选择 "Admin" 选项"')).toBe('在 Role 下拉菜单中选择 "Admin" 选项');+ });++ it('unwraps a whole description whose quoted value sits at either end', () => {+ expect(unwrapQuotes('""abc" in das Feld Email eingeben"')).toBe('"abc" in das Feld Email eingeben');+ expect(unwrapQuotes('"Type "abc""')).toBe('Type "abc"');+ });++ it('unwraps a whole description quoting a value before punctuation', () => {+ expect(unwrapQuotes('"Type "abc", then press Enter"')).toBe('Type "abc", then press Enter');+ });++ it('leaves a quote it cannot read as opening or closing', () => {+ expect(unwrapQuotes('"在Role下拉菜单中选择"Admin"选项"')).toBe('"在Role下拉菜单中选择"Admin"选项"');+ });+it('leaves an unquoted sentence alone', () => {expect(unwrapQuotes('Type "abc" in Email')).toBe('Type "abc" in Email');});diff --git a/src/core/capture/ai/text.ts b/src/core/capture/ai/text.tsindex 215ec1e..8ee7229 100644--- a/src/core/capture/ai/text.ts+++ b/src/core/capture/ai/text.ts@@ -1,6 +1,26 @@+const WORD = /[\p{L}\p{N}]/u;++// Whether the quotes inside a candidate wrapper pair up on their own. Each quote+// is read by its flanks: a word on the right only opens a span, a word on the+// left only closes one. A closer with nothing open means the outer quotes were+// two separate spans (`"Admin" in der Liste "Role"`), not one wrapper. A quote+// with words on both sides, as in unspaced CJK, cannot be read, so it stays put.+function quotesPairUp(inner: string): boolean {+ let open = 0;+ for (let i = 0; i < inner.length; i++) {+ if (inner[i] !== '"') continue;+ const wordLeft = i > 0 && WORD.test(inner[i - 1]);+ const wordRight = i < inner.length - 1 && WORD.test(inner[i + 1]);+ if (wordLeft === wordRight) return false;+ if (wordRight) open++;+ else if (open-- === 0) return false;+ }+ return open === 0;+}+export function unwrapQuotes(text: string): string {const trimmed = text.trim();const wrapped =- trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"');+ trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"') && quotesPairUp(trimmed.slice(1, -1));return wrapped ? trimmed.slice(1, -1).trim() : trimmed;}