0.0.15 • Published 10 months ago

prettier-plugin-go-template v0.0.15

Weekly downloads
1,912
License
MIT
Repository
github
Last release
10 months ago

prettier-plugin-go-template

NPM Badge CodeCov Badge Contributions Badge

Formatter plugin for go template files. The only peer dependency is prettier.

npm install --save-dev prettier prettier-plugin-go-template

Starting with Prettier 3 auto-discovery has been removed. Configuration is required ⬇️

// .prettierrc
{
  "plugins": ["prettier-plugin-go-template"]
}

The following file types will be detected automatically: .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, .html.tmpl If you want to add support for .html read the section on it below the examples.

{{ if or .Prev .Next -}}
{{ $p := where site.Pages }}
<div class="my-navigation">
{{ with $p.Next . -}}
<a href="{{ .RelPermalink }}">
<div class="row">
<div class="cell py-2">
  {{ .Title }} 
</div> </div> </a>
{{ end -}}
</div>
{{ end -}}
{{ if or .Prev .Next -}}
  {{ $p := where site.Pages }}
  <div class="my-navigation">
    {{ with $p.Next . -}}
      <a href="{{ .RelPermalink }}">
        <div class="row">
          <div class="cell py-2">{{ .Title }}</div>
        </div>
      </a>
    {{ end -}}
  </div>
{{ end -}}

GoHugo / .html

To use it with GoHugo and basic .html files, you'll have to override the used parser inside your .prettierrc file:

{
  "plugins": ["prettier-plugin-go-template"]
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "go-template",
      },
    },
  ],
}

VSCode

Make sure to always have installed both dependencies:

  • prettier
  • prettier-plugin-go-template

Also make sure that they are installed inside the same scope. Install both globally (npm i -g) or locally – otherwise prettier may not pick up the plugin.

Note: The global setup additional requires setting your VSCode prettier path to your global prettier path. You can read in this issue how to set it up – should be doable in less than a minute if you have npm & VSCode already running.

Additional Options

// .prettierrc
{
  /**
   * Enables & disables spacing between go statements.
   * E.g. {{ statement }} vs {{statement}}.
   * Default: true
   */
  "goTemplateBracketSpacing": true
}

Ignoring Code

Single Block

<div>
  <!-- prettier-ignore -->
  {{if }}
  {{end }}
</div>

Multiline

<html>
  {{/* prettier-ignore-start */}}
  <script>
    {{if }}
    Whatever.
    {{else }}
    Psych.
    {{end }}
  </script>
  {{/* prettier-ignore-end */}}
</html>

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13-beta.1

2 years ago

0.0.13

2 years ago

0.0.12-beta.4

2 years ago

0.0.12-beta.5

2 years ago

0.0.12-beta.2

2 years ago

0.0.12-beta.3

2 years ago

0.0.12

2 years ago

0.0.12-beta.1

3 years ago

0.0.11-beta.15

3 years ago

0.0.11-beta.14

3 years ago

0.0.11

3 years ago

0.0.11-beta.13

3 years ago

0.0.11-beta.11

3 years ago

0.0.11-beta.10

3 years ago

0.0.11-beta.9

3 years ago

0.0.11-beta.8

3 years ago

0.0.11-beta.7

3 years ago

0.0.11-beta.6

3 years ago

0.0.11-beta.5

3 years ago

0.0.11-beta.4

3 years ago

0.0.11-beta.3

4 years ago

0.0.11-beta.2

4 years ago

0.0.11-beta

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.1-alpha-7

4 years ago

0.0.1-alpha-6

4 years ago

0.0.1-alpha-5

4 years ago

0.0.1-alpha-3

4 years ago

0.0.1-alpha-4

4 years ago

0.0.1-alpha-2

4 years ago

0.0.1-alpha

4 years ago