00fab4ce13
* refactor: add legacy.jsxInMarkdown flag to config * refactor: jsxInMarkdown -> astroFlavoredMarkdown * refactor: remove `markdown.mode` * feat: wire up legacy.astroFlavoredMarkdown * test: add legacy to astro-markdown fixture * test: remark autolinking * test: remark components * test: remark expressions * test: remark strictness * chore: remove "mode" from md component * chore: remove "mode: md" from tests * Fixing legacy MD tests, adding named slots tests for MDX pages * chore: update lock file * WIP: debugging named slots in MDX * fix: handle named slots in MDX properly * chore: re-enabling slots tests for MDX pages * fixing test validation for svelte & vue * removing unused Tailwind test * legacy flag for Markdown component tests * adding is:raw to Markdown component test * adding is:raw to all Markdown component test fixtures * can't use is:raw when nesting markdown components * another nested test can't use is:raw * one more <Markdown> test fix * fixing another JSX markdown component test * chore: add changeset * e2e tests were missing the legacy flag * removing the broken tailwind E2E markdown page Co-authored-by: Tony Sullivan <tony.f.sullivan@outlook.com> Co-authored-by: Nate Moore <nate@astro.build>
108 lines
3.3 KiB
JavaScript
108 lines
3.3 KiB
JavaScript
import { renderMarkdown } from '../dist/index.js';
|
|
import chai from 'chai';
|
|
|
|
describe('autolinking', () => {
|
|
describe('plain md', () => {
|
|
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(`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`);
|
|
});
|
|
|
|
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(`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`);
|
|
});
|
|
|
|
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(
|
|
`<p>See <code>https://example.com</code> or ` +
|
|
`<code>www.example.com</code> for more.</p>`
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('astro-flavored md', () => {
|
|
const renderAstroMd = text => renderMarkdown(text, { isAstroFlavoredMd: true });
|
|
|
|
it('does not autolink URLs in code blocks', async () => {
|
|
const { code } = await renderAstroMd(
|
|
'See `https://example.com` or `www.example.com` for more.',
|
|
{}
|
|
);
|
|
|
|
chai
|
|
.expect(code.trim())
|
|
.to.equal(
|
|
`<p>See <code is:raw>https://example.com</code> or ` +
|
|
`<code is:raw>www.example.com</code> for more.</p>`
|
|
);
|
|
});
|
|
|
|
it('does not autolink URLs in fenced code blocks', async () => {
|
|
const { code } = await renderAstroMd(
|
|
'Example:\n```\nGo to https://example.com or www.example.com now.\n```'
|
|
);
|
|
|
|
chai
|
|
.expect(code)
|
|
.to.contain(`<pre is:raw`)
|
|
.to.contain(`Go to https://example.com or www.example.com now.`);
|
|
});
|
|
|
|
it('does not autolink URLs starting with a protocol when nested inside links', async () => {
|
|
const { code } = await renderAstroMd(
|
|
`See [http://example.com](http://example.com) or ` +
|
|
`<a test href="https://example.com">https://example.com</a>`
|
|
);
|
|
|
|
chai
|
|
.expect(code.replace(/\n/g, ''))
|
|
.to.equal(
|
|
`<p>See <a href="http://example.com">http://example.com</a> or ` +
|
|
`<a test href="https://example.com">https://example.com</a></p>`
|
|
);
|
|
});
|
|
|
|
it('does not autolink URLs starting with "www." when nested inside links', async () => {
|
|
const { code } = await renderAstroMd(
|
|
`See [www.example.com](https://www.example.com) or ` +
|
|
`<a test href="https://www.example.com">www.example.com</a>`
|
|
);
|
|
|
|
chai
|
|
.expect(code.replace(/\n/g, ''))
|
|
.to.equal(
|
|
`<p>See <a href="https://www.example.com">www.example.com</a> or ` +
|
|
`<a test href="https://www.example.com">www.example.com</a></p>`
|
|
);
|
|
});
|
|
|
|
it('does not autolink URLs when nested several layers deep inside links', async () => {
|
|
const { code } = await renderAstroMd(
|
|
`<a href="https://www.example.com">**Visit _our www.example.com or ` +
|
|
`http://localhost pages_ for more!**</a>`
|
|
);
|
|
|
|
chai
|
|
.expect(code.replace(/\n/g, ''))
|
|
.to.equal(
|
|
`<a href="https://www.example.com"><strong>` +
|
|
`Visit <em>our www.example.com or http://localhost pages</em> for more!` +
|
|
`</strong></a>`
|
|
);
|
|
});
|
|
})
|
|
});
|