From 26dd6a87815bcd735b1a2c7c11eeb071b003a3ee Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 14 Dec 2017 01:19:40 +0300 Subject: Write HXT output properly --- Pancake/Unclutter.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Pancake') 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 "" -- cgit v1.2.3