Skip to content

tokenizeInvisibles

tokenizeInvisibles(tokens): void

Defined in: prism/utils/invisibles.js:69

Function that will highlight all tabs and spaces in a token stream. Similar to showInvisibles, but this highlights all spaces and tabs as tokens instead. This also works with code blocks. If you only want to show spaces and tabs that are selected, then showInvisibles must be used instead.

Requires styling from prism-code-editor/invisibles.css.

Note that this function should be the last tokenization function that’s called. This is not just a performance optimization since tokenizeDataUris doesn’t work when it’s called after.

To use this function with editors, add it to onTokenize or as a tokenize listener.

createEditor(
"#editor",
{
...
onTokenize: tokenizeInvisibles
},
matchBrackets()
)

Or

createEditor(
"#editor",
{ ... },
// Other tokenizers before
matchBrackets(),
editor => editor.on("tokenize", tokenizeInvisibles)
)

To use this function with code blocks, call it inside tokenizeCallback.

renderCodeBlock({
language: "js",
value: "const foo = 'bar'",
tokenizeCallback(tokens) {
// Other tokenizers before
tokenizeInvisibles(tokens)
}
})

TokenStream

Tokens to mutate.

void