Giter Site home page Giter Site logo

Comments (5)

a-h avatar a-h commented on May 22, 2024

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.

joerdav avatar joerdav commented on May 22, 2024

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.

a-h avatar a-h commented on May 22, 2024

I see your point. It would look nicer to have the <span> elements broken up.

from templ.

joerdav avatar joerdav commented on May 22, 2024

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.

a-h avatar a-h commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.