import { renderMarkdown } from '../dist/index.js'; import chai from 'chai'; describe('autolinking', () => { it('autolinks URLs starting with a protocol in plain text', async () => { const { code } = await renderMarkdown(`See https://example.com for more.`, {}); chai .expect(code.replace(/\n/g, '')) .to.equal(`

See https://example.com for more.

`); }); it('autolinks URLs starting with "www." in plain text', async () => { const { code } = await renderMarkdown(`See www.example.com for more.`, {}); chai .expect(code.trim()) .to.equal(`

See www.example.com for more.

`); }); it('does not autolink URLs in code blocks', async () => { const { code } = await renderMarkdown( 'See `https://example.com` or `www.example.com` for more.', {} ); chai .expect(code.trim()) .to.equal( `

See https://example.com or ` + `www.example.com for more.

` ); }); it('does not autolink URLs in fenced code blocks', async () => { const { code } = await renderMarkdown( 'Example:\n```\nGo to https://example.com or www.example.com now.\n```', {} ); chai .expect(code) .to.contain(`
 {
		const { code } = await renderMarkdown(
			`See [http://example.com](http://example.com) or ` +
				`https://example.com`,
			{}
		);

		chai
			.expect(code.replace(/\n/g, ''))
			.to.equal(
				`

See http://example.com or ` + `https://example.com

` ); }); it('does not autolink URLs starting with "www." when nested inside links', async () => { const { code } = await renderMarkdown( `See [www.example.com](https://www.example.com) or ` + `www.example.com`, {} ); chai .expect(code.replace(/\n/g, '')) .to.equal( `

See www.example.com or ` + `www.example.com

` ); }); it('does not autolink URLs when nested several layers deep inside links', async () => { const { code } = await renderMarkdown( `**Visit _our www.example.com or ` + `http://localhost pages_ for more!**`, {} ); chai .expect(code.replace(/\n/g, '')) .to.equal( `` + `Visit our www.example.com or http://localhost pages for more!` + `` ); }); });