Adding prism.js to HTMLy

Posted on 12 January 2025 by andyrew 1 min

So, I found an article at Ignored By Dinosaurs describing how to add syntax highlighting to php-markdown code blocks...

I first downloaded the prism.js and prism.css, and placed each in the respective folders in my theme.

I then added a reference to them in my layout.html.php (heavily modified doks theme):

<link rel="stylesheet" href="<?php echo theme_path();?>css/prism.css">
<script src="<?php echo theme_path();?>js/prism.js"></script>

I then added "language-" to MarkdownExtra.php:

/**
     * Optional class prefix for fenced code block.
     * @var string
     */
    public $code_class_prefix = "language-";

Cleared the cache, and 🔥BOOM🔥 ;)

I have not, yet, figured-out how to correctly modify the colouring of the highlighting, but what-is surely beats the default B&W

So; it's so:

Prism Themes ;)