diff --git a/CHANGELOG.md b/CHANGELOG.md index c6458fe8..2de3d7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +- Add `script!` and `style!` inline tag helpers + [#448](https://github.com/lambda-fairy/maud/pull/448) ## [0.26.0] - 2024-01-15 diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 7647379c..4fd47941 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -462,3 +462,48 @@ pub mod macro_private { } } } + +/// Inline script tag +/// +/// # Usage +/// ``` +/// let page = maud::html! { +/// (maud::script!{ +/// console.log("Hello,"); +/// console.log("world!"); +/// }) +/// }; +/// assert_eq!( +/// page.into_string(), +/// r#""# +/// ); +/// ``` +#[macro_export] +macro_rules! script { + ($($t:tt)*) => { + $crate::PreEscaped(concat!("")) + }; +} + +/// Inline style tag +/// +/// # Usage +/// +/// ``` +/// let page = maud::html! { +/// (maud::style!{ +/// .red { color: red } +/// .green { color: green } +/// }) +/// }; +/// assert_eq!( +/// page.into_string(), +/// "" +/// ); +/// ``` +#[macro_export] +macro_rules! style { + ($($t:tt)*) => { + $crate::PreEscaped(concat!("")) + }; +}