我想将一个HTML实体(特别是©)放入我的文档中.然而,如果我输入它并将其Text直接送入火焰组合器中,那么&符号将被转义为字面意义©- 或者更确切地说,输出的HTML是©,这有点讽刺.
(如果我blaze-from-html在包含的HTML上使用©,blaze-from-html将其转换为unicode版权符号" ©",这有效,但我仍然想知道是否可以使用blaze访问较低级别的HTML并输入文字html源代码&.)
该BlazeHtml教程建议使用现实世界的模板与BlazeHtml一个Reader单子,但没有说明如何应该这样做.我试着遵循这个建议.结果让我感到困惑.
为了说明,假设我有一个简单的用户类型,我想使用单独的函数编写我的HTML,一个用于布局,另一个用于HTML页面的一部分,用于显示用户信息.如果我使用Reader Monad,它看起来像这样:
data User = User {
username :: Text
, userId :: nt
} deriving (Show)
userBox :: Reader User Html
userBox = do
user <- ask
return $ do
dl $ do
dt $ "Username"
dd $ H.toHtml $ username user
dt $ "UserId"
dd $ H.toHtml $ userId user
page :: Reader User Html
page = do
user <- ask
return $ H.docTypeHtml $ do
H.head $ title "Reader Monad Blaze Example"
H.body $ …Run Code Online (Sandbox Code Playgroud) 我有点困惑要使用哪个Haskell Html库。人们倾向于推荐使用Haskell平台中可用的库(就是这种情况Text.Html),但是似乎每个人都在使用Blaze.Html。
两者有什么区别?
我试图改写:
return $ renderHtml $ mconcat $ intersperse " " $ catMaybes links
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,进入:
return $ renderHtml $ mconcat $ unwords $ catMaybes links
Run Code Online (Sandbox Code Playgroud)
但它正在回归:
Couldn't match type ‘Char’
with ‘blaze-markup-0.7.0.2:Text.Blaze.Internal.MarkupM ()’
Expected type: H.Html
Actual type: Char
In the second argument of ‘($)’, namely
‘mconcat $ unwords $ catMaybes links’
In the second argument of ‘($)’, namely
‘renderHtml $ mconcat $ unwords $ catMaybes links’
In a stmt of a 'do' block:
return $ renderHtml $ mconcat $ unwords …Run Code Online (Sandbox Code Playgroud)