diff --git a/packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts b/packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts index 60ffc7afc0..aaa487a215 100644 --- a/packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts +++ b/packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts @@ -19,6 +19,10 @@ describe('parseHeaders', () => { '\\*vue\\*': '*vue*', '\\!vue\\!': '!vue!', + // #2688 + '[vue](vuejs.org) / [vue](vuejs.org)': 'vue / vue', + '[\\](vuejs.org)': '', + // #564 For multiple markdown tokens '`a` and `b`': 'a and b', '***bold and italic***': 'bold and italic', diff --git a/packages/@vuepress/shared-utils/__tests__/removeNonCodeWrappedHTML.spec.ts b/packages/@vuepress/shared-utils/__tests__/removeNonCodeWrappedHTML.spec.ts index cfa2594a92..cd80803d3e 100644 --- a/packages/@vuepress/shared-utils/__tests__/removeNonCodeWrappedHTML.spec.ts +++ b/packages/@vuepress/shared-utils/__tests__/removeNonCodeWrappedHTML.spec.ts @@ -44,7 +44,10 @@ test('removeNonCodeWrappedHTML', () => { '# H1 `` H2': '# H1 `` H2', '# H1 `` H2': '# H1 `` H2', '# H1 `` H2': '# H1 `` H2', - '# H1 `` H2': '# H1 `` H2' + '# H1 `` H2': '# H1 `` H2', + + // #2688 + '# \\': '# \\' } Object.keys(asserts).forEach(input => { diff --git a/packages/@vuepress/shared-utils/src/parseHeaders.ts b/packages/@vuepress/shared-utils/src/parseHeaders.ts index 2665b6c29b..5be50751b1 100644 --- a/packages/@vuepress/shared-utils/src/parseHeaders.ts +++ b/packages/@vuepress/shared-utils/src/parseHeaders.ts @@ -15,9 +15,9 @@ import parseEmojis from './parseEmojis' // wrapped by (markdown token: '`') tag. const removeMarkdownTokens = (str: string): string => String(str) - .replace(/\[(.*)\]\(.*\)/, '$1') // []() - .replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, '$2') // `{t}` | *{t}* | **{t}** | ***{t}*** | _{t}_ - .replace(/(\\)(\*|_|`|\!)/g, '$2') // remove escape char '\' + .replace(/(\[(.[^\]]+)\]\((.[^)]+)\))/g, '$2') // []() + .replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, '$2') // `{t}` | *{t}* | **{t}** | ***{t}*** | _{t}_ + .replace(/(\\)(\*|_|`|\!|<)/g, '$2') // remove escape char '\' const trim = (str: string): string => str.trim() diff --git a/packages/@vuepress/shared-utils/src/removeNonCodeWrappedHTML.ts b/packages/@vuepress/shared-utils/src/removeNonCodeWrappedHTML.ts index 7d5461b80c..270a4f102d 100644 --- a/packages/@vuepress/shared-utils/src/removeNonCodeWrappedHTML.ts +++ b/packages/@vuepress/shared-utils/src/removeNonCodeWrappedHTML.ts @@ -3,5 +3,5 @@ // Input: " b", Output: "b" // Input: "`` b", Output: "`` b" export = function removeNonCodeWrappedHTML (str: string): string { - return String(str).replace(/(^|[^><`])<.*>([^><`]|$)/g, '$1$2') + return String(str).replace(/(^|[^><`\\])<.*>([^><`]|$)/g, '$1$2') }