Remove katex from mermaid.tiny

This commit is contained in:
Sidharth Vinod
2024-03-01 12:54:42 +05:30
parent 3a12a63c32
commit 882e4971eb
8 changed files with 38 additions and 31 deletions

View File

@@ -68,7 +68,7 @@ export const addDiagrams = () => {
}
);
if (includeLargeDiagrams) {
if (includeLargeFeatures) {
registerLazyLoadedDiagrams(flowchartElk, mindmap);
}

View File

@@ -341,29 +341,36 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise<
return text.replace(katexRegex, 'MathML is unsupported in this environment.');
}
const { default: katex } = await import('katex');
return text
.split(lineBreakRegex)
.map((line) =>
hasKatex(line)
? `
if (includeLargeFeatures) {
const { default: katex } = await import('katex');
return text
.split(lineBreakRegex)
.map((line) =>
hasKatex(line)
? `
<div style="display: flex; align-items: center; justify-content: center; white-space: nowrap;">
${line}
</div>
`
: `<div>${line}</div>`
)
.join('')
.replace(katexRegex, (_, c) =>
katex
.renderToString(c, {
throwOnError: true,
displayMode: true,
output: isMathMLSupported() ? 'mathml' : 'htmlAndMathml',
})
.replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
);
: `<div>${line}</div>`
)
.join('')
.replace(katexRegex, (_, c) =>
katex
.renderToString(c, {
throwOnError: true,
displayMode: true,
output: isMathMLSupported() ? 'mathml' : 'htmlAndMathml',
})
.replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
);
}
return text.replace(
katexRegex,
'Katex is unsupported in mermaid.tiny.js. Please use mermaid.js or mermaid.min.js.'
);
};
export default {

View File

@@ -32,7 +32,7 @@ import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.
import { preprocessDiagram } from './preprocess.js';
import { decodeEntities } from './utils.js';
const version = packageVersion + (includeLargeDiagrams ? '' : '-tiny');
const version = packageVersion + (includeLargeFeatures ? '' : '-tiny');
const MAX_TEXTLENGTH = 50_000;
const MAX_TEXTLENGTH_EXCEEDED_MSG =

View File

@@ -1,2 +1,2 @@
// eslint-disable-next-line no-var
declare var includeLargeDiagrams: boolean;
declare var includeLargeFeatures: boolean;