Code Highlight 

Extension key

codehighlight

Package name

brotkrueml/codehighlight

Version

main

Language

en

Author

Chris Müller

License

This document is published under the Creative Commons BY 4.0 license.

Rendered

Sun, 30 Nov 2025 14:56:54 +0000


The extension provides a content element for code snippets. The code is highlighted for better readability. Various programming languages can be chosen, also some formatting settings. The code highlighting is based on PrismJS.


Table of Contents:

Introduction 

What does it do? 

In technical articles it is sometimes necessary to embed code snippets into the text of a page. To improve the readability of the snippets, the syntax highlighting of code is appreciated - as in modern IDEs.

The extension provides a new content element to achieve this goal. You can choose between several themes.

Screenshots 

PHP code snippet 

Example output using the Coy theme for a PHP code snippet with line numbers and line highlighting:

PHP code snippet with line numbers and line highlighting

PHP code snippet with line numbers and line highlighting

Shell command 

Example output using the Coy theme for a shell command with prompt:

Shell command with prompt

Shell command with prompt

CSS inline colours 

Example output using the Coy theme for a CSS snippet with activated inline colours (the coloured square before the colour definition):

CSS snippet with inline colours

CSS snippet with inline colours

Treeview 

Example for a treeview to highlight file system tree structures:

Treeview

Treeview

Release management 

This extension uses semantic versioning which basically means for you, that

  • Bugfix updates (for example, 1.0.0 => 1.0.1) just includes small bug fixes or security relevant stuff without breaking changes.
  • Minor updates (for example, 1.0.0 => 1.1.0) includes new features and smaller tasks without breaking changes.
  • Major updates (for example, 1.0.0 => 2.0.0) breaking changes which can be refactorings, features or bug fixes.

For editors 

Target group: Editors

Using the content element 

The extension is shipped with a content element Code Snippet. You'll find it in the content element wizard under the Special elements tab:

"Code Snippet" content element in the content element wizard

"Code Snippet" content element in the content element wizard

Selecting it creates a new content element.

General 

In the General tab insert the code snippet into the according field:

The "General" tab of the content element

The "General" tab of the content element

Options 

Here you'll find some settings to tune the visual representation of the code snippet. First of all you can select the programming language - dependent on the language the snippet is formatted:

General options

General options

Programming language
Make use of the filter on the right side of the select box to find the needed programming language. You can only select one language at a time. Leave it empty if the language you want is not available or you don't want syntax highlighting.
Filename
Give a filename if it makes sense for the code snippet. It will be shown near the snippet.

Line numbers 

Sometimes it is desirable to add line numbers, start them at a different number than 1 or highlight one or more lines to point out something important. You can adjust these settings under the Line numbers tab of the options:

Options for showing and adjusting line numbers

Options for showing and adjusting line numbers

Show line numbers
Activate this option to display line numbers at the beginning of the each code line.
Start with line number
Specify a line number with which the numbering is to begin. The entered number will also be used for "Highlight lines" as offset value.
Highlight lines

You can specify the lines to be highlighted in the following format:

  • A single number refers to the line with that number
  • Ranges are denoted by two numbers, separated with a hyphen (-)
  • Multiple line numbers or ranges are separated by commas
  • Whitespace is allowed anywhere and will be stripped off

Example: 1-2, 5, 9-20 (Lines 1 through 2, line 5, lines 9 through 20)

When using an offset in the field Start with line number the lines must be adjusted accordingly.

Command line 

Shell command with prompt

Shell command with prompt

To visualise the commands on a console you can activate the Display command line switch. A prompt will be shown before a code line.

Options for a command line snippet

Options for a command line snippet

Display command line

Display a command line with a prompt and, optionally, the output/response from the commands.

Please note: If you activate this option, don't select a programming language or the prompts are not visible!

User

Specify the user for a server command line (like Linux). The resulting prompt displays a # for the root user and $ for all other users.

Default value: Site configuration setting Command Line Default User or user

Host

Specify the host for a server command line (like Linux).

Default value: Site configuration setting Command Line Default Host or localhost

Prompt
For any other command line, such as a Windows prompt, specify the entire prompt, for example, PS C:\Users\Chris>. If this field is set, the values in the fields User and Host are ignored.
Output lines

You can specify the lines to be presented as output (no prompt and no highlighting) in the following format:

  • A single number refers to the line with that number
  • Ranges are denoted by two numbers, separated with a hyphen (-)
  • Multiple line numbers or ranges are separated by commas
  • Whitespace is allowed anywhere and will be stripped off

Example: 1-2, 5, 9-20 (Lines 1 through 2, line 5, lines 9 through 20)

Filter output

Alternative for "Output lines": Specify a prefix for lines with output, for example, (out) will treat lines beginning with (out) as output and remove the prefix.

You can see some examples for the rendering of the command line on the plugin page of the Prism library.

Styles 

To show a preview of a colour in CSS styles you can activate the Inline colour switch.

Options for a colour preview

Options for a colour preview

This adds a small square before the colour definitions:

CSS snippet with inline colours

CSS snippet with inline colours

Treeview 

To highlight file system tree structures the Treeview switch can be activated.

Options for a treeview

Options for a treeview

This adds icons for folders and files:

Example for a treeview

Example for a treeview

The treeview may be generated on Unix systems with tree -F.

Examples for a tree structure in the Code snippet field:

root_folder/
|-- a first folder/
|   |-- holidays.mov
|   |-- javascript-file.js
|   `-- some_picture.jpg
|-- documents/
|   |-- spreadsheet.xls
|   |-- manual.pdf
|   |-- document.docx
|   `-- presentation.ppt
|       `-- test
|-- empty_folder/
`-- README.md
Copied!

or:

├── a first folder/
|   ├── holidays.mov
|   ├── javascript-file.js
|   └── some_picture.jpg
├── documents/
|   ├── spreadsheet.xls
|   ├── manual.pdf
|   ├── document.docx
|   └── presentation.ppt
└── etc.
Copied!

Appearance 

The Appearance tab gives the possibility to select a layout or show the content element in section menus, like in other content elements.

Access 

On the Access tab you'll find the default fields, like Visibility of content element or the publish dates.

Installation 

Target group: Administrators

Some basic configuration is available which is explained in the Configuration section.

Installation via Composer 

The recommended way to install this extension is by using Composer. In your Composer-based TYPO3 project root, just type:

composer req brotkrueml/codehighlight
Copied!

and the recent stable version will be installed.

Installation in extension manager 

In a legacy installation, you can also install the extension from the TYPO3 Extension Repository (TER).

Preparation: Include static TypoScript 

The extension ships some TypoScript code which needs to be included.

  1. Switch to the root page of your site.
  2. Switch to the Template module and select Info/Modify.
  3. Press the link Edit the whole template record and switch to the tab Includes.
  4. Select Code Highlight (codehighlight) from the available items at the field Include static (from extensions):
Include static TypoScript

Include static TypoScript

Configuration 

Target group: Developers, Integrators

Site configuration 

Some site-wide configurations can be made in the site configuration. Select a site under Site Management > Sites and switch to the tab Code Highlight.

Site configuration

Site configuration

CSS file for theme 

In the value picker you have the choice between several themes for using on a website. As the extension uses PrismJS for the code highlighting you can have a look at their website to see the differences between the themes.

When selecting a theme, the path to the according CSS file is stored in the site configuration. You can also use an own theme to customise the look of the code snippets.

As the theme is assigned to a site, different sites can have different themes.

Usage of a URL hash 

If the option is enabled, the usage of a URL hash (like #codesnippet8.5-6) for highlighting code and as anchor is available. You can find more information in the chapter for editors.

Command line: default host 

Defines the default host for the command line, if none is given in the options of the content element. If a value is neither in the configuration nor in the content element given, localhost is used as last fallback.

Command line: default user 

Defines the default user for the command line, if none is given in the options of the content element. If a value is neither in the configuration nor in the content element given, user is used as last fallback.

Toolbar: display button "Copy to clipboard" 

If the option is enabled, a Copy button is displayed in the upper right corner when the user moves the mouse pointer over a code snippet.

Site sets (TYPO3 v13+) 

This extension provides support for site sets.

Add brotkrueml/codehighlight as dependency to the configuration of your site package:

EXT:your_sitepackage/Configuration/Sets/<your-set>/config.yaml
name: your-vendor/your-sitepackage
label: Sitepackage

dependencies:
  # ... some other dependencies

  - brotkrueml/codehighlight
Copied!

Settings 

If you want to change the layout or template of the content element or add a partial you can make a copy of them and adjust the Fluid root paths.

Path to template root 

Define the additional template root path, for example, EXT:your_sitepackage/Resources/Private/Templates/Codehighlight/.

EXT:your_sitepackage/Configuration/Sets/<your-set>/settings.yaml
# ... some other settings

tt_content:
   tx_codehighlight_codesnippet:
      templateRootPath: 'EXT:your_sitepackage/Resources/Private/Extensions/Codehighlight/Templates/'
Copied!

Path to template partials 

Define the additional partial root path, for example, EXT:your_sitepackage/Resources/Private/Partials/Codehighlight/.

EXT:your_sitepackage/Configuration/Sets/<your-set>/settings.yaml
# ... some other settings

tt_content:
   tx_codehighlight_codesnippet:
      partialRootPath: 'EXT:your_sitepackage/Resources/Private/Extensions/Codehighlight/Partials/'
Copied!

Path to template layouts 

Define the additional layout root path, for example, EXT:your_sitepackage/Resources/Private/Layouts/Codehighlight/.

EXT:your_sitepackage/Configuration/Sets/<your-set>/settings.yaml
# ... some other settings

tt_content:
   tx_codehighlight_codesnippet:
      layoutRootPath: 'EXT:your_sitepackage/Resources/Private/Extensions/Codehighlight/Layouts/'
Copied!

CSS file 

The extension comes with a default CSS file. If you don't want to include it or want to use an own CSS file you can empty the field or change the path.

EXT:your_sitepackage/Configuration/Sets/<your-set>/settings.yaml
# ... some other settings

tt_content:
   tx_codehighlight_codesnippet:
      cssFile: 'EXT:your_sitepackage/Resources/Public/Css/codehighlight.css'
Copied!

Constant editor (without site sets) 

Some constants can be defined in the constant editor. It is recommended to use site sets instead.

Select the category Codehighlight and make your adjustments.

Constant Editor

Constant editor

Files 

If you want to change the layout or template of the content element or add a partial you can make a copy of them and adjust the Fluid root paths.

Path to template root (FE) 

Enter the additional template root path, for example, EXT:your_sitepackage/Resources/Private/Templates/Codehighlight/.

Alternatively you can change the setting directly in the TypoScript setup:

tt_content.tx_codehighlight_codesnippet.templateRootPaths {
   10 = EXT:your_sitepackage/Resources/Private/Templates/Codehighlight/
}
Copied!

Path to template partials (FE) 

Enter the additional partial root path, for example, EXT:your_sitepackage/Resources/Private/Partials/Codehighlight/.

Alternatively you can change the setting directly in the TypoScript setup:

tt_content.tx_codehighlight_codesnippet.partialRootPaths {
   10 = EXT:your_sitepackage/Resources/Private/Partials/Codehighlight/
}
Copied!

Path to template layouts (FE) 

Enter the additional layout root path, for example, EXT:your_sitepackage/Resources/Private/Layouts/Codehighlight/.

Alternatively you can change the setting directly in the TypoScript setup:

tt_content.tx_codehighlight_codesnippet.layoutRootPaths {
   10 = EXT:your_sitepackage/Resources/Private/Layouts/Codehighlight/
}
Copied!

CSS file 

The extension comes with a default CSS file. If you don't want to include it or want to use an own CSS file you can empty the field or change the path.

Alternatively you can change the setting directly in the TypoScript setup:

tt_content.tx_codehighlight_codesnippet.cssFile {
   settings.cssFile = EXT:your_sitepackage/Resources/Public/Css/codehighlight.css
}
Copied!

Assets embedding 

The required CSS and JavaScript files from the PrismJS library and the extension's CSS file are embedded with the PageRenderer methods addCssFile() and addJsFooterFile(). This means, that they adhere to the configuration setting $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename'] and the TypoScript settings config.concatenateJs and config.concatenateCss (only available in TYPO3 v13). One exception from concatenation is the PrismJS autoloader JavaScript which is used to load the necessary language files.

Translation 

Target group: Developers, Integrators

All strings are translatable. Translations are managed on Crowdin. Click the button below to help translating!

Crowdin localization status

Override translations 

You can override translations in the usual way. Have a look into the according TYPO3 documentation: Custom translations.

However, if you feel that a translation provided by the translation server could be improved, please suggest an alternative on Crowdin.

Changelog 

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased 

5.0.0 - 2025-11-30 

Added 

  • Compatibility with TYPO3 v14

Removed 

  • Compatibility with TYPO3 v12 (#38)

4.2.1 - 2025-10-17 

Fixed 

  • Line number settings are not used by PrismJS (#39, thanks to Sebastian Klein)

4.2.0 - 2025-03-14 

Updated 

  • PrismJS to version 1.30.0

4.1.1 - 2024-09-21 

Fixed 

  • Invalid Fluid namespace definition with Fluid 4

4.1.0 - 2024-05-06 

Added 

  • Support for site sets in TYPO3 v13

4.0.0 - 2024-02-14 

Added 

  • Compatibility with TYPO3 v13

Removed 

  • Compatibility with TYPO3 v11 (#36)

3.1.1 - 2023-04-01 

Fixed 

  • Error when opening a site configuration in TYPO3 v12.3

3.1.0 - 2023-04-01 

Added 

  • Plugin "Treeview" to highlight file system tree structures

3.0.0 - 2023-03-04 

Added 

  • Compatibility with TYPO3 v12 (#35)

Changed 

  • Fluid template of code snippet content element

Removed 

  • Compatibility with TYPO3 v9 and TYPO3 v10 (#25, #26)

2.12.1 - 2022-11-12 

Fixed 

  • TCA configuration of content element is missing in TYPO3 v11.5.18 (#37)

2.12.0 - 2022-08-23 

Updated 

2.11.0 - 2022-04-19 

Added 

  • Compatibility with typo3/cms-composer-installers v4 (#33)

Changed 

  • The PrismJS autoloader JavaScript can't be concatenated anymore with other JavaScript files (#33)

Updated 

2.10.0 - 2022-02-19 

Updated 

2.9.0 - 2022-01-07 

Updated 

2.8.0 - 2021-11-01 

Added 

  • Button "Copy" to copy a code snippet to the clipboard (#27)

Fixed 

  • Move content element to group "special" in type select box (TYPO3 v10+)

2.7.0 - 2021-09-19 

Security 

  • Update PrismJS to version 1.25.0

2.6.1 - 2021-07-04 

Updated 

2.6.0 - 2021-06-28 

Updated 

2.5.0 - 2021-01-06 

Security 

  • Update PrismJS to version 1.23.0

2.4.0 - 2020-12-27 

Added 

  • Plugin "Inline colour" to show colour preview in CSS snippets
  • Compatibility with TYPO3 v11

2.3.0 - 2020-10-12 

Updated 

Fixed 

  • Show content element in wizard in TYPO3 v10

2.2.0 - 2020-08-08 

Updated 

2.1.0 - 2020-04-01 

Updated 

2.0.1 - 2019-12-20 

Added 

  • Add t3 pseudo language (#13)

Fixed 

  • Fixed an error when editing translated content (#14)

2.0.0 - 2019-11-07 

Added 

  • Possibility to display filename for snippet (#10)

Changed 

  • Move asset handling and HTML code generation from template to view helper (#8)
  • Move command line TypoScript settings to site configuration (#9)
  • Separate shell and bash, bnf and rbnf in the list of available languages

1.1.1 - 2019-10-13 

Fixed 

  • Use reference to lib.contentElement instead of assigning FLUIDTEMPLATE (#5)

1.1.0 - 2019-10-11 

Added 

  • Setting for default user and host in command line (#2)
  • Activate heading and appearance tab in content element (#3)
  • Using URL hash to highlight lines and jump to them (#4)

1.0.1 - 2019-10-03 

Added 

  • German translations

1.0.0 - 2019-10-01 

Added 

  • Content element "Code Snippet"
  • Syntax highlighting with PrismJS

Migration 

Target group: Integrators,Developers

From version 3.x to 4.0 

No migrations necessary.

From version 2.x to 3.0 

The template of the content element changed. If you copied and adjusted it, please have a look into the new template shipped by the extension and adjust your custom one accordingly.

From version 1.1 to 2.0 

The TypoScript settings

  • tt_content.tx_codehighlight_codesnippet.settings.commandLine.defaultServerHost and
  • tt_content.tx_codehighlight_codesnippet.settings.commandLine.defaultServerUser

respectively the Constant Editor settings for defining a default host and default user on the command line are moved into the site configuration. Please remove the mentioned settings and adjust your site configuration accordingly.

Maintenance 

Target group: Contributors, Developers

Translations 

The translation to other languages is done within the Crowdin service. It is appreciated to add missing or incomplete languages. Please navigate to the project home. If the language is not available please drop me a note and I will create it.

PrismJS library 

For syntax highlighting PrismJS is used. The JavaScript library and its dependencies are managed with npm and build with gulp:

cd Build
npm ci
npm run build
Copied!

The npm run build command runs the according gulp task and copies the Prism components (aka languages), plugins and themes to the Resources/Public/Vendor/PrismJs/ folder. Also a PHP file Resources/Private/PHP/AvailableProgrammingLanguages.php is generated with the available languages. It will be used for the select box of programming languages in the backend form. The option values are "translated" via the Resources/Private/Language/ProgrammingLanguages.xlf file.

Update 

To update the library to the recent version just call on the console:

cd Build
npm update prismjs
npm run build
Copied!

The copied artifacts can now be committed (along with the package.json file to the repository. Don't forget to add new files to the commit and add these to the translation file Resources/Private/Language/ProgrammingLanguages.xlf.

Packaging of extension for TER 

Set the new version in the files

  • ext_emconf.php
  • Documentation/guides.xml,

adjust the CHANGELOG.md and tag the release. The packaging of the extension for the TYPO3 Extension Repository (TER) can be done with:

make zip
Copied!

This creates/replaces a file ../zip/codehighlight_x.y.z.zip which is ready for upload to TER. x.y.z holds the recent version number.

Sitemap