Skip to content

Commit

Permalink
Disallow slashes (/) in void elements (#315)
Browse files Browse the repository at this point in the history
# Overview

The following syntax will no longer work:

```rust
html! {
    br /
    link rel="stylesheet" href="styles.css" /
}
```

This should be changed to the following:

```rust
html! {
    br;
    link rel="stylesheet" href="styles.css";
}
```

# Rationale

The `;` syntax was introduced in #96; the rationale for it can be found there.

Removing support for the older `/` syntax will simplify the API surface, and allow for the space to be used for other things.
  • Loading branch information
lambda-fairy authored Nov 7, 2021
1 parent 317bf9e commit dc6c88f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[#309](https://github.com/lambda-fairy/maud/pull/309)
- Remove Iron support
[#289](https://github.com/lambda-fairy/maud/pull/289)
- Disallow slashes (`/`) in void elements
[#315](https://github.com/lambda-fairy/maud/pull/315)

## [0.22.3] - 2021-09-27

Expand Down
14 changes: 0 additions & 14 deletions docs/content/elements-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ html! {
# ;
```

Before version 0.18,
Maud allowed the curly braces to be omitted.
This syntax was [removed][#137]
and now causes an error instead.

[#137]: https://github.com/lambda-fairy/maud/pull/137

## Void elements: `br;`

Terminate a void element using a semicolon:
Expand All @@ -47,13 +40,6 @@ html! {
The result will be rendered with HTML syntax –
`<br>` not `<br />`.

Maud also supports ending a void element with a slash:
`br /`.
This syntax is [deprecated][#96]
and should not be used in new code.

[#96]: https://github.com/lambda-fairy/maud/pull/96

## Custom elements and `data` attributes

Maud also supports elements and attributes with hyphens in them.
Expand Down
6 changes: 0 additions & 6 deletions maud/tests/basic_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ fn empty_elements() {
assert_eq!(result.into_string(), "pinkie<br>pie");
}

#[test]
fn empty_elements_slash() {
let result = html! { "pinkie" br / "pie" };
assert_eq!(result.into_string(), "pinkie<br>pie");
}

#[test]
fn simple_attributes() {
let result = html! {
Expand Down
9 changes: 9 additions & 0 deletions maud/tests/warnings/void-element-slash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use maud::html;

fn main() {
html! {
br /
// Make sure we're not stopping on the first error
input type="text" /
};
}
17 changes: 17 additions & 0 deletions maud/tests/warnings/void-element-slash.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: void elements must use `;`, not `/`
--> $DIR/void-element-slash.rs:5:12
|
5 | br /
| ^
|
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/96 for details

error: void elements must use `;`, not `/`
--> $DIR/void-element-slash.rs:7:27
|
7 | input type="text" /
| ^
|
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/96 for details
8 changes: 8 additions & 0 deletions maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ impl Parser {
{
// Void element
self.advance();
if punct.as_char() == '/' {
emit_error!(
punct,
"void elements must use `;`, not `/`";
help = "change this to `;`";
help = "see https://github.com/lambda-fairy/maud/pull/96 for details";
);
}
ast::ElementBody::Void {
semi_span: SpanRange::single_span(punct.span()),
}
Expand Down

0 comments on commit dc6c88f

Please sign in to comment.