0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/markdown/remark/test/autolinking.test.js
Emanuele Stoppa 062623438b
chore: use biome to sort imports - only test files (#10180)
* chore: use biome to sort imports

* do the sorting

* Update package.json

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
2024-02-21 14:08:19 +00:00

43 lines
1.3 KiB
JavaScript

import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { createMarkdownProcessor } from '../dist/index.js';
describe('autolinking', () => {
describe('plain md', () => {
let processor;
before(async () => {
processor = await createMarkdownProcessor();
});
it('autolinks URLs starting with a protocol in plain text', async () => {
const markdown = `See https://example.com for more.`;
const { code } = await processor.render(markdown);
assert.equal(
code.replace(/\n/g, ''),
`<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 markdown = `See www.example.com for more.`;
const { code } = await processor.render(markdown);
assert.equal(
code.trim(),
`<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 markdown = `See \`https://example.com\` or \`www.example.com\` for more.`;
const { code } = await processor.render(markdown);
assert.equal(
code.trim(),
`<p>See <code>https://example.com</code> or <code>www.example.com</code> for more.</p>`
);
});
});
});