From 916a68adab4e3e021179be67d79db050f7198070 Mon Sep 17 00:00:00 2001 From: Daniel Gnoutcheff Date: Tue, 14 Sep 2021 17:26:08 -0400 Subject: Filter control chars IkiWIki's XML-RPC layer won't accept them, even with XML escaping. --- app/Main.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/Main.hs') diff --git a/app/Main.hs b/app/Main.hs index 01e2b4c..eab879e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,7 +1,6 @@ {-# OPTIONS_GHC -fno-full-laziness #-} module Main (main) where -import Text.Pandoc hiding (handleError) import XMLParse -- Our slightly modified copy of Text.XML.HaXml.Parse import System.IO (hFlush, stdout) @@ -15,6 +14,7 @@ import qualified Network.XmlRpc.DTD_XMLRPC as XR import Text.XML.HaXml.XmlContent (Document (..), toXml, fromXml) import qualified Text.XML.HaXml.ByteStringPP as XPP import Text.XML.HaXml.Escape (xmlEscape, stdXmlEscaper) +import qualified Text.Pandoc as P -- Modified version of XMLParse.document that doesn't wait for anything after -- the top-level element @@ -89,7 +89,7 @@ rpcHtmlize args = toXml False . XR.MethodResponseParams . XR.Params . (:[]) . where Just (XR.Value_AString (XR.AString mdwn)) = lookup "content" args htmlize :: String -> String -htmlize mdwn = either (error . show) id . runPure $ do - pdoc <- readMarkdown readOpts (T.pack mdwn) - T.unpack <$> writeHtml5String def pdoc - where readOpts = def {readerExtensions = pandocExtensions} +htmlize = either (error . show) T.unpack . P.runPure . + (P.writeHtml5String P.def =<<) . P.readMarkdown readOpts . T.pack . + filter (\c -> c `elem` "\t\n\r" || (c>=' ' && c/='\x7f')) + where readOpts = P.def {P.readerExtensions = P.pandocExtensions} -- cgit v1.2.3