Closed saurabhnanda closed 6 years ago
Here's a real-life example...
successPage :: Storefront -> Html ()
successPage sf =
doctypehtml_ $ do
head_ $ do
title_ ([qc|Payment successful | {sf ^. clientName}|]) -- THIS INTERPOLATION
meta_ [name_ "viewport", content_ "width=device-width, initial-scale=1"]
-- TODO: do we need this?
link_ [rel_ "apple-toucht-icon", href_ "apple-touch-icon.png"]
...results in the following:
<!DOCTYPE HTML><html><head><title>Payment successful | &qout;REDACTED"</title><meta content="width=device-width, initial-scale=1" name="viewport"><link href="apple-touch-icon.png" rel="apple-toucht-icon"></head></html>
Even though sf ^. clientName
is actually Text
, if I change the interpolation to the following, the wrapping quotes in the generated HTML go away:
title_ ([qc|Payment successful | {sf ^. clientName :: Text}|])
Hmm, does putting :: String
in place of :: Text
still compile (and cause it to output double quotes) ?
Just wanting to chime in that I'm encountering this issue as well.
The double quote is usually put in by an extra show
. This happens if the incoming type has no ShowQ
instance. At the moment, this module instantiates Char
, String
, Data.ByteString.Char8.ByteString
, Data.ByteString.Lazy.Char8.ByteString
, Data.Text.Text
and Data.Text.Lazy.Text
.
If somehow your Text
library differs from one of the above (or different from the version associated when this module is installed), then an extra pair of quotes will show up.
Defining your own ShowQ
instance for that type will fix this issue, e.g.:
instance ShowQ Your.Text where
showQ = Your.unpack
We're using
qc
extensively in our project because it is hands-down the easiest way to interpolate stringy things. However, one issue we constantly keep running into is values getting wrapped in double-quotes. Sometime putting aText
type annotation makes the quotes go aways, sometimes not. eg.Is there some documentation describing why this happens, and how to be sure that the interpolated value isn't going to be wrapped in quotes?