How to customize HTML formatting with templ fmt? #563
Replies: 3 comments 5 replies
-
Good initiative! Regarding customization, I feel like there are two different issues open that point to wanting some kind of config file or similar: #230 #465 . What kind of settings do you think would neccesitate a config file? Another thing:
For this, if you insert a newline in your html element, templ breaks it into multiple lines upon running Meaning:
It doesn't solve long tailwind classes (or long alpine-related lines etc). But an easy way to break up html attributes into multiple lines is to just add a \n and have the editor hooked up with formatOnSave (or run templ fmt in |
Beta Was this translation helpful? Give feedback.
-
Discussion closed as per this issue: #576 |
Beta Was this translation helpful? Give feedback.
-
`[Customizing the formatting of templ (templ LSP) output can indeed enhance readability, especially when dealing with complex HTML elements with multiple attributes and Tailwind CSS classes. Here are a few potential approaches you could consider: Customizing templ fmt: Check if templ fmt provides any configuration options or command-line flags for customizing the formatting rules. Some formatting tools offer options to customize indentation, line breaks, and other formatting aspects. Since you're already familiar with Prettier and find its formatting style preferable for HTML, consider using Prettier to format HTML code within templ files. If Prettier doesn't have native support for templ files, you could consider creating a Prettier plugin for templ. In cases where automatic formatting tools don't meet your needs, you can resort to manual formatting. |
Beta Was this translation helpful? Give feedback.
-
I like having the templ LSP handle formatting since there can be html, go and javascript code in one file, however I really do not like the formatting applied to the html.
I normally work with prettier, and configure it such that all html tags have a single attribute per line.
I am working with templ and HTMX and I end up having 5 or more attributes on an element, along with the infinite length of tailwindcss class names.
It becomes difficult to see whats going on in a tidy manner.
Is there any way to customize the formatting of templ fmt?
Would it be possible to create a prettier plugin? I know that there is a prettier plugin for std library go templates that works perfectly.
Would love to hear if others have already solved this.
PS. I am using the templ LSP from Mason in neovim and I have set up tailwindcss, html and htmx to work with .templ files.
Beta Was this translation helpful? Give feedback.
All reactions