({ embedTokens, compile, fetch }, cb)
| 5 | const cached = {}; |
| 6 | |
| 7 | function walkFetchEmbed({ embedTokens, compile, fetch }, cb) { |
| 8 | let token; |
| 9 | let step = 0; |
| 10 | let count = 1; |
| 11 | |
| 12 | if (!embedTokens.length) { |
| 13 | return cb({}); |
| 14 | } |
| 15 | |
| 16 | while ((token = embedTokens[step++])) { |
| 17 | // eslint-disable-next-line no-shadow |
| 18 | const next = (function (token) { |
| 19 | return text => { |
| 20 | let embedToken; |
| 21 | if (text) { |
| 22 | if (token.embed.type === 'markdown') { |
| 23 | let path = token.embed.url.split('/'); |
| 24 | path.pop(); |
| 25 | path = path.join('/'); |
| 26 | // Resolves relative links to absolute |
| 27 | text = text.replace(/\[([^[\]]+)\]\(([^)]+)\)/g, x => { |
| 28 | const linkBeginIndex = x.indexOf('('); |
| 29 | if (x.slice(linkBeginIndex, linkBeginIndex + 2) === '(.') { |
| 30 | return ( |
| 31 | x.substring(0, linkBeginIndex) + |
| 32 | `(${window.location.protocol}//${window.location.host}${path}/` + |
| 33 | x.substring(linkBeginIndex + 1, x.length - 1) + |
| 34 | ')' |
| 35 | ); |
| 36 | } |
| 37 | return x; |
| 38 | }); |
| 39 | |
| 40 | // This may contain YAML front matter and will need to be stripped. |
| 41 | const frontMatterInstalled = |
| 42 | ($docsify.frontMatter || {}).installed || false; |
| 43 | if (frontMatterInstalled === true) { |
| 44 | text = $docsify.frontMatter.parseMarkdown(text); |
| 45 | } |
| 46 | |
| 47 | embedToken = compile.lexer(text); |
| 48 | } else if (token.embed.type === 'code') { |
| 49 | if (token.embed.fragment) { |
| 50 | const fragment = token.embed.fragment; |
| 51 | const pattern = new RegExp( |
| 52 | `(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]` |
| 53 | ); |
| 54 | text = stripIndent((text.match(pattern) || [])[1] || '').trim(); |
| 55 | } |
| 56 | |
| 57 | embedToken = compile.lexer( |
| 58 | '```' + |
| 59 | token.embed.lang + |
| 60 | '\n' + |
| 61 | text.replace(/`/g, '@DOCSIFY_QM@') + |
| 62 | '\n```\n' |
| 63 | ); |
| 64 | } else if (token.embed.type === 'mermaid') { |
no test coverage detected
searching dependent graphs…