From 60f9af17c15d98afb242c65d88c02748611e4793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Sun, 5 Apr 2020 19:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0marked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/markd/core.js | 31 +++++++++++++++++++++++++++---- src/markd/index.wc | 5 ++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/markd/core.js b/src/markd/core.js index 295b5d8..a33ceb9 100644 --- a/src/markd/core.js +++ b/src/markd/core.js @@ -9,6 +9,22 @@ const HR_LIST = ['=', '-', '_', '*'] const LIST_REG = /^(([\+\-\*])|(\d+\.))\s/ const TODO_REG = /^\-\s\[(x|\s)\]\s/ const ESCAPE_REG = /\\([-+*_`])/g + +const INLINE = { + strong: [ + /__([^\s_])__(?!_)/g, + /\*\*([^\s*])\*\*(?!\*)/g, + /__([^\s][\s\S]*?[^\s])__(?!_)/g, + /\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/g + ], + em: [ + /_([^\s_])_(?!_)/g, + /\*([^\s*])\*(?!\*)/g, + /_([^\s][\s\S]*?[^\s])_(?!_)/g, + /\*([^\s][\s\S]*?[^\s])\*(?!\*)/g + ], + del: [/~~([^\~])~~(?!~)/g, /~~([^\s][\s\S]*?[^\s])~~(?!~)/g] +} const log = console.log const Helper = { @@ -53,10 +69,17 @@ const Decoder = { // 内联样式 inline(str) { return str - .replace(/`(.*?[^\\])`/g, '$1') - .replace(/(__|\*\*)(.*?[^\\])\1/g, '$2') - .replace(/\b(_|\*)(.*?[^\\])\1\b/g, '$2') - .replace(/~~(.*?[^\\])~~/g, '$1') + .replace(/`([^`]*?[^`\\\s])`/g, '$1') + .replace(INLINE.strong[0], '$1') + .replace(INLINE.strong[1], '$1') + .replace(INLINE.strong[2], '$1') + .replace(INLINE.strong[3], '$1') + .replace(INLINE.em[0], '$1') + .replace(INLINE.em[1], '$1') + .replace(INLINE.em[2], '$1') + .replace(INLINE.em[3], '$1') + .replace(INLINE.del[0], '$1') + .replace(INLINE.del[1], '$1') .replace(/\!\[([^]*?)\]\(([^)]*?)\)/g, '$1') .replace(/\[([^]*?)\]\(([^)]*?)\)/g, '$1') .replace(ESCAPE_REG, '$1') // 处理转义字符 diff --git a/src/markd/index.wc b/src/markd/index.wc index 1e76e0b..a70add4 100644 --- a/src/markd/index.wc +++ b/src/markd/index.wc @@ -23,7 +23,10 @@ em, del { color: nth($cgr, 2); } -strong { +strong, +strong em, +strong, +del { color: nth($cd, 3); } a {