Skip to content

Commit

Permalink
feat(er): use square brackets to add aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tomperr committed Aug 22, 2023
1 parent cc8b457 commit a7ae1b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions demos/er.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@

<pre class="mermaid">
erDiagram
p as Person {
string firstName
string lastName
p[Person] {
string firstName
string lastName
}
a as "Customer Account" {
string email
a["Customer Account"] {
string email
}
p ||--o| a : has
</pre>
Expand Down
10 changes: 5 additions & 5 deletions docs/syntax/entityRelationshipDiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,27 @@ The `type` values must begin with an alphabetic character and may contain digits

### Entity Name Aliases (v\<MERMAID_RELEASE_VERSION>+)

An alias can be added to an entity using `as` keyword. If provided, the alias will be showed in the diagram instead of the entity name.
An alias can be added to an entity using square brackets. If provided, the alias will be showed in the diagram instead of the entity name.

```mermaid-example
erDiagram
p as Person {
p[Person] {
string firstName
string lastName
}
a as "Customer Account" {
a["Customer Account"] {
string email
}
p ||--o| a : has
```

```mermaid
erDiagram
p as Person {
p[Person] {
string firstName
string lastName
}
a as "Customer Account" {
a["Customer Account"] {
string email
}
p ||--o| a : has
Expand Down
11 changes: 6 additions & 5 deletions packages/mermaid/src/diagrams/er/parser/erDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
<block>[\n]+ /* nothing */
<block>"}" { this.popState(); return 'BLOCK_STOP'; }
<block>. return yytext[0];
"[" return 'SQS';
"]" return 'SQE';

"one or zero" return 'ZERO_OR_ONE';
"one or more" return 'ONE_OR_MORE';
Expand Down Expand Up @@ -62,7 +64,6 @@ o\{ return 'ZERO_OR_MORE';
\-\- return 'IDENTIFYING';
"to" return 'IDENTIFYING';
"optionally to" return 'NON_IDENTIFYING';
"as" return 'ALIAS';
\.\- return 'NON_IDENTIFYING';
\-\. return 'NON_IDENTIFYING';
[A-Za-z][A-Za-z0-9\-_]* return 'ALPHANUM';
Expand Down Expand Up @@ -114,15 +115,15 @@ statement
}
| entityName BLOCK_START BLOCK_STOP { yy.addEntity($1); }
| entityName { yy.addEntity($1); }
| entityName ALIAS entityName BLOCK_START attributes BLOCK_STOP
| entityName SQS entityName SQE BLOCK_START attributes BLOCK_STOP
{
/* console.log('detected block'); */
yy.addEntity($1, $3);
yy.addAttributes($1, $5);
yy.addAttributes($1, $6);
/* console.log('handled block'); */
}
| entityName ALIAS entityName BLOCK_START BLOCK_STOP { yy.addEntity($1, $3); }
| entityName ALIAS entityName { yy.addEntity($1, $3); }
| entityName SQS entityName SQE BLOCK_START BLOCK_STOP { yy.addEntity($1, $3); }
| entityName SQS entityName SQE { yy.addEntity($1, $3); }
| title title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('when parsing ER diagram it...', function () {
it('can have an alias', function () {
const entity = 'foo';
const alias = 'bar';
erDiagram.parser.parse(`erDiagram\n${entity} as "${alias}"\n`);
erDiagram.parser.parse(`erDiagram\n${entity}["${alias}"]\n`);
const entities = erDb.getEntities();
expect(entities.hasOwnProperty(entity)).toBe(true);
expect(entities[entity].alias).toBe(alias);
Expand Down
6 changes: 3 additions & 3 deletions packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ The `type` values must begin with an alphabetic character and may contain digits

### Entity Name Aliases (v<MERMAID_RELEASE_VERSION>+)

An alias can be added to an entity using `as` keyword. If provided, the alias will be showed in the diagram instead of the entity name.
An alias can be added to an entity using square brackets. If provided, the alias will be showed in the diagram instead of the entity name.

```mermaid-example
erDiagram
p as Person {
p[Person] {
string firstName
string lastName
}
a as "Customer Account" {
a["Customer Account"] {
string email
}
p ||--o| a : has
Expand Down

0 comments on commit a7ae1b6

Please sign in to comment.