diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 000000000..7e54e3631
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+**/*.spec.js
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
index a1aed17d7..e04aeb4d6 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,7 +1,8 @@
{
"env": {
"browser": true,
- "es6": true
+ "es6": true,
+ "node": true
},
"parserOptions": {
"ecmaFeatures": {
@@ -10,7 +11,7 @@
},
"sourceType": "module"
},
- "extends": ["prettier"],
+ "extends": ["prettier", "eslint:recommended"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"]
diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md
new file mode 100644
index 000000000..4f7444aa8
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/question.md
@@ -0,0 +1,15 @@
+---
+name: Question
+about: Get some help from the community.
+title: ''
+labels: 'Help wanted!, Type: Other'
+assignees: ''
+
+---
+
+## Help us help you!
+You want an answer. Here are some ways to get it quicker:
+* Use a clear and concise title.
+* Try to pose a clear and concise question.
+* Include as much, or as little, code as necessary.
+* Don't be shy to give us some screenshots, if it helps!
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 000000000..b8150e857
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,50 @@
+name: Build
+
+on: [push, pull_request]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ node-version: [10.x, 12.x]
+ steps:
+ - uses: actions/checkout@v1
+
+ - name: Setup Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v1
+ with:
+ node-version: ${{ matrix.node-version }}
+
+ - name: Install Yarn
+ run: npm i yarn --global
+
+ - name: Cache Node Modules
+ uses: actions/cache@v1
+ with:
+ path: .cache
+ key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
+
+ - name: Install Packages
+ run: |
+ yarn config set cache-folder $GITHUB_WORKSPACE/.cache/yarn
+ yarn install --frozen-lockfile
+ env:
+ CYPRESS_CACHE_FOLDER: ../../.cache/Cypress
+
+ - name: Run Build
+ run: yarn build
+
+ - name: Run Unit Tests
+ run: |
+ yarn test --coverage
+ cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
+ env:
+ COVERALLS_SERVICE_NAME: ${{ secrets.COVERALLS_SERVICE_NAME }}
+ COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
+
+ - name: Run E2E Tests
+ run: yarn e2e
+ env:
+ PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
+ CYPRESS_CACHE_FOLDER: .cache/Cypress
diff --git a/.github/workflows/lock-closed-issue.yml b/.github/workflows/lock-closed-issue.yml
new file mode 100644
index 000000000..ae74c03ef
--- /dev/null
+++ b/.github/workflows/lock-closed-issue.yml
@@ -0,0 +1,13 @@
+name: Lock closed issue
+
+on:
+ issues:
+ types: [closed]
+
+jobs:
+ triage:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: Dunning-Kruger/lock-issues@v1
+ with:
+ repo-token: "${{ secrets.GITHUB_TOKEN }}"
diff --git a/.github/workflows/release-preview-publish.yml b/.github/workflows/release-preview-publish.yml
new file mode 100644
index 000000000..b6c29b6a3
--- /dev/null
+++ b/.github/workflows/release-preview-publish.yml
@@ -0,0 +1,40 @@
+name: Publish release preview package
+
+on:
+ push:
+ branches:
+ - 'release/**'
+
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ node-version: [10.x]
+ steps:
+ - uses: actions/checkout@v1
+ - name: Setup Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v1
+ with:
+ node-version: ${{ matrix.node-version }}
+ - name: Install Yarn
+ run: npm i yarn --global
+
+ - name: Install Json
+ run: npm i json --global
+
+ - name: Install Packages
+ run: yarn install
+
+ - name: Publish
+ run: |
+ PREVIEW_VERSION=$(git rev-list --count --first-parent HEAD)
+ VERSION=$(echo ${{github.ref}} | tail -c +20)-preview.$PREVIEW_VERSION
+ echo $VERSION
+ npm version --no-git-tag-version --allow-same-version $VERSION
+ npm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
+ npm set registry https://npm.pkg.github.com/mermaid-js
+ json -I -f package.json -e 'this.name="@mermaid-js/mermaid"' # Package name needs to be set to a scoped one because GitHub registry requires this
+ json -I -f package.json -e 'this.repository="git://github.com/mermaid-js/mermaid"' # Repo url needs to have a specific format too
+ npm publish
+
diff --git a/.github/workflows/unlock-reopened-issues.yml b/.github/workflows/unlock-reopened-issues.yml
new file mode 100644
index 000000000..09469ed8b
--- /dev/null
+++ b/.github/workflows/unlock-reopened-issues.yml
@@ -0,0 +1,13 @@
+name: Unlock reopened issue
+
+on:
+ issues:
+ types: [reopened]
+
+jobs:
+ triage:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: Dunning-Kruger/unlock-issues@v1
+ with:
+ repo-token: "${{ secrets.GITHUB_TOKEN }}"
diff --git a/.gitignore b/.gitignore
index afceb98c0..498d78edc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
node_modules/
coverage/
+.idea/
dist/*.js
dist/*.map
@@ -9,3 +10,5 @@ dist/*.map
yarn-error.log
.npmrc
token
+
+package-lock.json
diff --git a/.vscode/settings.json b/.vscode/settings.json
index be2305cbc..ee8fae482 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -4,5 +4,5 @@
"typescript.validate.enable": false,
"javascript.validate.enable": false,
"editor.formatOnSave": false,
- "standard.enable": true
+ "editor.snippetSuggestions": "top"
}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 000000000..6e1c65ae3
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,98 @@
+# Contributing
+
+So you want to help? That's great!
+
+![Image of happy people jumping with excitement](https://media.giphy.com/media/BlVnrxJgTGsUw/giphy.gif)
+
+Here are a few things to know to get you started on the right path.
+
+## Committing code
+
+We make all changes via pull requests. As we have many pull requests from developers new to mermaid, the current approach is to have *knsv, Knut Sveidqvist* as a main reviewer of changes and merging pull requests. More precisely like this:
+
+* Large changes reviewed by knsv or other developer asked to review by knsv
+* Smaller low-risk changes like dependecies, documentation etc can be merged by active collaborators
+* documentation (updates to the docs folder is also allowed via direct commits)
+
+To commit code, create a branch, let it start with the type like feature or bug followed by the issue number for reference and some describing text.
+
+One example:
+
+`feature/945_state_diagrams`
+
+Another:
+
+`bug/123_nasty_bug_branch`
+
+## Committing documentation
+
+Less strict here, it is ok to commit directly in the develop branch if you are a collaborator.
+
+## Branching
+
+Going forward we will use a git flow inspired approach to branching. So development is done in develop, to do the development in the develop.
+
+Once development is done we branch a release branch from develop for testing.
+
+Once the release happens we merge the release branch to master and kill the release branch.
+
+This means... **branch off your pull request from develop**
+
+## Content of a pull request
+
+A new feature has been born. Great! But without the steps below it might just ... fade away ...
+
+### **Add unit tests for the parsing part**
+
+This is important so that, if someone else does a change to the grammar that does not know about this great feature, gets notified early on when that change breaks the parser. Another important aspect is that without proper parsing tests refactoring is pretty much impossible.
+
+### **Add e2e tests**
+
+This tests the rendering and visual apearance of the diagram. This ensures that the rendering of that feature in the e2e will be reviewed in the release process going forward. Less chance that it breaks!
+
+To start working with the e2e tests, run `yarn dev` to start the dev server, after that start cypress by running `cypress open` in the mermaid folder. (Make sure you have path to cypress in order, the binary is located in node_modules/.bin).
+
+The rendering tests are very straightforward to create. There is a function imgSnapshotTest. This function takes a diagram in text form, the mermaid options and renders that diagram in cypress.
+
+When running in ci it will take a snapshot of the rendered diagram and compare it with the snapshot from last build and flag for review it if it differs.
+
+This is what a rendering test looks like:
+```
+ it('should render forks and joins', () => {
+ imgSnapshotTest(
+ `
+ stateDiagram
+ state fork_state <<fork>>
+ [*] --> fork_state
+ fork_state --> State2
+ fork_state --> State3
+
+ state join_state <<join>>
+ State2 --> join_state
+ State3 --> join_state
+ join_state --> State4
+ State4 --> [*]
+ `,
+ { logLevel: 0 }
+ );
+ cy.get('svg');
+ });
+ ```
+
+
+### **Add documentation for it**
+
+Finally, if it is not in the documentation, no one will know about it and then **no one will use it**. Wouldn't that be sad? With all the effort that was put into the feature?
+
+The docs are located in the docs folder and are ofc written in markdown. Just pick the right section and start typing. If you want to add to the structure as in adding a new section and new file you do that via the _navbar.md.
+
+The changes in master is reflected in http://mermaid-js.github.io/mermaid/ once released the updates are commited to https://mermaid-js.github.io/#/
+
+## Last words
+
+Don't get daunted if it is hard in the beginning. We have a great community with only encouraging words. So if you get stuck, ask for help and hints in the slack forum. If you want to show off something good, show it off there.
+
+[Join our slack community if you want closer contact!](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE)
+
+
+![Image of superhero wishing you good luck](https://media.giphy.com/media/l49JHz7kJvl6MCj3G/giphy.gif)
diff --git a/README.md b/README.md
index 44a6a2c19..4fe123369 100644
--- a/README.md
+++ b/README.md
@@ -1,94 +1,89 @@
-[![Build Status](https://travis-ci.org/knsv/mermaid.svg?branch=master)](https://travis-ci.org/knsv/mermaid)
-[![Coverage Status](https://coveralls.io/repos/github/knsv/mermaid/badge.svg?branch=master)](https://coveralls.io/github/knsv/mermaid?branch=master)
-[![Join the chat at https://gitter.im/knsv/mermaid](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/knsv/mermaid?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-[![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/Mermaid/mermaid)
+
+| :mega: :mega: :mega: |
+| :----: |
+| * If you're upgrading from a version __< v8.2.0__, there are [non-backward-compatible changes](http://mermaid-js.github.io/mermaid/#/usage?id=to-enable-click-event-and-tags-in-nodes) related to security issues. Default behaviour of the library might have changed for your implementation.|
+
-# mermaid
+# mermaid [![Build Status](https://travis-ci.org/mermaid-js/mermaid.svg?branch=master)](https://travis-ci.org/mermaid-js/mermaid) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/Mermaid/mermaid)
+
+__Generate diagrams, charts, graphs or flows from markdown-like text via javascript.__
+See our [documentation](http://mermaid-js.github.io/mermaid/) and start simplifying yours. Play in our [live editor](https://mermaidjs.github.io/mermaid-live-editor/) or jump straight to the [installation and usage](http://mermaid-js.github.io/mermaid/#/usage).
+
-## Special note regarding version 8.2
+:trophy: _"The most exciting use of technology"_ - [JS Open Source Awards (2019)](https://osawards.com/javascript/#nominees)
-In version 8.2 a security improvement was introduced. A securityLevel configuration was introduced which sets the level of trust to be used on the parsed diagrams.
-
-* **`strict`**: (default) tags in text are encoded, click functionality is disabled
-* `loose`: tags in text are allowed, click functionality is enabled
-
-⚠️ **Note** : This changes the default behaviour of mermaid so that after upgrade to 8.2, if the securityLevel is not configured, tags in flowcharts are encoded as tags and clicking is prohibited.
-
-If your application is taking responsibility for the diagram source security you can set the securityLevel accordingly. By doing this clicks and tags are again allowed.
-
-```javascript
-mermaidAPI.initialize({
- securityLevel: 'loose'
-});
-```
-
-**🖖 Keep a steady pulse: mermaid needs more Collaborators [#866](https://github.com/knsv/mermaid/issues/866)**
-
-![banner](./img/header.png)
-
-Generation of diagrams and flowcharts from text in a similar manner as markdown.
-
-Ever wanted to simplify documentation and avoid heavy tools like Visio when explaining your code?
-
-This is why mermaid was born, a simple markdown-like script language for generating charts from text via javascript.
-
-**Mermaid was nominated and won the JS Open Source Awards (2019) in the category _The most exciting use of technology_!!! Thanks to all involved, people committing pull requests, people answering questions and special thanks to Tyler Long who is helping me maintain the project.**
-
-### Flowchart
-
-```
-graph TD;
- A-->B;
- A-->C;
- B-->D;
- C-->D;
-```
-![Flowchart](./img/flow.png)
-
-
-### Sequence diagram
-
-```
+
sequenceDiagram
- participant Alice
- participant Bob
- Alice->>John: Hello John, how are you?
- loop Healthcheck
- John->>John: Fight against hypochondria
- end
- Note right of John: Rational thoughts prevail!
- John-->>Alice: Great!
- John->>Bob: How about you?
- Bob-->>John: Jolly good!
-```
-![Sequence diagram](./img/sequence.png)
-
-
-### Gantt diagram
-
-```
+Alice->>John: Hello John, how are you?
+loop Healthcheck
+ John->>John: Fight against hypochondria
+end
+Note right of John: Rational thoughts!
+John-->>Alice: Great!
+John->>Bob: How about you?
+Bob-->>John: Jolly good!
+
graph TD
A[Christmas] -->|Get money| B(Go shopping)
-B --> C{Let me think}
+B --> C{{Let me think... Do I want something for work, something to spend every free second with, or something to get around?}}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]
@@ -399,6 +399,7 @@ merge newbranch
+ stateDiagram
+ [*] --> First
+ state First {
+ [*] --> second
+ second --> [*]
+ }
+
+
+ stateDiagram
+ State1: The state with a note
+ note right of State1
+ Important information! You can write
+ notes.
+ end note
+ State1 --> State2
+ note left of State2 : This is the note to the left.
+