From c134671e8f2963bc74e9509a6053a71aee60cbeb Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 19 Jul 2019 20:19:59 +1200 Subject: [PATCH] Update Stylish HTML Conduit to use fixed psuedoelement handling. --- stylish-haskell.cabal | 2 +- stylish-html-conduit/src/Data/HTML2CSS.hs | 15 +++++++++------ stylish-html-conduit/stylish-html-conduit.cabal | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal index 25f1931..9aa3dd6 100644 --- a/stylish-haskell.cabal +++ b/stylish-haskell.cabal @@ -10,7 +10,7 @@ name: stylish-haskell -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.5.0.0 +version: 0.6.0.0 -- A short (one-line) description of the package. synopsis: Apply CSS styles to a document tree. diff --git a/stylish-html-conduit/src/Data/HTML2CSS.hs b/stylish-html-conduit/src/Data/HTML2CSS.hs index 65d7624..f8b40e9 100644 --- a/stylish-html-conduit/src/Data/HTML2CSS.hs +++ b/stylish-html-conduit/src/Data/HTML2CSS.hs @@ -7,6 +7,7 @@ module Data.HTML2CSS( import qualified Data.List as L import qualified Data.Map as M +import qualified Data.HashMap.Strict as HM import qualified Data.Text as Txt import qualified Text.XML as XML @@ -73,15 +74,16 @@ traverseStyles' parent parentStyle previous builder textBuilder stylesheet el@( where stylishEl = elToStylish el parent previous maybeEl = Just stylishEl - style = cascade stylesheet stylishEl overrides parentStyle + rules = queryRules stylesheet stylishEl + style = cascade' (HM.lookupDefault [] "" rules) overrides parentStyle overrides | Just styleAttr <- "style" `M.lookup` attrs = fst $ parseProperties' $ tokenize styleAttr | otherwise = [] - traverseChildren = traversePsuedo' "before :before" : + traverseChildren = traversePsuedo' "before" ++ traverseChildren' Nothing children ++ - [traversePsuedo' "after :after"] - traversePsuedo' psuedos = traversePsuedo stylishEl psuedos style builder stylesheet + traversePsuedo' "after" + traversePsuedo' psuedo = traversePsuedo rules psuedo style builder traverseChildren' prev (XML.NodeContent txt:nodes) = textBuilder style txt : traverseChildren' prev nodes traverseChildren' prev (XML.NodeElement el:nodes) = @@ -89,8 +91,9 @@ traverseStyles' parent parentStyle previous builder textBuilder stylesheet el@( traverseChildren' (Just $ elToStylish el maybeEl prev) nodes traverseChildren' prev (_:nodes) = traverseChildren' prev nodes traverseChildren' _ [] = [] -traversePsuedo el psuedos parentStyle builder stylesheet = builder style [] - where style = cascade stylesheet (addPsuedoclasses el psuedos) [] parentStyle +traversePsuedo rules psuedo parentStyle builder + | Just rules' <- HM.lookup psuedo rules = [builder (cascade' rules' [] parentStyle) []] + | otherwise = [] elToStylish (XML.Element (XML.Name name _ _) attrs _) parent previous = ElementNode { diff --git a/stylish-html-conduit/stylish-html-conduit.cabal b/stylish-html-conduit/stylish-html-conduit.cabal index c099c5d..c5b2506 100644 --- a/stylish-html-conduit/stylish-html-conduit.cabal +++ b/stylish-html-conduit/stylish-html-conduit.cabal @@ -10,7 +10,7 @@ name: stylish-html-conduit -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.2 +version: 0.1.0.3 -- A short (one-line) description of the package. synopsis: Bridge between html-conduit and stylish-haskell @@ -61,7 +61,7 @@ library -- Other library packages from which modules are imported. build-depends: base >=4.9 && <4.10, - stylish-haskell >= 0.3.0, css-syntax, + stylish-haskell >= 0.6.0, css-syntax, unordered-containers, xml-conduit, text, containers, network-uri -- 2.30.2