npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prettier-hugo-plugin

v0.2.2

Published

Prettier plugin for Hugo and Go templates

Downloads

14

Readme

prettier-hugo-plugin

npm version npm downloads license: MIT

Prettier plugin for formatting Hugo/Go HTML templates. It teaches Prettier how to parse and print Go template tags embedded in HTML (used by Hugo), while delegating HTML formatting to Prettier’s HTML parser.

This plugin supports common Hugo/Go template constructs like if/else, range, with, define, block, and handles inline statements, multi-block constructs (e.g. else), and sections you don’t want to reformat.

Why this plugin?

  • Works with Prettier 3.x
  • Understands Go template delimiters like {{- ... -}}, {{< ... >}}, and {{% ... %}}
  • Preserves and embeds formatted HTML around Go template nodes
  • Supports prettier-ignore for both single lines and whole blocks
  • Respects bracket spacing option for template statements

Requirements

  • Node.js >= 20
  • Prettier ^3.0.0

Installation

Install Prettier and the plugin as dev dependencies:

  • npm: npm i -D prettier prettier-hugo-plugin
  • pnpm: pnpm add -D prettier prettier-hugo-plugin
  • yarn: yarn add -D prettier prettier-hugo-plugin

Usage

Prettier will auto-load plugins from node_modules when referenced in your config. Add the plugin and configure Prettier to use the GoTemplate language for your Hugo template extensions.

Example prettier config (prettier.config.cjs/mjs or .prettierrc) with recommended options:

/** @type {import('prettier').Config} */
module.exports = require('prettier-hugo-plugin').configs.recommended;

Example prettier config (prettier.config.cjs/mjs or .prettierrc) with overrides:

/** @type {import('prettier').Config} */
export default {
  plugins: ["prettier-hugo-plugin"],
  // Optional plugin option:
  goTemplateBracketSpacing: true,
  // Map typical Hugo template extensions to the GoTemplate parser
  overrides: [
    {
      files: [
        "**/*.html",
      ],
      options: { parser: "go-template" },
    },
  ],
};

Alternatively, you can pass the plugin on the CLI:

  • Format a file: npx prettier --plugin prettier-hugo-plugin --parser go-template path/to/template.html
  • Or rely on overrides and just run: npx prettier -w .

Supported syntax and behavior

  • Go/Hugo delimiters: {{ ... }}, {{- ... -}}, {{< ... >}}, {{% ... %}}, and comment pairs {{/* ... */}}
  • Block keywords: if, range, block, with, define, else, end
  • Prettier ignore controls:
    • Single line: put prettier-ignore in an HTML comment or Go template comment right before a statement
    • Block: wrap a section with {{ prettier-ignore-start }} ... {{ end }}
  • Preserves empty lines after blocks when appropriate, to keep readable spacing
  • Avoids reformatting content inside or tags that contain Go template expressions

Examples

Input:

{{if .Title}}
<title>{{.Title}}</title>
{{else}}
<title>My Site</title>
{{end}}

Formatted (with goTemplateBracketSpacing: true):

{{ if .Title }}
  <title>{{ .Title }}</title>
{{ else }}
  <title>My Site</title>
{{ end }}

Inline statements are grouped and break when long or multiline:

<p>{{- with .Params.long 
      -}}
  {{ . }}
{{- end -}}</p>

Configuration options

  • goTemplateBracketSpacing (boolean, default: true)
    • When true: prints space after {{ and before }} around statements, for example {{ if . }}. When false: prints compact statements {{if .}}.

All other formatting decisions are handled by Prettier’s standard HTML rules.

File extensions and editor support

This plugin registers a language named GoTemplate and associates it with these extensions:

  • .go.html, .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, .html.tmpl, .html.tpl

Most editors using Prettier will pick up the plugin when configured. For VS Code, ensure the Prettier extension is enabled, and that the file is formatted with Prettier.

Prettier ignore

  • Ignore the next node/line:
    • <!-- prettier-ignore -->\n{{ .SomeValue }}
    • {{/* prettier-ignore */}}\n{{ .SomeValue }}
  • Ignore a whole block:
    • {{ prettier-ignore-start }}
    • ... any content inside will be treated as plain text and not reformatted
    • {{ end }}

CLI tips

  • Dry run check: npx prettier --check .
  • Write changes: npx prettier --write .
  • Only Go/Hugo templates (if using overrides): npx prettier --write "**/*.gotmpl"

Troubleshooting

  • Plugin not applied: ensure plugins includes "prettier-hugo-plugin" and your files match overrides with parser "go-template".
  • Mixed HTML/Go errors: the plugin embeds formatted HTML and maps Go nodes back into place; malformed HTML near template delimiters can still confuse the HTML parser.
  • Unexpected reflow inside /: the plugin treats those with Go tags as unformattable to avoid breaking code. If necessary, use ignore controls.

Contributing

  • Requirements: Node 18+ recommended (Node 14+ supported), npm
  • Install: npm ci
  • Build: npm run build
  • Tests: npm test (watch: npm run watch:test)
  • Lint: npm run lint

Please open issues and pull requests in the GitHub repository. Before submitting, run tests and lint.

Release and CI

This repository includes a GitHub Actions workflow to publish to npm on release. To publish locally, use:

  • npm run release:plugin – build, collect/publish coverage, and publish
  • npm run release:plugin:local – publish to a local registry (e.g., verdaccio)

Coverage can be uploaded with npm run release:coverage (requires CODECOV token env or npm config as defined in package.json).