-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommended way to format html and rust code within the html!
macro
#1446
Comments
Sadly Rust doesn't provide a way for macros to format the code they're given. For the Rust code within the macro there's a trick you can use that might help. You can copy the code out of the macro to a normal function anywhere in your code and run In the future we might provide an IDE plugin to do this. |
I'm seeing some relevant discussion here rust-lang/rustfmt#3434
With my current rustfmt version |
The problem is that |
One nice (more or less) workaround I've found : format selection as html msvsc plugin https://marketplace.visualstudio.com/items?itemName=adrianwilczynski.format-selection-as-html |
I've produced a crate called Malvolio (available on crates.io) which allows you to construct HTML trees using the builder pattern and use them inside Yew components. Because the API is macro-free it works with rustfmt. It can be incrementally adopted but is currently lacking support for child components (which I intend to add in a future release) and listeners (support for those is also planned.) |
In vim i have following:
This allows me to format the block in the html macro. This can be added to almost any other editor. The only thing is that it has to be run manually. |
lua version for neovim:
what this does:
advantages: touching |
Here is a version that find the html! macro and format the following code block:
I failed to make it work on any rust file we can use it with autocmd but I'm sure someone can :) BTW switch to lua |
Btw are you sure prettier html parser doesn't conflict with some of yew's syntaxes like dynamic tags? @kantum |
@TechTheAwesome No idea, hopefully if someone finds out they will tell us here :) |
Well about that.... prettier struggles with: for the <> MAYBE something like this would work:
|
@kantum there's feedback for your vim command |
I created this plugin for yew code block formatting, it still has 1 or 2 caveats, but it seems to work fine on my code https://github.com/emilien-jegou/vim-yew-prettifier. ps: it doesn't use prettier internally, the name just resonates better to me than "formatter" |
Question
What is the recommended way to format html and rust code within the
html!
macro invocation?What I've tried (optional)
rustfmt 1.4.14 - doesn't (re)format anything within
html!
by defaultThe text was updated successfully, but these errors were encountered: