2022-06-09 22:31:36 -05:00
|
|
|
import { renderMarkdown } from '../dist/index.js';
|
|
|
|
import chai from 'chai';
|
2023-01-11 12:51:31 -05:00
|
|
|
import { mockRenderMarkdownParams } from './test-utils.js';
|
2022-06-09 22:31:36 -05:00
|
|
|
|
|
|
|
describe('autolinking', () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
describe('plain md', () => {
|
|
|
|
it('autolinks URLs starting with a protocol in plain text', async () => {
|
2023-01-11 12:51:31 -05:00
|
|
|
const { code } = await renderMarkdown(
|
|
|
|
`See https://example.com for more.`,
|
|
|
|
mockRenderMarkdownParams
|
|
|
|
);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05: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 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05:00
|
|
|
it('autolinks URLs starting with "www." in plain text', async () => {
|
2023-01-11 12:51:31 -05:00
|
|
|
const { code } = await renderMarkdown(
|
|
|
|
`See www.example.com for more.`,
|
|
|
|
mockRenderMarkdownParams
|
|
|
|
);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05: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 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05:00
|
|
|
it('does not autolink URLs in code blocks', async () => {
|
|
|
|
const { code } = await renderMarkdown(
|
|
|
|
'See `https://example.com` or `www.example.com` for more.',
|
2023-01-11 12:51:31 -05:00
|
|
|
mockRenderMarkdownParams
|
2022-06-09 22:33:13 -05:00
|
|
|
);
|
2022-07-22 17:47:21 -05:00
|
|
|
|
2022-07-22 17:45:16 -05: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-09 22:31:36 -05:00
|
|
|
});
|
|
|
|
});
|