~alcinnz/rhapsode

27745b944c7299f6756758baf21dc3754b03103d — Adrian Cochrane 5 years ago 256c26c
Support multi-valued CSS content: properties.
1 files changed, 8 insertions(+), 4 deletions(-)

M src/StyleTree.hs
M src/StyleTree.hs => src/StyleTree.hs +8 -4
@@ 68,6 68,13 @@ parseCue [Ident "none"] = Just NoCue
parseCue _ = Nothing

data StyleLeaf = Content {value :: Text} | Counter Text | Counters Text Text deriving Eq
parseContent (String txt:toks) = (\val -> Content txt : val) <$> parseContent toks
parseContent (Function "counter" : Ident c : LeftParen : toks) =
    (\val -> Counter c : val) <$> parseContent toks
parseContent (Function "counters" : Ident c : Comma : String sep : LeftParen : toks) =
    (\val -> Counters c sep : val) <$> parseContent toks
parseContent [] = Just []
parseContent _ = Nothing

parseCounters _ [Ident "none"] = Just []
parseCounters _ [] = Just []


@@ 201,10 208,7 @@ instance Style.PropertyParser StyleTree where
    longhand _ self "cue-before" toks = (\val -> self {cueBefore = val}) <$> parseCue toks
    longhand _ self "cue-after" toks = (\val -> self {cueAfter = val}) <$> parseCue toks

    longhand _ self "content" [String txt] = Just self {content = [Content txt]}
    longhand _ self "content" [Function "counter", Ident c, LeftParen] = Just self {content = [Counter c]}
    longhand _ self "content" [Function "counters", Ident c, Comma, String sep, LeftParen] =
        Just self {content = [Counters c sep]}
    longhand _ self "content" toks = (\val -> self {content = val}) <$> parseContent toks

    longhand _ self "counter-reset" toks = (\val -> self {counterReset = val}) <$> parseCounters 0 toks
    longhand _ self "counter-increment" toks = (\val -> self {counterIncrement = val}) <$> parseCounters 1 toks