0

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
  • Wow. Looks like the documentation is showing that error on their examples as well. Commented Aug 20, 2023 at 4:05

1 Answer 1

0

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:

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not using webpack. I wrote my own tool to render my static site. Due to what it says in the docs, ocumentation, I expected to be able to just install the dependency and start using the filter in the templates with no extra steps necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.