Skip to content

Commit

Permalink
Add mermaid as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Dec 25, 2017
1 parent 49844d9 commit e239912
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-it-mermaid",
"version": "0.2.1",
"version": "0.2.2",
"description": "Mermaid plugin for markdown-it.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -22,5 +22,8 @@
"webpack": "^3.10.0",
"webpack-node-externals": "^1.6.0",
"yarn-upgrade-all": "^0.1.3"
},
"dependencies": {
"mermaid": "^7.1.1"
}
}
39 changes: 25 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
import mermaid from 'mermaid'

const mermaidChart = (code) => {
if (typeof window === 'undefined' || !window.mermaid) {
if (typeof window === 'undefined') {
return `<div class="mermaid">${code}</div>`
}
let mermaidError = null
window.mermaid.parseError = (error, hash) => {
mermaid.parseError = (error, hash) => {
mermaidError = error
}
if (window.mermaid.parse(code) || mermaidError === null) {
if (mermaid.parse(code) || mermaidError === null) {
return `<div class="mermaid">${code}</div>`
} else {
return `<pre>${mermaidError}</pre>`
}
}

const MermaidPlugin = (md) => {
md.mermaid = {
gantt: {
axisFormat: (format) => {
window.mermaid.ganttConfig = {
axisFormatter: [
[format, (d) => {
return d.getDay() === 1
}]
]
}
}
mermaid.loadPreferences = (preferenceStore) => {
let mermaidTheme = preferenceStore.get('mermaid-theme')
if (mermaidTheme === undefined) {
mermaidTheme = 'default'
}
let ganttAxisFormat = preferenceStore.get('gantt-axis-format')
if (ganttAxisFormat === undefined) {
ganttAxisFormat = '%Y-%m-%d'
}
mermaid.initialize({
theme: mermaidTheme,
gantt: { axisFormatter: [
[ganttAxisFormat, (d) => {
return d.getDay() === 1
}]
]}
})
return {
'mermaid-theme': mermaidTheme,
'gantt-axis-format': ganttAxisFormat
}
}

Expand Down
47 changes: 46 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1023,12 +1023,32 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

[email protected]:
version "3.5.17"
resolved "https://registry.yarnpkg.com/d3/-/d3-3.5.17.tgz#bc46748004378b21a360c9fc7cf5231790762fb8"

d@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f"
dependencies:
es5-ext "^0.10.9"

dagre-d3-renderer@^0.4.25:
version "0.4.26"
resolved "https://registry.yarnpkg.com/dagre-d3-renderer/-/dagre-d3-renderer-0.4.26.tgz#648a491209b853ae96ddf3fea41a1f104479a5a1"
dependencies:
d3 "3.5.17"
dagre-layout "^0.8.0"
graphlib "^2.1.1"
lodash "^4.17.4"

dagre-layout@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/dagre-layout/-/dagre-layout-0.8.0.tgz#7147b6afb655602f855158dfea171db9aa98d4ff"
dependencies:
graphlib "^2.1.1"
lodash "^4.17.4"

dashdash@^1.12.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"
Expand Down Expand Up @@ -1699,6 +1719,12 @@ graceful-fs@^4.1.2:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

graphlib@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/graphlib/-/graphlib-2.1.1.tgz#42352c52ba2f4d035cb566eb91f7395f76ebc951"
dependencies:
lodash "^4.11.1"

har-schema@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e"
Expand Down Expand Up @@ -1763,6 +1789,10 @@ [email protected], hawk@~3.1.3:
hoek "2.x.x"
sntp "1.x.x"

he@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"

hmac-drbg@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
Expand Down Expand Up @@ -2159,7 +2189,7 @@ lodash.cond@^4.3.0:
version "4.5.2"
resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5"

lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.3.0:
lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down Expand Up @@ -2220,6 +2250,17 @@ memory-fs@^0.4.0, memory-fs@~0.4.1:
errno "^0.1.3"
readable-stream "^2.0.1"

mermaid@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/mermaid/-/mermaid-7.1.1.tgz#b013cfb807eea90087ead88bc8c1cd75baf95e71"
dependencies:
d3 "3.5.17"
dagre-d3-renderer "^0.4.25"
dagre-layout "^0.8.0"
he "^1.1.1"
lodash "^4.17.4"
moment "^2.20.1"

micromatch@^2.1.5:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
Expand Down Expand Up @@ -2287,6 +2328,10 @@ minimist@^1.1.0, minimist@^1.2.0:
dependencies:
minimist "0.0.8"

moment@^2.20.1:
version "2.20.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down

0 comments on commit e239912

Please sign in to comment.