UNPKG

@r4ai/remark-embed

Version:

[![JSR](https://jsr.io/badges/@r4ai/remark-embed)](https://jsr.io/@r4ai/remark-embed) [![codecov](https://codecov.io/gh/r4ai/remark-embed/graph/badge.svg?token=B9EZXC0PR8)](https://codecov.io/gh/r4ai/remark-embed) [![CI](https://github.com/r4ai/remark-emb

102 lines 4.28 kB
import type { Transformer } from "../../index.js"; import type { DeepReadonly, DeepRequired } from "../utils.js"; import type { Element } from "../utils.js"; import type { OEmbedLink, OEmbedPhoto, OEmbedRich, OEmbedVideo } from "./schemas.js"; export type TransformerOEmbedOptions = { /** * The providers to fetch oEmbed data from specific services. * * @defaultValue {@link defaultTransformerOEmbedOptions.providers} */ providers?: Record<string, { /** * The URL matcher. * If the URL is matched, the transformer will be applied. * * @param url The URL to match. * @returns Whether the URL is matched. * @example (url) => url.hostname === "example.com" */ match: (url: URL) => boolean; /** * The function to fetch the oEmbed data for the URL. * * @param url The URL to fetch. * @returns Fetch response containing the oEmbed data for the URL. * @example (url) => fetch(`https://example.com/oembed?${new URLSearchParams({ url: url.href })}`) */ response: (url: URL) => Promise<Response>; }>; /** * The post-processor for the HTML content to embed. * @param html The `html` field of the oEmbed metadata. * @returns The processed HTML content. */ postProcess?: (html: string) => string; /** * The transformer for the photo type of oEmbed. * * @see https://oembed.com/#:~:text=2.3.4.1.%20The%20photo%20type * @param url The URL to embed. * @param oEmbed The oEmbed metadata for the {@link url} * @param options The options for the {@link transformerOEmbed} * @returns The element to embed the photo. * @defaultValue {@link defaultTransformerOEmbedOptions.photo} */ photo?: (url: URL, oEmbed: DeepReadonly<OEmbedPhoto>, options: DeepRequired<DeepReadonly<TransformerOEmbedOptions>>) => Element; /** * The transformer for the video type of oEmbed. * * @see https://oembed.com/#:~:text=2.3.4.2.%20The%20video%20type * @param url The URL to embed. * @param oEmbed The oEmbed metadata for the {@link url} * @param options The options for the {@link transformerOEmbed} * @returns The element to embed the video. * @defaultValue {@link defaultTransformerOEmbedOptions.video} */ video?: (url: URL, oEmbed: DeepReadonly<OEmbedVideo>, options: DeepRequired<DeepReadonly<TransformerOEmbedOptions>>) => Element; /** * The transformer for the rich type of oEmbed. * * @see https://oembed.com/#:~:text=2.3.4.4.%20The%20rich%20type * @param url The URL to embed. * @param oEmbed The oEmbed metadata for the {@link url} * @param options The options for the {@link transformerOEmbed} * @returns The element to embed the rich content. * @defaultValue {@link defaultTransformerOEmbedOptions.rich} */ rich?: (url: URL, oEmbed: DeepReadonly<OEmbedRich>, options: DeepRequired<DeepReadonly<TransformerOEmbedOptions>>) => Element; /** * The transformer for the link type of oEmbed. * * @see https://oembed.com/#:~:text=2.3.4.3.%20The%20link%20type * @param url The URL to embed. * @param oEmbed The oEmbed metadata for the {@link url} * @param options The options for the {@link transformerOEmbed} * @returns The element to embed the link. * @defaultValue {@link defaultTransformerOEmbedOptions.link} */ link?: (url: URL, oEmbed: DeepReadonly<OEmbedLink>, options: DeepRequired<DeepReadonly<TransformerOEmbedOptions>>) => Element; }; export declare const defaultTransformerOEmbedOptions: DeepRequired<DeepReadonly<TransformerOEmbedOptions>>; /** * A transformer for oEmbed. * Embeds the content of the URL using the oEmbed metadata. * @see {@link https://oembed.com/ | oembed.com} * * @example * ```ts * const html = ( * await unified() * .use(remarkParse) * .use(remarkRehype) * .use(remarkEmbed, { * transformers: [transformerOEmbed()], * }) * .use(rehypeStringify) * .process(md) * ).toString() * ``` */ export declare const transformerOEmbed: (_options?: TransformerOEmbedOptions) => Transformer; //# sourceMappingURL=oembed.d.ts.map