Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/frugal/docs/dep/prism.ts>tokenize

A frugal web framework
Go to Latest
function tokenize
import { tokenize } from "https://deno.land/x/frugal@0.5.0/docs/dep/prism.ts";

This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input and the language definitions to use, and returns an array with the tokenized code.

When the language definition includes nested tokens, the function is called recursively on each of these tokens.

This method could be useful in other contexts as well, as a very crude parser.

Parameters

text: string

A string with the code to be highlighted.

grammar: Grammar

An object containing the tokens to use.

Usually a language definition like Prism.languages.markup.

Returns

Array<string | Token>

An array of strings, tokens and other arrays.