bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
271 stars 29 forks source link

Can we have macro names to exclude? #117

Closed ekanna closed 6 months ago

ekanna commented 6 months ago

Hi, I have a style! macro inside view! macro to generate scoped css. How to skip formatting this style! macro? Can we do something like macro_names_to_skip = [style]

For example, from the below code style! macro generates a css file with @scope rule.

#[component]
pub fn HeaderField() -> impl IntoView {
    view! {
        <div class="HeaderField start">
            <h1>Hello Kanna</h1>
        </div>

        {
            style! {
                h1 {
                    background-color: red;
                    color: white;
                }

                @media (orientation: portrait) {
                    h1 {
                      background-color: green;
                    }
                  }

            }
        }
    }
}

My generated css file

@scope (.HeaderField) to (.start) {
    h1 {
        background-color: red;
        color: white;
    }

    @media (orientation: portrait) {
        h1 {
          background-color: green;
        }
      }

}
bram209 commented 6 months ago

Hi, thank you for reporting the issue. With the unreleased version of leptosfmt (cargo install --git https://github.com/bram209/leptosfmt.git), the default behaviour for handling unknown macros has been improved. It should now preserve the original formatting.

Could you try it and let me know if this solves your issue?