|
|
|
@ -41,12 +41,18 @@ export function processIncludes(
|
|
|
|
if (region) {
|
|
|
|
if (region) {
|
|
|
|
const [regionName] = region
|
|
|
|
const [regionName] = region
|
|
|
|
const lines = content.split(/\r?\n/)
|
|
|
|
const lines = content.split(/\r?\n/)
|
|
|
|
|
|
|
|
let selectedLines = lines
|
|
|
|
let { start, end } = findRegion(lines, regionName.slice(1)) ?? {}
|
|
|
|
let { start, end } = findRegion(lines, regionName.slice(1)) ?? {}
|
|
|
|
|
|
|
|
|
|
|
|
if (start === undefined) {
|
|
|
|
if (start === undefined) {
|
|
|
|
// region not found, it might be a header
|
|
|
|
// region not found, it might be a header
|
|
|
|
|
|
|
|
const headerContent =
|
|
|
|
|
|
|
|
path.extname(includePath) === '.md'
|
|
|
|
|
|
|
|
? matter(content).content
|
|
|
|
|
|
|
|
: content
|
|
|
|
|
|
|
|
const headerLines = headerContent.split(/\r?\n/)
|
|
|
|
const tokens = md
|
|
|
|
const tokens = md
|
|
|
|
.parse(content, {
|
|
|
|
.parse(headerContent, {
|
|
|
|
path: includePath,
|
|
|
|
path: includePath,
|
|
|
|
relativePath: slash(path.relative(srcDir, includePath)),
|
|
|
|
relativePath: slash(path.relative(srcDir, includePath)),
|
|
|
|
cleanUrls
|
|
|
|
cleanUrls
|
|
|
|
@ -57,6 +63,7 @@ export function processIncludes(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
const token = tokens[idx]
|
|
|
|
const token = tokens[idx]
|
|
|
|
if (token) {
|
|
|
|
if (token) {
|
|
|
|
|
|
|
|
selectedLines = headerLines
|
|
|
|
start = token.map![1]
|
|
|
|
start = token.map![1]
|
|
|
|
const level = parseInt(token.tag.slice(1))
|
|
|
|
const level = parseInt(token.tag.slice(1))
|
|
|
|
for (let i = idx + 1; i < tokens.length; i++) {
|
|
|
|
for (let i = idx + 1; i < tokens.length; i++) {
|
|
|
|
@ -68,7 +75,7 @@ export function processIncludes(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
content = lines.slice(start, end).join('\n')
|
|
|
|
content = selectedLines.slice(start, end).join('\n')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (range) {
|
|
|
|
if (range) {
|
|
|
|
|