Skip to content

Code blocks

DocsForge supports rich code blocks with syntax highlighting, titles, line numbers, and more.

Basic code blocks

Use triple backticks with a language identifier:

``` python
def hello(name):
    print(f"Hello, {name}!")
```
def hello(name):
    print(f"Hello, {name}!")

Supported languages

DocsForge supports 300+ languages via Pygments, including:

  • python, py
  • javascript, js
  • typescript, ts
  • bash, sh, shell
  • yaml, yml
  • json
  • html
  • css
  • markdown, md
  • dockerfile
  • sql
  • rust
  • go
  • java
  • c, cpp
  • csharp, cs
  • ruby, rb
  • php
  • lua
  • r
  • julia
  • kotlin
  • swift
  • dart

Code block with title

``` python title="hello.py"
def hello(name):
    print(f"Hello, {name}!")
```
hello.py
def hello(name):
    print(f"Hello, {name}!")

Line numbers

``` python linenums="1"
def hello(name):
    print(f"Hello, {name}!")
    return True
```
1
2
3
def hello(name):
    print(f"Hello, {name}!")
    return True

Highlighting lines

``` python hl_lines="2 3"
def hello(name):
    message = f"Hello, {name}!"
    print(message)
    return message
```
def hello(name):
    message = f"Hello, {name}!"
    print(message)
    return message

Diff blocks

Show additions and deletions:

``` diff
  def hello(name):
-     print("Hello!")
+     print(f"Hello, {name}!")
      return True
```
  def hello(name):
-     print("Hello!")
+     print(f"Hello, {name}!")
      return True

Console blocks

Show command output:

``` console
$ docsforge build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: site
INFO    -  Documentation built in 2.34 seconds
```
$ docsforge build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: site
INFO    -  Documentation built in 2.34 seconds

No copy button

Disable the copy button for a specific block:

``` python
```

Or globally disable in config:

theme:
  features:
    # Don't include - content.code.copy

Next steps