Screenshot showing this module's info file using syntax highlighting
Screenshot depicting the server sided code highlighting field attached to an paragraph entity
Screenshot showing the settings of the server sided code highlighting field widget
Screenshot showing the settings of the server sided code highlighting field formatter

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

Supporting organizations: 
funding development

Project information

Releases