2.0.2 • Published 10 months ago
@koha-community/prettier-plugin-template-toolkit v2.0.2
prettier-plugin-template-toolkit
Formatter plugin for Template::Toolkit template files.
This is a fork of prettier-plugin-jinja-template, we are very grateful to the original author!
Install
npm install --save-dev prettier prettier-plugin-template-toolkitAdd the plugin to your .prettierrc:
{
"plugins": ["prettier-plugin-template-toolkit"]
}Use
To format basic .html files, you'll have to override the used parser inside your .prettierrc:
{
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "template-toolkit"
}
}
]
}Run it on all HTML files in your project:
npx prettier --write **/*.htmlIf you don't have a prettier config you can run the plugin with this command:
npx prettier --plugin=prettier-plugin-template-toolkit --parser=template-toolkit --write **/*.htmlIgnoring Code
Using range ignores is the best way to tell prettier to ignore part of files. Most of the time this is necessary for Template::Toolkit tags inside script or style tags:
<!-- prettier-ignore-start -->
<script>
window.someData = [% data %]
</script>
<!-- prettier-ignore-end -->
<!-- prettier-ignore-start -->
<style>
:root { --accent-color: [% theme_accent_color %] }
</style>
<!-- prettier-ignore-end -->Or using Template::Toolkit comments:
[%# prettier-ignore-start %]
<script>
window.someData = [% data %]
</script>
[%# prettier-ignore-end %]
[%# prettier-ignore-start %]
<style>
:root { --accent-color: [% theme_accent_color %] }
</style>
[%# prettier-ignore-end %]}