Add namespace support for element and attribute names

This commit is contained in:
msifeed 2016-07-18 13:07:58 +03:00
parent df4ed876ac
commit bad49d49c0
2 changed files with 17 additions and 0 deletions
maud_macros

View file

@ -49,6 +49,9 @@ macro_rules! question {
macro_rules! semi {
() => (TokenTree::Token(_, Token::Semi))
}
macro_rules! colon {
() => (TokenTree::Token(_, Token::Colon))
}
macro_rules! comma {
() => (TokenTree::Token(_, Token::Comma))
}
@ -548,6 +551,13 @@ impl<'cx, 'a, 'i> Parser<'cx, 'a, 'i> {
/// Parses a HTML element or attribute name.
fn name(&mut self) -> PResult<String> {
let mut s = match *self.input {
[ident!(_, namespace), colon!(), ident!(_, name), ..] => {
self.shift(3);
let mut r = String::from(&namespace.name.as_str() as &str);
r.push(':');
r.push_str(&name.name.as_str() as &str);
r
},
[ident!(_, name), ..] => {
self.shift(1);
String::from(&name.name.as_str() as &str)

View file

@ -87,6 +87,13 @@ mod elements {
html!(s, div readonly? input type="checkbox" checked? /).unwrap();
assert_eq!(s, r#"<div readonly><input type="checkbox" checked></div>"#);
}
#[test]
fn namespaces() {
let mut s = String::new();
html!(s, pon:controls a on:click="yay()" "Yay!").unwrap();
assert_eq!(s, r#"<pon:controls><a on:click="yay()">Yay!</a></pon:controls>"#);
}
}
mod splices {