Not able to include the below code in pugjs. I am getting errors.
<body>
<amp-state id="theFood">
<script type="application/json">
{
"cupcakes": {
"imageUrl": "https://amp.dev/static/samples/img/image2.jpg",
"style": "greenBorder"
},
"sushi": {
"imageUrl": "https://amp.dev/static/samples/img/image3.jpg",
"style": "redBorder"
}
}
</script>
</amp-state>
I converted in pugjs as
amp-state#theFood
script(type="application/json").
{
"cupcakes": {
"imageUrl": "https://amp.dev/static/samples/img/image2.jpg",
"style": "greenBorder"
},
"sushi": {
"imageUrl": "https://amp.dev/static/samples/img/image3.jpg",
"style": "redBorder"
}
}
But I am getting the below error. Does pugjs doesn't support JSON format? What Am I missing?
Complete error message in short
Pug supports JSON as long as it's written within a Pug script
block or it occurs all on one line within a vanilla HTML <script>
element.
You'll either need to remove the linebreaks that occur within that <script>
tag on line 3 of your file, or you'll need to use the Pug syntax like this:
script(type='application/json').
{
"cupcakes": ...
}
Pug really isn't designed to have Pug syntax mixed with selectively-compressed HTML markup like you're currently doing.