8000 Allow wildcard close tag for block elements by LLBlumire · Pull Request #20 · rs-tml/rstml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow wildcard close tag for block elements #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 17, 2023
Merged

Conversation

LLBlumire
Copy link
@LLBlumire LLBlumire commented Jul 7, 2023

As noted in #11 (does not close, but adds functionality discussed)

Currently, while permitted, it is inconvenient to use blocks as element open tag names. You must make sure the close block matches exactly.

example! {
    <{"FooBar"}>{"My content"}</{"FooBar"}>
}

This is inconvenient if you want to do anything non trivial in one of these blocks.

The changes in this pull request allow you to do the following instead.

example! {
    <{ does_something_non_trivial() }>{"My content"}</_>
}

The enabling, and exact syntax of the wildcard, is configurable via a config option:

let config = ParserConfig::new().block_element_close_wildcard(|close_tag| {
    // Construct a sample of what a wildcard block element close should be
    let close_sample = quote! { <{}></_> };
    let parsed = Parser::new(ParserConfig::new().block_element_close_wildcard(|_| true))
        .parse_simple(close_sample);
    let Ok([Node::Element(NodeElement {
        close_tag: Some(sample_close_tag),
        ..
    })]) = parsed.as_deref() else {
        unreachable!()
    };
    close_tag.name == sample_close_tag.name
});

The above is included as an example in the documentation for enabling </_> wildcards, though I am certain others may be desirable. The sample above is general enough that simply by modifying the wildcard close used in the config, one could set their wildcard close to anything they desire.

When enabled, wildcards can only be used to close block element open tags (not other tags); but block element open tags can still be closed with a duplicate if desired. When disabled, behaviour is as currently implemented.

@vldm
Copy link
Collaborator
vldm commented Jul 14, 2023

If you don't mind I will push the changes to your pr @LLBlumire

@LLBlumire
Copy link
Author

If you don't mind I will push the changes to your pr @LLBlumire

Hey, sorry for some reason I didn't get notified of your review. Feel free to push any changes you want

@vldm vldm added this pull request to the merge queue Jul 17, 2023
Merged via the queue into rs-tml:main with commit c0437c2 Jul 17, 2023
@LLBlumire
Copy link
Author

Thanks @vldm! Any idea when that will see a crates.io release?

@vldm
Copy link
Collaborator
vldm commented Jul 18, 2023

@LLBlumire i will check publish it asap. (Will check one more time and do release stuff)

@vldm
Copy link
Collaborator
vldm commented Jul 18, 2023

@LLBlumire done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0