Skip to Content
Nextra DocsCode Blocks

Code Blocks

Nextra uses Shiki for syntax highlighting at build time. All standard fenced code blocks are supported, plus several extra features.

Basic usage

```powershell Get-MgUser -All ```

Filename / title

Add a filename attribute to display a header above the code block:

```powershell filename="get-users.ps1" Get-MgUser -All ```
get-users.ps1
Get-MgUser -All

Line highlighting

Highlight specific lines with {lineNumbers}:

```powershell {1,3} $users = Get-MgUser -All # Process each user foreach ($user in $users) { Write-Host $user.DisplayName } ```
$users = Get-MgUser -All # Process each user foreach ($user in $users) { Write-Host $user.DisplayName }

Substring highlighting

Highlight a specific word or phrase with /word/:

```powershell /DisplayName/ $users = Get-MgUser -All -Property DisplayName Write-Host $users.DisplayName ```
$users = Get-MgUser -All -Property DisplayName Write-Host $users.DisplayName

Line numbers

Add showLineNumbers to display line numbers:

```powershell showLineNumbers $users = Get-MgUser -All foreach ($user in $users) { Write-Host $user.DisplayName } ```
$users = Get-MgUser -All foreach ($user in $users) { Write-Host $user.DisplayName }

Copy button

The copy button is enabled globally in this site via defaultShowCopyCode: true in next.config.mjs.

To disable it on a specific block, use copy=false:

```powershell copy=false This block won't have a copy button ```

Combining features

You can combine multiple attributes:

```powershell filename="example.ps1" showLineNumbers {2} $group = Get-MgGroup -GroupId $groupId Write-Host "Group: $($group.DisplayName)" ```
example.ps1
$group = Get-MgGroup -GroupId $groupId Write-Host "Group: $($group.DisplayName)"
Last updated on