${_} | `) + .join('')}
---|
' - } - - blockquoteLevel = len - return tmp - }) - - isParagraph = false - isBlockquote = true - continue - } - - // 任务 - let task = Decoder.task(it) - if (task) { - html += task - continue - } - - // 列表 - let listChecked = Helper.isList(it) - if (~listChecked) { - // 左侧空格长度 - let tmp = Helper.ltrim(it) - let ltrim = it.length - tmp.length - let word = tmp.replace(LIST_REG, '').trim() - let level = Math.floor(ltrim / 2) - let tag = listChecked > 0 ? 'ol' : 'ul' - - if (!isList) { - html += `<${tag}>` - if (listChecked === 1) { - orderListLevel = level - } else { - unorderListLevel = level - } - html += `${word} ` - } else { - if (listChecked === 1) { - if (level > orderListLevel) { - html = html.replace(/<\/li>$/, '') - html += `<${tag}>${word} ` - } else if (level === orderListLevel) { - html += `${word} ` - } else { - html += `${tag}>${word} ` - } - orderListLevel = level - } else { - if (level > unorderListLevel) { - html = html.replace(/<\/li>$/, '') - html += `<${tag}>${word} ` - } else if (level === unorderListLevel) { - html += `${word} ` - } else { - html += `${tag}>${word} ` - } - unorderListLevel = level - } - } - - isList = true - continue - } - - // log('it => ', isParagraph, it) - if (isParagraph) { - html += `${it}
` - } else { - html += `${it}
` - } - isParagraph = true + continue } + + // 同上代码块的处理 + if (isCodeBlock) { + html += it + '\n' + continue + } + + // 无属性标签 + if (Helper.isHr(it)) { + html += Decoder.hr() + continue + } + + // 优先处理一些常规样式 + it = Decoder.inline.call(this, it) + + // 标题只能是单行 + var head = Decoder.head(it) + if (head) { + isParagraph = false + html += head + continue + } + + // 引用 + if (it.startsWith('>')) { + if (isBlockquote) { + html += '
' + } + html += it.replace(/^(>+) /, (p, m) => { + let len = m.length + let tmp = '' + let loop = len + // 若之前已经有一个未闭合的引用, 需要减去已有缩进级别, 避免产生新的引用标签 + if (isBlockquote) { + loop = len - blockquoteLevel + } else { + } + + while (loop > 0) { + loop-- + tmp += '' + } + + blockquoteLevel = len + return tmp + }) + + isParagraph = false + isBlockquote = true + continue + } + + // 任务 + let task = Decoder.task(it) + if (task) { + html += task + continue + } + + // 列表 + let listChecked = Helper.isList(it) + if (~listChecked) { + // 左侧空格长度 + let tmp = Helper.ltrim(it) + let ltrim = it.length - tmp.length + let word = tmp.replace(LIST_REG, '').trim() + let level = Math.floor(ltrim / 2) + let tag = listChecked > 0 ? 'ol' : 'ul' + + if (!isList) { + html += `<${tag}>` + if (listChecked === 1) { + orderListLevel = level + } else { + unorderListLevel = level + } + html += `${word} ` + } else { + if (listChecked === 1) { + if (level > orderListLevel) { + html = html.replace(/<\/li>$/, '') + html += `<${tag}>${word} ` + } else if (level === orderListLevel) { + html += `${word} ` + } else { + html += `${tag}>${word} ` + } + orderListLevel = level + } else { + if (level > unorderListLevel) { + html = html.replace(/<\/li>$/, '') + html += `<${tag}>${word} ` + } else if (level === unorderListLevel) { + html += `${word} ` + } else { + html += `${tag}>${word} ` + } + unorderListLevel = level + } + } + + isList = true + continue + } + + // log('it => ', isParagraph, it) + if (isParagraph) { + html += `${it}
` + } else { + html += `${it}
` + } + isParagraph = true } } return html diff --git a/src/markd/index.wc b/src/markd/index.wc index a70add4..6b43191 100644 --- a/src/markd/index.wc +++ b/src/markd/index.wc @@ -216,6 +216,7 @@ h4 { } table { + width: 100%; border-spacing: 0; border-collapse: collapse;