Skip to content

Commit 5ce9818

Browse files
committed
Render plantuml only in fence
Signed-off-by: Chulki Lee <chulki.lee@gmail.com>
1 parent 1d7895c commit 5ce9818

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"markdown-it-ins": "~2.0.0",
9191
"markdown-it-mark": "~2.0.0",
9292
"markdown-it-mathjax": "~2.0.0",
93-
"markdown-it-plantuml": "^1.4.1",
9493
"markdown-it-regexp": "~0.4.0",
9594
"markdown-it-sub": "~1.0.0",
9695
"markdown-it-sup": "~1.0.0",
@@ -119,6 +118,7 @@
119118
"pdfobject": "~2.0.201604172",
120119
"pg": "~6.1.2",
121120
"pg-hstore": "~2.3.2",
121+
"plantuml-encoder": "^1.2.5",
122122
"prismjs": "~1.6.0",
123123
"randomcolor": "~0.5.3",
124124
"raphael": "~2.2.8",

public/js/extra.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -970,10 +972,6 @@ md.use(require('markdown-it-emoji'), {
970972
shortcuts: {}
971973
})
972974

973-
md.use(require('markdown-it-plantuml'), {
974-
server: plantumlServer
975-
})
976-
977975
window.emojify.setConfig({
978976
blacklist: {
979977
elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'],
@@ -1040,6 +1038,33 @@ md.renderer.rules.fence = (tokens, idx, options, env, self) => {
10401038
return `<pre><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`
10411039
}
10421040

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+
10431068
// youtube
10441069
const youtubePlugin = new Plugin(
10451070
// regexp to match

yarn.lock

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7898,11 +7898,6 @@ markdown-it-mathjax@~2.0.0:
78987898
resolved "https://registry.yarnpkg.com/markdown-it-mathjax/-/markdown-it-mathjax-2.0.0.tgz#ae2b4f4c5c719a03f9e475c664f7b2685231d9e9"
78997899
integrity sha1-ritPTFxxmgP55HXGZPeyaFIx2ek=
79007900

7901-
markdown-it-plantuml@^1.4.1:
7902-
version "1.4.1"
7903-
resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-1.4.1.tgz#3bd5e7d92eaa5c6c68eb29802f7b46a8e05ca998"
7904-
integrity sha512-13KgnZaGYTHBp4iUmGofzZSBz+Zj6cyqfR0SXUIc9wgWTto5Xhn7NjaXYxY0z7uBeTUMlc9LMQq5uP4OM5xCHg==
7905-
79067901
markdown-it-regexp@~0.4.0:
79077902
version "0.4.0"
79087903
resolved "https://registry.yarnpkg.com/markdown-it-regexp/-/markdown-it-regexp-0.4.0.tgz#d64d713eecec55ce4cfdeb321750ecc099e2c2dc"
@@ -9113,6 +9108,11 @@ packet-reader@0.2.0:
91139108
resolved "https://registry.yarnpkg.com/packet-reader/-/packet-reader-0.2.0.tgz#819df4d010b82d5ea5671f8a1a3acf039bcd7700"
91149109
integrity sha1-gZ300BC4LV6lZx+KGjrPA5vNdwA=
91159110

9111+
pako@1.0.3:
9112+
version "1.0.3"
9113+
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.3.tgz#5f515b0c6722e1982920ae8005eacb0b7ca73ccf"
9114+
integrity sha1-X1FbDGci4ZgpIK6ABerLC3ynPM8=
9115+
91169116
pako@~1.0.5:
91179117
version "1.0.10"
91189118
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.10.tgz#4328badb5086a426aa90f541977d4955da5c9732"
@@ -9630,6 +9630,14 @@ pkginfo@^0.2.3:
96309630
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.2.3.tgz#7239c42a5ef6c30b8f328439d9b9ff71042490f8"
96319631
integrity sha1-cjnEKl72wwuPMoQ52bn/cQQkkPg=
96329632

9633+
plantuml-encoder@^1.2.5:
9634+
version "1.2.5"
9635+
resolved "https://registry.yarnpkg.com/plantuml-encoder/-/plantuml-encoder-1.2.5.tgz#6b8e5b9e1a1dbd88b3fd9fb46f734eec7d44b548"
9636+
integrity sha512-viV7Sz+BJNX/sC3iyebh2VfLyAZKuu3+JuBs2ISms8+zoTGwPqwk3/WEDw/zROmGAJ/xD4sNd8zsBw/YmTo7ng==
9637+
dependencies:
9638+
pako "1.0.3"
9639+
utf8-bytes "0.0.1"
9640+
96339641
platform@1.3.5:
96349642
version "1.3.5"
96359643
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.5.tgz#fb6958c696e07e2918d2eeda0f0bc9448d733444"
@@ -12791,6 +12799,11 @@ utf-8-validate@~5.0.1:
1279112799
dependencies:
1279212800
node-gyp-build "~3.7.0"
1279312801

12802+
utf8-bytes@0.0.1:
12803+
version "0.0.1"
12804+
resolved "https://registry.yarnpkg.com/utf8-bytes/-/utf8-bytes-0.0.1.tgz#116b025448c9b500081cdfbf1f4d6c6c37d8837d"
12805+
integrity sha1-EWsCVEjJtQAIHN+/H01sbDfYg30=
12806+
1279412807
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
1279512808
version "1.0.2"
1279612809
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

0 commit comments

Comments
 (0)