Pug cannot find installed Highlight.js JSTransformer filter

50 Views Asked by At

The documentation says I just have to install the filters via npm in order to use them.

If you want to be able to use filters in your Pug template, you would first make sure that these features are installed:

$ npm install --save jstransformer-filter

Now, you should be able to render the following template:

:markdown-it(linkify)
  # Markdown

I tried this with highlight.js:

$ npm install --save jstransformer-highlight2

But when I compile the pug file:

:highlight.js(lang='c')
  int f(int x) {
      return x + 1;
  }

I get unknown filter errors:

unknown filter ":highlight"

I checked the filter source code and confirmed the filter's name is highlight.js. I also tried highlight, highlightjs and highlight-js, to no avail.

How do I make this work?

Do I have to pass an option to the pug compiler? The API documentation says it's for custom filters only.

1

There are 1 best solutions below

1
biodiscus On

if you use the Webpack to compile Pug templates, then try to use the modern webdiscus/pug-loader or the pug-plugin.

This loader and plugin supports the :highlight and the :markdown filters "out of the box".

You can see the demo seites with examples: