mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-02 21:59:39 +02:00
Updated gantt parsing with the new syntax
This commit is contained in:
@@ -15,12 +15,24 @@
|
||||
%x type_directive
|
||||
%x arg_directive
|
||||
%x close_directive
|
||||
%x acc_title
|
||||
%x acc_descr
|
||||
%x acc_descr_multiline
|
||||
%%
|
||||
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
||||
<open_directive>((?:(?!\}\%\%)[^:.])*) { this.begin('type_directive'); return 'type_directive'; }
|
||||
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||
|
||||
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";
|
||||
|
||||
\%\%(?!\{)*[^\n]* /* skip comments */
|
||||
[^\}]\%\%*[^\n]* /* skip comments */
|
||||
\%\%*[^\n]*[\n]* /* do nothing */
|
||||
@@ -117,8 +129,9 @@ statement
|
||||
| includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);}
|
||||
| todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);}
|
||||
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
||||
| accDescription {yy.setAccDescription($1.substr(15));$$=$1.substr(15);}
|
||||
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||
| acc_title acc_title_value { $$=$2.trim();yy.setTitle($$); }
|
||||
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
|
||||
| acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } | section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||
| clickStatement
|
||||
| taskTxt taskData {yy.addTask($1,$2);$$='task';}
|
||||
| directive
|
||||
|
@@ -157,18 +157,35 @@ describe('when parsing a gantt diagram it', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow for a title and accDescription', function () {
|
||||
it('should allow for a accessibility title and description (accDescr)', function () {
|
||||
const expectedTitle = 'Gantt Diagram';
|
||||
const expectedAccDescription = 'Tasks for Q4';
|
||||
const ganttString =
|
||||
'gantt\n' +
|
||||
`title ${expectedTitle}\n` +
|
||||
`accDescription ${expectedAccDescription}\n` +
|
||||
'dateFormat YYYY-MM-DD\n' +
|
||||
'section Section\n' +
|
||||
'A task :a1, 2014-01-01, 30d\n';
|
||||
const ganttString = `gantt
|
||||
accTitle: ${expectedTitle}
|
||||
accDescr: ${expectedAccDescription}
|
||||
dateFormat YYYY-MM-DD
|
||||
section Section
|
||||
A task :a1, 2014-01-01, 30d\n`;
|
||||
|
||||
const output = parser.parse(ganttString);
|
||||
parser.parse(ganttString);
|
||||
|
||||
expect(ganttDb.getTitle()).toBe(expectedTitle);
|
||||
expect(ganttDb.getAccDescription()).toBe(expectedAccDescription);
|
||||
});
|
||||
it('should allow for a accessibility title and multiline description (accDescr)', function () {
|
||||
const expectedTitle = 'Gantt Diagram';
|
||||
const expectedAccDescription = `Tasks for Q4 row1
|
||||
row2`;
|
||||
const ganttString = `gantt
|
||||
accTitle: ${expectedTitle}
|
||||
accDescr {
|
||||
${expectedAccDescription}
|
||||
}
|
||||
dateFormat YYYY-MM-DD
|
||||
section Section
|
||||
A task :a1, 2014-01-01, 30d\n`;
|
||||
|
||||
parser.parse(ganttString);
|
||||
|
||||
expect(ganttDb.getTitle()).toBe(expectedTitle);
|
||||
expect(ganttDb.getAccDescription()).toBe(expectedAccDescription);
|
||||
|
Reference in New Issue
Block a user