一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
49 行
1.6 KiB
TypeScript
49 行
1.6 KiB
TypeScript
import { describe, test, expect, jest, beforeEach, afterEach } from '@jest/globals';
|
||
import MarkdownIt = require('markdown-it');
|
||
import katexRule from './katex';
|
||
|
||
// Non-breaking space (U+00A0) inside math is the canonical trigger — this is
|
||
// what emails, Word, and web pastes typically inject and what KaTeX complains
|
||
// about with strict:'warn'.
|
||
const nbspMath = '$x = 1$';
|
||
|
||
const createMarkdownIt = (strict?: unknown) => {
|
||
const md = new MarkdownIt();
|
||
const context = {
|
||
userData: {} as Record<string, unknown>,
|
||
pluginWasUsed: { katex: false } as Record<string, boolean>,
|
||
};
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- plugin signature uses a narrower MarkdownIt type than the one exposed by markdown-it's own types
|
||
md.use(katexRule.plugin as any, { context, strict });
|
||
return md;
|
||
};
|
||
|
||
describe('katex', () => {
|
||
|
||
let warnSpy: jest.SpiedFunction<typeof console.warn>;
|
||
|
||
beforeEach(() => {
|
||
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||
});
|
||
|
||
afterEach(() => {
|
||
warnSpy.mockRestore();
|
||
});
|
||
|
||
test('warns by default on LaTeX-incompatible input', () => {
|
||
const md = createMarkdownIt();
|
||
const output = md.render(nbspMath);
|
||
expect(output).toContain('katex');
|
||
const warned = warnSpy.mock.calls.some(args => String(args[0]).includes('LaTeX-incompatible'));
|
||
expect(warned).toBe(true);
|
||
});
|
||
|
||
test('is silent when strict:"ignore" is passed via plugin options', () => {
|
||
const md = createMarkdownIt('ignore');
|
||
const output = md.render(nbspMath);
|
||
expect(output).toContain('katex');
|
||
const warned = warnSpy.mock.calls.some(args => String(args[0]).includes('LaTeX-incompatible'));
|
||
expect(warned).toBe(false);
|
||
});
|
||
});
|