feat: adding more accessibility tooling

This commit is contained in:
Cory Gwin
2022-03-17 19:48:22 +00:00
committed by GitHub
parent 0181cbf743
commit 50f522ae5c
12 changed files with 131 additions and 15 deletions

View File

@@ -56,7 +56,8 @@
"note" return 'note';
"activate" { this.begin('ID'); return 'activate'; }
"deactivate" { this.begin('ID'); return 'deactivate'; }
"title" return 'title';
"title"\s[^#\n;]+ return 'title';
"title:"\s[^#\n;]+ return 'legacy_title';
"accDescription"\s[^#\n;]+ return 'accDescription';
"sequenceDiagram" return 'SD';
"autonumber" return 'autonumber';
@@ -122,7 +123,8 @@ statement
| link_statement 'NEWLINE'
| properties_statement 'NEWLINE'
| details_statement 'NEWLINE'
| title text2 'NEWLINE' {$$=[{type:'setTitle', text:$2}]}
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
| legacy_title {yy.setTitle($1.substring(7));$$=$1.substring(7);}
| accDescription {yy.setAccDescription($1.substring(15));$$=$1.substring(15);}
| 'loop' restOfLine document end
{

View File

@@ -9,7 +9,6 @@ let messages = [];
const notes = [];
let title = '';
let description = '';
let titleWrapped = false;
let sequenceNumbersEnabled = false;
let wrapEnabled = false;
@@ -123,9 +122,6 @@ export const getActorKeys = function () {
export const getTitle = function () {
return title;
};
export const getTitleWrapped = function () {
return titleWrapped;
};
export const enableSequenceNumbers = function () {
sequenceNumbersEnabled = true;
};
@@ -324,9 +320,9 @@ export const getActorProperty = function (actor, key) {
return undefined;
};
export const setTitle = function (titleWrap) {
title = titleWrap.text;
titleWrapped = (titleWrap.wrap === undefined && autoWrap()) || !!titleWrap.wrap;
export const setTitle = function (txt) {
let sanitizedText = sanitizeText(txt, configApi.getConfig());
title = sanitizedText;
};
export const apply = function (param) {
@@ -410,7 +406,8 @@ export const apply = function (param) {
};
const setAccDescription = function (description_lex) {
description = description_lex;
let sanitizedText = sanitizeText(description_lex, configApi.getConfig());
description = sanitizedText;
};
const getAccDescription = function () {
@@ -436,7 +433,6 @@ export default {
getTitle,
parseDirective,
getConfig: () => configApi.getConfig().sequence,
getTitleWrapped,
clear,
parseMessage,
LINETYPE,

View File

@@ -60,7 +60,7 @@ Bob-->Alice: I am good thanks!`;
mermaidAPI.parse(str);
expect(parser.yy.showSequenceNumbers()).toBe(true);
});
it('it should handle a sequenceDiagram definition with a title', function () {
it('it should handle a sequenceDiagram definition with a title:', function () {
const str = `
sequenceDiagram
title: Diagram Title
@@ -82,10 +82,34 @@ Bob-->Alice: I am good thanks!`;
expect(messages[2].from).toBe('Bob');
expect(title).toBe('Diagram Title');
});
it('it should handle a sequenceDiagram definition with a title without a :', function () {
const str = `
sequenceDiagram
title Diagram Title
Alice->Bob:Hello Bob, how are you?
Note right of Bob: Bob thinks
Bob-->Alice: I am good thanks!`;
mermaidAPI.parse(str);
const actors = parser.yy.getActors();
expect(actors.Alice.description).toBe('Alice');
actors.Bob.description = 'Bob';
expect(parser.yy.getAccDescription()).toBe('');
const messages = parser.yy.getMessages();
const title = parser.yy.getTitle();
expect(messages.length).toBe(3);
expect(messages[0].from).toBe('Alice');
expect(messages[2].from).toBe('Bob');
expect(title).toBe('Diagram Title');
});
it('it should handle a sequenceDiagram definition with a accDescription', function () {
const str = `
sequenceDiagram
accDescription: Accessibility Description
accDescription Accessibility Description
Alice->Bob:Hello Bob, how are you?
Note right of Bob: Bob thinks
Bob-->Alice: I am good thanks!`;
@@ -1609,6 +1633,7 @@ participant Alice
renderer.bounds.init();
mermaidAPI.parse(str);
renderer.draw(str, 'tst');
const { bounds, models } = renderer.bounds.getBounds();