Home / File/ tokenizer.ts — astro Source File

tokenizer.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 2 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  72ec71bf_7ebc_f58d_ba2e_3a6d4c7522dd["tokenizer.ts"]
  57d5145b_d383_f4ee_3ff2_e2df842c3ffb["./options.js"]
  72ec71bf_7ebc_f58d_ba2e_3a6d4c7522dd --> 57d5145b_d383_f4ee_3ff2_e2df842c3ffb
  9e63cbe8_497c_4ffa_fe72_98f051e32a00["markdoc"]
  72ec71bf_7ebc_f58d_ba2e_3a6d4c7522dd --> 9e63cbe8_497c_4ffa_fe72_98f051e32a00
  style 72ec71bf_7ebc_f58d_ba2e_3a6d4c7522dd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Tokenizer } from '@markdoc/markdoc';
import Markdoc from '@markdoc/markdoc';
import type { MarkdocIntegrationOptions } from './options.js';

type TokenizerOptions = ConstructorParameters<typeof Tokenizer>[0];

export function getMarkdocTokenizer(options: MarkdocIntegrationOptions | undefined): Tokenizer {
	const key = cacheKey(options);

	if (!_cachedMarkdocTokenizers[key]) {
		const tokenizerOptions: TokenizerOptions = {
			// Strip <!-- comments --> from rendered output
			// Without this, they're rendered as strings!
			allowComments: true,
		};

		if (options?.allowHTML) {
			// allow indentation for Markdoc tags that are interleaved inside HTML block elements
			tokenizerOptions.allowIndentation = true;
			// enable HTML token detection in markdown-it
			tokenizerOptions.html = true;
		}
		if (options?.ignoreIndentation) {
			// allow indentation so nested Markdoc tags can be formatted for better readability
			tokenizerOptions.allowIndentation = true;
		}
		if (options?.typographer) {
			// enable typographer to convert straight quotes to curly quotes, etc.
			tokenizerOptions.typographer = options.typographer;
		}

		_cachedMarkdocTokenizers[key] = new Markdoc.Tokenizer(tokenizerOptions);
	}

	return _cachedMarkdocTokenizers[key];
}

// create this on-demand when needed since it relies on the runtime MarkdocIntegrationOptions and may change during
// the life of module in certain scenarios (unit tests, etc.)
let _cachedMarkdocTokenizers: Record<string, Tokenizer> = {};

function cacheKey(options: MarkdocIntegrationOptions | undefined): string {
	return JSON.stringify(options);
}

Domain

Subdomains

Dependencies

  • ./options.js
  • markdoc

Frequently Asked Questions

What does tokenizer.ts do?
tokenizer.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in tokenizer.ts?
tokenizer.ts defines 2 function(s): cacheKey, getMarkdocTokenizer.
What does tokenizer.ts depend on?
tokenizer.ts imports 2 module(s): ./options.js, markdoc.
Where is tokenizer.ts in the architecture?
tokenizer.ts is located at packages/integrations/markdoc/src/tokenizer.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/markdoc/src).

Analyze Your Own Codebase

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

Try Supermodel Free