-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support generic markdown file path reference (#509)
- Loading branch information
Showing
3 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`link should render external links correctly 1`] = ` | ||
<p> | ||
<a href="https://vuejs.org/" target="_blank" rel="noopener noreferrer">vue | ||
<OutboundLink/> | ||
</a> | ||
</p> | ||
`; | ||
|
||
exports[`link should render external links correctly 2`] = ` | ||
<p> | ||
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer">vue | ||
<OutboundLink/> | ||
</a> | ||
</p> | ||
`; | ||
|
||
exports[`link should render external links correctly 3`] = ` | ||
<p> | ||
<a href="https://google.com" target="_blank" rel="noopener noreferrer">some <strong>link</strong> with <code>code</code> | ||
<OutboundLink/> | ||
</a> | ||
</p> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Md } from './util' | ||
import link from '@/markdown/link.js' | ||
import { dataReturnable } from '@/markdown/index.js' | ||
|
||
const mdL = Md().use(link, { | ||
target: '_blank', | ||
rel: 'noopener noreferrer' | ||
}) | ||
|
||
dataReturnable(mdL) | ||
|
||
const internalLinkAsserts = { | ||
// START abosolute path usage | ||
'/': '/', | ||
|
||
'/foo/': '/foo/', | ||
'/foo/#hash': '/foo/#hash', | ||
|
||
'/foo/two.md': '/foo/two.html', | ||
'/foo/two.html': '/foo/two.html', | ||
// END abosolute path usage | ||
|
||
// START relative path usage | ||
'README.md': './', | ||
'./README.md': './', | ||
|
||
'index.md': './', | ||
'./index.md': './', | ||
|
||
'one.md': './one.html', | ||
'./one.md': './one.html', | ||
|
||
'foo/README.md': './foo/', | ||
'./foo/README.md': './foo/', | ||
|
||
'foo/README.md#hash': './foo/#hash', | ||
'./foo/README.md#hash': './foo/#hash', | ||
|
||
'../README.md': './../', | ||
'../README.md#hash': './../#hash', | ||
|
||
'../foo.md': './../foo.html', | ||
'../foo.md#hash': './../foo.html#hash', | ||
|
||
'../foo/one.md': './../foo/one.html', | ||
'../foo/one.md#hash': './../foo/one.html#hash' | ||
// END relative path usage | ||
} | ||
|
||
const externalLinks = [ | ||
'[vue](https://vuejs.org/)', | ||
'[vue](http://vuejs.org/)', | ||
'[some **link** with `code`](https://google.com)' // #496 | ||
] | ||
|
||
describe('link', () => { | ||
test('should convert internal links to router links correctly', () => { | ||
for (const before in internalLinkAsserts) { | ||
const input = `[${before}](${before})` | ||
const output = mdL.render(input) | ||
const after = getCompiledLink(output) | ||
expect(after).toBe(internalLinkAsserts[before]) | ||
} | ||
}) | ||
|
||
test('should render external links correctly', () => { | ||
for (const link of externalLinks) { | ||
const { html } = mdL.render(link) | ||
expect(html).toMatchSnapshot() | ||
} | ||
}) | ||
}) | ||
|
||
function getCompiledLink (output) { | ||
const { data: { routerLinks }} = output | ||
return routerLinks[0] | ||
} |