mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-13 12:29:42 +02:00
Adding acc to gitGrapg parser
This commit is contained in:
@@ -4,6 +4,13 @@ import mermaidAPI from '../../mermaidAPI';
|
|||||||
import * as configApi from '../../config';
|
import * as configApi from '../../config';
|
||||||
import { getConfig } from '../../config';
|
import { getConfig } from '../../config';
|
||||||
import common from '../common/common';
|
import common from '../common/common';
|
||||||
|
import {
|
||||||
|
setTitle,
|
||||||
|
getTitle,
|
||||||
|
getAccDescription,
|
||||||
|
setAccDescription,
|
||||||
|
clear as commonClear,
|
||||||
|
} from '../../commonDb';
|
||||||
|
|
||||||
let mainBranchName = getConfig().gitGraph.mainBranchName;
|
let mainBranchName = getConfig().gitGraph.mainBranchName;
|
||||||
let commits = {};
|
let commits = {};
|
||||||
@@ -14,6 +21,9 @@ let curBranch = mainBranchName;
|
|||||||
let direction = 'LR';
|
let direction = 'LR';
|
||||||
let seq = 0;
|
let seq = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function getId() {
|
function getId() {
|
||||||
return random({ length: 7 });
|
return random({ length: 7 });
|
||||||
}
|
}
|
||||||
@@ -326,6 +336,7 @@ export const clear = function () {
|
|||||||
branches[mainBranch] = null;
|
branches[mainBranch] = null;
|
||||||
curBranch = mainBranch;
|
curBranch = mainBranch;
|
||||||
seq = 0;
|
seq = 0;
|
||||||
|
commonClear();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBranchesAsObjArray = function () {
|
export const getBranchesAsObjArray = function () {
|
||||||
@@ -390,5 +401,9 @@ export default {
|
|||||||
getCurrentBranch,
|
getCurrentBranch,
|
||||||
getDirection,
|
getDirection,
|
||||||
getHead,
|
getHead,
|
||||||
|
setTitle,
|
||||||
|
getTitle,
|
||||||
|
getAccDescription,
|
||||||
|
setAccDescription,
|
||||||
commitType,
|
commitType,
|
||||||
};
|
};
|
||||||
|
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -13,6 +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
|
||||||
%options case-insensitive
|
%options case-insensitive
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +25,13 @@
|
|||||||
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
<type_directive>":" { this.popState(); this.begin('arg_directive'); return ':'; }
|
||||||
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
<type_directive,arg_directive>\}\%\% { this.popState(); this.popState(); return 'close_directive'; }
|
||||||
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
<arg_directive>((?:(?!\}\%\%).|\n)*) return 'arg_directive';
|
||||||
|
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)+ /*{console.log('New line');return 'NL';}*/ return 'NL';
|
(\r?\n)+ /*{console.log('New line');return 'NL';}*/ return 'NL';
|
||||||
\s+ /* skip all whitespace */
|
\s+ /* skip all whitespace */
|
||||||
\#[^\n]* /* skip comments */
|
\#[^\n]* /* skip comments */
|
||||||
@@ -90,6 +100,9 @@ line
|
|||||||
statement
|
statement
|
||||||
: commitStatement
|
: commitStatement
|
||||||
| mergeStatement
|
| 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)}
|
| BRANCH ID {yy.branch($2)}
|
||||||
| CHECKOUT ID {yy.checkout($2)}
|
| CHECKOUT ID {yy.checkout($2)}
|
||||||
// | RESET reset_arg {yy.reset($2)}
|
// | RESET reset_arg {yy.reset($2)}
|
||||||
|
Reference in New Issue
Block a user