A Neovim plugin for formatting Maud HTML templates in Rust.
This repository is a fork of eboody/maud-fmt.nvim.
It extends the original plugin with support for processing multiple html!
blocks within a single file.
- Automatically formats Maud HTML templates
- Properly indents nested elements, attributes, and content
- Handles Maud-specific syntax like
@match
,@if
, etc. - Correctly indents text content expressions like
(variable_name)
- Works with any Rust file containing Maud templates
Using lazy.nvim
{
"eboody/maud-fmt.nvim",
config = function()
require("maud-fmt").setup()
end,
ft = "rust", -- Only load for Rust files
}
Using packer.nvim
use {
"eboody/maud-fmt.nvim",
config = function()
require("maud-fmt").setup()
end
}
Using vim-plug
Plug 'eboody/maud-fmt.nvim'
" In your init.vim/init.lua after plug#end():
lua require('maud-fmt').setup()
After installation, you can format Maud HTML templates in Rust files using:
- Command:
:MaudFormat
- Default keybinding:
<leader>mf
(in normal mode)
Before formatting:
impl Render for Button<'_> {
fn render(&self) -> Markup {
html! {
@match self {
Button::Primary {
href, text
} => {
button.primary href=[href] download=(text) type="submit" {
(text)
}
},
Button::Secondary {
href, text
} => {
button.secondary href=[href] download=(text) {
(text)
}
}
}
(css())
}
}
}
After formatting:
impl Render for Button<'_> {
fn render(&self) -> Markup {
html! {
@match self {
Button::Primary {
href, text
} => {
button.primary href=[href] download=(text) type="submit" {
(text)
}
},
Button::Secondary {
href, text
} => {
button.secondary href=[href] download=(text) {
(text)
}
}
}
(css())
}
}
}
You can customize the formatter with the following options:
require('maud-fmt').setup({
indent_size = 2, -- Default indentation size (spaces)
keymaps = {
format = '<leader>mf', -- Keymap to format the current buffer
},
})
The formatter:
- Identifies
html!
blocks in your Rust code - Analyzes the structure of your Maud HTML markup
- Applies consistent indentation with proper nesting
- Handles Maud-specific syntax like class selectors (
.content
), ID selectors (#main
), and tag elements - Properly formats control structures like
@match
,@if
, etc. - Adds extra indentation for text content expressions
Checkout maud-extensions for easily working with js and css in maud templates: maud-extensions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.