utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.
Apache License 2.0
350 stars 14 forks source link

Non-identifier attribute names #2

Closed 17dec closed 5 years ago

17dec commented 5 years ago

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.

utkarshkukreti commented 5 years ago

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.

17dec commented 5 years ago

Works, thanks!

utkarshkukreti commented 5 years ago

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!