Fix for issue in classdiagram-v2 from the typescript updates

This commit is contained in:
Knut Sveidqvist
2022-10-07 12:17:35 +02:00
parent 802407c8ae
commit 047e15951a
2 changed files with 26 additions and 8 deletions

View File

@@ -56,6 +56,23 @@
<body> <body>
<div>Security check</div> <div>Security check</div>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid">
classDiagram
direction LR
class Student {
-idCard : IdCard
}
class IdCard{
-id : int
-name : string
}
class Bike{
-id : int
-name : string
}
Student "1" --o "1" IdCard : carries
Student "1" --o "1" Bike : rides
</pre>
<pre id="diagram" class="mermaid2">
mindmap mindmap
root root
A A
@@ -81,13 +98,14 @@ mindmap
::icon(mdi mdi-fire) ::icon(mdi mdi-fire)
gc7((grand<br/>grand<br/>child 8)) gc7((grand<br/>grand<br/>child 8))
</pre> </pre>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid2">
example-diagram example-diagram
</pre> </pre>
<!-- <div id="cy"></div> --> <!-- <div id="cy"></div> -->
<!-- <script src="http://localhost:9000/packages/mermaid-mindmap/dist/mermaid-mindmap-detector.js"></script> --> <!-- <script src="http://localhost:9000/packages/mermaid-mindmap/dist/mermaid-mindmap-detector.js"></script> -->
<!-- <script src="./mermaid-example-diagram-detector.js"></script> --> <!-- <script src="./mermaid-example-diagram-detector.js"></script> -->
<!-- <script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script> -->
<script src="./mermaid.js"></script> <script src="./mermaid.js"></script>
<script> <script>

View File

@@ -347,9 +347,10 @@ const buildMethodDisplay = function (parsedText) {
}; };
const buildLegacyDisplay = function (text) { const buildLegacyDisplay = function (text) {
// if for some reason we don't have any match, use old format to parse text // if for some reason we dont have any match, use old format to parse text
let displayText = ''; let displayText = '';
let cssStyle = ''; let cssStyle = '';
let memberText = '';
let returnType = ''; let returnType = '';
let methodStart = text.indexOf('('); let methodStart = text.indexOf('(');
let methodEnd = text.indexOf(')'); let methodEnd = text.indexOf(')');
@@ -370,29 +371,28 @@ const buildLegacyDisplay = function (text) {
} }
const parameters = text.substring(methodStart + 1, methodEnd); const parameters = text.substring(methodStart + 1, methodEnd);
const classifier = text.substring(methodEnd + 1, methodEnd + 2); const classifier = text.substring(methodEnd + 1, 1);
cssStyle = parseClassifier(classifier); cssStyle = parseClassifier(classifier);
displayText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')'; displayText = visibility + methodName + '(' + parseGenericTypes(parameters.trim()) + ')';
if (methodEnd <= text.length) { if (methodEnd < memberText.length) {
returnType = text.substring(methodEnd + 2).trim(); returnType = text.substring(methodEnd + 2).trim();
if (returnType !== '') { if (returnType !== '') {
returnType = ' : ' + parseGenericTypes(returnType); returnType = ' : ' + parseGenericTypes(returnType);
displayText += returnType; displayText += returnType;
} }
}
} else { } else {
// finally - if all else fails, just send the text back as written (other than parsing for generic types) // finally - if all else fails, just send the text back as written (other than parsing for generic types)
displayText = parseGenericTypes(text); displayText = parseGenericTypes(text);
} }
}
return { return {
displayText, displayText,
cssStyle, cssStyle,
}; };
}; };
/** /**
* Adds a <tspan> for a member in a diagram * Adds a <tspan> for a member in a diagram
* *