Convert HTML document to Rabbita VDom functions
Dependencies
moon add sennenki/rabbitifyimport "sennenki/rabbitify" @rabbitifylet html = "<div class=\"container\">Hello</div>"
let result = @rabbitify.convert(html)
// => @html.div(class="container") <| "Hello"let config : @rabbitify.Config = {
module_prefix: "@html.",
indent: Some(" "),
a_tag_mode: @rabbitify.Node,
convert_comments: false,
use_named_functions: true,
use_reverse_pipe: true,
}
let result = @rabbitify.convert_with(html, config)
// => @html.node("a", @html.Attrs::build().href("/home")) <| "Home"| Field | Type | Default | Description |
|---|---|---|---|
| module_prefix | String | "@html." | Prepended to all generated function names |
| indent | String? | Some(" ") | Indent string; None produces single-line output |
| a_tag_mode | ATagMode | Link | Link uses @html.a(...), Node uses @html.node("a", ...) |
| convert_comments | Bool | false | Whether to preserve HTML comments as MoonBit comments |
| use_named_functions | Bool | true | Use named functions (@html.div) instead of @html.node("div", ...) |
| use_reverse_pipe | Bool | true | Use <| for children instead of positional arguments |
# Build the CLI tool
rabbitify target/native/debug/build/rabbitify/rabbitify --help
# Convert an HTML file
rabbitify input.html
# Convert from file to file
rabbitify input.html -o output.mbt
# Convert from stdin
echo "<div>Hello</div>" | rabbitify
# Custom options
rabbitify --no-pipe --indent=none input.html| Option | Short | Default | Description |
|---|---|---|---|
| --output | -o | stdout | Output file path |
| --prefix | -p | @html. | Module prefix |
| --indent | -i | (2 spaces) | Indent string, or none for compact |
| --a-tag | link | <a> tag mode: link or node | |
| --named | (on) | Use named functions | |
| --no-named | Use @html.node(...) for all elements | ||
| --pipe | (on) | Use reverse pipe <| | |
| --no-pipe | Use positional children | ||
| --comments | Preserve HTML comments | ||
| --no-prefix | Omit module prefix | ||
| --help | -h | Show help | |
| --version | Show version |
// Simple conversion
@rabbitify.convert("<p>Hello</p>")
// => @html.p <| "Hello"
// Void elements
@rabbitify.convert("<br>")
// => @html.br()
// Attributes
@rabbitify.convert("<img src=\"photo.png\" alt=\"A photo\">")
// => @html.img(src="photo.png", alt="A photo")
// Styles
@rabbitify.convert("<div style=\"color:red\">text</div>")
// => @html.div(style=["color:red"]) <| "text"
// Node mode for unknown tags
@rabbitify.convert("<my-custom>content</my-custom>")
// => @html.node("my-custom", @html.Attrs::build()) <| "content"pub(all) struct Config {
module_prefix : String
indent : String?
a_tag_mode : ATagMode
convert_comments : Bool
use_named_functions : Bool
use_reverse_pipe : Bool
}fn convert(html : String) -> StringInstall
Download zipConvert HTML document to Rabbita VDom functions
Dependencies