11ty / eleventy-plugin-syntaxhighlight

A pack of Eleventy plugins for syntax highlighting in Markdown, Liquid, and Nunjucks templates.
https://www.11ty.dev/docs/plugins/syntaxhighlight/
MIT License
130 stars 32 forks source link

Add option to load languages explicitly #90

Open vrugtehagel opened 2 months ago

vrugtehagel commented 2 months ago

Resolves https://github.com/11ty/eleventy-plugin-syntaxhighlight/issues/47.

Adds a languages option to force-load languages before the init callback. Minor restructuring has been done to get the plugin in functional format, in order to allow for the init callback to run after the loading of the languages.

Example usage in an .eleventy.js config file:

export default function(eleventyConfig){
    eleventyConfig.addPlugin(SyntaxHighlight, {
        languages: ['css-extras', 'ruby'],
        init: function({Prism}){
            // do stuff with Prism.languages.ruby…
        }
    })
};

PS: The diff looks rather large due to an indentation change; please toggle "hide whitespace" to see the actual changes.