chore(katex): lint:fix

This commit is contained in:
NicolasNewman 2023-02-13 16:02:49 -06:00
parent fb5d80a7a1
commit bbc6eb6ee7
3 changed files with 33 additions and 22 deletions

View File

@ -22,7 +22,12 @@ export const setConf = function (cnf: any) {
* @param mermaidVersion - The version * @param mermaidVersion - The version
* @param error - The caught error * @param error - The caught error
*/ */
export const draw = (_text: string, id: string, mermaidVersion: string, error: Error | null = null) => { export const draw = (
_text: string,
id: string,
mermaidVersion: string,
error: Error | null = null
) => {
try { try {
log.debug('Renering svg for syntax error\n'); log.debug('Renering svg for syntax error\n');

View File

@ -59,11 +59,13 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) {
if (evaluate(getConfig().flowchart.htmlLabels)) { if (evaluate(getConfig().flowchart.htmlLabels)) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
const node = { const node = {
label: vertexText.replace( label: vertexText
/fa[blrs]?:fa-[\w-]+/g, .replace(/fa[blrs]?:fa-[\w-]+/g, (s) => `<i class='${s.replace(':', ' ')}'></i>`)
(s) => `<i class='${s.replace(':', ' ')}'></i>` .replace(/\$\$(.*)\$\$/g, (r, c) =>
).replace(/\$\$(.*)\$\$/g, (r, c) => katex
katex.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' }).replace(/\n/g, ' ').replace(/<annotation.*<\/annotation>/g, '') .renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' })
.replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
), ),
}; };
vertexNode = addHtmlLabel(svg, node).node(); vertexNode = addHtmlLabel(svg, node).node();
@ -147,7 +149,8 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) {
const labelText = vertexText.replace(/\$\$(.*)\$\$/g, (r, c) => const labelText = vertexText.replace(/\$\$(.*)\$\$/g, (r, c) =>
katex katex
.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' }) .renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' })
.replace(/\n/g, ' ').replace(/<annotation.*<\/annotation>/g, '') .replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
); );
// Add the node // Add the node
g.setNode(vertex.id, { g.setNode(vertex.id, {
@ -319,7 +322,10 @@ export const addEdges = function (edges, g, diagObj) {
edgeData.label = edge.text edgeData.label = edge.text
.replace(common.lineBreakRegex, '\n') .replace(common.lineBreakRegex, '\n')
.replace(/\$\$(.*)\$\$/g, (r, c) => .replace(/\$\$(.*)\$\$/g, (r, c) =>
katex.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' }).replace(/\n/g, ' ').replace(/<annotation.*<\/annotation>/g, '') katex
.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' })
.replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
); );
if (edge.style === undefined) { if (edge.style === undefined) {

View File

@ -58,13 +58,13 @@ export const addVertices = function (vert, g, svgId, root, _doc, diagObj) {
if (evaluate(getConfig().flowchart.htmlLabels)) { if (evaluate(getConfig().flowchart.htmlLabels)) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
const node = { const node = {
label: vertexText.replace( label: vertexText
/fa[blrs]?:fa-[\w-]+/g, .replace(/fa[blrs]?:fa-[\w-]+/g, (s) => `<i class='${s.replace(':', ' ')}'></i>`)
(s) => `<i class='${s.replace(':', ' ')}'></i>` .replace(/\$\$(.*)\$\$/g, (r, c) =>
).replace(/\$\$(.*)\$\$/g, (r, c) =>
katex katex
.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' }) .renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' })
.replace(/\n/g, ' ').replace(/<annotation.*<\/annotation>/g, '') .replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
), ),
}; };
vertexNode = addHtmlLabel(svg, node).node(); vertexNode = addHtmlLabel(svg, node).node();
@ -244,13 +244,13 @@ export const addEdges = function (edges, g, diagObj) {
edgeData.labelType = 'html'; edgeData.labelType = 'html';
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
}">${edge.text.replace( }">${edge.text
/fa[blrs]?:fa-[\w-]+/g, .replace(/fa[blrs]?:fa-[\w-]+/g, (s) => `<i class='${s.replace(':', ' ')}'></i>`)
(s) => `<i class='${s.replace(':', ' ')}'></i>` .replace(/\$\$(.*)\$\$/g, (r, c) =>
).replace(/\$\$(.*)\$\$/g, (r, c) =>
katex katex
.renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' }) .renderToString(c, { throwOnError: true, displayMode: true, output: 'mathml' })
.replace(/\n/g, ' ').replace(/<annotation.*<\/annotation>/g, '') .replace(/\n/g, ' ')
.replace(/<annotation.*<\/annotation>/g, '')
)}</span>`; )}</span>`;
} else { } else {
edgeData.labelType = 'text'; edgeData.labelType = 'text';