Skip to content
/ cssparse Public

A css parser powered by the style crate from Servo

License

Notifications You must be signed in to change notification settings

rtsao/cssparse

Repository files navigation

cssparse

A CSS parser powered by the style crate from Servo.

Why?

I was unable to find a single Node.js library that could reliably parse shorthand CSS property values without using Web APIs.

My desired use case was expanding shorthand properties into their constituent longform properties. For example:

background: center / contain no-repeat url("../foo.svg"), #eee 35% url("../bar.png");

The libraries I tested all failed to address my use case, for the following reasons:

  1. Doesn't parse property values at all
  2. Doesn't support background property values at all
  3. Merely tokenizes background property values, failing to parse the value into sufficiently useful information
  4. Fails when parsing valid background values (such as the example above)
  5. Relies on browser-specific APIs such as CSSStyleDeclaration

After many failed attempts, I have come to the conclusion that the most accurate and reliable way to parse CSS is to simply use the parser from a production-grade web browser. The style crate from Servo is a good choice because it has been integrated into Firefox.

About

A css parser powered by the style crate from Servo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published