summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-15 11:59:54 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-15 11:59:54 -0400
commite0029580b656a73f5804929880009fcdc8c03721 (patch)
treef93abda42dbc7792e85c6f62c92fe22acb761806
parentb97904c85f21bfb485f110b5b4f84abc5d6b0b66 (diff)
Switch back to Network.XmlRpc for output
Text.XML.HaXml.ByteStringPP mangles Unicode and is harder to use. Network.XmlRpc is good enough now that we've given up on control chars.
-rw-r--r--app/Main.hs36
1 files changed, 15 insertions, 21 deletions
diff --git a/app/Main.hs b/app/Main.hs
index c5275b6..b667aa4 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -7,14 +7,15 @@ import System.IO (hFlush, stdout)
import Text.XML.HaXml.Lex (xmlLex)
import Text.XML.HaXml.Posn (Posn ())
import Text.ParserCombinators.Poly.State (stGet)
+import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Char8 as BSL8
import qualified Data.Text as T
import Data.List.Split (chop)
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, xmlUnEscape, stdXmlEscaper)
+import Text.XML.HaXml.XmlContent (Document (..), fromXml)
+import Text.XML.HaXml.Escape (xmlUnEscape, stdXmlEscaper)
import qualified Text.Pandoc as P
+import qualified Network.XmlRpc.Internals as XRI
-- Modified version of XMLParse.document that doesn't wait for anything after
-- the top-level element
@@ -25,20 +26,17 @@ rpcMessage = do
(_,ge) <- stGet
return $ Document p ge e []
-escapeDoc :: Document i -> Document i
-escapeDoc (Document p s e m) = Document p s (xmlEscape stdXmlEscaper e) m
-
rpcIn :: IO [Document Posn]
rpcIn = map (either error id) . chop (xmlParseWith rpcMessage) .
xmlLex "<stdin>" <$> getContents
-rpcOut :: [Document ()] -> IO ()
-rpcOut = mapM_ $ (*> hFlush stdout) . BSL8.putStr . XPP.document . escapeDoc
+bslOut :: [BSL.ByteString] -> IO ()
+bslOut = mapM_ $ (*> hFlush stdout) . BSL8.putStrLn
main :: IO ()
-main = rpcOut . plugin =<< rpcIn
+main = bslOut . plugin =<< rpcIn
-plugin :: [Document Posn] -> [Document ()]
+plugin :: [Document Posn] -> [BSL.ByteString]
plugin [] = []
plugin (i:is) = case parseRpcCall i of
Just ("import", _) -> (hookCall :) $ case is of
@@ -67,28 +65,24 @@ parseRpcCall doc = case fromXml (unEscapeDoc doc) of
unEscapeDoc :: Document i -> Document i
unEscapeDoc (Document p s e m) = Document p s (xmlUnEscape stdXmlEscaper e) m
-hookCall :: Document ()
-hookCall = toXml False . XR.MethodCall (XR.MethodName "hook") . Just .
- XR.Params . map stringParam $
+hookCall :: BSL.ByteString
+hookCall = XRI.renderCall . XRI.MethodCall "hook" . map XRI.ValueString $
[ "type", "htmlize"
, "id", "mdwn"
, "call", "htmlize"
]
- where stringParam = XR.Param . XR.Value . (:[]) . XR.Value_AString .
- XR.AString
isSuccessResponse :: Document Posn -> Bool
isSuccessResponse doc = case fromXml doc of
Right (XR.MethodResponseParams _) -> True
_ -> False
-importResponse :: Document ()
-importResponse = toXml False . XR.MethodResponseParams . XR.Params . (:[]) .
- XR.Param . XR.Value . (:[]) . XR.Value_Nil $ XR.Nil ()
+importResponse :: BSL.ByteString
+importResponse = XRI.renderResponse $ XRI.Return XRI.ValueNil
-rpcHtmlize :: RpcArgs -> Document ()
-rpcHtmlize args = toXml False . XR.MethodResponseParams . XR.Params . (:[]) .
- XR.Param . XR.Value . (:[]) . XR.Value_AString . XR.AString $ htmlize mdwn
+rpcHtmlize :: RpcArgs -> BSL.ByteString
+rpcHtmlize args = XRI.renderResponse . XRI.Return . XRI.ValueString .
+ htmlize $ mdwn
where Just (XR.Value_AString (XR.AString mdwn)) = lookup "content" args
htmlize :: String -> String