文件
chen 301194963b
一些检查失败了
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
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

49 行
1.6 KiB
TypeScript

此文件含有不可见的 Unicode 字符

此文件含有人类无法区分的不可见的 Unicode 字符,但可以由计算机进行不同的处理。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

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);
});
});