mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 23:39:50 +02:00
Update text logic and change workaround for markdown
This commit is contained in:
@@ -123,42 +123,13 @@ export class ClassMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.classifier = potentialClassifier;
|
this.classifier = potentialClassifier;
|
||||||
// TODO: Right now getting rid of spacing in id / name, TODO: Add optional spacing
|
// Preserve one space only
|
||||||
const combinedText = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`;
|
this.id = this.id.startsWith(' ') ? ' ' + this.id.trim() : this.id.trim();
|
||||||
this.text = combinedText;
|
|
||||||
if (combinedText.includes('~')) {
|
|
||||||
const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length;
|
|
||||||
let count = numOfTildes;
|
|
||||||
if (count !== 1) {
|
|
||||||
const odd = count % 2 > 0;
|
|
||||||
|
|
||||||
// Replace all '~' with '>'
|
const combinedText = `${this.visibility ? '\\' + this.visibility : ''}${parseGenericTypes(this.id)}${this.memberType === 'method' ? `(${parseGenericTypes(this.parameters)})${this.returnType ? ' : ' + parseGenericTypes(this.returnType) : ''}` : ''}`;
|
||||||
let replacedRaw = combinedText.substring(1).replaceAll('~', '>');
|
this.text = combinedText.replaceAll('<', '<').replaceAll('>', '>');
|
||||||
|
if (this.text.startsWith('\\<')) {
|
||||||
// Replace the first half of '>' with '<'
|
this.text = this.text.replace('\\<', '~');
|
||||||
while (count > 0) {
|
|
||||||
replacedRaw = replacedRaw.replace('>', '<');
|
|
||||||
count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2
|
|
||||||
}
|
|
||||||
if (odd) {
|
|
||||||
// Replace first occurrence.
|
|
||||||
if (this.memberType === 'method') {
|
|
||||||
replacedRaw = replacedRaw.replace('<', '~');
|
|
||||||
} else {
|
|
||||||
// Replace middle occurrence.
|
|
||||||
const ltOccurrences = replacedRaw.match(/</g) ?? [];
|
|
||||||
if (ltOccurrences.length > 1) {
|
|
||||||
let ltCount = 0;
|
|
||||||
|
|
||||||
replacedRaw = replacedRaw.replace('<', (match) => {
|
|
||||||
ltCount++;
|
|
||||||
return ltCount === ltOccurrences.length ? '~' : match;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.text = this.text.charAt(0) + replacedRaw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,6 +109,12 @@ const addText = async (
|
|||||||
textContent = node.label!;
|
textContent = node.label!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createText() will cause unwanted behavior because of classDiagram syntax so workarounds are needed
|
||||||
|
|
||||||
|
if (!useHtmlLabels && textContent.startsWith('\\')) {
|
||||||
|
textContent = textContent.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasKatex(textContent)) {
|
if (hasKatex(textContent)) {
|
||||||
useHtmlLabels = true;
|
useHtmlLabels = true;
|
||||||
}
|
}
|
||||||
@@ -126,7 +132,6 @@ const addText = async (
|
|||||||
let bbox;
|
let bbox;
|
||||||
let numberOfLines = 1;
|
let numberOfLines = 1;
|
||||||
|
|
||||||
// createText() creates unwanted behavior because of syntax, so fix
|
|
||||||
if (!useHtmlLabels) {
|
if (!useHtmlLabels) {
|
||||||
// Undo font-weight
|
// Undo font-weight
|
||||||
select(text).selectAll('tspan').attr('font-weight', '');
|
select(text).selectAll('tspan').attr('font-weight', '');
|
||||||
|
@@ -87,8 +87,6 @@ export function markdownToHTML(markdown: string, { markdownAutoWrap }: MermaidCo
|
|||||||
return `${node.text}`;
|
return `${node.text}`;
|
||||||
} else if (node.type === 'escape') {
|
} else if (node.type === 'escape') {
|
||||||
return node.text;
|
return node.text;
|
||||||
} else if (node.type === 'list') {
|
|
||||||
return node.raw;
|
|
||||||
}
|
}
|
||||||
return `Unsupported markdown: ${node.type}`;
|
return `Unsupported markdown: ${node.type}`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user