From 0af412ab90bdaac6d6bc2349e52c3ccf51358a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 11 Feb 2020 23:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=8C=E5=86=85=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/markd/parser.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/markd/parser.js b/src/markd/parser.js index e82a79f..b9c1257 100644 --- a/src/markd/parser.js +++ b/src/markd/parser.js @@ -8,6 +8,7 @@ const HR_LIST = ['=', '-', '_', '*'] const LIST_REG = /^(([\+\-\*])|(\d+\.))\s/ const TODO_REG = /^\-\s\[(x|\s)\]\s/ +const ESCAPE_REG = /\\([-+*_`])/g const log = console.log const Helper = { @@ -55,7 +56,11 @@ class Tool { // 初始化字符串, 处理多余换行等 static init(str) { // 去掉\r, 将\t转为空格(2个) - str = str.replace(/\r/g, '').replace(/\t/g, ' ') + str = str + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' ') + .replace(/\u00a0/g, ' ') + .replace(/\u2424/g, '\n') var list = [] var lines = str.split('\n') var isCodeBlock = false // 是否代码块 @@ -163,12 +168,13 @@ class Tool { // 优先处理一些常规样式 it = it - .replace(/`(.*?)`/g, '$1') - .replace(/(\-\-|\*\*)(.*?)\1/g, '$2') - .replace(/(\-|\_|\*)(.*?)\1/g, '$2') - .replace(/~~(.*?)~~/g, '$1') + .replace(/`(.*?[^\\])`/g, '$1') + .replace(/(__|\*\*)(.*?[^\\])\1/g, '$2') + .replace(/\b(_|\*)(.*?[^\\])\1\b/g, '$2') + .replace(/~~(.*?[^\\])~~/g, '$1') .replace(/\!\[([^]*?)\]\(([^)]*?)\)/g, '$1') .replace(/\[([^]*?)\]\(([^)]*?)\)/g, '$1') + .replace(ESCAPE_REG, '$1') // 处理转义字符 // 引用 if (it.startsWith('>')) {