Spope
Spope

Reputation: 481

Nunjucks precompile clean html

I use Nunjucks percompiled template and I'd like to clean the template.js output from useless spaces and linebreak.

Compiled template keeps useless space and line break from original template:

"<form>\n        <div class=\"choices\">\n            <div class=\"choice\">\n"

Custom tags like nunjucks-tag-spaceless do the regex stuff client side. There is no way to do this during compile step to save size / time ?

Upvotes: 1

Views: 1609

Answers (2)

Dmytro K.
Dmytro K.

Reputation: 169

You can try to use jlto library for your purpose: https://www.npmjs.com/package/jlto

Upvotes: 2

nams
nams

Reputation: 81

You can create a custom filter within the nunjucks realisation code that cleans up your html according to the logic/library you use and executes it after the realisation of the template as and when the filter is called. For more details on how to, you can check the Documentation. For the implementation of the filter to clean up html, you can go through this Link. Hope this helps.

Upvotes: 0

Related Questions