mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
feat(compiler): support embedded mermaid (#629)
This commit is contained in:
parent
bf060befb7
commit
42ea8af245
@ -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>`
|
||||
@ -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)) {
|
||||
|
||||
@ -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})
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user