Home / File/ rehype.ts — astro Source File

rehype.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 11 imports 11 functions

Entity Profile

Dependency Diagram

graph LR
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8["rehype.ts"]
  dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f["../../core/errors/errors.js"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> dd6187d6_53c4_ce90_a1d1_3a0b5e7e7d3f
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  a370a45c_02f1_30de_445d_47ee08d095a2["../core/viteUtils.js"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> a370a45c_02f1_30de_445d_47ee08d095a2
  6d6c494c_c8df_be75_fbfb_a5f4768e2e5c["../vite-plugin-astro/metadata.js"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> 6d6c494c_c8df_be75_fbfb_a5f4768e2e5c
  578ea01d_496b_3b43_98f2_7b2f0ce78d7e["../vite-plugin-astro/types.js"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> 578ea01d_496b_3b43_98f2_7b2f0ce78d7e
  82f345a2_2234_43f1_c3c4_eea191acdca8["markdown-remark"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> 82f345a2_2234_43f1_c3c4_eea191acdca8
  f76e2597_e3e8_c502_d293_a666b44d49ce["hast"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> f76e2597_e3e8_c502_d293_a666b44d49ce
  350bf1c9_161e_6d98_d477_5ac7e492812d["mdast-util-mdx"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> 350bf1c9_161e_6d98_d477_5ac7e492812d
  03fa0bc9_b24b_2cf3_1b96_2104cbcd14a3["mdast-util-mdx-jsx"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> 03fa0bc9_b24b_2cf3_1b96_2104cbcd14a3
  d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> d7b51bf7_4a46_1479_0cea_09e174fc7c48
  b909a1d2_5b96_acd8_d198_1f106f44e2c3["vfile"]
  89da4403_ab4a_62fa_64f0_d53bd0b3aee8 --> b909a1d2_5b96_acd8_d198_1f106f44e2c3
  style 89da4403_ab4a_62fa_64f0_d53bd0b3aee8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { RehypePlugin } from '@astrojs/markdown-remark';
import type { RootContent } from 'hast';
import type {} from 'mdast-util-mdx';
import type {
	MdxJsxAttribute,
	MdxJsxFlowElementHast,
	MdxJsxTextElementHast,
} from 'mdast-util-mdx-jsx';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
import { AstroError } from '../core/errors/errors.js';
import { AstroErrorData } from '../core/errors/index.js';
import { resolvePath } from '../core/viteUtils.js';
import { createDefaultAstroMetadata } from '../vite-plugin-astro/metadata.js';
import type { PluginMetadata } from '../vite-plugin-astro/types.js';

const ClientOnlyPlaceholder = 'astro-client-only';

export const rehypeAnalyzeAstroMetadata: RehypePlugin = () => {
	return (tree, file) => {
		// Initial metadata for this MDX file, it will be mutated as we traverse the tree
		const metadata = createDefaultAstroMetadata();

		// Parse imports in this file. This is used to match components with their import source
		const imports = parseImports(tree.children);

		visit(tree, (node) => {
			if (node.type !== 'mdxJsxFlowElement' && node.type !== 'mdxJsxTextElement') return;

			const tagName = node.name;
			if (
				!tagName ||
				!isComponent(tagName) ||
				!(hasClientDirective(node) || hasServerDeferDirective(node))
			)
				return;

			// From this point onwards, `node` is confirmed to be an island component

			// Match this component with its import source
			const matchedImport = findMatchingImport(tagName, imports);
			if (!matchedImport) {
				throw new AstroError({
					...AstroErrorData.NoMatchingImport,
					message: AstroErrorData.NoMatchingImport.message(node.name!),
				});
			}

			// If this is an Astro component, that means the `client:` directive is misused as it doesn't
			// work on Astro components as it's server-side only. Warn the user about this.
			if (matchedImport.path.endsWith('.astro')) {
				const clientAttribute = node.attributes.find(
					(attr) => attr.type === 'mdxJsxAttribute' && attr.name.startsWith('client:'),
				) as MdxJsxAttribute | undefined;
				if (clientAttribute) {
					console.warn(
						`You are attempting to render <${node.name!} ${
							clientAttribute.name
						} />, but ${node.name!} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`,
					);
// ... (316 more lines)

Domain

Subdomains

Dependencies

  • ../../core/errors/errors.js
  • ../core/errors/index.js
  • ../core/viteUtils.js
  • ../vite-plugin-astro/metadata.js
  • ../vite-plugin-astro/types.js
  • hast
  • markdown-remark
  • mdast-util-mdx
  • mdast-util-mdx-jsx
  • unist-util-visit
  • vfile

Frequently Asked Questions

What does rehype.ts do?
rehype.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in rehype.ts?
rehype.ts defines 11 function(s): addClientMetadata, addClientOnlyMetadata, addServerDeferMetadata, findMatchingImport, getAstroMetadata, hasClientDirective, hasClientOnlyDirective, hasServerDeferDirective, isComponent, parseImports, and 1 more.
What does rehype.ts depend on?
rehype.ts imports 11 module(s): ../../core/errors/errors.js, ../core/errors/index.js, ../core/viteUtils.js, ../vite-plugin-astro/metadata.js, ../vite-plugin-astro/types.js, hast, markdown-remark, mdast-util-mdx, and 3 more.
Where is rehype.ts in the architecture?
rehype.ts is located at packages/astro/src/jsx/rehype.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/jsx).

Analyze Your Own Codebase

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

Try Supermodel Free