{"id":13500471,"url":"https://github.com/yoshuawuyts/html","last_synced_at":"2025-04-12T21:34:08.070Z","repository":{"id":152469932,"uuid":"603584609","full_name":"yoshuawuyts/html","owner":"yoshuawuyts","description":"Type-safe HTML support for Rust","archived":false,"fork":false,"pushed_at":"2024-05-13T20:07:24.000Z","size":5595,"stargazers_count":250,"open_issues_count":19,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-04T01:09:03.987Z","etag":null,"topics":["css","html","rust"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoshuawuyts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-19T00:22:50.000Z","updated_at":"2025-02-15T14:47:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3062749-e317-4389-9108-a64ac8644e01","html_url":"https://github.com/yoshuawuyts/html","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshuawuyts%2Fhtml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshuawuyts%2Fhtml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshuawuyts%2Fhtml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoshuawuyts%2Fhtml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoshuawuyts","download_url":"https://codeload.github.com/yoshuawuyts/html/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636896,"owners_count":21137527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","html","rust"],"created_at":"2024-07-31T22:01:02.566Z","updated_at":"2025-04-12T21:34:08.049Z","avatar_url":"https://github.com/yoshuawuyts.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ehtml\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cstrong\u003e\n    Type-safe HTML support for Rust\n  \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Crates version --\u003e\n  \u003ca href=\"https://crates.io/crates/html\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/html.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://crates.io/crates/html\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/d/html.svg?style=flat-square\"\n      alt=\"Download\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- docs.rs docs --\u003e\n  \u003ca href=\"https://docs.rs/html\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\"\n      alt=\"docs.rs docs\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://docs.rs/html\"\u003e\n      API Docs\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/yoshuawuyts/html/releases\"\u003e\n      Releases\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/yoshuawuyts/html/blob/master.github/CONTRIBUTING.md\"\u003e\n      Contributing\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n\n## Philosophy\n\nHTML is easy to get started with, but hard to get right. There are several\nhundred element kinds, element attributes, and deeply nested hierachies - with\nsome relationships even being conditional on each other. Remembering all of this\nis difficult and error-prone, but luckily we don't have to remember any of this\nby using the type system! Rust's type system enables us to model the entire HTML\nspec, allowing us to catch all errors ahead of time during compilation.\n\nThis project comes in layers. The bottom-most layer is the HTML spec itself. We\ndownload it, and parse it into definition files. We then take these definitions,\nand use it to generate the `html-sys` crate. This crate is semantically correct,\nand knows how to render itself to string representations. We then combine\n`html-sys` with `web-sys` (wip) to create a higher-level HTML interface,\ncomplete with support for events. This can be used to manipulate HTML both in\nbrowser (wip) and non-browser contexts.\n\n# Examples\nWe can create HTML structures one-by-one:\n\n```rust\n#![recursion_limit = \"512\"]\n\nuse html::text_content::OrderedList;\nlet tree = OrderedList::builder()\n    .list_item(|li| li.text(\"nori\").class(\"cat\"))\n    .list_item(|li| li.text(\"chashu\").class(\"cat\"))\n    .build();\nlet string = tree.to_string();\n```\n\nBut we can also use Rust's native control flow structures such as loops to\niterate over items and create HTML:\n\n```rust\n#![recursion_limit = \"512\"]\n\nuse html::text_content::OrderedList;\nlet mut ol = OrderedList::builder();\nfor name in [\"hello\", \"world\"] {\n    ol.list_item(|li| li.text(name));\n}\nlet tree = ol.build();\n```\n\nWe can also create elements separately and append them later:\n```rust\n#![recursion_limit = \"512\"]\n\nuse html::text_content::{OrderedList, ListItem};\nlet mut ol = OrderedList::builder();\nlet li = ListItem::builder().text(\"hello\").build();\nol.push(li);\nlet tree = ol.build();\n```\n\n## Building the project\n\nTo fetch, scrape, parse, and generate code; clone the project and then run:\n\n```bash\n$ cargo xtask all\n```\n\nThis will run all stages of the `html-bindgen` crate, and create a fresh copy of\nall generated code. If you make a change to any of the codegen stages, please\nre-run xtask to update the generated code.\n\n## References\n\n- [Using HTML as a Compile Target (2023)](https://blog.yoshuawuyts.com/compiled-html/)\n- [`web-sys`](https://docs.rs/web-sys/latest/web_sys/)\n\n## Installation\n```sh\n$ cargo add html\n```\n\n## Safety\nThis crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in\n100% Safe Rust.\n\n## Contributing\nWant to join us? Check out our [\"Contributing\" guide][contributing] and take a\nlook at some of these issues:\n\n- [Issues labeled \"good first issue\"][good-first-issue]\n- [Issues labeled \"help wanted\"][help-wanted]\n\n[contributing]: https://github.com/yoshuawuyts/html/blob/master.github/CONTRIBUTING.md\n[good-first-issue]: https://github.com/yoshuawuyts/html/labels/good%20first%20issue\n[help-wanted]: https://github.com/yoshuawuyts/html/labels/help%20wanted\n\n## License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr/\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshuawuyts%2Fhtml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoshuawuyts%2Fhtml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoshuawuyts%2Fhtml/lists"}