Skip to content

Commit

Permalink
fix(markdown): do not treat autolink as a component (close #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Feb 18, 2021
1 parent 2402a6c commit 9f6cffa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,32 @@ describe('@vuepress/markdown > plugins > customComponentPlugin', () => {
})
})
})

describe('compatibility with other markdown syntax', () => {
it('should work with autolink', () => {
const source = [
'<https://github.com>',
'<localhost:5001/foo>',
'<made-up-scheme://foo,bar>',
'<foo@bar.example.com>',
'<foo+special@Bar.baz-bar0.com>',
'<a+b+c:d>',
].join('\n\n')

const expected =
[
'<a href="https://github.com">https://github.com</a>',
'<a href="localhost:5001/foo">localhost:5001/foo</a>',
'<a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a>',
'<a href="mailto:foo@bar.example.com">foo@bar.example.com</a>',
'<a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a>',
'<a href="a+b+c:d">a+b+c:d</a>',
]
.map((a) => `<p>${a}</p>`)
.join('\n') + '\n'

const rendered = md.render(source)
expect(rendered).toBe(expected)
})
})
})
11 changes: 11 additions & 0 deletions packages/@vuepress/markdown/__tests__/plugins/linksPlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
'[https-github](https://github.com)',
'[http-github](http://github.com)',
'[github](//github.com)',
// autolink
'<https://github.com>',
'<http://github.com>',
].join('\n\n')

it('should render default attrs and `<OutboundLink/>`', () => {
Expand All @@ -22,6 +25,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
'<a href="https://github.com" target="_blank" rel="noopener noreferrer">https-github<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="noopener noreferrer">http-github<OutboundLink/></a>',
'<a href="//github.com" target="_blank" rel="noopener noreferrer">github<OutboundLink/></a>',
'<a href="https://github.com" target="_blank" rel="noopener noreferrer">https://github.com<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="noopener noreferrer">http://github.com<OutboundLink/></a>',
]
.map((a) => `<p>${a}</p>`)
.join('\n') + '\n'
Expand All @@ -45,6 +50,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
'<a href="https://github.com" target="_blank" rel="noopener noreferrer" foo="bar">https-github<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="noopener noreferrer" foo="bar">http-github<OutboundLink/></a>',
'<a href="//github.com" target="_blank" rel="noopener noreferrer" foo="bar">github<OutboundLink/></a>',
'<a href="https://github.com" target="_blank" rel="noopener noreferrer" foo="bar">https://github.com<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="noopener noreferrer" foo="bar">http://github.com<OutboundLink/></a>',
]
.map((a) => `<p>${a}</p>`)
.join('\n') + '\n'
Expand All @@ -67,6 +74,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
'<a href="https://github.com" target="_blank" rel="foobar">https-github<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="foobar">http-github<OutboundLink/></a>',
'<a href="//github.com" target="_blank" rel="foobar">github<OutboundLink/></a>',
'<a href="https://github.com" target="_blank" rel="foobar">https://github.com<OutboundLink/></a>',
'<a href="http://github.com" target="_blank" rel="foobar">http://github.com<OutboundLink/></a>',
]
.map((a) => `<p>${a}</p>`)
.join('\n') + '\n'
Expand All @@ -89,6 +98,8 @@ describe('@vuepress/markdown > plugins > linksPlugin', () => {
'<a href="https://github.com" target="_self" rel="noopener noreferrer">https-github</a>',
'<a href="http://github.com" target="_self" rel="noopener noreferrer">http-github</a>',
'<a href="//github.com" target="_self" rel="noopener noreferrer">github</a>',
'<a href="https://github.com" target="_self" rel="noopener noreferrer">https://github.com</a>',
'<a href="http://github.com" target="_self" rel="noopener noreferrer">http://github.com</a>',
]
.map((a) => `<p>${a}</p>`)
.join('\n') + '\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
],
// MODIFIED HERE: Treat unknown tags as block tags (custom components), excluding known inline tags
[
new RegExp('^</?(?!(' + inlineTags.join('|') + ')(?![\\w-]))\\w+-?'),
new RegExp(
'^</?(?!(' + inlineTags.join('|') + ')(?![\\w-]))\\w[\\w-]*[\\s/>]'
),
/^$/,
true,
],
Expand Down

0 comments on commit 9f6cffa

Please sign in to comment.