इसे छोड़कर कंटेंट पर जाएं

Unified API Reference

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

Astro offers optional support for unified, a popular Markdown ecosystem, via the @astrojs/markdown-remark package. This allows you to customize and extend the rendering process using remark and rehype plugins. It also provides a set of helpers and types helpful when building integrations or plugins.

For features and usage examples, see Markdown processors in the Markdown guide.

The following helpers are imported from @astrojs/markdown-remark:

import {
createMarkdownProcessor,
isUnifiedProcessor,
parseFrontmatter,
rehypeHeadingIds,
unified,
} from "@astrojs/markdown-remark";

Type: (opts?: AstroMarkdownOptions) => Promise<MarkdownRenderer>

जोड़ा गया: @astrojs/markdown-remark@3.2.0

Creates a standalone unified-based Markdown renderer. This is useful when you need to render Markdown independently of a project’s configured markdown.processor.

src/utils/markdown.ts
import { createMarkdownProcessor } from "@astrojs/markdown-remark";
const processor = await createMarkdownProcessor();
const { code, metadata } = await processor.render("# Hello world");

Type: (p: { name: string; }) => boolean

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Determines whether the given Markdown processor is unified. This is useful when you need to check the type of a processor before applying unified-specific logic.

The following example checks, within an integration, whether the configured Markdown processor is unified:

src/integrations/my-integration.ts
import { isUnifiedProcessor } from "@astrojs/markdown-remark";
import type { AstroIntegration } from "astro";
export default function myIntegration(): AstroIntegration {
return {
name: "my-integration",
hooks: {
"astro:config:done": ({ config }) => {
if (isUnifiedProcessor(config.markdown.processor)) {
// Apply unified-specific logic here
}
},
},
};
}

Type: RehypePlugin

जोड़ा गया: @astrojs/markdown-remark@1.2.0

Generates and collects heading IDs for all headings in the Markdown content. This makes them available when importing or rendering Markdown content.

See heading IDs and plugins in the Markdown guide for usage example.

Type: (options?: UnifiedProcessorOptions) => MarkdownProcessor

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Creates a unified-based processor to render .md and .mdx files. Pass it to markdown.processor to use unified as the default Markdown processor.

Type: UnifiedProcessorOptions

You can customize the unified processor behavior with the following options.

Type: RemarkPlugins
Default: []

Pass remark plugins to customize how your Markdown is built. You can import and apply the plugin function (recommended), or pass the plugin name as a string.

The following example passes the remark-toc plugin, with a custom heading option, to the unified processor:

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
import remarkToc from "remark-toc";
export default defineConfig({
markdown: {
processor: unified({
remarkPlugins: [[remarkToc, { heading: "contents" }]],
}),
},
});

Type: RehypePlugins
Default: []

Pass rehype plugins to customize how your HTML is generated from the Markdown content. You can import and apply the plugin function (recommended), or pass the plugin name as a string.

The following example passes the rehype-accessible-emojis plugin to the unified processor:

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
import { rehypeAccessibleEmojis } from "rehype-accessible-emojis";
export default defineConfig({
markdown: {
processor: unified({
rehypePlugins: [rehypeAccessibleEmojis],
}),
},
});

Type: RemarkRehype

Pass options to the remark-rehype plugin to control how Markdown is transformed into HTML.

The following example customizes the footnote labels:

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
export default defineConfig({
markdown: {
processor: unified({
remarkRehype: {
footnoteLabel: "Footnotes",
footnoteBackLabel: "Back to reference 1",
},
}),
},
});

Type: PluggableList
Default: []

Pass recma plugins to customize the estree output of your MDX files. This is useful for modifying or injecting JavaScript variables.

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
import myRecmaPlugin from "./my-recma-plugin.mjs";
export default defineConfig({
markdown: {
processor: unified({
recmaPlugins: [myRecmaPlugin],
}),
},
});

You can use AST Explorer to play with estree outputs, and try estree-util-visit for searching across JavaScript nodes.

Type: boolean
Default: true

Whether to enable or disable GitHub-flavored Markdown (GFM) support.

To disable this, set the gfm option to false:

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
export default defineConfig({
markdown: {
processor: unified({
gfm: false,
}),
},
});
Learn more about using GitHub Flavored Markdown in Astro.

Type: boolean | Smartypants
Default: true

Whether to use the SmartyPants formatter to transform straight quotes into smart quotes, dashes into en/em dashes, and triple dots into ellipses.

You can either disable it or provide a configuration object with the properties supported by retext-smartypants to customize its behavior.

The following example disables smart punctuation support:

astro.config.mjs
import { defineConfig } from "astro/config";
import { unified } from "@astrojs/markdown-remark";
export default defineConfig({
markdown: {
processor: unified({
smartypants: false,
}),
},
});
Learn more about configuring smart punctuation in the Markdown guide.

The following types are imported from @astrojs/markdown-remark:

import type {
AstroMarkdownOptions,
MarkdownHeading,
MarkdownProcessor,
MarkdownRenderOptions,
MarkdownRenderResult,
MarkdownRenderer,
RehypePlugin,
RehypePlugins,
RemarkPlugin,
RemarkPlugins,
RemarkRehype,
ShikiConfig,
Smartypants,
SyntaxHighlightConfig,
SyntaxHighlightConfigType,
} from "@astrojs/markdown-remark";

Type: { syntaxHighlight?: SyntaxHighlightConfig | SyntaxHighlightConfigType | false; shikiConfig?: ShikiConfig; image?: { domains?: string[]; remotePatterns?: RemotePattern[]; }; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes the Markdown processor configuration. This contains all the markdown options plus the following.

Type: { domains?: string[]; remotePatterns?: RemotePattern[]; }

Specifies the image configuration for the Markdown processor.

Type: string[]

See image.domains in the configuration reference.

Type: RemotePattern[]

See image.remotePatterns in the configuration reference.

Type: { depth: number; slug: string; text: string; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Represents a heading in a Markdown or MDX document.

Type: number

The heading level, from 1 (<h1>) to 6 (<h6>).

Type: string

Specifies the generated slug used as the id attribute for anchor links.

Type: string

Contains the heading’s rendered text content.

Type: object

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes the configured markdown.processor. This is useful when you want to indicate that a variable accepts any built-in Markdown processor.

Type: { fileURL?: URL; frontmatter?: Record<string, any>; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes the options available when rendering Markdown content.

Type: URL

Specifies the URL of the Markdown file being rendered.

Type: Record<string, any>

Provides the frontmatter data for the Markdown content.

Type: { code: string; metadata: { headings: MarkdownHeading[]; localImagePaths: string[]; remoteImagePaths: string[]; frontmatter: Record<string, any>; }; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes a rendered Markdown file.

Type: string

Contains the rendered HTML code.

Type: { headings: MarkdownHeading[]; localImagePaths: string[]; remoteImagePaths: string[]; frontmatter: Record<string, any>; }

Describes the metadata associated with the rendered content.

Type: MarkdownHeading[]

A list of extracted headings.

MarkdownRenderResult.metadata.localImagePaths
Section titled “MarkdownRenderResult.metadata.localImagePaths”

Type: string[]

An array of local image paths referenced in the rendered content.

MarkdownRenderResult.metadata.remoteImagePaths
Section titled “MarkdownRenderResult.metadata.remoteImagePaths”

Type: string[]

An array of remote image paths referenced in the rendered content.

Type: Record<string, any>

The frontmatter passed to the renderer.

Type: { render: (content: string, opts?: MarkdownRenderOptions) => Promise<MarkdownRenderResult>; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Specifies the interface implemented by a standalone Markdown processor.

Type: (content: string, opts?: MarkdownRenderOptions) => Promise<MarkdownRenderResult>

Generates the rendered HTML and metadata for the given Markdown content. You can customize the rendering process using options as second argument.

Type: Plugin<PluginParameters, HastRoot>

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Defines a rehype plugin in the unified ecosystem.

Type: (string | [string, any] | RehypePlugin | [RehypePlugin, any])[]

जोड़ा गया: @astrojs/markdown-remark@7.2.0

A list of rehype plugins to customize the HTML output generated from Markdown content. Each entry is either an imported plugin or the package name that Astro should automatically import.

Type: Plugin<PluginParameters, MdastRoot>

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Defines a remark plugin in the unified ecosystem.

Type: (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[]

जोड़ा गया: @astrojs/markdown-remark@7.2.0

A list of remark plugins to customize the Markdown processing. Each entry is either an imported plugin or the package name that Astro should automatically import.

Type: Record<string, unknown>

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Specifies the options passed to the remark-rehype plugin.

Type: object

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes the options to configure the Shiki syntax highlighter.

Learn more about syntax highlighting with example usage.

Type: LanguageRegistration[]

A list of Shiki languages to enable in the syntax highlighter.

Type: Record<string, string>

Defines custom aliases to map to a Shiki language ID.

See Shiki language aliases for more information.

Type: ThemePresets | ThemeRegistration | ThemeRegistrationRaw

Specifies the default theme for syntax highlighting. This can be a Shiki bundled theme or a custom Shiki theme.

Learn more about setting a default Shiki theme with example usage.

Type: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>

An object mapping theme names to their corresponding Shiki theme configurations.

Learn how to set dark and light themes with example usage.

Type: 'light' | 'dark' | string | false

Specifies the default theme to use when [ShikiConfig.themes] is defined.

Type: boolean | null

Whether to prevent horizontal scrolling by wrapping long lines.

Type: ShikiTransformer[]

A list of Shiki transformers to customize the generated HTML.

Learn how to apply transformers to <Code /> when you only need them for specific code blocks.

Type: object

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Describes the configuration options for retext-smartypants.

Learn more about using smart punctuation in Astro.

Type: { type: SyntaxHighlightConfigType; excludeLangs?: string[]; }

जोड़ा गया: @astrojs/markdown-remark@7.2.0

Specifies the configured syntax highlighter and the languages to exclude from highlighting.

Learn more about using syntax highlighting with example usage.

Type: 'shiki' | 'prism'

जोड़ा गया: @astrojs/markdown-remark@7.2.0

A union of supported syntax highlighter in Astro.

योगदान करें समुदाय प्रायोजक