markdown-it-external-anchor
Version:
Mark external, absolute links with necessary attributes
31 lines (24 loc) • 1.02 kB
JavaScript
import { test } from 'node:test';
import MarkdownIt from 'markdown-it';
import mod from './index.js';
const md = MarkdownIt();
// Note: example.com is external, example.org is internal
md.use(mod, { domain: 'example.org' });
test('external link has added attributes', (t) => {
const example = '[text](https://example.com)';
const result = md.renderInline(example);
t.assert.ok(result.includes(`rel="noopener noreferrer"`));
t.assert.ok(result.includes(`target="_blank"`));
});
test('internal, relative link has no added attributes', (t) => {
const example = '[text](/example)';
const result = md.renderInline(example);
t.assert.ok(!result.includes(`rel="noopener noreferrer"`));
t.assert.ok(!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.assert.ok(!result.includes(`rel="noopener noreferrer"`));
t.assert.ok(!result.includes(`target="_blank"`));
});