在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:bodil/typed-html开源软件地址:https://github.com/bodil/typed-html开源编程语言:Rust 98.6%开源软件介绍:typed-htmlThis crate provides the Not Currently MaintainedThis project is not currently being maintained. If you would like to take over maintainership, please leave an issue. Quick Previewlet mut doc: DOMTree<String> = html!(
<html>
<head>
<title>"Hello Kitty"</title>
<meta name=Metadata::Author content="Not Sanrio Co., Ltd"/>
</head>
<body>
<h1>"Hello Kitty"</h1>
<p class="official">
"She is not a cat. She is a human girl."
</p>
{ (0..3).map(|_| html!(
<p class="emphasis">
"Her name is Kitty White."
</p>
)) }
<p class="citation-needed">
"We still don't know how she eats."
</p>
</body>
</html>
);
let doc_str = doc.to_string(); SyntaxThis macro largely follows JSX syntax, but with some differences:
Valid HTML5The macro will only accept valid HTML5 tags, with no tags or attributes marked experimental or obsolete. If it won't accept something you want it to accept, we can discuss it over a pull request (experimental tags and attributes, in particular, are mostly omitted just for brevity, and you're welcome to implement them). The structure validation is simplistic by necessity, as it defers to the type system: a few elements will have one or more required children, and any element which accepts children will have a restriction on the type of the children, usually a broad group as defined by the HTML spec. Many elements have restrictions on children of children, or require a particular ordering of optional elements, which isn't currently validated. Attribute ValuesBrace blocks in the attribute value position should return the expected type for the attribute. The type checker will complain if you return an unsupported type. You can also use literals or a few simple Rust expressions as attribute values (see the Syntax section above). The As a special case, if you use a string literal, the macro will instead use the
Examplelet classList: SpacedSet<Class> = ["foo", "bar", "baz"].into();
html!(
<div>
<div class="foo bar baz" /> // parses a string literal
<div class=["foo", "bar", "baz"] /> // uses From<[&str, &str, &str]>
<div class=classList /> // uses a variable in scope
<div class={ // evaluates a code block
SpacedSet::from(["foo", "bar", "baz"])
} />
</div>
) Generated NodesBrace blocks in the child node position are expected to return an
Examplehtml!(
<ul>
{ (1..=5).map(|i| html!(
<li>{ text!("{}", i) }</li>
)) }
</ul>
) RenderingYou have two options for actually producing something useful from the DOM tree that comes out of the macro. Render to a stringThe DOM tree data structure implements let doc: DOMTree<String> = html!(
<p>"Hello Kitty"</p>
);
let doc_str = doc.to_string();
assert_eq!("<p>Hello Kitty</p>", doc_str); Render to a virtual DOMThe DOM tree structure also implements a method called LicenceCopyright 2018 Bodil Stokke This software is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. Code of ConductPlease note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论