2024-02-12 07:25:29 -05:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { before, describe, it } from 'node:test';
|
2023-09-14 05:22:16 -05:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2022-06-09 22:31:36 -05:00
|
|
|
|
|
|
|
describe('autolinking', () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
describe('plain md', () => {
|
|
|
|
let processor;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
processor = await createMarkdownProcessor();
|
|
|
|
});
|
2023-09-14 05:22:16 -05:00
|
|
|
|
2022-07-22 17:45:16 -05:00
|
|
|
it('autolinks URLs starting with a protocol in plain text', async () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
const markdown = `See https://example.com for more.`;
|
|
|
|
const { code } = await processor.render(markdown);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2024-02-12 07:25:29 -05:00
|
|
|
assert.equal(
|
|
|
|
code.replace(/\n/g, ''),
|
|
|
|
`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`
|
|
|
|
);
|
2022-07-22 17:45:16 -05:00
|
|
|
});
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05:00
|
|
|
it('autolinks URLs starting with "www." in plain text', async () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
const markdown = `See www.example.com for more.`;
|
|
|
|
const { code } = await processor.render(markdown);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2024-02-12 07:25:29 -05:00
|
|
|
assert.equal(
|
|
|
|
code.trim(),
|
|
|
|
`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`
|
|
|
|
);
|
2022-07-22 17:45:16 -05:00
|
|
|
});
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05:00
|
|
|
it('does not autolink URLs in code blocks', async () => {
|
2024-02-12 07:25:29 -05:00
|
|
|
const markdown = `See \`https://example.com\` or \`www.example.com\` for more.`;
|
|
|
|
const { code } = await processor.render(markdown);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2024-02-12 07:25:29 -05:00
|
|
|
assert.equal(
|
|
|
|
code.trim(),
|
|
|
|
`<p>See <code>https://example.com</code> or <code>www.example.com</code> for more.</p>`
|
|
|
|
);
|
2022-07-22 17:45:16 -05:00
|
|
|
});
|
2022-06-09 22:31:36 -05:00
|
|
|
});
|
|
|
|
});
|