mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-12 03:49:43 +02:00
feat(mathml): added additional config option for forcing legacy rendering
This commit is contained in:
@@ -120,6 +120,13 @@ export interface MermaidConfig {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
legacyMathML?: boolean;
|
legacyMathML?: boolean;
|
||||||
|
/**
|
||||||
|
* This option forces Mermaid to rely on KaTeX's own stylesheet for rendering MathML. Due to differences between OS
|
||||||
|
* fonts and browser's MathML implementation, this option is recommended if consistent rendering is important.
|
||||||
|
* If set to true, ignores legacyMathML.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
forceLegacyMathML?: boolean;
|
||||||
/**
|
/**
|
||||||
* This option controls if the generated ids of nodes in the SVG are
|
* This option controls if the generated ids of nodes in the SVG are
|
||||||
* generated randomly or based on a seed.
|
* generated randomly or based on a seed.
|
||||||
|
@@ -337,11 +337,12 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise<
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMathMLSupported() && !config.legacyMathML) {
|
if (!(isMathMLSupported() || config.legacyMathML || config.forceLegacyMathML)) {
|
||||||
return text.replace(katexRegex, 'MathML is unsupported in this environment.');
|
return text.replace(katexRegex, 'MathML is unsupported in this environment.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { default: katex } = await import('katex');
|
const { default: katex } = await import('katex');
|
||||||
|
const outputMode = (config.forceLegacyMathML) || (!isMathMLSupported() && config.legacyMathML) ? 'htmlAndMathml' : 'mathml';
|
||||||
return text
|
return text
|
||||||
.split(lineBreakRegex)
|
.split(lineBreakRegex)
|
||||||
.map((line) =>
|
.map((line) =>
|
||||||
@@ -357,7 +358,7 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise<
|
|||||||
.renderToString(c, {
|
.renderToString(c, {
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
displayMode: true,
|
displayMode: true,
|
||||||
output: isMathMLSupported() ? 'mathml' : 'htmlAndMathml',
|
output: outputMode
|
||||||
})
|
})
|
||||||
.replace(/\n/g, ' ')
|
.replace(/\n/g, ' ')
|
||||||
.replace(/<annotation.*<\/annotation>/g, '')
|
.replace(/<annotation.*<\/annotation>/g, '')
|
||||||
|
@@ -180,6 +180,13 @@ properties:
|
|||||||
fall back to legacy rendering for KaTeX.
|
fall back to legacy rendering for KaTeX.
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
forceLegacyMathML:
|
||||||
|
description: |
|
||||||
|
This option forces Mermaid to rely on KaTeX's own stylesheet for rendering MathML. Due to differences between OS
|
||||||
|
fonts and browser's MathML implementation, this option is recommended if consistent rendering is important.
|
||||||
|
If set to true, ignores legacyMathML.
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
deterministicIds:
|
deterministicIds:
|
||||||
description: |
|
description: |
|
||||||
This option controls if the generated ids of nodes in the SVG are
|
This option controls if the generated ids of nodes in the SVG are
|
||||||
|
Reference in New Issue
Block a user