From 7290a23c85af205845af946a442be4f55f4f5e8d Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 17 Dec 2024 01:44:41 +0100 Subject: [PATCH 01/11] Simplify usage example --- README.md | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d269903..c3c9bc5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and named after a small helper function I once wrote in JS. ## Show me a simple example ```rs -use el::{Attr, Render, html::*}; +use el::{Render, html::*}; let page: String = html(( head(( diff --git a/src/lib.rs b/src/lib.rs index fa3ed62..8b56c08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ //! ## Usage example //! //! ``` -//! use el::{Attr, Render, html::*}; +//! use el::{Render, html::*}; //! //! let page: String = html(( //! head(( From ec7bc571b1e7dd81fe2fd7c730acba2309109eef Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 19 Dec 2024 18:02:26 +0100 Subject: [PATCH 02/11] Add Rel attr --- CHANGELOG.md | 4 +++ src/html/attr.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 033eb1a..e7d4241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ A dependency update to an incompatible version is considered a breaking change. ## Unreleased +### Added + +- `html::attr::Rel` + ## v0.1.2 - 2024-12-14 ### Added diff --git a/src/html/attr.rs b/src/html/attr.rs index 636a552..7a6b71a 100644 --- a/src/html/attr.rs +++ b/src/html/attr.rs @@ -107,6 +107,35 @@ macro_rules! attr_enum { } } }; + ( + $name:ident as $article:ident $actual:expr, separated by $separator:expr; + at $url:expr; + $( $valname:ident => $valstr:expr, )* + ) => { + #[doc = concat!("Create (or append to) ", stringify!($article), " `", $actual, "` attribute")] + #[doc = concat!("(", $url, ").")] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + pub enum $name { + $( + #[doc = concat!("The value `", stringify!($valstr), "`.")] + $valname, + )* + } + + impl fmt::Display for $name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $( Self::$valname => $valstr.fmt(f), )* + } + } + } + + impl ElementComponent for $name { + fn add_to_element(self, element: &mut Element) { + Attr::append($actual, self, $separator).add_to_element(element); + } + } + }; } //////////////// @@ -757,6 +786,40 @@ attr_enum! { UnsafeUrl => "unsafe-url", } +attr_enum! { + Rel as a "rel", separated by " "; + at url!(normal, "rel"); + Alternate => "alternate", + Author => "author", + Bookmark => "bookmark", + Canonical => "canonical", + DnsPrefetch => "dns-prefetch", + External => "external", + Expect => "expect", + Help => "help", + Icon => "icon", + License => "license", + Manifest => "manifest", + Me => "me", + Modulepreload => "modulepreload", + Next => "next", + Nofollow => "nofollow", + Noopener => "noopener", + Noreferrer => "noreferrer", + Opener => "opener", + Pingback => "pingback", + Preconnect => "preconnect", + Prefetch => "prefetch", + Preload => "preload", + Prerender => "prerender", + Prev => "prev", + PrivacyPolicy => "privacy-policy", + Search => "search", + Stylesheet => "stylesheet", + Tag => "tag", + TermsOfService => "terms-of-service", +} + attr_append! { rel as a "rel", separated by " "; at url!(normal, "rel"); From 0167d3cea35f23f9a9f095375a1a59f3c5af88cb Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 20 Dec 2024 16:42:48 +0100 Subject: [PATCH 03/11] Fix html comment rendering Apparently I just completely forgot to actually include , and instead just rendered the comment contents. --- CHANGELOG.md | 4 ++++ src/lib.rs | 24 +++++++++++++++++++++++- src/render.rs | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d4241..5e02e1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ A dependency update to an incompatible version is considered a breaking change. - `html::attr::Rel` +### Fixed + +- Rendering of HTML comments + ## v0.1.2 - 2024-12-14 ### Added diff --git a/src/lib.rs b/src/lib.rs index 8b56c08..921d6dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,7 @@ pub use self::{element::*, render::*}; #[cfg(test)] mod tests { - use crate::{html::*, Attr, Element, Render}; + use crate::{html::*, Attr, Content, Element, Render}; #[test] fn simple_website() { @@ -189,4 +189,26 @@ mod tests { r#""#, ); } + + #[test] + fn comments() { + assert_eq!( + html((" ", Content::comment("abc"))) + .render_to_string() + .unwrap(), + r#"<!--abc--> "#, + ); + + assert_eq!( + html(Content::comment("Hello !")) + .render_to_string() + .unwrap(), + r#""#, + ); + + assert_eq!( + html(Content::comment("->"#, + ); + } } diff --git a/src/render.rs b/src/render.rs index 52770b5..127574d 100644 --- a/src/render.rs +++ b/src/render.rs @@ -246,6 +246,8 @@ fn render_text(w: &mut W, text: &str) -> Result<()> { } fn render_comment(w: &mut W, text: &str) -> Result<()> { + write!(w, "")?; Ok(()) } From 353934381b82143787dfa7dde43b48550878bc94 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 21 Dec 2024 20:04:46 +0100 Subject: [PATCH 04/11] Bump version to 0.1.3 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e02e1a..faa900d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ A dependency update to an incompatible version is considered a breaking change. ## Unreleased +## v0.1.3 - 2024-12-21 + ### Added - `html::attr::Rel` diff --git a/Cargo.toml b/Cargo.toml index 55f6be4..81cf422 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "el" -version = "0.1.2" +version = "0.1.3" edition = "2021" authors = ["Garmelon "] description = "Write and manipulate HTML elements as data" From ec7a461758ef57b464dc551fbd343b99584d1876 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 1 Jan 2025 22:09:32 +0100 Subject: [PATCH 05/11] Update axum-core to 0.5.0 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa900d..44c909b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ A dependency update to an incompatible version is considered a breaking change. ## Unreleased +### Changed + +- **(breaking)** Updated `axum-core` dependency to `0.5.0` + ## v0.1.3 - 2024-12-21 ### Added diff --git a/Cargo.toml b/Cargo.toml index 81cf422..4614621 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["web-programming", "template-engine"] axum = ["dep:axum-core", "dep:http"] [dependencies] -axum-core = { version = "0.4.5", optional = true } +axum-core = { version = "0.5.0", optional = true } http = { version = "1.1.0", optional = true } [lints] From 59b81d637ba695dccca5eecfc700295c5858d384 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 1 Jan 2025 22:36:59 +0100 Subject: [PATCH 06/11] Relax lower bound on http dependency Originally, I just used the current version when adding the dependency, but I see no reason to forbid earlier compatible versions. --- CHANGELOG.md | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44c909b..acb3fed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ A dependency update to an incompatible version is considered a breaking change. ### Changed - **(breaking)** Updated `axum-core` dependency to `0.5.0` +- Relaxed lower bound on `http` dependency to `1.0.0` ## v0.1.3 - 2024-12-21 diff --git a/Cargo.toml b/Cargo.toml index 4614621..20a72d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ axum = ["dep:axum-core", "dep:http"] [dependencies] axum-core = { version = "0.5.0", optional = true } -http = { version = "1.1.0", optional = true } +http = { version = "1.0.0", optional = true } [lints] rust.unsafe_code = { level = "forbid", priority = 1 } From bb7dedc9eb4ced25a64eab275ee58ce1550dd128 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 1 Jan 2025 22:40:28 +0100 Subject: [PATCH 07/11] Bump version to 0.2.0 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acb3fed..5f9dfd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ A dependency update to an incompatible version is considered a breaking change. ## Unreleased +## v0.2.0 - 2025-01-01 + ### Changed - **(breaking)** Updated `axum-core` dependency to `0.5.0` diff --git a/Cargo.toml b/Cargo.toml index 20a72d2..c2d5f44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "el" -version = "0.1.3" +version = "0.2.0" edition = "2021" authors = ["Garmelon "] description = "Write and manipulate HTML elements as data" From 190e00ed621cfe64d89387caf50a3a16cefef6c7 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 16 Apr 2025 22:12:21 +0200 Subject: [PATCH 08/11] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3c9bc5..842db85 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ See the top-level crate documentation for more info. ## But what about that small helper function? -Here it is in full, for posteriority: +Here it is in full, for posterity: ```js function el(name, attributes, ...children) { From f08eda2758fb7e96cd9633793bc54f75642b109f Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 16 Apr 2025 22:16:08 +0200 Subject: [PATCH 09/11] Satisfy clippy --- src/check.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/check.rs b/src/check.rs index c4f3387..01f3a59 100644 --- a/src/check.rs +++ b/src/check.rs @@ -58,10 +58,9 @@ pub fn is_valid_raw_text(tag_name: &str, text: &str) -> bool { // "[...] followed by characters that case-insensitively match the tag // name of the element [...]" // - // Note: Since we know that tag names are ascii-only, we can convert - // both to lowercase for a case-insensitive comparison without weird - // unicode shenanigans. - if potential_tag_name.to_ascii_lowercase() != tag_name.to_ascii_lowercase() { + // Note: Since we know that tag names are ascii-only, we can use an + // ASCII-based case insensitive comparison without unicode shenanigans. + if !potential_tag_name.eq_ignore_ascii_case(tag_name) { continue; } From d26ef729eb0684287ab6fc1134629b21a6278e45 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 20 Apr 2026 21:16:41 +0200 Subject: [PATCH 10/11] Update edition, URL, and lints --- Cargo.toml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c2d5f44..b976823 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "el" version = "0.2.0" -edition = "2021" +edition = "2024" authors = ["Garmelon "] description = "Write and manipulate HTML elements as data" -repository = "https://github.com/Garmelon/el" +repository = "https://git.plugh.de/Garmelon/el" license = "MIT OR Apache-2.0" keywords = ["html", "svg", "mathml", "hiccup"] categories = ["web-programming", "template-engine"] @@ -19,10 +19,12 @@ http = { version = "1.0.0", optional = true } [lints] rust.unsafe_code = { level = "forbid", priority = 1 } # Lint groups -rust.deprecated_safe = "warn" -rust.future_incompatible = "warn" -rust.keyword_idents = "warn" -rust.rust_2018_idioms = "warn" +rust.deprecated-safe = "warn" +rust.future-incompatible = "warn" +rust.keyword-idents = "warn" +rust.nonstandard-style = "warn" +rust.refining-impl-trait = "warn" +rust.rust-2018-idioms = "warn" rust.unused = "warn" # Individual lints rust.let_underscore_drop = "warn" From 01d9e06d635c25f39413e8e2c22816689a55f7be Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 20 Apr 2026 22:29:53 +0200 Subject: [PATCH 11/11] Run cargo fmt --- src/axum.rs | 2 +- src/element.rs | 10 +++++++--- src/lib.rs | 10 ++++++---- src/render.rs | 3 +-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/axum.rs b/src/axum.rs index 44059bb..d0b7c64 100644 --- a/src/axum.rs +++ b/src/axum.rs @@ -1,5 +1,5 @@ use axum_core::response::IntoResponse; -use http::{header, HeaderValue, StatusCode}; +use http::{HeaderValue, StatusCode, header}; use crate::{Document, Render}; diff --git a/src/element.rs b/src/element.rs index b8fd828..b2b12e0 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,4 +1,4 @@ -use std::collections::{btree_map::Entry, BTreeMap, HashMap}; +use std::collections::{BTreeMap, HashMap, btree_map::Entry}; /// The kind of an element. /// @@ -501,8 +501,12 @@ element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11); element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12); element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13); element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14); -element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15); -element_component_tuple!(C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16); +element_component_tuple!( + C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15 +); +element_component_tuple!( + C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16 +); /// A full HTML document including doctype. /// diff --git a/src/lib.rs b/src/lib.rs index 921d6dc..bf907f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,7 @@ pub use self::{element::*, render::*}; #[cfg(test)] mod tests { - use crate::{html::*, Attr, Content, Element, Render}; + use crate::{Attr, Content, Element, Render, html::*}; #[test] fn simple_website() { @@ -130,9 +130,11 @@ mod tests { assert!(script("hello world").render_to_string().is_err()); - assert!(script("hello