From 42ea8af245fe04fc79ef53377ef48f7d88e96838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garc=C3=ADa?= Date: Tue, 23 Oct 2018 09:29:14 +0200 Subject: [PATCH] feat(compiler): support embedded mermaid (#629) --- src/core/render/compiler.js | 7 +++++++ src/core/render/embed.js | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index c27c4951e..74d9ed382 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -30,6 +30,11 @@ const compileMedia = { url } }, + mermaid(url) { + return { + url + } + }, iframe(url, title) { return { code: `` @@ -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)) { diff --git a/src/core/render/embed.js b/src/core/render/embed.js index f82a77d57..5a4874d52 100644 --- a/src/core/render/embed.js +++ b/src/core/render/embed.js @@ -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: `
\n${text}\n
`}] + 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