diff --git a/src/code/colorful.js b/src/code/colorful.js
index 272f573..a11e646 100644
--- a/src/code/colorful.js
+++ b/src/code/colorful.js
@@ -22,9 +22,14 @@ const INLINE = {
strong: [/__([\s\S]*?[^\s\\])__(?!_)/g, /\*\*([\s\S]*?[^\s\\])\*\*(?!\*)/g],
em: [/_([\s\S]*?[^\s\\])_(?!_)/g, /\*([\s\S]*?[^\s\\*])\*(?!\*)/g],
del: /~~([\s\S]*?[^\s\\~])~~/g,
+ qlinkVar: /^\[(\d+)\]: ([\S]+)\s*?((['"])[\s\S]*?\4)?\s*?$/gm, // 引用声明
qlink: /\[([^\]]*?)\]\[(\d*?)\]/g, // 引用链接
img: /\!\[([^\]]*?)\]\(([^)]*?)\)/g,
- a: /\[([^\]]*?)\]\(([^)]*?)(\s+"([\s\S]*?)")*?\)/g
+ a: /\[([^\]]*?)\]\(([^)]*?)(\s+"([\s\S]*?)")*?\)/g,
+ head: /^(#{1,6} )(.*)$/gm,
+ quote: /^(>{1,} )(.*)$/gm,
+ task: /^([\-\+\*]) \[( |x)\] (.*)$/gm,
+ list: /^([ \t]*?([\-\+\*]|\d+\.) )(.*)$/gm
}
function parseJs(code) {
@@ -56,12 +61,23 @@ function rebuild(code) {
export function colorMd(code) {
code = code
+ .replace(INLINE.head, '[cm]$1[/cm][tag]$2[/tag]')
+ .replace(INLINE.quote, '[cm]$1[/cm]$2')
+ .replace(
+ INLINE.task,
+ '[cm]$1 [[/cm][attr]$2[/attr][cm]][/cm] $3'
+ )
+ .replace(INLINE.list, '[cm]$1[/cm]$3')
.replace(INLINE.strong[0], '[cm]__[/cm]$1[cm]__[/cm]')
.replace(INLINE.strong[1], '[cm]**[/cm]$1[cm]**[/cm]')
.replace(INLINE.em[0], '[cm]_[/cm]$1[cm]_[/cm]')
.replace(INLINE.em[1], '[cm]*[/cm]$1[cm]*[/cm]')
.replace(INLINE.del, '[cm]~~[/cm]$1[cm]~~[/cm]')
- .replace(INLINE.qlink, '[[attr]$1[/attr]]([link]$2[/link])')
+ .replace(
+ INLINE.qlinkVar,
+ '[[attr]$1[/attr]]: [link]$2[/link] [tag]$3[/tag]'
+ )
+ .replace(INLINE.qlink, '[[attr]$1[/attr]][[link]$2[/link]]')
.replace(INLINE.img, '![[attr]$1[/attr]]([link]$2[/link])')
.replace(INLINE.a, (m1, txt, link, m2, attr = '') => {
if (attr) {
diff --git a/src/markd/core.js b/src/markd/core.js
index 2086215..36c88e5 100644
--- a/src/markd/core.js
+++ b/src/markd/core.js
@@ -32,8 +32,7 @@ const Helper = {
isHr(str) {
var s = str[0]
if (HR_LIST.includes(s)) {
- var reg = new RegExp('^\\' + escape(s) + '{3,}$')
- return reg.test(str)
+ return str.slice(0, 3) === s.repeat(3) ? str.slice(3) : false
}
return false
},
@@ -119,8 +118,8 @@ const Decoder = {
.replace(ESCAPE_RE, '$1') // 处理转义字符
},
// 分割线
- hr() {
- return '