summaryrefslogtreecommitdiff
path: root/packages/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown')
-rw-r--r--packages/markdown/remark/src/index.ts2
-rw-r--r--packages/markdown/remark/src/rehype-jsx.ts7
-rw-r--r--packages/markdown/remark/test/autolinking.test.js30
3 files changed, 17 insertions, 22 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index a11419474..817174e4c 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -101,7 +101,7 @@ export async function renderMarkdown(
.use(rehypeEscape)
.use(rehypeIslands)
.use([rehypeCollectHeaders])
- .use(rehypeStringify, { allowDangerousHtml: true })
+ .use(rehypeStringify, { allowDangerousHtml: true });
let result: string;
try {
diff --git a/packages/markdown/remark/src/rehype-jsx.ts b/packages/markdown/remark/src/rehype-jsx.ts
index 06783ba85..a6761124c 100644
--- a/packages/markdown/remark/src/rehype-jsx.ts
+++ b/packages/markdown/remark/src/rehype-jsx.ts
@@ -1,5 +1,5 @@
-import type { RehypePlugin } from './types.js';
import { visit } from 'unist-util-visit';
+import type { RehypePlugin } from './types.js';
const MDX_ELEMENTS = ['mdxJsxFlowElement', 'mdxJsxTextElement'];
@@ -36,12 +36,11 @@ export default function rehypeJsx(): ReturnType<RehypePlugin> {
// from creating a nested link to `www.example.com`
if (node.name === 'a') {
visit(node, 'element', (el, elIndex, elParent) => {
- const isAutolink = (
+ const isAutolink =
el.tagName === 'a' &&
el.children.length === 1 &&
el.children[0].type === 'text' &&
- el.children[0].value.match(/^(https?:\/\/|www\.)/i)
- );
+ el.children[0].value.match(/^(https?:\/\/|www\.)/i);
// If we found an autolink, remove it by replacing it with its text-only child
if (isAutolink) {
diff --git a/packages/markdown/remark/test/autolinking.test.js b/packages/markdown/remark/test/autolinking.test.js
index 9224247e0..513d12ac6 100644
--- a/packages/markdown/remark/test/autolinking.test.js
+++ b/packages/markdown/remark/test/autolinking.test.js
@@ -3,10 +3,7 @@ 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.`,
- {}
- );
+ const { code } = await renderMarkdown(`See https://example.com for more.`, {});
chai
.expect(code.replace(/\n/g, ''))
@@ -14,10 +11,7 @@ describe('autolinking', () => {
});
it('autolinks URLs starting with "www." in plain text', async () => {
- const { code } = await renderMarkdown(
- `See www.example.com for more.`,
- {}
- );
+ const { code } = await renderMarkdown(`See www.example.com for more.`, {});
chai
.expect(code.trim())
@@ -32,8 +26,10 @@ describe('autolinking', () => {
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>`);
+ .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 () => {
@@ -51,7 +47,7 @@ describe('autolinking', () => {
it('does not autolink URLs starting with a protocol when nested inside links', async () => {
const { code } = await renderMarkdown(
`See [http://example.com](http://example.com) or ` +
- `<a test href="https://example.com">https://example.com</a>`,
+ `<a test href="https://example.com">https://example.com</a>`,
{}
);
@@ -59,14 +55,14 @@ describe('autolinking', () => {
.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>`
+ `<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 renderMarkdown(
`See [www.example.com](https://www.example.com) or ` +
- `<a test href="https://www.example.com">www.example.com</a>`,
+ `<a test href="https://www.example.com">www.example.com</a>`,
{}
);
@@ -74,14 +70,14 @@ describe('autolinking', () => {
.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>`
+ `<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 renderMarkdown(
`<a href="https://www.example.com">**Visit _our www.example.com or ` +
- `http://localhost pages_ for more!**</a>`,
+ `http://localhost pages_ for more!**</a>`,
{}
);
@@ -89,8 +85,8 @@ describe('autolinking', () => {
.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>`
+ `Visit <em>our www.example.com or http://localhost pages</em> for more!` +
+ `</strong></a>`
);
});
});