Skip to main content
OwnDocs

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 11

Options

showLineNumbersbooleanDefault: true

Enables numbering explicitly.

showLineNumbers=NnumberDefault: 1

Starts numbering from line N.

Was this page helpful?