Merge pull request #6820 from kriss-u/fix/6815_escape_namespace_class_diagram

fix: add classLiteral to the language for class diagram namespace
This commit is contained in:
Shubham P
2025-08-06 08:12:54 +00:00
committed by GitHub
4 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'mermaid': patch
---
fix: Add escaped class literal name on namespace

View File

@@ -512,4 +512,17 @@ describe('Class diagram', () => {
); );
}); });
}); });
it('should handle backticks for namespace and class names', () => {
imgSnapshotTest(
`
classDiagram
namespace \`A::B\` {
class \`IPC::Sender\`
}
RenderProcessHost --|> \`IPC::Sender\`
`,
{}
);
});
}); });

View File

@@ -15,4 +15,12 @@ describe('class diagram', function () {
expect(() => parser.parse(`classDiagram\nnamespace ${prop} {\n\tclass A\n}`)).not.toThrow(); expect(() => parser.parse(`classDiagram\nnamespace ${prop} {\n\tclass A\n}`)).not.toThrow();
}); });
}); });
describe('backtick escaping', function () {
it('should handle backtick-quoted namespace names', function () {
expect(() =>
parser.parse(`classDiagram\nnamespace \`A::B\` {\n\tclass \`IPC::Sender\`\n}`)
).not.toThrow();
});
});
}); });

View File

@@ -242,6 +242,7 @@ classLabel
namespaceName namespaceName
: alphaNumToken { $$=$1; } : alphaNumToken { $$=$1; }
| classLiteralName { $$=$1; }
| alphaNumToken DOT namespaceName { $$=$1+'.'+$3; } | alphaNumToken DOT namespaceName { $$=$1+'.'+$3; }
| alphaNumToken namespaceName { $$=$1+$2; } | alphaNumToken namespaceName { $$=$1+$2; }
; ;