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