Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Hashtags in Timeline Titles, Sections, and Events #5399

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/mermaid/src/diagrams/timeline/parser/timeline.jison
Expand Up @@ -18,18 +18,18 @@
\#[^\n]* /* skip comments */

"timeline" return 'timeline';
"title"\s[^#\n;]+ return 'title';
"title"\s[^\n;]+ return 'title';
accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; }
<acc_title>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; }
accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; }
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}
<acc_descr_multiline>[\}] { this.popState(); }
<acc_descr_multiline>[^\}]* return "acc_descr_multiline_value";
"section"\s[^#:\n;]+ return 'section';
"section"\s[^:\n;]+ return 'section';

// event starting with "==>" keyword
":"\s[^#:\n;]+ return 'event';
":"\s[^:\n;]+ return 'event';
[^#:\n;]+ return 'period';


Expand Down
16 changes: 16 additions & 0 deletions packages/mermaid/src/diagrams/timeline/timeline.spec.js
@@ -1,5 +1,6 @@
import { parser as timeline } from './parser/timeline.jison';
import * as timelineDB from './timelineDb.js';
import * as commonDb from '../common/commonDb.js';
import { setLogLevel } from '../../diagram-api/diagramAPI.js';

describe('when parsing a timeline ', function () {
Expand Down Expand Up @@ -98,5 +99,20 @@ describe('when parsing a timeline ', function () {
}
});
});

it('TL-6 should handle a title, section, task, and events with hashtags', function () {
let str = `timeline
title #my#title#
section #a#bc-123#
task1: #ev#ent1# : #ev#ent2# : #ev#ent3#
`;
timeline.parse(str);
expect(commonDb.getDiagramTitle()).equal('#my#title#');
expect(timelineDB.getSections()).to.deep.equal(['#a#bc-123#']);
expect(timelineDB.getTasks()[0].task).equal('task1');
expect(timelineDB.getTasks()[0].events[0]).equal('#ev#ent1# ');
expect(timelineDB.getTasks()[0].events[1]).equal('#ev#ent2# ');
expect(timelineDB.getTasks()[0].events[2]).equal('#ev#ent3#');
});
});
});