Skip to content

Commit 4d61b1e

Browse files
committed
refactor: embed files feature, resolve #383, resolve #333, resolve #134
1 parent c4d83f2 commit 4d61b1e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/core/render/compiler.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const compileMedia = {
5858
const id = `docsify-get-${uid++}`
5959
let ext = url.match(/\.(\w+)$/)
6060

61-
ext = config.ext || (ext && ext[1])
61+
ext = config.lang || (ext && ext[1])
6262
if (ext === 'md') ext = 'markdown'
6363

6464
if (!process.env.SSR) {
@@ -182,6 +182,32 @@ export class Compiler {
182182
const { str, config } = getAndRemoveConfig(title)
183183
title = str
184184

185+
if (config.include) {
186+
if (!isAbsolutePath(href)) {
187+
href = getPath(contentBase, href)
188+
}
189+
190+
let media
191+
if (config.type && (media = compileMedia[config.type])) {
192+
return media.call(_self, href, title)
193+
}
194+
195+
let type = null
196+
if (/\.(md|markdown)/.test(href)) {
197+
type = 'markdown'
198+
} else if (/\.html?/.test(href)) {
199+
type = 'html'
200+
} else if (/\.(mp4|ogg)/.test(href)) {
201+
type = 'video'
202+
} else if (/\.mp3/.test(href)) {
203+
type = 'audio'
204+
}
205+
console.log(href)
206+
if (type) {
207+
return compileMedia[type].call(_self, href, title)
208+
}
209+
}
210+
185211
if (
186212
!/:|(\/{2})/.test(href) &&
187213
!_self.matchNotCompileLink(href) &&
@@ -235,25 +261,6 @@ export class Compiler {
235261
url = getPath(contentBase, href)
236262
}
237263

238-
let media
239-
if (config.type && (media = compileMedia[config.type])) {
240-
return media.call(_self, url, title)
241-
}
242-
243-
let type = null
244-
if (/\.(md|markdown)/.test(url)) {
245-
type = 'markdown'
246-
} else if (/\.html?/.test(url)) {
247-
type = 'html'
248-
} else if (/\.(mp4|ogg)/.test(url)) {
249-
type = 'video'
250-
} else if (/\.mp3/.test(url)) {
251-
type = 'audio'
252-
}
253-
if (type) {
254-
return compileMedia[type].call(_self, url, title)
255-
}
256-
257264
return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`
258265
}
259266

0 commit comments

Comments
 (0)