Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require braces around the body of an element #137

merged 6 commits into from Jun 20, 2018


Copy link

commented Jun 16, 2018


Maud now requires braces around the body of an HTML element. For example, this code

html! {
    h1 a href="/" "Pinkie Pie's awesome website"
    div#main (contents)

must now be written as

html! {
    h1 {
        a href="/" { "Pinkie Pie's awesome website" }
    div#main { (contents) }

This change was made to address usability issues, as well as improve visual harmony with surrounding Rust code.


Omitting the braces around an element body can reduce clutter. The feature is also easy to implement, and does not introduce ambiguity in the formal grammar.

However, over the last few months I have found many arguments for removing the feature:

  • In #117, a user questioned why label "Email" for="email" didn't work. If we had required braces around the body, then it would be clear why label { "Email" } for="email" wouldn't parse.

  • A void element (e.g. input type="text";) is always terminated by a semicolon. But an element with a single node in its body (e.g. p "hello") does not require a semicolon. This is inconsistent with Rust syntax in general, which requires semicolons on statements unless they have return values or end with a braced block.

  • The shorthand syntax also hides errors. If the user omits the trailing semicolon on a void element, then Maud will emit an extra end tag. For example, this code:

    html! {
        input name="cuteness" type="number"  // note missing `;`
        button "Update!"

    results in the following HTML:

    <input name="cuteness" type="number">

    It's possible for the library to detect and warn about these cases, but we should aim to avoid this situation in the first place.


Do we need a deprecation period for this change?

I don't think so. Template engines tend to be direct dependencies, not transitive ones (like Serde), so it should be easy to pin an older version if you're not ready to deal with the breakage yet.

I have another question. Should I ask it here?

Go for it! 馃槃

@lambda-fairy lambda-fairy changed the title [WIP] Require braces around the body of an element Require braces around the body of an element Jun 17, 2018

This comment has been minimized.

Copy link

commented Jun 17, 2018

Seems sensible. The unit tests read nicer, in my opinion.

@lambda-fairy lambda-fairy merged commit 1f68ef0 into master Jun 20, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed
@lambda-fairy lambda-fairy deleted the snaggletooth branch Jun 20, 2018
lambda-fairy added a commit to lambda-fairy/maud-book that referenced this pull request Jul 15, 2018

This comment has been minimized.

Copy link

commented Aug 2, 2018

This one bites. Went back to an older site to update it and got 150 errors of this, and fixing them all bloated one of my templates from 560 chars (without whitespace / control chars) to 644 chars, a 13% bloat.

I'm not sure how feasible it is, but I would love for it to be an option to disable redudnant braces. Its probably the Pythonista talking, and you are right that it is Rust and this isn't really the domain of terse beautiful syntax, but it did feel like magic to go from:

<button class="btn">Thing</button>


button.btn "Thing"

Like sanity in a space where so little has existed for twenty years.

button.btn { "Thing" }

Isn't worse than the original, but its for sure a lot less magical.

In some ways it is even more redundant than regular html, since you have the braces and the quotations demarking the text body whereas with html you delineate the tags only, which kind of sucks.

Not really any point here, just going to miss how beautiful Maud was. It felt as close to no boilerplate markup as you could get. I'd definitely love some tunable to make the extra braces a warning or something. For now I'm just going to keep a local copy and revert the braces requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can鈥檛 perform that action at this time.