~alcinnz/rhapsode

afbc3c0556a0b1d45834091a6c9a3ddfc3ebe4f8 — Adrian Cochrane 5 years ago aea2a65
Fix for parsing HTTP responses, test for speech media.
1 files changed, 6 insertions(+), 1 deletions(-)

M src/Main.hs
M src/Main.hs => src/Main.hs +6 -1
@@ 42,14 42,19 @@ externalStyles html manager base = go $ linkedStyles html
linkedStyles (XML.Element "link" attrs _)
    | Just link <- "href" `M.lookup` attrs,
        Just "stylesheet" <- "rel" `M.lookup` attrs,
        testMedia attrs,
        Just uri <- parseURIReference $ unpack link = [uri]
linkedStyles (XML.Element _ _ children) =
    concat [linkedStyles el | XML.NodeElement el <- children]

internalStyles (XML.Element "style" _ children) = [strContent children]
internalStyles (XML.Element "style" attrs children)
    | testMedia attrs = [strContent children]
internalStyles (XML.Element _ _ children) =
    concat [internalStyles el | XML.NodeElement el <- children]

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


strContent (XML.NodeContent text : rest) = unpack text ++ strContent rest
-- We do want to read in comments for CSS, just not for display.