utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-identifier attribute names

17dec opened this issue · comments

commented

Thanks for this crate - I'm loving its elegant and simple design.

Is there a way to set attributes that aren't rust identifiers? For example:

markup::define! {
    Hello {
        // "type" is a keyword, so this fails
        input[type="number"]
        // '-' isn't allowed in an identifier
        br[data-id=1]
    }
}

Supporting string literals as attribute names might be a clean way to solve this.

I'm glad you like it!

A function to parse this kind of thing already existed; not sure how I forgot to use it here earlier. Putting type and data-id in quotes should now work:

markup::define! {
    Hello {
        // "type" is a keyword, so this fails
        input["type"="number"]
        // '-' isn't allowed in an identifier
        br["data-id"=1]
    }
}

Let me know if you still have issues with this.

commented

Works, thanks!

I improved this further by making the parser treat keywords like they're identifiers. You can do input[type = "number"] now as of version 0.1.4!