Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

37 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import { ommlToLatex } from '../src/serializer/mathSerializer';
const M = 'xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"';
const omath = (inner: string) => `<m:oMath ${M}>${inner}</m:oMath>`;
/**
* 回归(auto-fix.md 坑表):OMML → LaTeX 转换的 JS 兜底路径(ommlToLatex)。
*
* - 分数等基本结构要转成正确的 LaTeX 命令。
* - 梯度/反向传播页用的 ∂(U+2202)/∇(U+2207):早先因为不在 Greek 归一化范围 →
* 泄漏成 lone surrogateKaTeX 报错把源码渲染成红字。postProcessLatex 补了
* ∂→\partial、∇→\nabla 的兜底。
*/
describe('mathSerializer · ommlToLatex', () => {
it('分数 m:f → \\frac{a}{b}', () => {
const latex = ommlToLatex(
omath(
'<m:f><m:num><m:r><m:t>a</m:t></m:r></m:num><m:den><m:r><m:t>b</m:t></m:r></m:den></m:f>',
),
);
expect(latex).toBe('\\frac{a}{b}');
});
it('∂ (U+2202) → \\partial(不泄漏原字符)', () => {
const latex = ommlToLatex(omath('<m:r><m:t>\u2202</m:t></m:r>'));
expect(latex).toContain('\\partial');
expect(latex).not.toContain('\u2202');
});
it('∇ (U+2207) → \\nabla(不泄漏原字符)', () => {
const latex = ommlToLatex(omath('<m:r><m:t>\u2207</m:t></m:r>'));
expect(latex).toContain('\\nabla');
expect(latex).not.toContain('\u2207');
});
});