Skip to content

Commit

Permalink
refactor: simplify regexp and reserve escaped '`'
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Jun 4, 2018
1 parent 4503cfc commit 5e0651f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/util/parseHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ const unescapeHtml = html => String(html)
.replace(/>/g, '>')

const removeMarkdownToken = str => String(str)
.replace(/`(.*)`/, '$1') // ``
.replace(/\[(.*)\]\(.*\)/, '$1') // []()
.replace(/\*\*(.*)\*\*/, '$1') // **
.replace(/\*(.*[^\\])\*/, '$1') // *
.replace(/_(.*[^\\])_/g, '$1') // _ _
.replace(/(\\)(\*|_)/g, '$2') // remove escaped char '\'
.replace(/\[(.*)\]\(.*\)/, '$1') // []()
.replace(/(`|\*\*|\*|_)(.*[^\\])\1/, '$2') // `{t}` | *{t}* | **{t}** | _{t}_
.replace(/(\\)(\*|_|`)/g, '$2') // remove escape char '\'

exports.removeTailHtml = (str) => {
return String(str).replace(/<.*>\s*$/g, '')
Expand Down

0 comments on commit 5e0651f

Please sign in to comment.