Skip to content

Commit

Permalink
feat(compiler): support embedded mermaid (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos García authored and QingWei-Li committed Oct 23, 2018
1 parent bf060be commit 42ea8af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const compileMedia = {
url
}
},
mermaid(url) {
return {
url
}
},
iframe(url, title) {
return {
code: `<iframe src="${url}" ${title || 'width=100% height=400'}></iframe>`
Expand Down Expand Up @@ -141,6 +146,8 @@ export class Compiler {
let type = 'code'
if (/\.(md|markdown)/.test(href)) {
type = 'markdown'
} else if (/\.mmd/.test(href)) {
type = 'mermaid'
} else if (/\.html?/.test(href)) {
type = 'iframe'
} else if (/\.(mp4|ogg)/.test(href)) {
Expand Down
8 changes: 7 additions & 1 deletion src/core/render/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
text.replace(/`/g, '@DOCSIFY_QM@') +
'\n```\n'
)
} else if (token.embed.type === 'mermaid') {
embedToken = [{type: 'html', text: `<div class="mermaid">\n${text}\n</div>`}]
embedToken.links = {}
}
}
cb({token, embedToken})
Expand Down Expand Up @@ -64,7 +67,10 @@ export function prerenderEmbed({compiler, raw = '', fetch}, done) {
const embed = compiler.compileEmbed(href, title)

if (embed) {
if (embed.type === 'markdown' || embed.type === 'code') {
if (embed.type === 'markdown' ||
embed.type === 'code' ||
embed.type === 'mermaid'
) {
embedTokens.push({
index,
embed
Expand Down

0 comments on commit 42ea8af

Please sign in to comment.