Skip to content
Snippets Groups Projects
Commit 39d18642 authored by François Grand's avatar François Grand
Browse files

refactor: turn MermaidUtil.isMermaidId() to more general isMermaidEqualIds()

refs #318
parent 44a24a47
No related branches found
No related tags found
No related merge requests found
......@@ -134,7 +134,7 @@ export class PreBarrage extends Nub {
if (uid !== undefined) {
let pos = 0;
for (const c of this.children) {
if (MermaidUtil.isMermaidId(c.uid, uid)) {
if (MermaidUtil.isMermaidEqualIds(c.uid, uid)) {
res.child = c;
res.position = pos;
break;
......
......@@ -3,16 +3,25 @@
*/
export class MermaidUtil {
/**
* check if an id is a Mermaid generated id
* @param id to check. Can be equal to the original,graph provided id or Mermaid transformed (ie. flowchart-id-xx)
* @param ref reference id
* check if two ids are equal in a Mermaid way
* @param id1 first id to compare. Can be equal to the original,graph provided id or Mermaid transformed (ie. flowchart-id-xx)
* @param id2 second to compare (same remarks)
*/
public static isMermaidId(id: string, ref: string): boolean {
if (id === ref) {
public static isMermaidEqualIds(id1: string, id2: string): boolean {
if (id1 === id2) {
return true;
}
const mid = "flowchart-" + id + "-"; // Mermaid generated element id
return ref.startsWith(mid);
const mid = "flowchart-" + id1 + "-"; // Mermaid generated element id
if (id2.startsWith(mid)) {
return true;
}
const mid2 = "flowchart-" + id2 + "-"; // so the same in reverse order
if (mid2.startsWith(id1)) {
return true;
}
return false;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment