From 21dd4815c2b76f9c25e0bb60e71a29ae423dabe0 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sat, 10 Feb 2018 12:21:23 +0800 Subject: [PATCH] feat(compiler): support embedded file as code block, close #134 --- src/core/render/compiler.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 3223beca2..15dbe13c1 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -42,6 +42,21 @@ const compileMedia = { }, audio (url, config) { return `` + }, + code (url, config) { + const request = get(url, false) + const id = `docsify-get-${request.uid}` + let ext = url.match(/\.(\w+)$/) + + ext = config.ext || (ext && ext[0]) + + request.then(text => { + document.getElementById(id).innerHTML = this.compile( + '```' + ext + '\n ' + text + '\n```\n' + ) + }) + + return `
` } }