chore(katex): included uncommited files

This commit is contained in:
NicolasNewman
2023-05-31 16:42:54 +09:00
parent cf54ddc62b
commit 077cc653d0
2 changed files with 10 additions and 5 deletions

View File

@@ -174,7 +174,7 @@ export const parseGenericTypes = function (text: string): string {
// TODO: find a better method for detecting support. This interface was added in the MathML 4 spec. // TODO: find a better method for detecting support. This interface was added in the MathML 4 spec.
// Firefox versions between [4,71] (0.47%) and Safari versions between [5,13.4] (0.17%) don't have this interface implemented but MathML is supported // Firefox versions between [4,71] (0.47%) and Safari versions between [5,13.4] (0.17%) don't have this interface implemented but MathML is supported
export const isMathMLSupported = window.MathMLElement !== undefined; export const isMathMLSupported = () => window.MathMLElement !== undefined;
export const katexRegex = /\$\$(.*)\$\$/g; export const katexRegex = /\$\$(.*)\$\$/g;
@@ -223,7 +223,7 @@ export const calculateMathMLDimensions = (text: string, config: MermaidConfig) =
* @returns String containing MathML if KaTeX is supported, or an error message if it is not and stylesheets aren't present * @returns String containing MathML if KaTeX is supported, or an error message if it is not and stylesheets aren't present
*/ */
export const renderKatex = (text: string, config: MermaidConfig): string => { export const renderKatex = (text: string, config: MermaidConfig): string => {
if (isMathMLSupported || (!isMathMLSupported && config.legacyMathML)) { if (isMathMLSupported() || (!isMathMLSupported() && config.legacyMathML)) {
return text return text
.split(lineBreakRegex) .split(lineBreakRegex)
.map((line) => .map((line) =>
@@ -241,7 +241,7 @@ export const renderKatex = (text: string, config: MermaidConfig): string => {
.renderToString(c, { .renderToString(c, {
throwOnError: true, throwOnError: true,
displayMode: true, displayMode: true,
output: isMathMLSupported ? 'mathml' : 'htmlAndMathml', output: isMathMLSupported() ? 'mathml' : 'htmlAndMathml',
}) })
.replace(/\n/g, ' ') .replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '') .replace(/<annotation.*<\/annotation>/g, '')

View File

@@ -61,7 +61,8 @@ export const addVertices = function (vert, g, svgId, root, _doc, diagObj) {
vertexText.replace( vertexText.replace(
/fa[blrs]?:fa-[\w-]+/g, /fa[blrs]?:fa-[\w-]+/g,
(s) => `<i class='${s.replace(':', ' ')}'></i>` (s) => `<i class='${s.replace(':', ' ')}'></i>`
) ),
getConfig()
), ),
}; };
vertexNode = addHtmlLabel(svg, node).node(); vertexNode = addHtmlLabel(svg, node).node();
@@ -242,7 +243,11 @@ export const addEdges = function (edges, g, diagObj) {
edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}" style="${ edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}" style="${
edgeData.labelStyle edgeData.labelStyle
}">${renderKatex( }">${renderKatex(
edge.text.replace(/fa[blrs]?:fa-[\w-]+/g, (s) => `<i class='${s.replace(':', ' ')}'></i>`) edge.text.replace(
/fa[blrs]?:fa-[\w-]+/g,
(s) => `<i class='${s.replace(':', ' ')}'></i>`
),
getConfig()
)}</span>`; )}</span>`;
} else { } else {
edgeData.labelType = 'text'; edgeData.labelType = 'text';