Commit 2d6a43f4 authored by Adrian Cochrane's avatar Adrian Cochrane

Fix CSS charset detection.

Previously I didn't handle cases where the charset was unspecified,
or where it wasn't valid text in the charsets I trialled.
parent e41dd031
......@@ -84,9 +84,15 @@ retreiveStyles uri html manager base = do
lowerVars _ = CSSCond.B False
lowerToks _ = CSSCond.B False
applyCSScharset (charset:charsets) bytes | cssCharset (CSSTok.tokenize text) == charset = text
applyCSScharset (charset:charsets) bytes | cssCharset (CSSTok.tokenize text') == charset = text
| otherwise = applyCSScharset charsets bytes
where text = convertCharset charset bytes
where
text = convertCharset charset bytes
-- I don't know how better to handle these errors in the APIs I'm using...
text' = unsafePerformIO $ catch (evaluate text) handleDecodeError
handleDecodeError :: UnicodeException -> IO Text -- Type signature REQUIRED
handleDecodeError _ = return ""
applyCSScharset _ bytes = convertCharset "utf-8" bytes
cssCharset toks | (CSSTok.AtKeyword "charset":toks') <- skipCSSspace toks,
(CSSTok.String charset:_) <- skipCSSspace toks' = charset
| otherwise = ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment