mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Updated user journey diagram parsing with the new syntax
This commit is contained in:
parent
34ffe2790b
commit
ae91f794d6
@ -1,6 +1,13 @@
|
|||||||
import mermaidAPI from '../../mermaidAPI';
|
import mermaidAPI from '../../mermaidAPI';
|
||||||
import * as configApi from '../../config';
|
import * as configApi from '../../config';
|
||||||
import common from '../common/common';
|
import common from '../common/common';
|
||||||
|
import {
|
||||||
|
setTitle,
|
||||||
|
getTitle,
|
||||||
|
getAccDescription,
|
||||||
|
setAccDescription,
|
||||||
|
clear as commonClear,
|
||||||
|
} from '../../commonDb';
|
||||||
|
|
||||||
const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig());
|
const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig());
|
||||||
|
|
||||||
@ -23,22 +30,7 @@ export const clear = function () {
|
|||||||
title = '';
|
title = '';
|
||||||
description = '';
|
description = '';
|
||||||
rawTasks.length = 0;
|
rawTasks.length = 0;
|
||||||
};
|
commonClear();
|
||||||
|
|
||||||
const setTitle = function (txt) {
|
|
||||||
title = sanitizeText(txt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTitle = function () {
|
|
||||||
return title;
|
|
||||||
};
|
|
||||||
|
|
||||||
const setAccDescription = function (txt) {
|
|
||||||
description = sanitizeText(txt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getAccDescription = function () {
|
|
||||||
return description;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addSection = function (txt) {
|
export const addSection = function (txt) {
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
%lex
|
%lex
|
||||||
%options case-insensitive
|
%options case-insensitive
|
||||||
|
%x acc_title
|
||||||
|
%x acc_descr
|
||||||
|
%x acc_descr_multiline
|
||||||
|
|
||||||
// Directive states
|
// Directive states
|
||||||
%x open_directive type_directive arg_directive
|
%x open_directive type_directive arg_directive
|
||||||
@ -25,7 +28,13 @@
|
|||||||
|
|
||||||
"journey" return 'journey';
|
"journey" return 'journey';
|
||||||
"title"\s[^#\n;]+ return 'title';
|
"title"\s[^#\n;]+ return 'title';
|
||||||
"accDescription"\s[^#\n;]+ return 'accDescription';
|
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';
|
||||||
[^#:\n;]+ return 'taskName';
|
[^#:\n;]+ return 'taskName';
|
||||||
":"[^#\n;]+ return 'taskData';
|
":"[^#\n;]+ return 'taskData';
|
||||||
@ -65,7 +74,9 @@ directive
|
|||||||
|
|
||||||
statement
|
statement
|
||||||
: title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
: title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
|
||||||
| accDescription {yy.setAccDescription($1.substring(15));$$=$1.substring(15);}
|
| 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);}
|
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||||
| taskName taskData {yy.addTask($1, $2);$$='task';}
|
| taskName taskData {yy.addTask($1, $2);$$='task';}
|
||||||
| directive
|
| directive
|
||||||
|
@ -19,15 +19,38 @@ describe('when parsing a journey diagram it', function () {
|
|||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should handle an accDescription', function () {
|
it('it should handle an accessibility description (accDescr)', function () {
|
||||||
const str =
|
const str =
|
||||||
'journey\n' +
|
'journey\n' +
|
||||||
'accDescription A user journey for family shopping\n' +
|
'accDescr: A user journey for family shopping\n' +
|
||||||
'title Adding journey diagram functionality to mermaid\n' +
|
'title Adding journey diagram functionality to mermaid\n' +
|
||||||
'section Order from website';
|
'section Order from website';
|
||||||
|
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
});
|
});
|
||||||
|
it('it should handle an accessibility multiline description (accDescr)', function () {
|
||||||
|
const str =
|
||||||
|
'journey\n' +
|
||||||
|
`accDescr {
|
||||||
|
A user journey for
|
||||||
|
family shopping
|
||||||
|
}` +
|
||||||
|
'title Adding journey diagram functionality to mermaid\n' +
|
||||||
|
'section Order from website';
|
||||||
|
|
||||||
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
|
expect(journeyDb.getAccDescription()).toBe('A user journey for\nfamily shopping');
|
||||||
|
expect(journeyDb.getTitle()).toBe('Adding journey diagram functionality to mermaid');
|
||||||
|
});
|
||||||
|
it('it should handle an accessibility title (accDescr)', function () {
|
||||||
|
const str = `journey
|
||||||
|
accTitle: The title
|
||||||
|
section Order from website`;
|
||||||
|
|
||||||
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
|
expect(journeyDb.getAccDescription()).toBe('');
|
||||||
|
expect(journeyDb.getTitle()).toBe('The title');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle a section definition', function () {
|
it('should handle a section definition', function () {
|
||||||
const str =
|
const str =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user