Home / Function/ runHighlighterWithAstro() — astro Function Reference

runHighlighterWithAstro() — astro Function Reference

Architecture documentation for the runHighlighterWithAstro() function in highlighter.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  87dc8e3b_0856_4624_1bfd_14c2b3bdc21b["runHighlighterWithAstro()"]
  c3f3e4e9_d2b7_1cfa_2a27_54ddbd32ea17["highlighter.ts"]
  87dc8e3b_0856_4624_1bfd_14c2b3bdc21b -->|defined in| c3f3e4e9_d2b7_1cfa_2a27_54ddbd32ea17
  style 87dc8e3b_0856_4624_1bfd_14c2b3bdc21b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro-prism/src/highlighter.ts lines 7–39

export function runHighlighterWithAstro(lang: string | undefined, code: string) {
	if (!lang) {
		lang = 'plaintext';
	}
	let classLanguage = `language-${lang}`;
	const ensureLoaded = (language: string) => {
		if (language && !Prism.languages[language]) {
			loadLanguages([language]);
		}
	};

	if (languageMap.has(lang)) {
		ensureLoaded(languageMap.get(lang)!);
	} else if (lang === 'astro') {
		ensureLoaded('typescript');
		addAstro(Prism);
	} else {
		ensureLoaded('markup-templating'); // Prism expects this to exist for a number of other langs
		ensureLoaded(lang);
	}

	if (lang && !Prism.languages[lang]) {
		console.warn(`Unable to load the language: ${lang}`);
	}

	const grammar = Prism.languages[lang];
	let html = code;
	if (grammar) {
		html = Prism.highlight(code, grammar, lang);
	}

	return { classLanguage, html };
}

Domain

Subdomains

Frequently Asked Questions

What does runHighlighterWithAstro() do?
runHighlighterWithAstro() is a function in the astro codebase, defined in packages/astro-prism/src/highlighter.ts.
Where is runHighlighterWithAstro() defined?
runHighlighterWithAstro() is defined in packages/astro-prism/src/highlighter.ts at line 7.

Analyze Your Own Codebase

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

Try Supermodel Free