summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-14 17:26:08 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-14 17:26:08 -0400
commit916a68adab4e3e021179be67d79db050f7198070 (patch)
tree5050dd56b82a3a73a9fa9ee64617cf1a7243a487
parent36d8716f1689cc1f6fe474871f8c814188295a9f (diff)
Filter control chars
IkiWIki's XML-RPC layer won't accept them, even with XML escaping.
-rw-r--r--app/Main.hs10
1 files changed, 5 insertions, 5 deletions
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}