~alcinnz/haskell-stylist

47fcc45147cdd7d199eb013316a0e6039aa9c940 — Adrian Cochrane 5 years ago 0f4220e + 28191a3
Merge branch 'master' of git.nzoss.org.nz:alcinnz/stylish-haskell
1 files changed, 5 insertions(+), 1 deletions(-)

M README.md
M README.md => README.md +5 -1
@@ 11,4 11,8 @@ The second major number indicates that more of CSS has been implemented within t
The first major number indicates any other change to the API, and might break your code.

## API
So far I've only implemented a CSS parser via the function `Stylish.Parse.parse` which returns a variant of the passed in `StyleSheet`. `StyleSheet` is a typeclass implementing the logic for parsing CSS atrules and storing style rules.
To parse a CSS stylesheet call `Data.CSS.Syntax.StyleSheet.parse` which returns a variant of the passed in `StyleSheet`. `StyleSheet` is a typeclass specifying methods for parsing at-rules (`parseAtRule`), storing parsed style rules (`addRule`), and optionally setting the stylesheet's priority (`setPriority`).

If these ultimately call down into a `Data.CSS.Syntax.Style.QueryableStyleSheet` you can call `queryRules` to find all matching style rules organized by psuedoelement. Once you have these style rules (typically by specifying a psuedoelement) you can call `cascade'` to resolve them into any instance of `PropertyParser`. To query rules not targetting a psuedoelement, you can either lookup the "" psuedoelement or use the `cascade` shorthand.

`PropertyParser` allows to declaratively (via Haskell pattern matching) specify how to parse CSS properties, and how they're impacted by CSS inheritance. It has four methods: `longhand` and `shorthand` specify how to parse CSS properties, whilst `temp` and `inherit` specifies what the default values should be.