diff --git a/src/app/plugins/arborium/runtime.test.ts b/src/app/plugins/arborium/runtime.test.ts index 60af347c..81d31e2f 100644 --- a/src/app/plugins/arborium/runtime.test.ts +++ b/src/app/plugins/arborium/runtime.test.ts @@ -134,6 +134,35 @@ describe('highlightCode', () => { }); }); + it('treats escaped Arborium output as plain fallback', async () => { + const normalizeLanguage = vi.fn((language: string) => language); + const detectLanguage = vi.fn(() => null); + const highlight = vi.fn(async () => '<span>'); + const module = { + normalizeLanguage, + detectLanguage, + highlight, + } as unknown as ArboriumModule; + const loadModule = vi.fn(async () => module); + + const { highlightCode } = await import('.'); + + const result: HighlightResult = await highlightCode( + { + code: '', + language: 'typescript', + }, + { loadModule } + ); + + expect(result).toEqual({ + mode: 'plain', + html: '<span>', + language: 'typescript', + }); + expect(highlight).toHaveBeenCalledWith('typescript', ''); + }); + it('returns plain escaped code with the resolved language when highlighting fails', async () => { const normalizeLanguage = vi.fn((language: string) => language === 'ts' ? 'typescript' : language diff --git a/src/app/plugins/arborium/runtime.ts b/src/app/plugins/arborium/runtime.ts index 39e2211b..8f9da59d 100644 --- a/src/app/plugins/arborium/runtime.ts +++ b/src/app/plugins/arborium/runtime.ts @@ -90,6 +90,9 @@ export async function highlightCode( try { const html = await arborium.highlight(resolvedLanguage, code); + if (html === escapeHtml(code)) { + return plainResult(code, resolvedLanguage); + } return { mode: 'highlighted', html,