mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-10 07:44:40 +01:00
modifications to generic parser
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
setDiagramTitle,
|
||||
getDiagramTitle,
|
||||
} from '../../commonDb.js';
|
||||
import { ClassMember } from './classTypes.js';
|
||||
import type {
|
||||
ClassRelation,
|
||||
ClassNode,
|
||||
@@ -22,7 +23,6 @@ import type {
|
||||
ClassMap,
|
||||
NamespaceMap,
|
||||
NamespaceNode,
|
||||
ClassMember,
|
||||
} from './classTypes.js';
|
||||
|
||||
const MERMAID_DOM_ID_PREFIX = 'classId-';
|
||||
|
||||
@@ -181,46 +181,31 @@ export const getMin = function (...values: number[]): number {
|
||||
export const parseGenericTypes = function (input: string): string {
|
||||
const inputSets = input.split(/(,)/);
|
||||
const output = [];
|
||||
let finalResult = '';
|
||||
let skipNextSet = false;
|
||||
|
||||
for (let i = 0; i < inputSets.length; i++) {
|
||||
const previousIndex = i - 1;
|
||||
const nextIndex = i + 1;
|
||||
let thisSet = inputSets[i];
|
||||
|
||||
// based on logic below - if we have already combined this set with the previous, we want to skip it
|
||||
if (skipNextSet) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if the original input included a value such as "~K, V~"", these will be split into
|
||||
// an array of ["~K",","," V~"].
|
||||
// This means that on each call of processSet, there will only be 1 ~ present
|
||||
// To account for this, if we encounter a ",", we are checking the previous and next sets in the array
|
||||
// to see if they contain matching ~'s
|
||||
// in which case we are assuming that they should be rejoined and sent to be processed
|
||||
// we are also removing
|
||||
if (thisSet === ',' && previousIndex > -1 && nextIndex <= inputSets.length) {
|
||||
if (thisSet === ',' && i > 0 && i + 1 < inputSets.length) {
|
||||
const previousSet = inputSets[i - 1];
|
||||
const nextSet = inputSets[i + 1];
|
||||
|
||||
if (shouldCombineSets(previousSet, nextSet)) {
|
||||
thisSet = previousSet + ',' + nextSet;
|
||||
skipNextSet = true;
|
||||
// remove previous set
|
||||
i++; // Move the index forward to skip the next iteration since we're combining sets
|
||||
output.pop();
|
||||
}
|
||||
} else {
|
||||
skipNextSet = false;
|
||||
}
|
||||
|
||||
output.push(processSet(thisSet));
|
||||
}
|
||||
|
||||
finalResult = output.join('');
|
||||
// one last scan to see if any sets were missed
|
||||
finalResult = processSet(finalResult);
|
||||
return finalResult;
|
||||
return output.join('');
|
||||
};
|
||||
|
||||
const shouldCombineSets = (previousSet: string, nextSet: string): boolean => {
|
||||
@@ -234,7 +219,6 @@ const processSet = (input: string): string => {
|
||||
const chars = [...input];
|
||||
const tildeCount = chars.reduce((count, char) => (char === '~' ? count + 1 : count), 0);
|
||||
|
||||
// ignoring any
|
||||
if (tildeCount <= 1) {
|
||||
return input;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user