Comments (5)
It's formatted that way because span
is an inline element:
<p>This is <span>inline</span></o>
If you used <div>
instead, I'd expect it to introduce a new line.
from templ.
I think most HTML formatters attempt to limit line length in cases like this.
I wanted to use prettier as an example here but it did something arguably worse:
(replaced all braces with quotes to make it valid HTML)
<div>
<p class="%= templ.Classes(invalid()) %">"%= msg %"</p>
<form action="%= action %" method="post">
<span class="%= templ.Classes(cell()) %"
><input type="text" value="%= t.name %" name="name"
/></span>
<span class="%= templ.Classes(cell()) %"
><input type="text" value="%= t.description %" name="description"
/></span>
<span class="%= templ.Classes(cell()) %"
>Done?
<input
type="checkbox"
value="true"
name="status"
checked?="%= t.status %"
/></span>
<span class="%= templ.Classes(cell()) %"
><input type="submit" value="Submit"
/></span>
</form>
</div>
from templ.
I see your point. It would look nicer to have the <span>
elements broken up.
from templ.
I think my expectation of what would happen was just wrong, having it all on one line is a valid approach.
Potentially better?? Is what html-tidy.org does, but also arguably not too readable still.
<div>
<p class="%= templ.Classes(invalid()) %">"%= msg %"</p>
<form action="%=%20action%20%" method="post">
<span class="%= templ.Classes(cell()) %"><input type="text"
value="%= t.name %" name="name"></span> <span class=
"%= templ.Classes(cell()) %"><input type="text" value=
"%= t.description %" name="description"></span> <span class=
"%= templ.Classes(cell()) %">Done? <input type="checkbox"
value="true" name="status"></span> <span class=
"%= templ.Classes(cell()) %"><input type="submit" value=
"Submit"></span>
</form>
</div>
from templ.
Just testing this, because I made a few updates to the formatting in v2 syntax.
The input...
package testrawelements
templ form(action string, t todo, msg string) {
<div>
<p class={ templ.Classes(invalid()) }>{ msg }</p>
<form action={ action } method="post">
<span class={ templ.Classes(cell()) }><input type="text" value={ t.name } name="name"/></span>
<span class={ templ.Classes(cell()) }><input type="text" value={ t.description } name="description"/></span>
<span class={ templ.Classes(cell()) }>Done? <input type="checkbox" value="true" name="status" checked?={ t.status }/></span>
<span class={ templ.Classes(cell()) }><input type="submit" value="Submit"/></span>
</form>
</div>
}
With <span>
elements, they all get put onto one line.
package testrawelements
templ form(action string, t todo, msg string) {
<div>
<p class={ templ.Classes(invalid()) }>{ msg }</p>
<form action={ action } method="post"><span class={ templ.Classes(cell()) }><input type="text" value={ t.name } name="name"/></span><span class={ templ.Classes(cell()) }><input type="text" value={ t.description } name="description"/></span><span class={ templ.Classes(cell()) }>Done? <input type="checkbox" value="true" name="status" checked?={ t.status }/></span><span class={ templ.Classes(cell()) }><input type="submit" value="Submit"/></span></form>
</div>
}
But if I convert the <span>
elements to <div>
elements it comes out perfect.
package testrawelements
templ form(action string, t todo, msg string) {
<div>
<p class={ templ.Classes(invalid()) }>{ msg }</p>
<form action={ action } method="post">
<div class={ templ.Classes(cell()) }><input type="text" value={ t.name } name="name"/></div>
<div class={ templ.Classes(cell()) }><input type="text" value={ t.description } name="description"/></div>
<div class={ templ.Classes(cell()) }>Done? <input type="checkbox" value="true" name="status" checked?={ t.status }/></div>
<div class={ templ.Classes(cell()) }><input type="submit" value="Submit"/></div>
</form>
</div>
}
I think the formatting makes sense, since in the output, block elements start a new line, whereas inline don't. I'll close this, feel free to re-open it if you think there's more to do.
from templ.
Related Issues (20)
- templ version check: failed to read go.mod file: open /go.mod: no such file or directory HOT 2
- I need a break statement HOT 3
- Starting the LSP in vscode with no .templ files present will crash it HOT 2
- templ generate --watch generates code which fails to render (skaffold+ko on minikube) HOT 3
- Enable generating Go code, not just HTML HOT 2
- proxy injected script shouldn't error when re-evaluated
- Errors in go portions of a template report line numbers in the go file instead of the templ file HOT 2
- Golang code generated always import github.com/a-h/templ even if not used HOT 2
- Issue with for loop parsing for: expected nodes, but none were found: line 96, col 13 HOT 3
- vscode: show _templ.go files greyed out? HOT 8
- Can/could templ support plain text? HOT 3
- lsp: formatting malformed when CSS expressions are too long HOT 6
- proposal: add templ.JSONScript and templ.JSON functions HOT 4
- proposal: deprecate CSS components in favour of 3rd party CSS pre-processors HOT 11
- Bug: hot reloader adds a wrong reload script in nested body responses HOT 1
- fmt: broken mutliline raw string formatting
- Website SEO HOT 1
- proposal: Allow for primitives & fmt.Stringer in addition to string in templates HOT 2
- vscode: Bad highlighting when using generic functions HOT 3
- Binary in`templ_Darwin_arm64.tar.gz` v0.2.697 displays version 0.2.696 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.