To improve the readability of code, many text editors use language-specific syntax highlighting. This module uses the highlight.php library to offer similar functionality when displaying code snippets on your site. highlight.php itself is a port of the popular highlight.js, and allows the syntax highlighting to be done on the web-server. Instead of relying on the client to do highlighting, the advantage of server-sided code highlighting is that this allows to cache the results and not be dependent on JavaScript running in the browser.
This module introduces the "Code snippet (server-sided code highlighting)" field, which can be attached to any field-able entity (like nodes or Paragraphs). The provided widget allows to enter the code snippet in a text area and select the programming language (currently 185 languages are supported). The formatter allows indicating whether your theme styles the syntax highlighting or that one of the 94 style sheets is delivered to the browser.
Requirements
This module depends on the scrivo/highlight.php library and the contributed Vendor Stream Wrapper module. When using composer require drupal/ssch to install this module, both these dependencies should automatically be installed.
Similar projects
- CKEditor CodeSnippet, uses the Code Snippet plugin to enable syntax highlighting for the CKEditor. The highlight.js library is used to do the syntax highlighting and runs in the browser of the website visitor.
- CKEditor Syntax Highlighter, uses the Syntaxhighlighter Interface plugin to enable syntax highlighting for the CKEditor. The SyntaxHighlighter library is used to do the code highlighting and runs in the browser of the website visitor.
- Syntax Highlighter, provides syntax highlighting using the SyntaxHighlighter library, which runs in the client of the visitor.
- Syntax Highlighting Field Formatter, provides a field formatter to apply syntax highlighting using PHP's built-in highlighting functionality.
- GeSHi Filter for syntax highlighting, which uses the GeSHi library to perform the syntax highlighting. Like our module, the code highlighting is done on the web-server, however, a filter is used to format code snippets while our module introduces a separate field, including a widget and formatter, to insert code snippets.
Project information
- Project categories: Content editing experience, Content display, Developer tools
43 sites report using this module
- Created by watergate on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.




