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)
- Getting multiple error message when parsing a simple templ file HOT 23
- VS Code plugin: changelog tab HOT 1
- Vm instead of generator HOT 5
- HTMX Hyperscript attribute is not accepted. HOT 1
- Using external JS lib HOT 15
- dynamic class wont work for form inputs HOT 3
- Quick template <%code%> alternative HOT 12
- lsp: textDocument/definition failed HOT 2
- parse error with templ elements HOT 5
- templ fmt indents weirdly if @component is put before/after text HOT 14
- css: Support arguments in CSS components HOT 1
- generator: option to disable whitespace normalization HOT 7
- element expression breaks on multiline function calls HOT 4
- email generation - inline css possible ? HOT 3
- bug: example code for blog HOT 1
- Back button nav HOT 3
- Idea: web components with templ HOT 5
- Explore batching strings HOT 9
- Explore multi type support HOT 1
- vscode: syntax broken when using children HOT 2
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.