|
|
|
@ -145,12 +145,21 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const [src, regionName] = token.src ?? []
|
|
|
|
|
|
|
|
|
|
if (src) {
|
|
|
|
|
if (!src) return fence(...args)
|
|
|
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
|
loader.addDependency(src)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isAFile = fs.lstatSync(src).isFile()
|
|
|
|
|
if (fs.existsSync(src) && isAFile) {
|
|
|
|
|
if (!fs.existsSync(src) || !isAFile) {
|
|
|
|
|
token.content = isAFile
|
|
|
|
|
? `Code snippet path not found: ${src}`
|
|
|
|
|
: `Invalid code snippet option`
|
|
|
|
|
token.info = ''
|
|
|
|
|
return fence(...args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let content = fs.readFileSync(src, 'utf8')
|
|
|
|
|
|
|
|
|
|
if (regionName) {
|
|
|
|
@ -161,20 +170,13 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => {
|
|
|
|
|
content = dedent(
|
|
|
|
|
lines
|
|
|
|
|
.slice(region.start, region.end)
|
|
|
|
|
.filter((line: string) => !region.regexp.test(line.trim()))
|
|
|
|
|
.filter((line) => !region.regexp.test(line.trim()))
|
|
|
|
|
.join('\n')
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
token.content = content
|
|
|
|
|
} else {
|
|
|
|
|
token.content = isAFile
|
|
|
|
|
? `Code snippet path not found: ${src}`
|
|
|
|
|
: `Invalid code snippet option`
|
|
|
|
|
token.info = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fence(...args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|