fix: treat escaped arborium output as plain
This commit is contained in:
2 files changed
+32
No files matched your search
@@ -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: '<span>',
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user