Home / Function/ rehypeEscape() — astro Function Reference

rehypeEscape() — astro Function Reference

Architecture documentation for the rehypeEscape() function in escape.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  8388b40c_1ab1_ee60_60c4_72326935c8b7["rehypeEscape()"]
  ceb433a2_14a4_d7fb_5f75_9b5373ee6f20["escape.ts"]
  8388b40c_1ab1_ee60_60c4_72326935c8b7 -->|defined in| ceb433a2_14a4_d7fb_5f75_9b5373ee6f20
  style 8388b40c_1ab1_ee60_60c4_72326935c8b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/vite-plugin-html/transform/escape.ts lines 8–31

const rehypeEscape: Plugin<[{ s: MagicString }], Root> = ({ s }) => {
	return (tree) => {
		visit(tree, (node: Root | RootContent) => {
			if (node.type === 'text' || node.type === 'comment') {
				if (needsEscape(node.value)) {
					s.overwrite(
						node.position!.start.offset!,
						node.position!.end.offset!,
						escapeTemplateLiteralCharacters(node.value),
					);
				}
			} else if (node.type === 'element') {
				if (!node.properties) return;
				for (let [key, value] of Object.entries(node.properties)) {
					key = key.replace(/([A-Z])/g, '-$1').toLowerCase();
					const newKey = needsEscape(key) ? escapeTemplateLiteralCharacters(key) : key;
					const newValue = needsEscape(value) ? escapeTemplateLiteralCharacters(value) : value;
					if (newKey === key && newValue === value) continue;
					replaceAttribute(s, node, key, value === '' ? newKey : `${newKey}="${newValue}"`);
				}
			}
		});
	};
};

Domain

Subdomains

Frequently Asked Questions

What does rehypeEscape() do?
rehypeEscape() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-html/transform/escape.ts.
Where is rehypeEscape() defined?
rehypeEscape() is defined in packages/astro/src/vite-plugin-html/transform/escape.ts at line 8.

Analyze Your Own Codebase

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

Try Supermodel Free