-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
30 lines (24 loc) · 1.02 KB
/
test.mjs
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
import test from "ava";
import MarkdownIt from "markdown-it";
import markdownItExternalAnchor from "./index.js";
const md = MarkdownIt();
// Note: example.com is external, example.org is internal
md.use(markdownItExternalAnchor, {domain: 'example.org'});
test('external link has added attributes', (t) => {
const example = "[text](https://example.com)";
const result = md.renderInline(example);
t.true(result.includes(`rel="noopener noreferrer"`))
t.true(result.includes(`target="_blank"`))
});
test('internal, relative link has no added attributes', (t) => {
const example = "[text](/example)";
const result = md.renderInline(example);
t.false(result.includes(`rel="noopener noreferrer"`))
t.false(result.includes(`target="_blank"`))
});
test('internal, absolute link has no added attributes', (t) => {
const example = "[text](https://example.org)}";
const result = md.renderInline(example);
t.false(result.includes(`rel="noopener noreferrer"`))
t.false(result.includes(`target="_blank"`))
});