Enables numbering explicitly.
Line Numbers
1 min readStableBeginner
Line numbers are enabled by default on every code block. Use showLineNumbers explicitly or showLineNumbers=N to start numbering from a specific line.
Quick Start
Numbers appear automatically with no metadata.
TypeScript
TypeScript
const greeting: string = 'Hello, World!'
console.log(greeting)Adding Options
Add showLineNumbers explicitly for the same result, keeping intent clear.
TypeScript
TypeScript
import { cache } from 'react'
const getCachedContent = cache(async (slug: string) => {
return readFile(`./content/${slug}.mdx`, 'utf-8')
})Advanced
Start numbering from a specific line with showLineNumbers=N, useful for snippets pulled from the middle of a file.
TypeScript
TypeScript
const a = 1 // line 10
const b = 2 // line 11Options
showLineNumbersbooleanDefault: trueshowLineNumbers=NnumberDefault: 1Starts numbering from line N.
Related pages
Was this page helpful?