This commit is contained in:
yulixing 2019-10-31 10:55:59 +08:00
parent 2592f502b4
commit cbdaf866a5

View File

@ -76,18 +76,22 @@ router.get('/text', async (req, res, next) => {
function parseText(text) {
const result = []
const textArr = text.split('\n')
const textReg = /^(#+) (.*)(::)*(.*)$/
const textReg = /^(#+) (.*)::(.*)$/
let lastLevel = 0
let lastIdx = 0
const posArr = [result]
textArr.map(item => {
if (item.indexOf('::') === -1) {
item += '::'
}
const execRes = textReg.exec(item)
if (!execRes) return
const curLevel = execRes[1].split('').length - 2
if (curLevel < 0) return
const text = execRes[2]
const content = execRes[4]
const content = execRes[3]
if (curLevel === lastLevel) {
const curPos = posArr[curLevel]
curPos.push({