mirror of
https://github.com/mermaid-js/mermaid.git
synced 2024-08-28 21:16:07 +02:00
trim state ids as they are processed by docTranslator
This commit is contained in:
parent
90d9724d1a
commit
e7b4f7f6ca
1 changed files with 38 additions and 32 deletions
|
@ -94,9 +94,14 @@ const docTranslator = (parent, node, first) => {
|
|||
docTranslator(parent, node.state1, true);
|
||||
docTranslator(parent, node.state2, false);
|
||||
} else {
|
||||
if (node.stmt === STMT_STATE && node.id === '[*]') {
|
||||
node.id = first ? parent.id + '_start' : parent.id + '_end';
|
||||
node.start = first;
|
||||
if (node.stmt === STMT_STATE) {
|
||||
if (node.id === '[*]') {
|
||||
node.id = first ? parent.id + '_start' : parent.id + '_end';
|
||||
node.start = first;
|
||||
} else {
|
||||
// This is just a plain state, not a start or end
|
||||
node.id = node.id.trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (node.doc) {
|
||||
|
@ -170,7 +175,7 @@ const extract = (_doc) => {
|
|||
switch (item.stmt) {
|
||||
case STMT_STATE:
|
||||
addState(
|
||||
item.id,
|
||||
item.id.trim(),
|
||||
item.type,
|
||||
item.doc,
|
||||
item.description,
|
||||
|
@ -184,10 +189,10 @@ const extract = (_doc) => {
|
|||
addRelation(item.state1, item.state2, item.description);
|
||||
break;
|
||||
case STMT_CLASSDEF:
|
||||
addStyleClass(item.id, item.classes);
|
||||
addStyleClass(item.id.trim(), item.classes);
|
||||
break;
|
||||
case STMT_APPLYCLASS:
|
||||
setCssClass(item.id, item.styleClass);
|
||||
setCssClass(item.id.trim(), item.styleClass);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -215,11 +220,12 @@ export const addState = function (
|
|||
styles = null,
|
||||
textStyles = null
|
||||
) {
|
||||
const trimmedId = id?.trim();
|
||||
// add the state if needed
|
||||
if (currentDocument.states[id] === undefined) {
|
||||
log.info('Adding state ', id, descr);
|
||||
currentDocument.states[id] = {
|
||||
id: id,
|
||||
if (currentDocument.states[trimmedId] === undefined) {
|
||||
log.info('Adding state ', trimmedId, descr);
|
||||
currentDocument.states[trimmedId] = {
|
||||
id: trimmedId,
|
||||
descriptions: [],
|
||||
type,
|
||||
doc,
|
||||
|
@ -229,49 +235,49 @@ export const addState = function (
|
|||
textStyles: [],
|
||||
};
|
||||
} else {
|
||||
if (!currentDocument.states[id].doc) {
|
||||
currentDocument.states[id].doc = doc;
|
||||
if (!currentDocument.states[trimmedId].doc) {
|
||||
currentDocument.states[trimmedId].doc = doc;
|
||||
}
|
||||
if (!currentDocument.states[id].type) {
|
||||
currentDocument.states[id].type = type;
|
||||
if (!currentDocument.states[trimmedId].type) {
|
||||
currentDocument.states[trimmedId].type = type;
|
||||
}
|
||||
}
|
||||
|
||||
if (descr) {
|
||||
log.info('Setting state description', id, descr);
|
||||
log.info('Setting state description', trimmedId, descr);
|
||||
if (typeof descr === 'string') {
|
||||
addDescription(id, descr.trim());
|
||||
addDescription(trimmedId, descr.trim());
|
||||
}
|
||||
|
||||
if (typeof descr === 'object') {
|
||||
descr.forEach((des) => addDescription(id, des.trim()));
|
||||
descr.forEach((des) => addDescription(trimmedId, des.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
if (note) {
|
||||
currentDocument.states[id].note = note;
|
||||
currentDocument.states[id].note.text = common.sanitizeText(
|
||||
currentDocument.states[id].note.text,
|
||||
currentDocument.states[trimmedId].note = note;
|
||||
currentDocument.states[trimmedId].note.text = common.sanitizeText(
|
||||
currentDocument.states[trimmedId].note.text,
|
||||
configApi.getConfig()
|
||||
);
|
||||
}
|
||||
|
||||
if (classes) {
|
||||
log.info('Setting state classes', id, classes);
|
||||
log.info('Setting state classes', trimmedId, classes);
|
||||
const classesList = typeof classes === 'string' ? [classes] : classes;
|
||||
classesList.forEach((klass) => setCssClass(id, klass.trim()));
|
||||
classesList.forEach((klass) => setCssClass(trimmedId, klass.trim()));
|
||||
}
|
||||
|
||||
if (styles) {
|
||||
log.info('Setting state styles', id, styles);
|
||||
log.info('Setting state styles', trimmedId, styles);
|
||||
const stylesList = typeof styles === 'string' ? [styles] : styles;
|
||||
stylesList.forEach((style) => setStyle(id, style.trim()));
|
||||
stylesList.forEach((style) => setStyle(trimmedId, style.trim()));
|
||||
}
|
||||
|
||||
if (textStyles) {
|
||||
log.info('Setting state styles', id, styles);
|
||||
log.info('Setting state styles', trimmedId, styles);
|
||||
const textStylesList = typeof textStyles === 'string' ? [textStyles] : textStyles;
|
||||
textStylesList.forEach((textStyle) => setTextStyle(id, textStyle.trim()));
|
||||
textStylesList.forEach((textStyle) => setTextStyle(trimmedId, textStyle.trim()));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -368,10 +374,10 @@ function endTypeIfNeeded(id = '', type = DEFAULT_STATE_TYPE) {
|
|||
* @param relationTitle
|
||||
*/
|
||||
export function addRelationObjs(item1, item2, relationTitle) {
|
||||
let id1 = startIdIfNeeded(item1.id);
|
||||
let type1 = startTypeIfNeeded(item1.id, item1.type);
|
||||
let id2 = startIdIfNeeded(item2.id);
|
||||
let type2 = startTypeIfNeeded(item2.id, item2.type);
|
||||
let id1 = startIdIfNeeded(item1.id.trim());
|
||||
let type1 = startTypeIfNeeded(item1.id.trim(), item1.type);
|
||||
let id2 = startIdIfNeeded(item2.id.trim());
|
||||
let type2 = startTypeIfNeeded(item2.id.trim(), item2.type);
|
||||
|
||||
addState(
|
||||
id1,
|
||||
|
@ -412,9 +418,9 @@ export const addRelation = function (item1, item2, title) {
|
|||
if (typeof item1 === 'object') {
|
||||
addRelationObjs(item1, item2, title);
|
||||
} else {
|
||||
const id1 = startIdIfNeeded(item1);
|
||||
const id1 = startIdIfNeeded(item1.trim());
|
||||
const type1 = startTypeIfNeeded(item1);
|
||||
const id2 = endIdIfNeeded(item2);
|
||||
const id2 = endIdIfNeeded(item2.trim());
|
||||
const type2 = endTypeIfNeeded(item2);
|
||||
|
||||
addState(id1, type1);
|
||||
|
|
Loading…
Reference in a new issue