fix: treat escaped arborium output as plain

This commit is contained in:
hazre committed 2026-03-27 12:31:54 +01:00
1 parent 0e0290f557
commit bce5b50a24
2 files changed
+32

No files matched your search

+29
View File
@@ -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: '<span>',
language: 'typescript',
},
{ loadModule }
);
expect(result).toEqual({
mode: 'plain',
html: '&lt;span&gt;',
language: 'typescript',
});
expect(highlight).toHaveBeenCalledWith('typescript', '<span>');
});
it('returns plain escaped code with the resolved language when highlighting fails', async () => {
const normalizeLanguage = vi.fn((language: string) =>
language === 'ts' ? 'typescript' : language
+3
View File
@@ -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,