Skip to content

Commit 9f6cffa

Browse files
committed
fix(markdown): do not treat autolink as a component (close #60)
1 parent 2402a6c commit 9f6cffa

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Diff for: packages/@vuepress/markdown/__tests__/plugins/customComponentPlugin.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,32 @@ describe('@vuepress/markdown > plugins > customComponentPlugin', () => {
773773
})
774774
})
775775
})
776+
777+
describe('compatibility with other markdown syntax', () => {
778+
it('should work with autolink', () => {
779+
const source = [
780+
'<https://github.com>',
781+
'<localhost:5001/foo>',
782+
'<made-up-scheme://foo,bar>',
783+
784+
785+
'<a+b+c:d>',
786+
].join('\n\n')
787+
788+
const expected =
789+
[
790+
'<a href="https://github.com">https://github.com</a>',
791+
'<a href="localhost:5001/foo">localhost:5001/foo</a>',
792+
'<a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a>',
793+
'<a href="mailto:[email protected]">[email protected]</a>',
794+
'<a href="mailto:[email protected]">[email protected]</a>',
795+
'<a href="a+b+c:d">a+b+c:d</a>',
796+
]
797+
.map((a) => `<p>${a}</p>`)
798+
.join('\n') + '\n'
799+
800+
const rendered = md.render(source)
801+
expect(rendered).toBe(expected)
802+
})
803+
})
776804
})

Diff for: packages/@vuepress/markdown/__tests__/plugins/linksPlugin.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
99
'[https-github](https://github.com)',
1010
'[http-github](http://github.com)',
1111
'[github](//github.com)',
12+
// autolink
13+
'<https://github.com>',
14+
'<http://github.com>',
1215
].join('\n\n')
1316

1417
it('should render default attrs and `<OutboundLink/>`', () => {
@@ -22,6 +25,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
2225
'<a href="https://github.com" target="_blank" rel="noopener noreferrer">https-github<OutboundLink/></a>',
2326
'<a href="http://github.com" target="_blank" rel="noopener noreferrer">http-github<OutboundLink/></a>',
2427
'<a href="//github.com" target="_blank" rel="noopener noreferrer">github<OutboundLink/></a>',
28+
'<a href="https://github.com" target="_blank" rel="noopener noreferrer">https://github.com<OutboundLink/></a>',
29+
'<a href="http://github.com" target="_blank" rel="noopener noreferrer">http://github.com<OutboundLink/></a>',
2530
]
2631
.map((a) => `<p>${a}</p>`)
2732
.join('\n') + '\n'
@@ -45,6 +50,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
4550
'<a href="https://github.com" target="_blank" rel="noopener noreferrer" foo="bar">https-github<OutboundLink/></a>',
4651
'<a href="http://github.com" target="_blank" rel="noopener noreferrer" foo="bar">http-github<OutboundLink/></a>',
4752
'<a href="//github.com" target="_blank" rel="noopener noreferrer" foo="bar">github<OutboundLink/></a>',
53+
'<a href="https://github.com" target="_blank" rel="noopener noreferrer" foo="bar">https://github.com<OutboundLink/></a>',
54+
'<a href="http://github.com" target="_blank" rel="noopener noreferrer" foo="bar">http://github.com<OutboundLink/></a>',
4855
]
4956
.map((a) => `<p>${a}</p>`)
5057
.join('\n') + '\n'
@@ -67,6 +74,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
6774
'<a href="https://github.com" target="_blank" rel="foobar">https-github<OutboundLink/></a>',
6875
'<a href="http://github.com" target="_blank" rel="foobar">http-github<OutboundLink/></a>',
6976
'<a href="//github.com" target="_blank" rel="foobar">github<OutboundLink/></a>',
77+
'<a href="https://github.com" target="_blank" rel="foobar">https://github.com<OutboundLink/></a>',
78+
'<a href="http://github.com" target="_blank" rel="foobar">http://github.com<OutboundLink/></a>',
7079
]
7180
.map((a) => `<p>${a}</p>`)
7281
.join('\n') + '\n'
@@ -89,6 +98,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
8998
'<a href="https://github.com" target="_self" rel="noopener noreferrer">https-github</a>',
9099
'<a href="http://github.com" target="_self" rel="noopener noreferrer">http-github</a>',
91100
'<a href="//github.com" target="_self" rel="noopener noreferrer">github</a>',
101+
'<a href="https://github.com" target="_self" rel="noopener noreferrer">https://github.com</a>',
102+
'<a href="http://github.com" target="_self" rel="noopener noreferrer">http://github.com</a>',
92103
]
93104
.map((a) => `<p>${a}</p>`)
94105
.join('\n') + '\n'

Diff for: packages/@vuepress/markdown/src/plugins/customComponentPlugin/htmlBlockRule.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
2222
],
2323
// MODIFIED HERE: Treat unknown tags as block tags (custom components), excluding known inline tags
2424
[
25-
new RegExp('^</?(?!(' + inlineTags.join('|') + ')(?![\\w-]))\\w+-?'),
25+
new RegExp(
26+
'^</?(?!(' + inlineTags.join('|') + ')(?![\\w-]))\\w[\\w-]*[\\s/>]'
27+
),
2628
/^$/,
2729
true,
2830
],

0 commit comments

Comments
 (0)