~alcinnz/rhapsode

7157dd647e870dd74af90f0ba02534b9054c33bc — Adrian Cochrane 5 years ago 2adc7fb
Fix counters parsing & usage.
2 files changed, 14 insertions(+), 36 deletions(-)

M src/DefaultCSS.hs
M src/StyleTree.hs
M src/DefaultCSS.hs => src/DefaultCSS.hs +3 -28
@@ 74,35 74,10 @@ userAgentCSS = unlines [
  "       cue-before: url(bulletpoint.wav) -5db",
  "}",
  "",
  "ol {counter-reset: -rhaps-ol1}",
  "ol ol {counter-reset: -rhaps-ol2}",
  "ol ol ol {counter-reset: -rhaps-ol3}",
  "ol ol ol ol {counter-reset: -rhaps-ol4}",
  "ol ol ol ol ol {counter-reset: -rhaps-ol5}",
  "ol ol ol ol ol ol {counter-reset: -rhaps-ol6}",
  "ol {counter-reset: -rhaps-ol}",
  "ol li::before {",
  "counter-increment: -rhaps-ol1;",
  "content: counter(-rhaps-ol1)",
  "}",
  "ol ol li::before {",
  "counter-increment: -rhaps-ol2;",
  "content: counters(-rhaps-ol1, -rhaps-ol2)",
  "}",
  "ol ol ol li::before {",
  "counter-increment: -rhaps-ol3;",
  "content: counters(-rhaps-ol1, -rhaps-ol2, -rhaps-ol3)",
  "}",
  "ol ol ol ol li::before {",
  "counter-increment: -rhaps-ol4;",
  "content: counters(-rhaps-ol1, -rhaps-ol2, -rhaps-ol3, -rhaps-ol4)",
  "}",
  "ol ol ol ol ol li::before {",
  "counter-increment: -rhaps-ol5;",
  "content: counters(-rhaps-ol1, -rhaps-ol2, -rhaps-ol3, -rhaps-ol4, -rhaps-ol5)",
  "}",
  "ol ol ol ol ol ol li::before {",
  "counter-increment: -rhaps-ol6;",
  "content: counters(-rhaps-ol1, -rhaps-ol2, -rhaps-ol3, -rhaps-ol4, -rhaps-ol5, -rhaps-ol6)",
  "counter-increment: -rhaps-ol;",
  "content: counters(-rhaps-ol, ' ')",
  "}",
  "",
  "",

M src/StyleTree.hs => src/StyleTree.hs +11 -8
@@ 69,12 69,12 @@ parseCue _ = Nothing

data StyleLeaf = Content {value :: Text} deriving Eq

parseCounters [Ident "none"] = Just []
parseCounters [] = Just []
parseCounters (Ident counter : Number _ (NVInteger count) : toks) =
    (:) (counter, count) <$> parseCounters toks
parseCounters (Ident counter : toks) = (:) (counter, 0) <$> parseCounters toks
parseCounters _ = Nothing
parseCounters _ [Ident "none"] = Just []
parseCounters _ [] = Just []
parseCounters x (Ident counter : Number _ (NVInteger count) : toks) =
    (:) (counter, count) <$> parseCounters x toks
parseCounters x (Ident counter : toks) = (:) (counter, x) <$> parseCounters x toks
parseCounters _ _ = Nothing

data StyleTree = StyleTree {
    voice :: Maybe Voice,


@@ 98,6 98,7 @@ data StyleTree = StyleTree {

    counterReset :: [(Text, Integer)],
    counterIncrement :: [(Text, Integer)],
    counterSet :: [(Text, Integer)],

    children :: [StyleTree],
    content :: [StyleLeaf]


@@ 126,6 127,7 @@ instance Style.PropertyParser StyleTree where

        counterReset = [],
        counterIncrement = [],
        counterSet = [],

        children = [],
        content = []


@@ 201,8 203,9 @@ instance Style.PropertyParser StyleTree where

    longhand _ self "content" [String txt] = Just self {content = [Content txt]}

    longhand _ self "counter-reset" toks = (\val -> self {counterReset = val}) <$> parseCounters toks
    longhand _ self "counter-increment" toks = (\val -> self {counterIncrement = val}) <$> parseCounters 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
    longhand _ self "counter-set" toks = (\val -> self {counterSet = val}) <$> parseCounters 0 toks

    longhand _ self _ [Ident "inherit"] = Just self
    longhand _ _ _ _ = Nothing