diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index 1beb1a89e..b41da8134 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -4,6 +4,13 @@ import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; import { getConfig } from '../../config'; import common from '../common/common'; +import { + setTitle, + getTitle, + getAccDescription, + setAccDescription, + clear as commonClear, +} from '../../commonDb'; let mainBranchName = getConfig().gitGraph.mainBranchName; let commits = {}; @@ -14,6 +21,9 @@ let curBranch = mainBranchName; let direction = 'LR'; let seq = 0; +/** + * + */ function getId() { return random({ length: 7 }); } @@ -326,6 +336,7 @@ export const clear = function () { branches[mainBranch] = null; curBranch = mainBranch; seq = 0; + commonClear(); }; export const getBranchesAsObjArray = function () { @@ -390,5 +401,9 @@ export default { getCurrentBranch, getDirection, getHead, + setTitle, + getTitle, + getAccDescription, + setAccDescription, commitType, }; diff --git a/src/diagrams/git/gitGraphParserV2.spec.js b/src/diagrams/git/gitGraphParserV2.spec.js index 670c3a371..9d740d5ae 100644 --- a/src/diagrams/git/gitGraphParserV2.spec.js +++ b/src/diagrams/git/gitGraphParserV2.spec.js @@ -616,4 +616,29 @@ describe('when parsing a gitGraph', function () { ); } }); + describe('accessibility', () => { + it('should handle a title and a description (accDescr)', () => { + const str = `gitGraph: + accTitle: This is a title + accDescr: This is a description + commit + `; + parser.parse(str); + expect(parser.yy.getTitle()).toBe('This is a title'); + expect(parser.yy.getAccDescription()).toBe('This is a description'); + }); + it('should handle a title and a multiline description (accDescr)', () => { + const str = `gitGraph: + accTitle: This is a title + accDescr { + This is a description + using multiple lines + } + commit + `; + parser.parse(str); + expect(parser.yy.getTitle()).toBe('This is a title'); + expect(parser.yy.getAccDescription()).toBe('This is a description\nusing multiple lines'); + }); + }); }); diff --git a/src/diagrams/git/parser/gitGraph.jison b/src/diagrams/git/parser/gitGraph.jison index 7c1105144..bb2ff9ae6 100644 --- a/src/diagrams/git/parser/gitGraph.jison +++ b/src/diagrams/git/parser/gitGraph.jison @@ -13,6 +13,9 @@ %x type_directive %x arg_directive %x close_directive +%x acc_title +%x acc_descr +%x acc_descr_multiline %options case-insensitive @@ -22,6 +25,13 @@ ":" { this.popState(); this.begin('arg_directive'); return ':'; } \}\%\% { this.popState(); this.popState(); return 'close_directive'; } ((?:(?!\}\%\%).|\n)*) return 'arg_directive'; +accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; } +(?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; } +accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; } +(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; } +accDescr\s*"{"\s* { this.begin("acc_descr_multiline");} +[\}] { this.popState(); } +[^\}]* return "acc_descr_multiline_value"; (\r?\n)+ /*{console.log('New line');return 'NL';}*/ return 'NL'; \s+ /* skip all whitespace */ \#[^\n]* /* skip comments */ @@ -90,6 +100,9 @@ line statement : commitStatement | mergeStatement + | 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);} | BRANCH ID {yy.branch($2)} | CHECKOUT ID {yy.checkout($2)} // | RESET reset_arg {yy.reset($2)}