Home / File/ plugins.ts — astro Source File

plugins.ts — astro Source File

Architecture documentation for plugins.ts, a typescript file in the astro codebase. 14 imports, 0 dependents.

File typescript CoreAstro RoutingSystem 14 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  d7312c7b_f89c_b923_6191_574b373e0444["plugins.ts"]
  c9598570_76ac_7dd8_56a7_b8994dc3f0bd["./index.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> c9598570_76ac_7dd8_56a7_b8994dc3f0bd
  9748ac95_ccdf_44cd_37fd_d5e439e1928b["./rehype-apply-frontmatter-export.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 9748ac95_ccdf_44cd_37fd_d5e439e1928b
  899caef3_20f6_5784_d87e_10ef652968f3["./rehype-collect-headings.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 899caef3_20f6_5784_d87e_10ef652968f3
  0f250b55_e4b6_9260_5a32_5ff9fb454b7e["./rehype-images-to-component.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 0f250b55_e4b6_9260_5a32_5ff9fb454b7e
  7f61ee47_dc75_7572_0674_1e3c748ef00f["./rehype-meta-string.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 7f61ee47_dc75_7572_0674_1e3c748ef00f
  266ec0d4_2199_989b_a8ff_c5a6cade5325["./rehype-optimize-static.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 266ec0d4_2199_989b_a8ff_c5a6cade5325
  82f345a2_2234_43f1_c3c4_eea191acdca8["markdown-remark"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 82f345a2_2234_43f1_c3c4_eea191acdca8
  8482adb2_32d8_4a04_7e12_83abee7f874a["mdx"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 8482adb2_32d8_4a04_7e12_83abee7f874a
  8c9d3d30_e7fa_6898_26b0_03d93d9c96f8["rehype.js"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 8c9d3d30_e7fa_6898_26b0_03d93d9c96f8
  e5a862f6_93a8_41da_e955_8ab49095d030["rehype-raw"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> e5a862f6_93a8_41da_e955_8ab49095d030
  37c1053a_3eb4_b601_e732_7f56687f9a53["remark-gfm"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 37c1053a_3eb4_b601_e732_7f56687f9a53
  1f1ea76c_95e6_f181_4104_c30c8bbf306e["remark-smartypants"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 1f1ea76c_95e6_f181_4104_c30c8bbf306e
  73c4190e_04f4_08fe_0368_d6cedabb3214["source-map"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 73c4190e_04f4_08fe_0368_d6cedabb3214
  54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7["unified"]
  d7312c7b_f89c_b923_6191_574b373e0444 --> 54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7
  style d7312c7b_f89c_b923_6191_574b373e0444 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import {
	rehypeHeadingIds,
	rehypePrism,
	rehypeShiki,
	remarkCollectImages,
} from '@astrojs/markdown-remark';
import { createProcessor, nodeTypes } from '@mdx-js/mdx';
import { rehypeAnalyzeAstroMetadata } from 'astro/jsx/rehype.js';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';
import remarkSmartypants from 'remark-smartypants';
import { SourceMapGenerator } from 'source-map';
import type { PluggableList } from 'unified';
import type { MdxOptions } from './index.js';
import { rehypeApplyFrontmatterExport } from './rehype-apply-frontmatter-export.js';
import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js';
import { rehypeImageToComponent } from './rehype-images-to-component.js';
import rehypeMetaString from './rehype-meta-string.js';
import { rehypeOptimizeStatic } from './rehype-optimize-static.js';

// Skip nonessential plugins during performance benchmark runs
const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);

interface MdxProcessorExtraOptions {
	sourcemap: boolean;
}

export function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions) {
	return createProcessor({
		remarkPlugins: getRemarkPlugins(mdxOptions),
		rehypePlugins: getRehypePlugins(mdxOptions),
		recmaPlugins: mdxOptions.recmaPlugins,
		remarkRehypeOptions: mdxOptions.remarkRehype,
		jsxImportSource: 'astro',
		// Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
		format: 'mdx',
		mdExtensions: [],
		elementAttributeNameCase: 'html',
		SourceMapGenerator: extraOptions.sourcemap ? SourceMapGenerator : undefined,
	});
}

function getRemarkPlugins(mdxOptions: MdxOptions): PluggableList {
	let remarkPlugins: PluggableList = [];

	if (!isPerformanceBenchmark) {
		if (mdxOptions.gfm) {
			remarkPlugins.push(remarkGfm);
		}
		if (mdxOptions.smartypants) {
			remarkPlugins.push(remarkSmartypants);
		}
	}

	remarkPlugins.push(...mdxOptions.remarkPlugins, remarkCollectImages);

	return remarkPlugins;
}

function getRehypePlugins(mdxOptions: MdxOptions): PluggableList {
	let rehypePlugins: PluggableList = [
		// ensure `data.meta` is preserved in `properties.metastring` for rehype syntax highlighters
		rehypeMetaString,
		// rehypeRaw allows custom syntax highlighters to work without added config
		[rehypeRaw, { passThrough: nodeTypes }],
	];

	const syntaxHighlight = mdxOptions.syntaxHighlight;
	if (syntaxHighlight && !isPerformanceBenchmark) {
		const syntaxHighlightType =
			typeof syntaxHighlight === 'string' ? syntaxHighlight : syntaxHighlight?.type;
		const excludeLangs =
			typeof syntaxHighlight === 'object' ? syntaxHighlight?.excludeLangs : undefined;
		// Apply syntax highlighters after user plugins to match `markdown/remark` behavior
		if (syntaxHighlightType === 'shiki') {
			rehypePlugins.push([rehypeShiki, mdxOptions.shikiConfig, excludeLangs]);
		} else if (syntaxHighlightType === 'prism') {
			rehypePlugins.push([rehypePrism, excludeLangs]);
		}
	}

	rehypePlugins.push(...mdxOptions.rehypePlugins, rehypeImageToComponent);

	if (!isPerformanceBenchmark) {
		// getHeadings() is guaranteed by TS, so this must be included.
		// We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins.
		rehypePlugins.push([rehypeHeadingIds], rehypeInjectHeadingsExport);
	}

	rehypePlugins.push(
		// Render info from `vfile.data.astro.frontmatter` as JS
		rehypeApplyFrontmatterExport,
		// Analyze MDX nodes and attach to `vfile.data.__astroMetadata`
		rehypeAnalyzeAstroMetadata,
	);

	if (mdxOptions.optimize) {
		// Convert user `optimize` option to compatible `rehypeOptimizeStatic` option
		const options = mdxOptions.optimize === true ? undefined : mdxOptions.optimize;
		rehypePlugins.push([rehypeOptimizeStatic, options]);
	}

	return rehypePlugins;
}

Domain

Subdomains

Dependencies

  • ./index.js
  • ./rehype-apply-frontmatter-export.js
  • ./rehype-collect-headings.js
  • ./rehype-images-to-component.js
  • ./rehype-meta-string.js
  • ./rehype-optimize-static.js
  • markdown-remark
  • mdx
  • rehype-raw
  • rehype.js
  • remark-gfm
  • remark-smartypants
  • source-map
  • unified

Frequently Asked Questions

What does plugins.ts do?
plugins.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in plugins.ts?
plugins.ts defines 3 function(s): createMdxProcessor, getRehypePlugins, getRemarkPlugins.
What does plugins.ts depend on?
plugins.ts imports 14 module(s): ./index.js, ./rehype-apply-frontmatter-export.js, ./rehype-collect-headings.js, ./rehype-images-to-component.js, ./rehype-meta-string.js, ./rehype-optimize-static.js, markdown-remark, mdx, and 6 more.
Where is plugins.ts in the architecture?
plugins.ts is located at packages/integrations/mdx/src/plugins.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/mdx/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free