Back to Highlight Js

Plugin Recipes

docs/plugin-recipes.rst

11.11.1626 B
Original Source

.. highlight:: javascript

Plugin Recipes

Below is a collection of useful plugin "recipes" that you might find helpful.

data-language

Let's say you'd like to track the language that was auto-detected via a data attribute <https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes>_. This might prove useful if you desired to add a dynamic label via CSS with :before, etc.

::

hljs.addPlugin( {
  'after:highlightElement': ({el, result}) => {
    // move the language from the result into the dataset
    el.dataset.language = result.language }
})