rabbitify

    Convert HTML document to Rabbita VDom functions

    frontend
    commandline
    html
    rabbita
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    4 months ago
    Downloads
    15

    #sennenki/rabbitify

    HTML to rabbita MoonBit virtual-dom library converter.

    #Installation

    moon add sennenki/rabbitify

    Add to your moon.pkg:

    import "sennenki/rabbitify" @rabbitify

    #Library Usage

    let html = "<div class=\"container\">Hello</div>"
    let result = @rabbitify.convert(html)
    // => @html.div(class="container") <| "Hello"

    #Custom Configuration

    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"

    #Configuration Options

    FieldTypeDefaultDescription
    module_prefixString"@html."Prepended to all generated function names
    indentString?Some(" ")Indent string; None produces single-line output
    a_tag_modeATagModeLinkLink uses @html.a(...), Node uses @html.node("a", ...)
    convert_commentsBoolfalseWhether to preserve HTML comments as MoonBit comments
    use_named_functionsBooltrueUse named functions (@html.div) instead of @html.node("div", ...)
    use_reverse_pipeBooltrueUse <| for children instead of positional arguments

    #API

    • convert(html : String) -> String — Convert HTML string with default config
    • convert_with(html : String, config : Config) -> String — Convert HTML string with custom config
    • convert_document(doc : @html.Document, config : Config) -> String — Convert a pre-parsed document

    #CLI Usage

    # 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

    #CLI Options

    OptionShortDefaultDescription
    --output-ostdoutOutput file path
    --prefix-p@html.Module prefix
    --indent-i (2 spaces)Indent string, or none for compact
    --a-taglink<a> tag mode: link or node
    --named(on)Use named functions
    --no-namedUse @html.node(...) for all elements
    --pipe(on)Use reverse pipe <|
    --no-pipeUse positional children
    --commentsPreserve HTML comments
    --no-prefixOmit module prefix
    --help-hShow help
    --versionShow version

    #Examples

    // 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"

    ATagMode

    pub(all) enum ATagMode {
    Link
    Node
    }

    Determines how <a> tags are rendered.

    Config

    pub(all) struct Config {
    module_prefix : String
    indent : String?
    a_tag_mode : ATagMode
    convert_comments : Bool
    use_named_functions : Bool
    use_reverse_pipe : Bool
    }

    Configuration for HTML-to-rabbita conversion.

    • module_prefix: Prepended to all generated function names (e.g. "@html.").
    • indent: Indent string for pretty-printing; None produces single-line output.
    • a_tag_mode: How to handle <a> tags — Link uses @html.a(...), Node uses @html.node("a", ...).
    • convert_comments: Whether to preserve HTML comments as MoonBit comments.
    • use_named_functions: Whether to use named rabbita functions (e.g. @html.div) instead of @html.node("div", ...).
    • use_reverse_pipe: Whether to use the reverse pipe operator <| for passing children.
    impl Default for Config

    convert

    fn convert(html : String) -> String

    Convert an HTML string to rabbita code using default configuration.

    convert_document

    fn convert_document(doc :
    Document
    , config : Config) -> String

    Convert a pre-parsed HTML document to rabbita code with the given configuration.

    convert_with

    fn convert_with(html : String, config : Config) -> String

    Convert an HTML string to rabbita code with the given configuration.