prettier - Standalone prettier, html formatter isn't properly formatting JS
问题描述
I'm formatting code directly on the browser using the Prettier Standalone version.
Here is my code:
import parserHtml from "prettier/parser-html";
import prettier from "prettier/standalone"
const rawHtml = `<script SameSite="None; Secure" src="https://unpkg.com/typebot-js"></script>
<div id="typebot-container" style="width: 100%; height: 600px;"></div>
<script>
Typebot.initContainer("typebot-container", {publishId: "remember-on-second-visit-iblkqj1-pw",hiddenVariables: {test: "null",}});
</script>`
const snippet = prettier.format(
rawHtml,
{ parser: "html", plugins: [parserHtml] }
);
It will output:
<script SameSite="None; Secure" src="https://unpkg.com/typebot-js"></script>
<div id="typebot-container" style="width: 100%; height: 600px;"></div>
<script>
Typebot.initContainer("typebot-container", {publishId: "remember-on-second-visit-iblkqj1-pw",hiddenVariables: {test: "null",}});
</script>
Whereas if I'm pasting the HTML code on my IDE, Prettier will correctly format the JS code:
<script SameSite="None; Secure" src="https://unpkg.com/typebot-js"></script>
<div id="typebot-container" style="width: 100%; height: 600px"></div>
<script>
Typebot.initContainer("typebot-container", {
publishId: "remember-on-second-visit-iblkqj1-pw",
hiddenVariables: { test: "null" },
});
</script>
What am I missing?
解决方案
推荐阅读
- typo3 - 如何交付在模板外创建的 TYPO3 Fluid Form 元素?
- java - Android中随机输出中的EditText所有可能的数字
- java - 为什么这个二进制搜索代码在 Eclipse IDE 上给出错误的输出?
- anylogic - 插入从数据库加载的参数后,代理群体产生错误
- amazon-web-services - com.amazonaws.services.gluejobexecutor.model.InternalServiceException:要更新的项目大小已超过允许的最大大小
- sql - SQL:在有区间的交集中求和
- javascript - 如何将 x 天添加到从 datepicker 的 getDate() 返回的日期并以特定日期格式返回?
- laravel - 带有 Laravel 后端端到端测试的 Vue SPA
- spring - jdbc 无法在同一事务中找到 jpa 存储库刷新的数据
- c++ - 如何为这个函数 c++ 提供正确的返回类型?