~alcinnz/haskell-stylist

c134671e8f2963bc74e9509a6053a71aee60cbeb — Adrian Cochrane 4 years ago 6344dc8
Update Stylish HTML Conduit to use fixed psuedoelement handling.
M stylish-haskell.cabal => stylish-haskell.cabal +1 -1
@@ 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.

M stylish-html-conduit/src/Data/HTML2CSS.hs => stylish-html-conduit/src/Data/HTML2CSS.hs +9 -6
@@ 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 {

M stylish-html-conduit/stylish-html-conduit.cabal => stylish-html-conduit/stylish-html-conduit.cabal +2 -2
@@ 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