2023-09-14 10:22:16 +00:00
|
|
|
import { createMarkdownProcessor } from '../dist/index.js';
|
2022-06-10 03:31:36 +00:00
|
|
|
import chai from 'chai';
|
|
|
|
|
|
|
|
describe('autolinking', () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
describe('plain md', async () => {
|
|
|
|
const processor = await createMarkdownProcessor();
|
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
it('autolinks URLs starting with a protocol in plain text', async () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
const { code } = await processor.render(`See https://example.com for more.`);
|
2022-07-22 22:47:21 +00:00
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
chai
|
|
|
|
.expect(code.replace(/\n/g, ''))
|
|
|
|
.to.equal(`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`);
|
|
|
|
});
|
2022-07-22 22:47:21 +00:00
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
it('autolinks URLs starting with "www." in plain text', async () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
const { code } = await processor.render(`See www.example.com for more.`);
|
2022-07-22 22:47:21 +00:00
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
chai
|
|
|
|
.expect(code.trim())
|
|
|
|
.to.equal(`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`);
|
|
|
|
});
|
2022-07-22 22:47:21 +00:00
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
it('does not autolink URLs in code blocks', async () => {
|
2023-09-14 10:22:16 +00:00
|
|
|
const { code } = await processor.render(
|
|
|
|
'See `https://example.com` or `www.example.com` for more.'
|
2022-06-10 03:33:13 +00:00
|
|
|
);
|
2022-07-22 22:47:21 +00:00
|
|
|
|
2022-07-22 22:45:16 +00:00
|
|
|
chai
|
|
|
|
.expect(code.trim())
|
|
|
|
.to.equal(
|
|
|
|
`<p>See <code>https://example.com</code> or ` +
|
|
|
|
`<code>www.example.com</code> for more.</p>`
|
|
|
|
);
|
|
|
|
});
|
2022-06-10 03:31:36 +00:00
|
|
|
});
|
|
|
|
});
|