Skip to content

Commit d264e50

Browse files
authored
fix($shared-utils): improve title inference and header extraction for markdown links syntax
1 parent cd4ad04 commit d264e50

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ describe('parseHeaders', () => {
1919
'\\*vue\\*': '*vue*',
2020
'\\!vue\\!': '!vue!',
2121

22+
// #2688
23+
'[vue](vuejs.org) / [vue](vuejs.org)': 'vue / vue',
24+
'[\\<ins>](vuejs.org)': '<ins>',
25+
2226
// #564 For multiple markdown tokens
2327
'`a` and `b`': 'a and b',
2428
'***bold and italic***': 'bold and italic',

packages/@vuepress/shared-utils/__tests__/removeNonCodeWrappedHTML.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ test('removeNonCodeWrappedHTML', () => {
4444
'# H1 `<Comp></Comp>` H2': '# H1 `<Comp></Comp>` H2',
4545
'# H1 `<Comp a="b"></Comp>` H2': '# H1 `<Comp a="b"></Comp>` H2',
4646
'# H1 `<Comp/>` H2': '# H1 `<Comp/>` H2',
47-
'# H1 `<Comp a="b"/>` H2': '# H1 `<Comp a="b"/>` H2'
47+
'# H1 `<Comp a="b"/>` H2': '# H1 `<Comp a="b"/>` H2',
48+
49+
// #2688
50+
'# \\<ins>': '# \\<ins>'
4851
}
4952

5053
Object.keys(asserts).forEach(input => {

packages/@vuepress/shared-utils/src/parseHeaders.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import parseEmojis from './parseEmojis'
1515
// wrapped by <code>(markdown token: '`') tag.
1616

1717
const removeMarkdownTokens = (str: string): string => String(str)
18-
.replace(/\[(.*)\]\(.*\)/, '$1') // []()
19-
.replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, '$2') // `{t}` | *{t}* | **{t}** | ***{t}*** | _{t}_
20-
.replace(/(\\)(\*|_|`|\!)/g, '$2') // remove escape char '\'
18+
.replace(/(\[(.[^\]]+)\]\((.[^)]+)\))/g, '$2') // []()
19+
.replace(/(`|\*{1,3}|_)(.*?[^\\])\1/g, '$2') // `{t}` | *{t}* | **{t}** | ***{t}*** | _{t}_
20+
.replace(/(\\)(\*|_|`|\!|<)/g, '$2') // remove escape char '\'
2121

2222
const trim = (str: string): string => str.trim()
2323

packages/@vuepress/shared-utils/src/removeNonCodeWrappedHTML.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// Input: "<a> b", Output: "b"
44
// Input: "`<a>` b", Output: "`<a>` b"
55
export = function removeNonCodeWrappedHTML (str: string): string {
6-
return String(str).replace(/(^|[^><`])<.*>([^><`]|$)/g, '$1$2')
6+
return String(str).replace(/(^|[^><`\\])<.*>([^><`]|$)/g, '$1$2')
77
}

0 commit comments

Comments
 (0)