TextformatterPrism by abdus

Prism JS Syntax Highlighter

ProcessWire Prism JS Syntax Highlighter

A module to parse given HTML and syntax-highlight code elements using Prism

Changelog


  • v2.0.0
    • Improved language parsing logic
    • Prevent 404s from nonexistent files
    • Renamed hookable functions, update your hooks accordingly. See below for more information.

Features


Installation


  • Add module to /site/modules/ and then install.
    Or go to Modules > Install > Add New and use any of the options provided to to install.

  • Create a text/textarea field and pick Prism Syntax Highlighter from Details > Text Formatters.

    Protip: This module parses HTML markup, so it should come after HTML parsers such as Markdown textformatters.

  • Add code elements within the field content with language-xxxx classes. Or pick a default language from configuration page if you are unable to specify the classes.

  • Select any plugins you want. To use some plugins, extra classes are required. See plugin documentation.

  • Install these recommended modules for the best experience:

Customization


  • Go to module configuration to specify:
  • Auto inclusion of highlighters for parsed languages
  • Default language for inline code elements or ones without language-xxxx classes.
  • Ability to use minified/non-minified component and parser files
  • Plugins
  • Themes
  • Custom JS and CSS for configuration / theming
  • Ability to use hooks to specify custom CSS and JS

Hooks


Hook into TextformatterPrism::getCss and TextformatterPrism::getJs in your ready.php file.

  • $event->arguments includes two arguments, first one $languages an array of parsed language names, second $plugins an array of picked plugin names. To include your own JS/CSS mutate $event->return.
// specify custom CSS
wire()->addHookAfter('TextformatterPrism::getCss', function (HookEvent $event) {
    $css = $event->return;
    $css[] = '/path/to/custom.css'
    // return an array of urls
    $event->return = $css;
});
// Specify custom JS
wire()->addHookAfter('TextformatterPrism::getJs', function (HookEvent $event) {
    $js = $event->return;
    $js[] = '/path/to/custom.js'
    // return an array of urls
    $event->return = $js;
});

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #515
    In the 515th issue of ProcessWire Weekly we’ll check out the latest core updates, new modules, and more. Read on!
    Weekly.pw / 23 March 2024
  • Invoices Site Profile
    The new invoices site profile is a free invoicing application developed in ProcessWire. It enables you to create invoices, record payments to them, email invoices to clients, print invoices, and more. This post covers all the details.
    Blog / 15 March 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH