mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-25 10:20:06 +02:00
Updated requirement diagram parsing with the new syntax
This commit is contained in:
@@ -13,7 +13,9 @@
|
|||||||
%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'; }
|
||||||
@@ -22,8 +24,13 @@
|
|||||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||||
|
|
||||||
"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";
|
||||||
(\r?\n)+ return 'NEWLINE';
|
(\r?\n)+ return 'NEWLINE';
|
||||||
\s+ /* skip all whitespace */
|
\s+ /* skip all whitespace */
|
||||||
\#[^\n]* /* skip comments */
|
\#[^\n]* /* skip comments */
|
||||||
@@ -94,9 +101,10 @@ start
|
|||||||
directive
|
directive
|
||||||
: openDirective typeDirective closeDirective
|
: openDirective typeDirective closeDirective
|
||||||
| openDirective typeDirective ':' argDirective closeDirective
|
| openDirective typeDirective ':' argDirective closeDirective
|
||||||
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
|
| acc_title acc_title_value { console.log('acc_title');$$=$2.trim();yy.setTitle($$); }
|
||||||
| accDescription {yy.setAccDescription($1.substring(15));$$=$1.substring(15);};
|
| acc_descr acc_descr_value { console.log('acc_descr');$$=$2.trim();yy.setAccDescription($$); }
|
||||||
|
| acc_descr_multiline_value { console.log('acc_descr_multiline_value');$$=$1.trim();yy.setAccDescription($$); }
|
||||||
|
;
|
||||||
openDirective
|
openDirective
|
||||||
: open_directive { yy.parseDirective('%%{', 'open_directive'); };
|
: open_directive { yy.parseDirective('%%{', 'open_directive'); };
|
||||||
|
|
||||||
|
@@ -72,22 +72,38 @@ describe('when parsing requirement diagram it...', function () {
|
|||||||
expect(Object.keys(requirementDb.getRelationships()).length).toBe(0);
|
expect(Object.keys(requirementDb.getRelationships()).length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will use a title and accDescription', function () {
|
it('will use a accessibility title and description (accDescr)', function () {
|
||||||
const expectedTitle = 'test title';
|
const expectedTitle = 'test title';
|
||||||
const expectedAccDescription = 'my chart description';
|
const expectedAccDescription = 'my chart description';
|
||||||
const expectedDocRef = 'test_ref';
|
|
||||||
|
|
||||||
let lines = [
|
const doc = `requirementDiagram
|
||||||
`requirementDiagram`,
|
accTitle: ${expectedTitle}
|
||||||
``,
|
accDescr: ${expectedAccDescription}
|
||||||
`title ${expectedTitle}`,
|
element test_name {
|
||||||
`accDescription ${expectedAccDescription}`,
|
type: test_type
|
||||||
`element test_name {`,
|
docref: test_ref
|
||||||
`type: test_type`,
|
}`;
|
||||||
`docref: test_ref`,
|
|
||||||
`}`,
|
reqDiagram.parser.parse(doc);
|
||||||
];
|
|
||||||
let doc = lines.join('\n');
|
expect(requirementDb.getTitle()).toBe(expectedTitle);
|
||||||
|
expect(requirementDb.getAccDescription()).toBe(expectedAccDescription);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will use a accessibility title and multiline description (accDescr)', function () {
|
||||||
|
const expectedTitle = 'test title';
|
||||||
|
const expectedAccDescription = `my chart description
|
||||||
|
line 2`;
|
||||||
|
|
||||||
|
const doc = `requirementDiagram
|
||||||
|
accTitle: ${expectedTitle}
|
||||||
|
accDescr {
|
||||||
|
${expectedAccDescription}
|
||||||
|
}
|
||||||
|
element test_name {
|
||||||
|
type: test_type
|
||||||
|
docref: test_ref
|
||||||
|
}`;
|
||||||
|
|
||||||
reqDiagram.parser.parse(doc);
|
reqDiagram.parser.parse(doc);
|
||||||
|
|
||||||
|
@@ -2,6 +2,13 @@ import * as configApi from '../../config';
|
|||||||
import { log } from '../../logger';
|
import { log } from '../../logger';
|
||||||
import mermaidAPI from '../../mermaidAPI';
|
import mermaidAPI from '../../mermaidAPI';
|
||||||
import common from '../common/common';
|
import common from '../common/common';
|
||||||
|
import {
|
||||||
|
setTitle,
|
||||||
|
getTitle,
|
||||||
|
getAccDescription,
|
||||||
|
setAccDescription,
|
||||||
|
clear as commonClear,
|
||||||
|
} from '../../commonDb';
|
||||||
|
|
||||||
let relations = [];
|
let relations = [];
|
||||||
let latestRequirement = {};
|
let latestRequirement = {};
|
||||||
@@ -137,24 +144,7 @@ const clear = () => {
|
|||||||
requirements = {};
|
requirements = {};
|
||||||
latestElement = {};
|
latestElement = {};
|
||||||
elements = {};
|
elements = {};
|
||||||
};
|
commonClear();
|
||||||
|
|
||||||
export const setTitle = function (txt) {
|
|
||||||
let sanitizedText = sanitizeText(txt, configApi.getConfig());
|
|
||||||
title = sanitizedText;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTitle = function () {
|
|
||||||
return title;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const setAccDescription = function (txt) {
|
|
||||||
let sanitizedText = sanitizeText(txt, configApi.getConfig());
|
|
||||||
accDescription = sanitizedText;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAccDescription = function () {
|
|
||||||
return accDescription;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Reference in New Issue
Block a user