From fec99b19a7ca7886471d2e5554b7a1e21dbb2c98 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 31 Dec 2020 17:27:11 +1300 Subject: [PATCH] Add support for `@document regexp()`.. --- src/Data/CSS/Preprocessor/Conditions.hs | 4 ++++ stylist.cabal | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Data/CSS/Preprocessor/Conditions.hs b/src/Data/CSS/Preprocessor/Conditions.hs index 64debc5..7a3871c 100644 --- a/src/Data/CSS/Preprocessor/Conditions.hs +++ b/src/Data/CSS/Preprocessor/Conditions.hs @@ -21,6 +21,7 @@ import Data.Text.Internal (Text(..)) import Data.Text (unpack) import Network.URI (URI(..), URIAuth(..), parseURI) import Control.Concurrent.Async (forConcurrently) +import Text.Regex.TDFA ((=~)) import Data.List @@ -85,6 +86,9 @@ instance PropertyParser p => StyleSheet (ConditionalStyles p) where | isUnstyled self = parseAtBlock self toks | otherwise = addAtRule self "document" toks -- TODO Support regexp() conditions, requires new dependency + addAtRule self "document" (Function "regexp":String pattern:RightParen:toks) + | hostUrlS self =~ unpack pattern = parseAtBlock self toks + | otherwise = addAtRule self "document" toks addAtRule self "document" tokens = (self, skipAtRule tokens) addAtRule self "media" toks diff --git a/stylist.cabal b/stylist.cabal index 2c5a434..e25700b 100644 --- a/stylist.cabal +++ b/stylist.cabal @@ -10,7 +10,7 @@ name: stylist -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 2.2.0.0 +version: 2.3.0.0 -- A short (one-line) description of the package. synopsis: Apply CSS styles to a document tree. @@ -70,7 +70,8 @@ library -- Other library packages from which modules are imported. build-depends: base >=4.9 && <=4.12, css-syntax >=0.1 && <0.2, text, unordered-containers >= 0.2 && <0.3, hashable, - network-uri >= 2.6 && <2.7, async >= 2.1 && <2.3 + network-uri >= 2.6 && <2.7, async >= 2.1 && <2.3, + regex-tdfa >= 1.3 -- Directories containing source files. hs-source-dirs: src @@ -89,5 +90,5 @@ test-suite test-stylist build-depends: base >=4.9 && <=4.12, css-syntax >=0.1 && <0.2, text, unordered-containers >= 0.2 && <0.3, hashable, network-uri >= 2.6 && <2.7, async >= 2.1 && <2.3, hspec, QuickCheck, - scientific >= 0.3 && <1.0 + scientific >= 0.3 && <1.0, regex-tdfa >= 1.3 ghc-options: -Wall -- 2.30.2