From 7157dd647e870dd74af90f0ba02534b9054c33bc Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 31 Jul 2019 20:59:04 +1200 Subject: [PATCH] Fix counters parsing & usage. --- src/DefaultCSS.hs | 31 +++---------------------------- src/StyleTree.hs | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/DefaultCSS.hs b/src/DefaultCSS.hs index 2511aea..211a4db 100644 --- a/src/DefaultCSS.hs +++ b/src/DefaultCSS.hs @@ -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, ' ')", "}", "", "", diff --git a/src/StyleTree.hs b/src/StyleTree.hs index 4e750a5..5259d45 100644 --- a/src/StyleTree.hs +++ b/src/StyleTree.hs @@ -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 -- 2.30.2