From 30fd99c7eae39ad3b83f277886fa2d8ef81c05c3 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Tue, 16 May 2023 13:16:55 +1200 Subject: [PATCH] Add priority method to text preprocessor, improve handling of negatives. --- src/Data/CSS/Preprocessor/Text.hs | 1 + src/Data/CSS/Preprocessor/Text/CounterStyle.hs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Data/CSS/Preprocessor/Text.hs b/src/Data/CSS/Preprocessor/Text.hs index 6537a64..3d08c79 100644 --- a/src/Data/CSS/Preprocessor/Text.hs +++ b/src/Data/CSS/Preprocessor/Text.hs @@ -82,6 +82,7 @@ instance PropertyParser p => PropertyParser (TextStyle p) where afterPseudo = Nothing, markerPseudo = Nothing } + priority self = priority $ inner self shorthand _ key value | key `elem` ["counter-reset", "counter-increment", "counter-set"], diff --git a/src/Data/CSS/Preprocessor/Text/CounterStyle.hs b/src/Data/CSS/Preprocessor/Text/CounterStyle.hs index 3e08362..cd28da5 100644 --- a/src/Data/CSS/Preprocessor/Text/CounterStyle.hs +++ b/src/Data/CSS/Preprocessor/Text/CounterStyle.hs @@ -201,11 +201,12 @@ fallbackSym :: Text fallbackSym = "\0" counterRenderCore :: CounterStyle -> Int -> Text -counterRenderCore CounterStyle { system = Cyclic, symbols = syms } x = - syms !! (pred x `rem` length syms) counterRenderCore CounterStyle { system = Fixed n, symbols = syms } x - | x - n < length syms = syms !! (x - n) + | x - n < length syms && x >= n = syms !! (x - n) | otherwise = fallbackSym +counterRenderCore _ x | x < 0 = fallbackSym +counterRenderCore CounterStyle { system = Cyclic, symbols = syms } x = + syms !! (pred x `rem` length syms) counterRenderCore CounterStyle { system = Symbolic, symbols = syms } x = succ (quot x' n) `Txt.replicate` (syms !! rem x' n) where (n, x') = (length syms, pred x) @@ -314,6 +315,7 @@ counterRender self@CounterStyle { fallback = Just self' } x | otherwise = inRange y rest inRange _ [] = False counterRender self@CounterStyle { padLength = m, padChar = pad } x + | Fixed _ <- system self = text -- Handles negatives specially here. | x < 0 = Txt.concat [ negativePrefix self, counterRender self { ranges = Just [(0, maxBound)] } $ -x, -- No fallback! -- 2.30.2