mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
7f5e71982d
commit
4eb39d57b9
4 changed files with 18 additions and 23 deletions
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
2
packages/webapi/mod.d.ts
vendored
2
packages/webapi/mod.d.ts
vendored
|
@ -1,5 +1,5 @@
|
|||
export { pathToPosix } from './lib/utils';
|
||||
export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js';
|
||||
export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js';
|
||||
export declare const polyfill: {
|
||||
(target: any, options?: PolyfillOptions): any;
|
||||
internals(target: any, name: string): any;
|
||||
|
|
Loading…
Reference in a new issue