mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Add special handling to avoid markdown to HTML issues
This commit is contained in:
parent
191e4217fc
commit
20a58d6dbb
@ -121,20 +121,45 @@ export class ClassMember {
|
||||
}
|
||||
|
||||
this.classifier = potentialClassifier;
|
||||
this.text = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`; //.replaceAll('~', '<');
|
||||
this.text = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`;
|
||||
const combinedText = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`;
|
||||
if (combinedText.includes('~')) {
|
||||
let count = (combinedText.match(/~/g) ?? []).length;
|
||||
const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length;
|
||||
let count = numOfTildes;
|
||||
if (count !== 1) {
|
||||
const odd = count % 2 > 0;
|
||||
|
||||
// Replace all '~' with '>'
|
||||
let replacedRaw = combinedText.replaceAll('~', '>');
|
||||
// Replace all '~' with '>'
|
||||
let replacedRaw = combinedText.substring(1).replaceAll('~', '>');
|
||||
|
||||
// Replace the first half of '>' with '<'
|
||||
while (count > 0) {
|
||||
replacedRaw = replacedRaw.replace('>', '<');
|
||||
count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2
|
||||
// Replace the first half of '>' with '<'
|
||||
while (count > 0) {
|
||||
replacedRaw = replacedRaw.replace('>', '<');
|
||||
count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2
|
||||
}
|
||||
if (odd) {
|
||||
if (this.memberType === 'method') {
|
||||
replacedRaw = replacedRaw.replace('<', '~');
|
||||
} else {
|
||||
// Replace the middle occurrence of '<' with '~'
|
||||
const ltOccurrences = replacedRaw.match(/</g) ?? [];
|
||||
if (ltOccurrences.length > 1) {
|
||||
let ltCount = 0;
|
||||
|
||||
replacedRaw = replacedRaw.replace(/</g, (match) => {
|
||||
ltCount++;
|
||||
return ltCount === ltOccurrences.length ? '~' : match;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
this.text = this.text.charAt(0) + replacedRaw;
|
||||
if (this.visibility === '~') {
|
||||
this.text = this.text.replace('~', '\\~');
|
||||
}
|
||||
} else if (count === 1 && this.visibility === '~') {
|
||||
this.text = this.text.replace('~', '\\~');
|
||||
}
|
||||
this.text = replacedRaw;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user