css icon indicating copy to clipboard operation
css copied to clipboard

Proper way to distinguish between Elements, IDs, Classes, and Attributes

Open jimafisk opened this issue 1 year ago • 0 comments

Thanks for this great project, I'm really enjoying the simplicity of the API :tada:

Does this library have a standard way to separate the tag names, ID's, classes, and attributes used in the selector? It seems like they are currently being grouped together in rule.Style.Selector.Text().

I do see that there is a "Tokens" option, that could potentially be used for this:

ss := css.Parse(csstext)
rules := ss.GetCSSRuleList()
for _, rule := range rules {
	for _, t := range rule.Style.Selector.Tokens {
		fmt.Println("type: " + t.Type.String())
		fmt.Println("value: " + t.Value)
	}
}

IDs are easy to identify since they get printed like:

type: HASH     
value: #myid 

However, Elements like h1 are more difficult to distinguish from classes like .myclass:

type: IDENT
value: h1
type: CHAR
value: .
type: IDENT
value: myclass  

Is the expectation that users should just split the selector into parts manually themselves? Thank you!

jimafisk avatar Jun 21 '24 17:06 jimafisk