{"id":20481394,"url":"https://github.com/newtoallofthis123/html_tag","last_synced_at":"2026-07-12T23:31:43.646Z","repository":{"id":214479945,"uuid":"736640650","full_name":"newtoallofthis123/html_tag","owner":"newtoallofthis123","description":"The enigmatic way to write HTML in Rust","archived":false,"fork":false,"pushed_at":"2024-01-28T15:37:34.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-06T02:09:39.146Z","etag":null,"topics":["crate","html-generator","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/html_tag/latest","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/newtoallofthis123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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-12-28T13:06:10.000Z","updated_at":"2023-12-28T13:08:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"8aec37ea-1a6e-46e4-b304-189daee35f9e","html_url":"https://github.com/newtoallofthis123/html_tag","commit_stats":null,"previous_names":["newtoallofthis123/html_tag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/newtoallofthis123/html_tag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newtoallofthis123%2Fhtml_tag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newtoallofthis123%2Fhtml_tag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newtoallofthis123%2Fhtml_tag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newtoallofthis123%2Fhtml_tag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/newtoallofthis123","download_url":"https://codeload.github.com/newtoallofthis123/html_tag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newtoallofthis123%2Fhtml_tag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35405750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-12T02:00:06.386Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["crate","html-generator","rust"],"created_at":"2024-11-15T16:08:06.003Z","updated_at":"2026-07-12T23:31:43.624Z","avatar_url":"https://github.com/newtoallofthis123.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTML Tag\n\nHTML Tag, the enigmatic way to write HTML in your Rust code.\n\n## What is it?\n\nHTML Tag is a wrapper struct that allows you to write HTML in your Rust code.\nIt essentially removes the use of raw strings or the need to use macros such as the `html!` macro from the `html` crate to return a `String` of HTML.\n\n## Why?\n\nWhen I was experimenting with the HTMX library, I found that I was writing a lot of raw HTML strings in my Rust code.\n\nStuff like this\n\n```rust\nfind_files(\u0026search.q).iter().for_each(|x| {\n        html += format!(\"\u003cp\u003e\u003ca class='link' href='/assets/{}'\u003e{}\u003c/a\u003e\u003c/p\u003e\", x, x).as_str();\n});\n```\n\nwas not very readable and was prone to errors.\nHence I wanted to find a way to write HTML in my Rust code in a more readable and debug-able way.\n\nEnter HTML Tag.\n\nUsing HTML Tag, the above code can be written as\n\n```rust\nhtml = HtmlTag::new(\"div\");\nfind_files(\u0026search.q).iter().for_each(|x| {\n    let mut tag = HtmlTag::new(\"p\")\n        .add_child(HtmlTag::new(\"a\")\n        .add_class(\"link\")\n        .set_href(format!(\"/assets/{}\", x))\n        .set_body(x));\n    html += tag.to_string();\n});\n```\n\n## How to use it?\n\nHTML Tag is very simple to use.\nBasically, you create a new `HtmlTag` struct with the tag name as the argument.\nThen you can add attributes to the tag using the `add_attribute` method.\nHowever, for the common attributes and classes, there are methods that you can use to add them.\n\nYou can go through the [documentation](https://docs.rs/html_tag) for more information.\n\n## When to use it?\n\nFirst up, html_tag is not a replacement for the `html!` macro from the `html` crate.\nIt is more of a wrapper struct that allows you to write HTML in your Rust code.\n\nYou can use it when you want to write HTML in your Rust code, especially when you are dealing with HATEOAS APIs.\n\nIf you want full HTML generation you are better off using something like [html_builder](https://docs.rs/html-builder/0.5.1/html_builder/)\n\nMoreover, this also means that you can have modular control of the html string that you are generating.\n\nHence, you can do something like this for example\n\n```rust\nlet mut html = HtmlTag::new(\"div\");\nlet interested = true\nif interested {\n    html.with_child(HtmlTag::new(\"p\").with_body(\"I am interested\"));\n} else {\n    html.with_child(HtmlTag::new(\"p\").with_body(\"I am not interested\"));\n}\n```\n\nThis is a very simple example, but you can see how you can have modular control over the HTML string that you are generating.\n\n## How to contribute?\n\nIf you have any ideas on how to improve this crate, feel free to open an issue or a pull request.\n\nI am a complete noob when it comes to Rust and especially when it comes to writing crates that are well optimised and well documented.\nSo any help is appreciated.\n\nSome areas that I would like to improve on are\n\n- [ ] Make the crate more memory efficient\n- [ ] Make the crate more performant\n- [ ] Improve the documentation\n- [ ] Add more examples\n\nAny of the above or any other improvements are welcome.\n\n## License\n\nThis crate is licensed under the MIT License.\nYou can read the license [here](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewtoallofthis123%2Fhtml_tag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnewtoallofthis123%2Fhtml_tag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewtoallofthis123%2Fhtml_tag/lists"}