Home / File/ html.tag.ts — astro Source File

html.tag.ts — astro Source File

Architecture documentation for html.tag.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  60d1be76_cd98_f7e8_4ba2_44daa9480023["html.tag.ts"]
  8254a139_45c1_14e5_768f_deed73f35a6f["../css/parse-inline-css-to-react.js"]
  60d1be76_cd98_f7e8_4ba2_44daa9480023 --> 8254a139_45c1_14e5_768f_deed73f35a6f
  9e63cbe8_497c_4ffa_fe72_98f051e32a00["markdoc"]
  60d1be76_cd98_f7e8_4ba2_44daa9480023 --> 9e63cbe8_497c_4ffa_fe72_98f051e32a00
  style 60d1be76_cd98_f7e8_4ba2_44daa9480023 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Config, Schema } from '@markdoc/markdoc';
import Markdoc from '@markdoc/markdoc';

const booleanAttributes = new Set([
	'allowfullscreen',
	'async',
	'autofocus',
	'autoplay',
	'checked',
	'controls',
	'default',
	'defer',
	'disabled',
	'disablepictureinpicture',
	'disableremoteplayback',
	'download',
	'formnovalidate',
	'hidden',
	'inert',
	'ismap',
	'itemscope',
	'loop',
	'multiple',
	'muted',
	'nomodule',
	'novalidate',
	'open',
	'playsinline',
	'readonly',
	'required',
	'reversed',
	'selected',
]);

// local
import { parseInlineCSSToReactLikeObject } from '../css/parse-inline-css-to-react.js';

// a Markdoc tag that will render a given HTML element and its attributes, as produced by the htmlTokenTransform function
export const htmlTag: Schema<Config, never> = {
	attributes: {
		name: { type: String, required: true },
		attrs: { type: Object },
	},

	transform(node, config) {
		const { name, attrs: unsafeAttributes } = node.attributes;
		const children = node.transformChildren(config);

		// pull out any "unsafe" attributes which need additional processing
		const { style, ...safeAttributes } = unsafeAttributes as Record<string, unknown>;

		// Convert boolean attributes to boolean literals
		for (const [key, value] of Object.entries(safeAttributes)) {
			if (booleanAttributes.has(key)) {
				// If the attribute exists, ensure its value is a boolean
				safeAttributes[key] = value === '' || value === true || value === 'true';
			}
		}

		// if the inline "style" attribute is present we need to parse the HTML into a react-like React.CSSProperties object
		if (typeof style === 'string') {
			const styleObject = parseInlineCSSToReactLikeObject(style);
			safeAttributes.style = styleObject;
		}

		// create a Markdoc Tag for the given HTML node with the HTML attributes and children
		return new Markdoc.Tag(name, safeAttributes, children);
	},
};

Domain

Subdomains

Dependencies

  • ../css/parse-inline-css-to-react.js
  • markdoc

Frequently Asked Questions

What does html.tag.ts do?
html.tag.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 html.tag.ts?
html.tag.ts defines 1 function(s): htmlTag.transform.
What does html.tag.ts depend on?
html.tag.ts imports 2 module(s): ../css/parse-inline-css-to-react.js, markdoc.
Where is html.tag.ts in the architecture?
html.tag.ts is located at packages/integrations/markdoc/src/html/tagdefs/html.tag.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/integrations/markdoc/src/html/tagdefs).

Analyze Your Own Codebase

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

Try Supermodel Free