~alcinnz/rhapsode

1b39f12f0f263ef9035da20391067540047afc29 — Adrian Cochrane 4 years ago be540b8
Simplify CSS parsing with new Haskell Stylist API.
1 files changed, 4 insertions(+), 9 deletions(-)

M src/Main.hs
M src/Main.hs => src/Main.hs +4 -9
@@ 51,15 51,13 @@ renderElLBS el = XML.renderLBS XML.def $ XML.Document {
    }

retreiveStyles uri html manager base = do
    style <- H2C.externalStylesForURL authorStyle testMedia html base loadURL
    userStyle <- loadUserStyles style
    userStyle <- loadUserStyles agentStyle
    importedStyle <- CSSCond.loadImports loadURL lowerVars lowerToks userStyle []
    return $ CSSCond.resolve lowerVars lowerToks Style.queryableStyleSheet importedStyle
  where
    emptyStyle :: CSSCond.ConditionalStyles StyleTree
    emptyStyle = CSSCond.conditionalStyles uri "document"
    agentStyle = H2C.cssPriorityAgent emptyStyle `CSS.parse` Txt.pack userAgentCSS
    authorStyle = H2C.internalStylesForURL testMedia agentStyle base html
    agentStyle = H2C.cssPriorityAgent authorStyle `CSS.parse` Txt.pack userAgentCSS
    authorStyle :: CSSCond.ConditionalStyles StyleTree
    authorStyle = H2C.html2css html base

    loadURL url = do -- TODO parallelise.
        request <- requestFromURI url


@@ 85,9 83,6 @@ loadUserStyles styles = do
        CSS.parse style (Txt.pack source) `loadFiles` files
    loadFiles style [] = return style

testMedia attrs = media == Nothing || media == Just "speech"
    where media = "media" `M.lookup` attrs


stylize styles html = H2C.traversePrepopulatedStyles buildChild buildNode buildText styles html
    where