yesodweb / css-text

CSS parser and renderer.
MIT License
16 stars 8 forks source link

Fixed Arbitrary fixes and nested block parsing. #8

Open jgm opened 9 years ago

jgm commented 9 years ago

This fixes PR #7 and #6.

The fix to runtests.hs adds the @ for media queries, and adds a resize to limit the size of the structures, which can now be deeply nested. I also added more media query types.

The fix to Parse.hs allows indefinitely nested blocks to be parsed, and fixes the problems noted in #6.

jgm commented 9 years ago

It's still not right -- do not merge yet.

jgm commented 9 years ago

The more I find out about CSS, the more I think this module needs to be rewritten. Here's a valid CSS snippet:

@page { 
  size: 21.0cm 29.7cm; /* A4 */
  @top { 
    text-align: right;
    vertical-align: center;
    content: string (chapter);
  }
}

Currently the parser gets this completely wrong:

Right [NestedBlock "@page" [LeafBlock ("size:21cm; @top",[("text-align","right")])]]

The basic data structure NestedBlock isn't quite right for this kind of thing. In general nested blocks don't contain sequences of "regular blocks" and other nested blocks. Rather, they contain sequences of properties and other nested blocks.

A further issue; unless we hard-code things like @font-face, there will be an ambiguity with @font-face{} -- is it a NestedBlock or a LeafBlock? Though this would also be solved if we made the change I just suggested. Get rid of NestedBlock and CSSBlock, and just have something like

data Element = Stanza Selector [Element] | Property
type Property = (Text, Text)
type Selector = Text

Looking carefully at the CSS syntax definition might yield better ideas.