@koha-community/prettier-plugin-template-toolkit
Version:
Prettier plugin for formatting Template::Toolkit templates.
79 lines (62 loc) • 1.72 kB
Markdown
# prettier-plugin-template-toolkit
Formatter plugin for Template::Toolkit template files.
This is a fork of [prettier-plugin-jinja-template](https://github.com/davidodenwald/prettier-plugin-jinja-template), we are very grateful to the original author!
## Install
```bash
npm install --save-dev prettier prettier-plugin-template-toolkit
```
Add the plugin to your `.prettierrc`:
```json
{
"plugins": ["prettier-plugin-template-toolkit"]
}
```
## Use
To format basic .html files, you'll have to override the used parser inside your `.prettierrc`:
```json
{
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "template-toolkit"
}
}
]
}
```
Run it on all HTML files in your project:
```bash
npx prettier --write **/*.html
```
If you don't have a prettier config you can run the plugin with this command:
```bash
npx prettier --plugin=prettier-plugin-template-toolkit --parser=template-toolkit --write **/*.html
```
### Ignoring 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:
```html
<!-- 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:
```tt
[%# 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 %]}
```