How to show utf8 text with binding and heist?

I used writeBS writeTextfrom Snap and renderTemplatefrom heist, but none of them seem to support unicode.

site :: Snap ()
site = do
    ifTop (writeBS "你好世界") <|>
    route [("test", testSnap)]

testSnap :: Snap ()
testSnap = do
     fromJust $ C.renderTemplate hs "test"

-- test.tpl

你好世界

I was expecting it to print “你好 世界” for the route /or /test, but in fact its output is just some dirty code.

0
source share
1 answer

writeBS writeText. , OverloadedStrings. ByteString Text. ByteString . . . Data.Text.Encoding Text ByteString . :

writeBS $ encodeUtf8 "你好世界"
writeText "你好世界"

, , , ByteString OverloadedStrings , . , ... .

, :

route [("test", cRender "test")]

, , - . , cRender . , , .

site = route [ ("/test1", writeBS "你好世界")
             , ("/test2", writeBS $ encodeUtf8 "你好世界")
             , ("/test3", writeText "你好世界")
             , ("/test4", modifyResponse (setContentType "text/html;charset=utf-8") >> writeText "你好世界")
             , ("/testHeist", cRender "test")
             ]

test4 testHeist . 2 3 , - .

0

All Articles