Skip to content
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

Support for customizable attribute selectors? #397

Closed
GregBrimble opened this issue Jan 14, 2021 · 1 comment
Closed

Support for customizable attribute selectors? #397

GregBrimble opened this issue Jan 14, 2021 · 1 comment

Comments

@GregBrimble
Copy link

GregBrimble commented Jan 14, 2021

Wondering if you'd be interested in adding customizable attribute selectors as an option for the parser? # = id and . = class are currently hard-coded, which is obviously what you'd expect to see for HTML, but if you're trying to parse something else (e.g. JSX), it might be valuable to map those attribute selectors to something else (e.g. className for React).

I'm more than happy to make a PR if that's something you'd like to add to this project :) Thanks!

@fb55
Copy link
Owner

fb55 commented Feb 28, 2021

You probably don't want this libraries output to change. Eg. div[class^=test] should similarly be updated to use className as the attribute name.

If all you care for is the class attribute, this should suffice to transform the output:

let output = CSSwhat.parse(selector);
let transformed = output.map(selector => selector.map(sel => {
    if (sel.type === 'attribute' && sel. name === 'class') {
        return { ...sel, name: 'className' };
    }
    return sel;
});

@fb55 fb55 closed this as completed Feb 28, 2021
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

No branches or pull requests

2 participants