diff --git a/src/utils/frontmatter-utils.ts b/src/utils/frontmatter-utils.ts index 156cef7..2c4356c 100644 --- a/src/utils/frontmatter-utils.ts +++ b/src/utils/frontmatter-utils.ts @@ -240,9 +240,9 @@ export class FrontmatterUtils { } } - // Pattern 3: ``` with any language specifier + // Pattern 3: ``` with any language specifier (one or more characters) if (!jsonString) { - match = afterDrawing.match(/```[a-z-]*\s*\n([\s\S]*?)```/); + match = afterDrawing.match(/```[a-z-]+\s*\n([\s\S]*?)```/); if (match) { jsonString = match[1]; } @@ -263,8 +263,8 @@ export class FrontmatterUtils { const patterns = [ /```compressed-json\s*\n([\s\S]*?)```/, /```json\s*\n([\s\S]*?)```/, - /```[a-z-]*\s*\n([\s\S]*?)```/, - /```\s*\n([\s\S]*?)```/ + /```[a-z-]+\s*\n([\s\S]*?)```/, // One or more chars for language + /```\s*\n([\s\S]*?)```/ // No language specifier ]; for (const pattern of patterns) { diff --git a/tests/frontmatter-utils.test.ts b/tests/frontmatter-utils.test.ts index 9568155..0050e09 100644 --- a/tests/frontmatter-utils.test.ts +++ b/tests/frontmatter-utils.test.ts @@ -629,6 +629,26 @@ No compressed-json, json, or other language specifier expect(result.elementCount).toBe(2); }); + test('parses Excalidraw with code fence lacking language specifier (coverage for lines 253-255)', () => { + // Specific test to ensure Pattern 4 code path is exercised + // Uses only basic code fence with no language hint after ## Drawing + const content = ` +excalidraw-plugin + +## Drawing +\`\`\` +{"elements": [{"id": "elem1"}, {"id": "elem2"}, {"id": "elem3"}], "appState": {"gridSize": 20}, "version": 2} +\`\`\``; + + const result = FrontmatterUtils.parseExcalidrawMetadata(content); + + expect(result.isExcalidraw).toBe(true); + expect(result.elementCount).toBe(3); + expect(result.hasCompressedData).toBe(false); + expect(result.metadata?.version).toBe(2); + expect(result.metadata?.appState).toEqual({"gridSize": 20}); + }); + test('tries patterns in entire content if no ## Drawing section', () => { const content = `\`\`\`json {"elements": [{"id": "1"}], "appState": {}, "version": 2, "type":"excalidraw"}