mirror of https://github.com/laurent22/joplin.git
parent
604dcbc35b
commit
fd5a4dcbbf
|
@ -291,4 +291,29 @@ describe('MdToHtml', () => {
|
|||
expect(html.html).toContain(opening + trimmedTex + closing);
|
||||
}
|
||||
});
|
||||
|
||||
it('should render inline KaTeX after a numbered equation', async () => {
|
||||
const mdToHtml = newTestMdToHtml();
|
||||
|
||||
// This test is intended to verify that inline KaTeX renders correctly
|
||||
// after creating a numbered equation with \begin{align}...\end{align}.
|
||||
//
|
||||
// See https://github.com/laurent22/joplin/issues/9455 for details.
|
||||
|
||||
const markdown = [
|
||||
'$$',
|
||||
'\\begin{align}\\text{Block}\\end{align}',
|
||||
'$$',
|
||||
'',
|
||||
'$\\text{Inline}$',
|
||||
].join('\n');
|
||||
const { html } = await mdToHtml.render(markdown, null, { bodyOnly: true });
|
||||
|
||||
// Because we don't control the output of KaTeX, this test should be as general as
|
||||
// possible while still verifying that rendering (without an error) occurs.
|
||||
|
||||
// Should have rendered the inline and block content without errors
|
||||
expect(html).toContain('Inline</span>');
|
||||
expect(html).toContain('Block</span>');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -43,12 +43,22 @@ function stringifyKatexOptions(options: any) {
|
|||
// \prob: {tokens: Array(12), numArgs: 1}
|
||||
// \expval: {tokens: Array(14), numArgs: 2}
|
||||
// \wf: {tokens: Array(6), numArgs: 0}
|
||||
// \@eqnsw: "1"
|
||||
//
|
||||
// Additionally, some KaTeX macros don't follow this general format. For example
|
||||
// \@eqnsw: "1"
|
||||
// is created by \begin{align}...\end{align} environments, and doesn't have a "tokens" property.
|
||||
|
||||
if (options.macros) {
|
||||
const toSerialize: any = {};
|
||||
for (const k of Object.keys(options.macros)) {
|
||||
const macroText: string[] = options.macros[k].tokens.map((t: any) => t.text);
|
||||
toSerialize[k] = `${macroText.join('')}_${options.macros[k].numArgs}`;
|
||||
const macro = options.macros[k];
|
||||
if (typeof macro === 'string') {
|
||||
toSerialize[k] = `${macro}_string`;
|
||||
} else {
|
||||
const macroText: string[] = macro.tokens.map((t: any) => t.text);
|
||||
toSerialize[k] = `${macroText.join('')}_${macro.numArgs}`;
|
||||
}
|
||||
}
|
||||
newOptions.macros = toSerialize;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue