From 152795666932cf92af33635d2f98dcbe93e911ba Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sun, 4 Sep 2022 01:56:43 +0100 Subject: [PATCH 1/3] fix(git): support unusual prefixes in branch name jison throws an error if a branch name starts with an unusual prefix. For example, a branch named `branch/test-branch` will throw a parse error, since jison thinks it's a `branch` command, and not a branch id. An easy fix is to use the `(?=\s|$)` regex to ensure that only 'branch ' or 'branch\n' will be parsed as the branch command. Fixes: https://github.com/mermaid-js/mermaid/issues/3362 --- src/diagrams/git/gitGraphParserV2.spec.js | 28 +++++++++++++++++++++++ src/diagrams/git/parser/gitGraph.jison | 10 ++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/diagrams/git/gitGraphParserV2.spec.js b/src/diagrams/git/gitGraphParserV2.spec.js index 9a33e288f..b69dd97ac 100644 --- a/src/diagrams/git/gitGraphParserV2.spec.js +++ b/src/diagrams/git/gitGraphParserV2.spec.js @@ -363,6 +363,34 @@ describe('when parsing a gitGraph', function () { expect(Object.keys(parser.yy.getBranches()).length).toBe(2); }); + it('should allow branch names starting with unusual prefixes', function () { + const str = `gitGraph: + commit + %% branch names starting with numbers are not recommended, but are supported by git + branch branch01 + branch checkout02 + branch cherry-pick03 + branch branch/example-branch + branch merge/test_merge + `; + + parser.parse(str); + const commits = parser.yy.getCommits(); + expect(Object.keys(commits).length).toBe(1); + expect(parser.yy.getCurrentBranch()).toBe('merge/test_merge'); + expect(parser.yy.getDirection()).toBe('LR'); + expect(Object.keys(parser.yy.getBranches()).length).toBe(6); + expect(Object.keys(parser.yy.getBranches())).toEqual( + expect.arrayContaining([ + 'branch01', + 'checkout02', + 'cherry-pick03', + 'branch/example-branch', + 'merge/test_merge', + ]) + ); + }); + it('should handle new branch checkout', function () { const str = `gitGraph: commit diff --git a/src/diagrams/git/parser/gitGraph.jison b/src/diagrams/git/parser/gitGraph.jison index 29edec808..15909a314 100644 --- a/src/diagrams/git/parser/gitGraph.jison +++ b/src/diagrams/git/parser/gitGraph.jison @@ -36,7 +36,7 @@ accDescr\s*"{"\s* { this.begin("ac \#[^\n]* /* skip comments */ \%%[^\n]* /* skip comments */ "gitGraph" return 'GG'; -"commit" return 'COMMIT'; +commit(?=\s|$) return 'COMMIT'; "id:" return 'COMMIT_ID'; "type:" return 'COMMIT_TYPE'; "msg:" return 'COMMIT_MSG'; @@ -44,12 +44,12 @@ accDescr\s*"{"\s* { this.begin("ac "REVERSE" return 'REVERSE'; "HIGHLIGHT" return 'HIGHLIGHT'; "tag:" return 'COMMIT_TAG'; -"branch" return 'BRANCH'; +branch(?=\s|$) return 'BRANCH'; "order:" return 'ORDER'; -"merge" return 'MERGE'; -"cherry-pick" return 'CHERRY_PICK'; +merge(?=\s|$) return 'MERGE'; +cherry-pick(?=\s|$) return 'CHERRY_PICK'; // "reset" return 'RESET'; -"checkout" return 'CHECKOUT'; +checkout(?=\s|$) return 'CHECKOUT'; "LR" return 'DIR'; "BT" return 'DIR'; ":" return ':'; From bfa69aa084783ae606769132fc21b9d8f697a319 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 12 Sep 2022 10:55:13 +0530 Subject: [PATCH 2/3] chore(docs): Remove edit this page --- docs/mindmap.md | 2 -- src/docs/mindmap.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/mindmap.md b/docs/mindmap.md index 6ab954f5b..8a7e21eb7 100644 --- a/docs/mindmap.md +++ b/docs/mindmap.md @@ -2,8 +2,6 @@ # Mindmap -**Edit this Page** [![N|Solid](img/GitHub-Mark-32px.png)](https://github.com/mermaid-js/mermaid/blob/develop/src/docs/mindmap.md) - > Mindmap: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stabel except for the icon integration which is the experimental part. "A mind map is a diagram used to visually organize information into a hierarchy, showing relationships among pieces of the whole. It is often created around a single concept, drawn as an image in the center of a blank page, to which associated representations of ideas such as images, words and parts of words are added. Major ideas are connected directly to the central concept, and other ideas branch out from those major ideas." Wikipedia diff --git a/src/docs/mindmap.md b/src/docs/mindmap.md index d7f1b4817..85a05e04b 100644 --- a/src/docs/mindmap.md +++ b/src/docs/mindmap.md @@ -1,7 +1,5 @@ # Mindmap -**Edit this Page** [![N|Solid](img/GitHub-Mark-32px.png)](https://github.com/mermaid-js/mermaid/blob/develop/src/docs/mindmap.md) - > Mindmap: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stabel except for the icon integration which is the experimental part. "A mind map is a diagram used to visually organize information into a hierarchy, showing relationships among pieces of the whole. It is often created around a single concept, drawn as an image in the center of a blank page, to which associated representations of ideas such as images, words and parts of words are added. Major ideas are connected directly to the central concept, and other ideas branch out from those major ideas." Wikipedia From ca5fbb7fa8934428f636642f843224945279e3fa Mon Sep 17 00:00:00 2001 From: mmorel-35 Date: Mon, 12 Sep 2022 07:20:57 +0000 Subject: [PATCH 3/3] chore: update browsers list --- docs/Setup.md | 31 +++++++++++++++++++++---------- src/docs/Setup.md | 31 +++++++++++++++++++++---------- yarn.lock | 6 +++--- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/docs/Setup.md b/docs/Setup.md index 1f948ee01..2ef56e1d8 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -1407,6 +1407,15 @@ This sets the auto-wrap padding for the diagram (sides only) **Notes:** Default value: 0. +## parse + +### Parameters + +- `text` **[string][5]** +- `parseError` **[Function][6]?** + +Returns **[boolean][7]** + ## setSiteConfig ## setSiteConfig @@ -1424,7 +1433,7 @@ function _Default value: At default, will mirror Global Config_ - `conf` **MermaidConfig** The base currentConfig to use as siteConfig -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## getSiteConfig @@ -1436,7 +1445,7 @@ Returns **[object][5]** The siteConfig **Notes**: Returns **any** values in siteConfig. -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## setConfig @@ -1475,10 +1484,10 @@ $(function () { ### Parameters -- `id` **[string][6]** The id of the element to be rendered -- `text` **[string][6]** The graph definition -- `cb` **function (svgCode: [string][6], bindFunctions: function (element: [Element][7]): void): void** -- `container` **[Element][7]** Selector to element in which a div with the graph temporarily will be +- `id` **[string][5]** The id of the element to be rendered +- `text` **[string][5]** The graph definition +- `cb` **function (svgCode: [string][5], bindFunctions: function (element: [Element][9]): void): void** +- `container` **[Element][9]** Selector to element in which a div with the graph temporarily will be inserted. If one is provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. @@ -1517,7 +1526,7 @@ Pushes in a directive to the configuration ### Parameters -- `directive` **[object][5]** The directive to push in +- `directive` **[object][8]** The directive to push in ## reset @@ -1615,6 +1624,8 @@ Returns **void** [2]: Setup.md?id=render [3]: 8.6.0_docs.md [4]: #mermaidapi-configuration-defaults -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[7]: https://developer.mozilla.org/docs/Web/API/Element +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[9]: https://developer.mozilla.org/docs/Web/API/Element diff --git a/src/docs/Setup.md b/src/docs/Setup.md index a9d8e87e2..41e706825 100644 --- a/src/docs/Setup.md +++ b/src/docs/Setup.md @@ -1405,6 +1405,15 @@ This sets the auto-wrap padding for the diagram (sides only) **Notes:** Default value: 0. +## parse + +### Parameters + +- `text` **[string][5]** +- `parseError` **[Function][6]?** + +Returns **[boolean][7]** + ## setSiteConfig ## setSiteConfig @@ -1422,7 +1431,7 @@ function _Default value: At default, will mirror Global Config_ - `conf` **MermaidConfig** The base currentConfig to use as siteConfig -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## getSiteConfig @@ -1434,7 +1443,7 @@ Returns **[object][5]** The siteConfig **Notes**: Returns **any** values in siteConfig. -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## setConfig @@ -1473,10 +1482,10 @@ $(function () { ### Parameters -- `id` **[string][6]** The id of the element to be rendered -- `text` **[string][6]** The graph definition -- `cb` **function (svgCode: [string][6], bindFunctions: function (element: [Element][7]): void): void** -- `container` **[Element][7]** Selector to element in which a div with the graph temporarily will be +- `id` **[string][5]** The id of the element to be rendered +- `text` **[string][5]** The graph definition +- `cb` **function (svgCode: [string][5], bindFunctions: function (element: [Element][9]): void): void** +- `container` **[Element][9]** Selector to element in which a div with the graph temporarily will be inserted. If one is provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. @@ -1515,7 +1524,7 @@ Pushes in a directive to the configuration ### Parameters -- `directive` **[object][5]** The directive to push in +- `directive` **[object][8]** The directive to push in ## reset @@ -1613,6 +1622,8 @@ Returns **void** [2]: Setup.md?id=render [3]: 8.6.0_docs.md [4]: #mermaidapi-configuration-defaults -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[7]: https://developer.mozilla.org/docs/Web/API/Element +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[9]: https://developer.mozilla.org/docs/Web/API/Element diff --git a/yarn.lock b/yarn.lock index 58c3d2818..8b0ce83d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3937,9 +3937,9 @@ camelcase@^6.2.0: integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== caniuse-lite@^1.0.30001359: - version "1.0.30001390" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001390.tgz" - integrity sha512-sS4CaUM+/+vqQUlCvCJ2WtDlV81aWtHhqeEVkLokVJJa3ViN4zDxAGfq9R8i1m90uGHxo99cy10Od+lvn3hf0g== + version "1.0.30001397" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001397.tgz" + integrity sha512-SW9N2TbCdLf0eiNDRrrQXx2sOkaakNZbCjgNpPyMJJbiOrU5QzMIrXOVMRM1myBXTD5iTkdrtU/EguCrBocHlA== caseless@~0.12.0: version "0.12.0"