# gotmplfmt **Repository Path**: mirrors_miekg/gotmplfmt ## Basic Information - **Project Name**: gotmplfmt - **Description**: Fmt Go HTML templates - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-02-16 - **Last Updated**: 2026-04-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # gotmplfmt Fmt Go HTML templates. Gotmplfmt only has one option (setting the width). The indenting used is 1 tab - this allow your editor's tab setting to do its work. The formatter is rather simple, there is no AST creation, it just iterates over a list of tokens. An AST was tried, but it being to smart/advanced it lead to problems, specifically usually the tree is a broken AST, missing close tags. Also which AST? The template one, of the HTML one? And templates may be partial which leads to more brokenness, hence a dumber approach was needed. Before a {{block}} or {{define}} an extra newline is introduced. Both HTML tag and template verbs are used for the indentation; in a complete template this does what you expect. For the HTML block tags: html, body, head, meta, main, nav we do not add a positive indent. ```gotmpl {{if .X}} {{else}} {{end}} ``` instead of: ```gotmpl {{if .X}} {{else}} {{end}} ``` where the second `` would indent the template even further. ## Usage 1. `go build` 2. `./gotmplfmt < template.go.tmpl` # Before ![Before fmt](Before.png) # After ![After fmt](After.png)