in docs.js [72:128]
function replaceMarkdownText(codeTxt, docInfo, filePath) {
if (!/^([\s]*)(---[\s\S]*---)/.test(codeTxt)) {
const {repoUrl, commitId, docName, version} = docInfo;
const prefix = repoUrl.replace('.git', '/tree') + `/${commitId}`;
const depth = filePath.split('/docs')[1].match(/\//g).length - 2;
let title = codeTxt.trim().split('\n')[0]
title = title.match(/(?<=([ ])).*/g)[0];
title = title.replace(/:/g, ':')
codeTxt =
`---
title: ${title}
type: projectDoc
layout: baseof
---\n` + codeTxt;
codeTxt = codeTxt
.replace(/(\[[\s\S]*?\])\(([\s\S]*?)\)/g, function (match, p1, p2) {
if (p2 && p2.startsWith('http') || isImage(p2)) {
return match
}
if (p2.startsWith('../')) {
const parentDepth = p2.match(/\.\.\//g).length;
if (parentDepth >= depth) {
const url = p2.replace(/\.\.\//g, '')
return `${p1}(${prefix}/${url})`
}
}
const str = p2
.toLowerCase()
.replace(/\.md/g, '')
if (str.startsWith('#')) {
return `${p1}(${str})`
}
if (str.startsWith('./')) {
return `${p1}(./../${str.slice(2)})`
}
return `${p1}(../${str})`
})
.replace(/<img(.*?)src="(.*?)"(.*?)>/g, function (match, p1, p2, p3) {
if (p2 && p2.startsWith('http')) {
return match
}
const imgName = `${docName}_${version}_` + p2.split('/').pop();
return `<img${p1}src="/images/${imgName}"${p3}>`
})
.replace(/(\!\[[\s\S]*?\])\((.*?)\)/g, function (match, p1, p2,) {
if (p2 && p2.startsWith('http')) {
return match
}
const imgName = `${docName}_${version}_` + p2.split('/').pop();
return `${p1}(/images/${imgName})`
})
}
return codeTxt
}