Highlights every match of the word or pattern. The match is literal, not a regular expression.
Word Highlighting
1 min readStableIntermediate
Highlight every occurrence of a word or pattern using the /pattern/ syntax, useful for calling out variable names and identifiers.
Quick Start
Highlight a single literal word.
TypeScript
TypeScript
const secret = process.env.JWT_SECRET
const encoded = new TextEncoder().encode(secret)Adding Options
Highlight a type or function name across a longer block.
TypeScript
TypeScript
interface DocumentPage {
title: string
slug: string
}
function renderPage(page: DocumentPage): string {
return `# ${page.title}`
}Advanced
Combine word highlighting with line highlighting and a file title.
lib/auth.ts
TypeScript
import { SignJWT } from 'jose'
export async function createSession(payload) {
return new SignJWT(payload).setProtectedHeader({ alg: 'HS256' })
}Options
/pattern/stringRelated pages
Was this page helpful?