escape.ts — astro Source File
Architecture documentation for escape.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ceb433a2_14a4_d7fb_5f75_9b5373ee6f20["escape.ts"] a23a07d0_d3e7_8ff8_5fc3_de6da7bcaed7["./utils.js"] ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 --> a23a07d0_d3e7_8ff8_5fc3_de6da7bcaed7 f76e2597_e3e8_c502_d293_a666b44d49ce["hast"] ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 --> f76e2597_e3e8_c502_d293_a666b44d49ce 57045b72_8cbd_6e93_7687_5176cbcd502d["magic-string"] ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 --> 57045b72_8cbd_6e93_7687_5176cbcd502d 54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7["unified"] ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 --> 54ce55cc_9dc1_4ebd_28dd_358c1e22d4e7 d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"] ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 --> d7b51bf7_4a46_1479_0cea_09e174fc7c48 style ceb433a2_14a4_d7fb_5f75_9b5373ee6f20 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { Root, RootContent } from 'hast';
import type MagicString from 'magic-string';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';
import { escapeTemplateLiteralCharacters, needsEscape, replaceAttribute } from './utils.js';
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}"`);
}
}
});
};
};
export default rehypeEscape;
Domain
Subdomains
Functions
Dependencies
- ./utils.js
- hast
- magic-string
- unified
- unist-util-visit
Source
Frequently Asked Questions
What does escape.ts do?
escape.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 escape.ts?
escape.ts defines 1 function(s): rehypeEscape.
What does escape.ts depend on?
escape.ts imports 5 module(s): ./utils.js, hast, magic-string, unified, unist-util-visit.
Where is escape.ts in the architecture?
escape.ts is located at packages/astro/src/vite-plugin-html/transform/escape.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/vite-plugin-html/transform).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free