Fix `data-` prefix duplication
The `data-` prefix is being duplicated, such that `data-foo="bar"` is being rendered as `data-data-foo="bar"`. This change removes the prefix at the `Element` level, and leaves its addition at the `Display` level, causing it to be rendered correctly.
This commit is contained in:
parent
4c49aca99f
commit
c2584878a5
|
@ -77,7 +77,7 @@ fn extract_data_attrs(attrs: &mut StringyMap<Ident, TokenTree>) -> StringyMap<St
|
|||
let prefix = "data_";
|
||||
if key_name.starts_with(prefix) {
|
||||
let value = attrs.remove(&key).unwrap();
|
||||
data.insert(format!("data-{}", &key_name[prefix.len()..]), value);
|
||||
data.insert(key_name[prefix.len()..].to_string(), value);
|
||||
}
|
||||
}
|
||||
data
|
||||
|
|
|
@ -410,3 +410,13 @@ declare_elements!{
|
|||
width: String, // FIXME size
|
||||
} in [FlowContent, PhrasingContent] with PhrasingContent;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_data_attributes() {
|
||||
use crate as typed_html;
|
||||
use crate::dom::DOMTree;
|
||||
|
||||
let frag: DOMTree<String> = html!(<div data-id="1234">"Boo!"</div>);
|
||||
|
||||
assert_eq!("<div data-id=\"1234\">Boo!</div>", frag.to_string());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue