Skip to content

Commit 75513fa

Browse files
authored
Add plantuml support (#1096)
Add plantuml support
2 parents 87beaa0 + 5ce9818 commit 75513fa

File tree

7 files changed

+2729
-92
lines changed

7 files changed

+2729
-92
lines changed

config.json.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
{
123123
"connectionString": "change this",
124124
"container": "change this"
125+
},
126+
"plantuml":
127+
{
128+
"server": "http://www.plantuml.com/plantuml"
125129
}
126130
}
127131
}

lib/config/environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ module.exports = {
126126
email: process.env.CMD_SAML_ATTRIBUTE_EMAIL
127127
}
128128
},
129+
plantuml: {
130+
server: process.env.CMD_PLANTUML_SERVER
131+
},
129132
email: toBooleanConfig(process.env.CMD_EMAIL),
130133
allowEmailRegister: toBooleanConfig(process.env.CMD_ALLOW_EMAIL_REGISTER),
131134
allowGravatar: toBooleanConfig(process.env.CMD_ALLOW_GRAVATAR),

lib/web/statusRouter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ statusRouter.get('/config', function (req, res) {
9797
urlpath: config.urlPath,
9898
debug: config.debug,
9999
version: config.fullversion,
100+
plantumlServer: config.plantuml.server,
100101
DROPBOX_APP_KEY: config.dropbox.appKey,
101102
allowedUploadMimeTypes: config.allowedUploadMimeTypes
102103
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"pdfobject": "~2.0.201604172",
119119
"pg": "~6.1.2",
120120
"pg-hstore": "~2.3.2",
121+
"plantuml-encoder": "^1.2.5",
121122
"prismjs": "~1.6.0",
122123
"randomcolor": "~0.5.3",
123124
"raphael": "~2.2.8",

public/js/extra.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env browser, jquery */
2-
/* global moment, serverurl */
2+
/* global moment, serverurl, plantumlServer */
33

44
import Prism from 'prismjs'
55
import hljs from 'highlight.js'
@@ -31,6 +31,8 @@ require('prismjs/components/prism-gherkin')
3131
require('./lib/common/login')
3232
require('../vendor/md-toc')
3333
var Viz = require('viz.js')
34+
const plantumlEncoder = require('plantuml-encoder')
35+
3436
const ui = getUIElements()
3537

3638
// auto update last change
@@ -1036,6 +1038,33 @@ md.renderer.rules.fence = (tokens, idx, options, env, self) => {
10361038
return `<pre><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`
10371039
}
10381040

1041+
const makePlantumlURL = (umlCode) => {
1042+
let format = 'svg'
1043+
let code = plantumlEncoder.encode(umlCode)
1044+
return `${plantumlServer}/${format}/${code}`
1045+
}
1046+
1047+
// https://github.com/qjebbs/vscode-plantuml/tree/master/src/markdown-it-plantuml
1048+
md.renderer.rules.plantuml = (tokens, idx) => {
1049+
let token = tokens[idx]
1050+
if (token.type !== 'plantuml') {
1051+
return tokens[idx].content
1052+
}
1053+
1054+
let url = makePlantumlURL(token.content)
1055+
return `<img src="${url}" />`
1056+
}
1057+
1058+
// https://github.com/qjebbs/vscode-plantuml/tree/master/src/markdown-it-plantuml
1059+
md.core.ruler.push('plantuml', (state) => {
1060+
let blockTokens = state.tokens
1061+
for (let blockToken of blockTokens) {
1062+
if (blockToken.type === 'fence' && blockToken.info === 'plantuml') {
1063+
blockToken.type = 'plantuml'
1064+
}
1065+
}
1066+
})
1067+
10391068
// youtube
10401069
const youtubePlugin = new Plugin(
10411070
// regexp to match

public/js/lib/common/constant.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ window.domain = '<%- domain %>'
22
window.urlpath = '<%- urlpath %>'
33
window.debug = <%- debug %>
44
window.version = '<%- version %>'
5+
window.plantumlServer = '<%- plantumlServer %>'
56

67
window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %>
78

0 commit comments

Comments
 (0)