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