Code Syntax Highlighting

Code blocks are automatically syntax-highlighted using PrismJS[1]. All 290+ PrismJS languages[2] are supported — language components load automatically on demand.

Every code block includes a Copy button for easy clipboard copying.

Syntax by Source Format

The Maven Site Plugin supports multiple source formats through Doxia. Each format has its own syntax for code blocks:

Markdown

Markdown

Use fenced code blocks with the language identifier after the opening fence:

```java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello!");
    }
}
```

Renders as:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello!");
    }
}
XHTML

XHTML

Use the <pre><code class="language-xxx"> pattern:

<pre><code class="language-java">public class Hello {
    public static void main(String[] args) {
        System.out.println(&quot;Hello!&quot;);
    }
}</code></pre>
Tip

Content inside <code> must be HTML-escaped (<&lt;, >&gt;, &&amp;, "&quot;).

Java (Doxia Sink)

Java (Doxia Sink)

When generating documentation or Maven reports programmatically with the Doxia Sink API[3], use this pattern to produce syntax-highlighted code blocks:

SinkEventAttributes attrs = new SinkEventAttributes();
attrs.addAttribute(SinkEventAttributes.CLASS, "language-yaml");

sink.verbatim(attrs);
sink.rawText("<code class=\"language-yaml\">");
sink.text("object: # this is a YAML object\n");
sink.text("  pi: 3.14\n");
sink.rawText("</code>");
sink.verbatim_();

Examples

The below examples all use Markdown to demonstrate syntax highlighting of various languages.

Java

```java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello!");
    }
}
```

Shell Commands

```bash
mvn clean install site
echo $HOME > /tmp/my-home.txt
```

Shell with Output

Use shell-session to show commands with their output:

```shell-session
$ ls -l
total 0
-rw-r--r-- 1 user user 0 Jan 1 00:00 file.txt
```

XML

```xml
<dependency>
    <groupId>org.sentrysoftware.maven</groupId>
    <artifactId>sentry-maven-skin</artifactId>
    <version>7.0.00</version>
</dependency>
```

YAML

```yaml
server:
  port: 8080
  host: localhost
database:
  url: jdbc:postgresql://localhost/mydb
```

JSON

```json
{
  "name": "my-project",
  "version": "1.0.0",
  "dependencies": {
    "lodash": "^4.17.21"
  }
}
```

SQL

```sql
SELECT u.name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.active = true
GROUP BY u.name;
```

Python

```python
def greet(name: str) -> str:
    """Return a greeting message."""
    return f"Hello, {name}!"

if __name__ == "__main__":
    print(greet("World"))
```

Configuration

Code highlighting and copy features can be configured globally or per-page:

Setting Description Default
syntaxHighlighting CSS selector for code blocks to highlight pre > code[class*=language-]
copyToClipboard CSS selector for elements with copy button pre

Disable Syntax Highlighting

To disable PrismJS syntax highlighting:

Site-Wide (site.xml)

Site-Wide (site.xml)

<custom>
  <syntaxHighlighting>false</syntaxHighlighting>
</custom>
Per-Page (Frontmatter)

Per-Page (Frontmatter)

syntaxHighlighting: false

# Plain Text Page

Code blocks won't be syntax-highlighted.

Disable Copy Button

To remove the copy-to-clipboard button:

Site-Wide (site.xml)

Site-Wide (site.xml)

<custom>
  <copyToClipboard>false</copyToClipboard>
</custom>
Per-Page (Frontmatter)

Per-Page (Frontmatter)

copyToClipboard: false

# No Copy Buttons

Code blocks won't have copy buttons.

Custom Selectors

Use CSS selectors to control which elements get each feature:

Site-Wide (site.xml)

Site-Wide (site.xml)

<custom>
  <!-- Only highlight Java and XML code -->
  <syntaxHighlighting>pre > code[class*=language-java], pre > code[class*=language-xml]</syntaxHighlighting>

  <!-- Add copy button to code and specific divs -->
  <copyToClipboard>pre, .copyable</copyToClipboard>
</custom>
Per-Page (Frontmatter)

Per-Page (Frontmatter)

syntaxHighlighting: pre > code[class*=language-java]
copyToClipboard: pre, .copyable

# Custom Code Settings

Only Java is highlighted, copy button on pre and .copyable.

Language Reference

Common languages and their fence identifiers:

Category Language Markdown Fence Identifier
JVM Java ```java
Kotlin ```kotlin
Groovy ```groovy
Scala ```scala
Web HTML ```html
CSS ```css
JavaScript ```javascript
```js
TypeScript ```typescript
```ts
JSON ```json
Config YAML ```yaml
XML ```xml
TOML ```toml
INI / Properties ```ini
Shell Bash ```bash
PowerShell ```powershell
```ps
Shell Session ```shell-session
Batch ```batch
Backend Python ```python
Go ```go
Rust ```rust
C# ```csharp
Ruby ```ruby
PHP ```php
Data SQL ```sql
GraphQL ```graphql
Regex ```regex
Build Dockerfile ```docker
Makefile ```makefile
Gradle (Groovy) ```groovy
Gradle (Kotlin) ```kotlin
Docs Markdown ```markdown
```md
LaTeX ```latex

See the full list of 290+ supported languages[2] on the PrismJS website.

See Also

Searching...
No results.