diff options
author | defanor <defanor@uberspace.net> | 2017-12-14 01:19:40 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-12-14 01:19:40 +0300 |
commit | 26dd6a87815bcd735b1a2c7c11eeb071b003a3ee (patch) | |
tree | 30fc4e0c625ae4402217467f2217a3265d67f844 | |
parent | f735c69d6d0d13858588c3c35317ef294f2382d6 (diff) |
Write HXT output properly
-rw-r--r-- | Pancake/Unclutter.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Pancake/Unclutter.hs b/Pancake/Unclutter.hs index 9cf2331..eccc050 100644 --- a/Pancake/Unclutter.hs +++ b/Pancake/Unclutter.hs @@ -40,8 +40,8 @@ import System.FilePath import Data.List import Text.Regex.TDFA.String import Text.Regex.Base.RegexLike -import Text.XML.HXT.Core (readString, withParseHTML, runX, XmlTree, (>>>), yes) -import Text.XML.HXT.DOM.ShowXml (xshow) +import Text.XML.HXT.Core ( writeDocumentToString, readString + , withParseHTML, runX, (>>>), yes) import Text.XML.HXT.XSLT (xsltApplyStylesheetFromURI) import Data.Text.Encoding (decodeUtf8', decodeLatin1, encodeUtf8) import qualified Data.Text as T @@ -72,10 +72,12 @@ tryUnclutter rs u d = do then do let txt = T.unpack $ either (const $ decodeLatin1 d) id $ decodeUtf8' d doc = readString [withParseHTML yes] txt - rc <- runX (doc >>> xsltApplyStylesheetFromURI src) :: IO [XmlTree] + rc <- runX $ doc + >>> xsltApplyStylesheetFromURI src + >>> writeDocumentToString [] pure $ case rc of - [] -> d - _ -> encodeUtf8 $ T.pack $ xshow rc + [str] -> encodeUtf8 $ T.pack str + _ -> d else pure d Nothing -> pure d where uStr = uriToString id u "" |