-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.js
executable file
·34 lines (26 loc) · 1.85 KB
/
link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const markdownit = require('markdown-it');
const assert = require('assert');
const markdownitExternalLink = require('../dist/cjs/index').default;
const testString = `This is an [Example](http://example.com) link, [Google](https://google.com) link, [Facebook](https://facebook.com) link, [Test Example](http://test.example.com/) link, [Test2 Example](http://test2.example.com/) link and [Relative](/docs/concept/) link.`;
describe('Test `external` links', () => {
it('single domain', () => {
const expectedOutput = `<p>This is an <a href="http://example.com">Example</a> link, <a href="https://google.com" target="_blank" rel="noopener">Google</a> link, <a href="https://facebook.com" target="_blank" rel="noopener">Facebook</a> link, <a href="http://test.example.com/" target="_blank" rel="noopener">Test Example</a> link, <a href="http://test2.example.com/" target="_blank" rel="noopener">Test2 Example</a> link and <a href="/docs/concept/">Relative</a> link.</p>\n`;
const md = markdownit();
md.use(markdownitExternalLink, {
'hosts': ['http://example.com']
});
assert.strictEqual(md.render(testString), expectedOutput);
});
it('multiple domains', () => {
const expectedOutput = `<p>This is an <a href="http://example.com">Example</a> link, <a href="https://google.com" target="_blank" rel="noopener">Google</a> link, <a href="https://facebook.com" target="_blank" rel="noopener">Facebook</a> link, <a href="http://test.example.com/">Test Example</a> link, <a href="http://test2.example.com/" target="_blank" rel="noopener">Test2 Example</a> link and <a href="/docs/concept/">Relative</a> link.</p>\n`;
const md = markdownit();
md.use(markdownitExternalLink, {
'hosts': [
'http://example.com',
'http://test.example.com'
]
});
assert.strictEqual(md.render(testString), expectedOutput);
});
});