Does Splice support Unicode?

This is my code:

 testSplice :: C.Splice Handler
 testSplice = return $ C.yieldRuntimeText $ do
    return "中文"

And I bind it to a tag:

  splices :: Splices (C.Splice Handler)
  splices =
      "testSplice" ## testSplice

And used it on layout.tpl:

   <meta charset="UTF-8"> 
   <testSplice/>

And the output in the browser

    - 

What did I do wrong?


Sorry for the delay, I was busy for a while, and now I am returning, and I think I can not ask the question specific enough @mightybyte Here is the code where the problem arises, I hope this makes the question more specific:

test.hs:

{-# LANGUAGE OverloadedStrings #-}
import Snap
import Heist
import qualified Heist.Compiled as C
import Data.Monoid
import Control.Monad.Trans.Either
import Data.Maybe

main :: IO ()
main = quickHttpServe site

site :: Snap ()
site = 
    route [("/", testSnap)]

testSnap :: Snap ()
testSnap = do
    hs <- liftIO $ load "template" splices
    let runtime = fromJust $ C.renderTemplate hs "test"
    builder <-liftIO  (fst runtime)
    writeBuilder builder
  where
    splices :: Splices (C.Splice IO)
    splices = 
        "testSplice" ## testSplice

load :: MonadIO n
    => FilePath
    -> Splices (C.Splice n)
    -> IO (HeistState n)
load baseDir splices = do
    tmap <- runEitherT $ do
        let t = loadTemplates baseDir
            hc = HeistConfig
                    defaultInterpretedSplices
                    defaultLoadTimeSplices
                    splices
                    mempty
                    [t]
        initHeist hc
    either (error . concat) return tmap

testSplice :: C.Splice IO
testSplice = return $ C.yieldRuntimeText $ do return "中文" 

template / test.tpl

<html>
  <head>
    <meta charset="UTF-8">
  </head>
 <body>
     <testSplice/>
 </body>
 </html>

Now I tried heist-0.13.0.2 and now it works great, Daniel works great!

+4
source share
1 answer

UPDATE: The problem described in this answer has been fixed in heistversion 0.13.0.2 .

yieldRuntimeText:

yieldRuntimeText :: Monad n => RuntimeSplice n Text -> DList (Chunk n)
yieldRuntimeText = yieldRuntime .  liftM fromText

fromText? :

import           Blaze.ByteString.Builder
import           Blaze.ByteString.Builder.Char8

:

. , , . Unicode, UTF (, "Blaze.ByteString.Builder.Char.UTF-8" ).

:

fromText :: Text -> BuilderSource

O(n). Serialize the lower 8-bits of all characters in the strict text.

Mmmmm, , , Text to Builder UTF-8? yieldRuntimeText , :

import           Blaze.ByteString.Builder
import           Blaze.ByteString.Builder.Char.Utf8

yieldRuntimeTextUtf8 :: Monad n => RuntimeSplice n Text -> DList (Chunk n)
yieldRuntimeTextUtf8 = yieldRuntime .  liftM fromText
+3

All Articles