xml-conduit-stylist 1.0.1.0 → 1.1.0.0
raw patch · 2 files changed
+16/−4 lines, 2 filesdep ~stylist
Dependency ranges changed: stylist
Files
- src/Data/HTML2CSS.hs +14/−2
- xml-conduit-stylist.cabal +2/−2
src/Data/HTML2CSS.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+-- | Bindings from `xml-conduit` to `haskell-stylist`. module Data.HTML2CSS( externalStyles, externalStylesForURL, internalStyles, internalStylesForURL, -- legacy html2css, cssPriorityAgent, cssPriorityUser, cssPriorityAuthor, -- parsing@@ -17,20 +18,22 @@ import Data.CSS.Syntax.Tokens (tokenize) import Data.CSS.Preprocessor.Conditions import qualified Data.CSS.Preprocessor.Conditions.Expr as Query- import Network.URI ---- Constants+-- | Set the priority for a CSS stylesheet being parsed. cssPriorityAgent, cssPriorityUser, cssPriorityAuthor :: StyleSheet s => s -> s cssPriorityAgent = setPriority 1 cssPriorityUser = setPriority 2 cssPriorityAuthor = setPriority 3 ---- Parsing+-- | Converts a parsed XML or HTML file to a `ConditionalStyles` `StyleSheet`. html2css :: PropertyParser p => XML.Document -> URI -> ConditionalStyles p-html2css xml url = ConditionalStyles {+html2css xml url = testIsStyled $ ConditionalStyles { hostURL = url, mediaDocument = "document",+ isUnstyled = False, rules = Priority 3 : html2css' (XML.documentRoot xml) (conditionalStyles url "document"), propertyParser = temp }@@ -51,9 +54,11 @@ | otherwise = [] ---- Parsing (legacy)+-- | LEGACY: Extract relative links to external stylesheets. externalStyles :: StyleSheet s => s -> (M.Map XML.Name Txt.Text -> Bool) -> XML.Element -> (URI -> IO Txt.Text) -> IO s externalStyles a b c d = externalStylesForURL a b c nullURI d+-- | LEGACY: Extract absolutized links to external stylesheets. externalStylesForURL stylesheet testMedia html base loadURL = do css <- externalStyles' testMedia html base loadURL return $ foldl (\a (b, c) -> parseForURL a b c) (cssPriorityAuthor stylesheet) css@@ -73,7 +78,9 @@ linkedStyles' testMedia (XML.Element _ _ children) = concat [linkedStyles' testMedia el | XML.NodeElement el <- children] +-- | LEGACY: Extract internally embedded CSS stylesheets. internalStyles a b c = internalStylesForURL a b nullURI c+-- | LEGACY: Extract internally embedded CSS stylesheets, with absolutized URLs. internalStylesForURL testMedia stylesheet base html = foldl (\s -> parseForURL s base) (cssPriorityAuthor stylesheet) $ internalStyles' testMedia html@@ -93,12 +100,16 @@ strContent [] = "" ---- Styling+-- | Converts a parsed XML or HTML document to a specified style tree type. traverseStyles :: PropertyParser s => (s -> [o] -> o) -> (s -> Txt.Text -> o) -> QueryableStyleSheet s -> XML.Element -> o traverseStyles = traverseStyles' Nothing temp Nothing (\x y -> Nothing)+-- | Converts a parsed XML or HTML document to a specified style tree type,+-- with a routine to compute alternative contents based on the raw element or computed styles. traversePrepopulatedStyles :: PropertyParser s => (s -> XML.Element -> Maybe [o]) -> (s -> [o] -> o) -> (s -> Txt.Text -> o) -> QueryableStyleSheet s -> XML.Element -> o traversePrepopulatedStyles = traverseStyles' Nothing temp Nothing+-- | Full routine for converting a parsed XML or HTML document to a specified style tree type. traverseStyles' :: PropertyParser s => Maybe Element -> s -> Maybe Element -> (s -> XML.Element -> Maybe [o]) -> (s -> [o] -> o) -> (s -> Txt.Text -> o) -> QueryableStyleSheet s -> XML.Element -> o@@ -129,6 +140,7 @@ | Just rules' <- HM.lookup psuedo rules = [builder (cascade' rules' [] parentStyle) []] | otherwise = [] +-- | Converts a xml-conduit Element to a stylist Element. elToStylish (XML.Element (XML.Name name _ _) attrs _) parent previous = ElementNode { name = name,
xml-conduit-stylist.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.0.1.0+version: 1.1.0.0 -- A short (one-line) description of the package. synopsis: Bridge between xml-conduit/html-conduit and stylist@@ -61,7 +61,7 @@ -- Other library packages from which modules are imported. build-depends: base >=4.9 && <4.10,- stylist >=1.1.1 && <2, css-syntax, unordered-containers,+ stylist >=1.2.0 && <2, css-syntax, unordered-containers, xml-conduit >=1.8 && < 1.9, text, containers, network-uri