| @@ -489,7 +489,8 @@ impl BodyLowerer<'_, '_, '_> { |
| 489 | 489 | }) |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | | − /// A tag name: letters, digits, `-` and `_`, starting with a letter. |
| 492 | + /// A tag name: letters, digits, `-`, `_` and `:`, starting with a |
| 493 | + /// letter (an HTML literal's set bar `.`, the class shorthand). |
| 493 | 494 | fn spec_name<'t>( |
| 494 | 495 | &mut self, |
| 495 | 496 | toks: &'t [Tok], |
| @@ -497,7 +498,7 @@ impl BodyLowerer<'_, '_, '_> { |
| 497 | 498 | ) -> PugResult<(Option<String>, &'t [Tok])> { |
| 498 | 499 | match toks { |
| 499 | 500 | [Tok::Ch(c, _), ..] if is_name_start(*c) => { |
| 500 | | − let (name, rest) = take_name(toks); |
| 501 | + let (name, rest) = take_name(toks, is_tag_char); |
| 501 | 502 | Ok((Some(name), rest)) |
| 502 | 503 | } |
| 503 | 504 | [Tok::Ch(c, range), ..] if *c != '.' && *c != '#' && *c != '(' => { |
| @@ -528,7 +529,7 @@ impl BodyLowerer<'_, '_, '_> { |
| 528 | 529 | }); |
| 529 | 530 | } |
| 530 | 531 | }; |
| 531 | | − let (name, after) = take_name(rest); |
| 532 | + let (name, after) = take_name(rest, is_name_char); |
| 532 | 533 | if name.is_empty() { |
| 533 | 534 | // Point at the token found, or at the selector itself. |
| 534 | 535 | let at = after.first().map_or(range, |t| t.range()); |
| @@ -570,7 +571,7 @@ impl BodyLowerer<'_, '_, '_> { |
| 570 | 571 | [Tok::Ch(' ', _), rest @ ..] | [Tok::Ch(',', _), rest @ ..] => toks = rest, |
| 571 | 572 | [Tok::Ch(c, _), ..] if is_name_start(*c) => { |
| 572 | 573 | let span = toks[0].range(); |
| 573 | | − let (name, rest) = take_name(toks); |
| 574 | + let (name, rest) = take_name(toks, is_attr_char); |
| 574 | 575 | match rest { |
| 575 | 576 | [Tok::Ch('=', _), rest @ ..] => { |
| 576 | 577 | let (value, rest) = self.attr_value(rest, number, line_range)?; |
| @@ -784,12 +785,13 @@ fn is_comment(toks: &[Tok]) -> bool { |
| 784 | 785 | matches!(toks, [Tok::Ch('/', _), Tok::Ch('/', _), ..]) |
| 785 | 786 | } |
| 786 | 787 | |
| 787 | | −/// A name's characters, and the tokens after them. |
| 788 | | −fn take_name(toks: &[Tok]) -> (String, &[Tok]) { |
| 788 | +/// A name's characters, and the tokens after them: `name_char` decides |
| 789 | +/// (tag, attribute and shorthand names differ — issue #300). |
| 790 | +fn take_name(toks: &[Tok], name_char: fn(char) -> bool) -> (String, &[Tok]) { |
| 789 | 791 | let mut name = String::new(); |
| 790 | 792 | let mut rest = toks; |
| 791 | 793 | while let [Tok::Ch(c, _), tail @ ..] = rest { |
| 792 | | − if !is_name_char(*c) { |
| 794 | + if !name_char(*c) { |
| 793 | 795 | break; |
| 794 | 796 | } |
| 795 | 797 | name.push(*c); |
| @@ -802,10 +804,24 @@ fn is_name_start(c: char) -> bool { |
| 802 | 804 | c.is_ascii_alphabetic() |
| 803 | 805 | } |
| 804 | 806 | |
| 807 | +/// The base set: letters, digits, `-` and `_`. |
| 805 | 808 | fn is_name_char(c: char) -> bool { |
| 806 | 809 | is_name_start(c) || c.is_ascii_digit() || c == '-' || c == '_' |
| 807 | 810 | } |
| 808 | 811 | |
| 812 | +/// A tag name: an HTML literal's set bar `.` (a dot is the class |
| 813 | +/// shorthand), so `:` is in (`svg:rect`, `xml:lang`). |
| 814 | +fn is_tag_char(c: char) -> bool { |
| 815 | + is_name_char(c) || c == ':' |
| 816 | +} |
| 817 | + |
| 818 | +/// An attribute name: an HTML literal's set exactly (issue #300) — `:` |
| 819 | +/// and `.` too (htmx 4's `hx-target:inherited`, Alpine's |
| 820 | +/// `x-on:click.prevent`). Inside the parens a dot is no shorthand. |
| 821 | +fn is_attr_char(c: char) -> bool { |
| 822 | + is_name_char(c) || c == ':' || c == '.' |
| 823 | +} |
| 824 | + |
| 809 | 825 | /// One separating space between the spec and the content, if there. |
| 810 | 826 | fn drop_one_space(toks: &[Tok]) -> &[Tok] { |
| 811 | 827 | match toks { |