-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Mermaid configuration options, version and style #5
Open
cmidgley
wants to merge
7
commits into
Jellyvision:master
Choose a base branch
from
cmidgley:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
829a7e8
mermaid to 8.5, started working on config options
cmidgley bdac0dc
Improved config usage
cmidgley 3210e87
Fixed some bugs and added 'style' config option
cmidgley da2b372
Updated README
cmidgley b4e45b1
Fixed a few nits
cmidgley 04f6ccb
Merge branch 'master' of https://github.com/Jellyvision/jsdoc-mermaid
cmidgley e980017
Added disableScript option
cmidgley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
const doctrine = require('doctrine') | ||
|
||
// get access to configuration options | ||
const env = require('jsdoc/env'); | ||
const config = env.conf.mermaid || {}; | ||
|
||
const escapeHtmlChar = { | ||
'&': '&', | ||
'<': '<', | ||
|
@@ -18,11 +22,19 @@ exports.handlers = { | |
newDoclet: function (e) { | ||
if (!e.doclet.comment || !/@mermaid\b/.test(e.doclet.comment)) return | ||
let tags = doctrine.parse(e.doclet.comment, { unwrap: true, tags: ['mermaid'], recoverable: true }).tags | ||
let htmls = tags.map(tag => '<div class="mermaid">' + escapeHtml(tag.description) + '</div>') | ||
var style = config.style ? ' style="' + config.style + '"' : '' | ||
let htmls = tags.map(tag => '<div class="mermaid"' + style + '>' + escapeHtml(tag.description) + '</div>') | ||
|
||
if (htmls) { | ||
e.doclet.description = e.doclet.description || '' | ||
if (!isAddedMermaid[e.doclet.memberof]) { | ||
e.doclet.description += '<script src="https://unpkg.com/[email protected]/dist/mermaid.min.js"></script>' | ||
var version = config.version ? '@' + config.version : '' | ||
var altConfig = {...config} | ||
delete altConfig.version | ||
delete altConfig.style | ||
e.doclet.description += | ||
'<script src="https://unpkg.com/mermaid' + version + '/dist/mermaid.min.js"></script>\n' + | ||
'<script>mermaid.initialize(' + JSON.stringify(altConfig) + ');</script>\n' | ||
isAddedMermaid[e.doclet.memberof] = true | ||
} | ||
e.doclet.description += htmls.join('') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ yarn add -D jsdoc-mermaid # OR npm install -D jsdoc-mermaid | |
|
||
And then add `jsdoc-mermaid` to your jsdoc configuration file. That's it! | ||
|
||
```javascript | ||
```json | ||
{ | ||
"plugins": ["jsdoc-mermaid"] | ||
} | ||
|
@@ -49,6 +49,43 @@ When you open that page in JSDoc, you should have a shiny new graph! | |
|
||
![jsdoc-mermaid example](https://user-images.githubusercontent.com/2096353/31104126-b9159786-a7a0-11e7-95ed-689a7f158803.png) | ||
|
||
## Customizing Mermaid | ||
|
||
You can optionally include a section in your JSDoc configuration file (such as ```conf.json```) to define Mermaid custom configurations. Simply add a section called ```"mermaid"```: | ||
|
||
```json | ||
{ | ||
"mermaid": { | ||
"theme": "forest" | ||
} | ||
} | ||
``` | ||
|
||
This package also some new properties to the mermaid configuration: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing a verb / grammar. "also supports ... " |
||
|
||
* ```version```: Let's you specify which Mermaid version to use. If not provided, defaults to latest Mermaid. | ||
* ```style```: Let's you add optional CSS styles to the surrounding ```<div>``` tag (which also has class ```mermaid``` if you want to use a proper stylesheet). | ||
|
||
```json | ||
{ | ||
"mermaid": { | ||
"theme": "nuetral", | ||
"style": "display: flex", | ||
"version": "8.3.0", | ||
"flowchart": { | ||
"curve": "cardinal", | ||
"htmlLabels": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Mermaid configuration documentation | ||
|
||
* [Mermaid API](https://mermaid-js.github.io/mermaid/#/mermaidAPI), however the properties are often incorrect | ||
* [Mermaid configuration defaults](https://mermaid-js.github.io/mermaid/#/mermaidAPI?id=mermaidapi-configuration-defaults) shows the defaults, and appears to be more accurate | ||
* [Source code for the API](https://github.com/mermaid-js/mermaid/blob/master/src/mermaidAPI.js) which is harder to parse but the most accurate | ||
|
||
|
||
## Built With | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3