Support Speculation Rules API formatting in HTML (#12882)

* Add script formatting for `speculationrules`

* Fix lint problems
This commit is contained in:
Sosuke Suzuki authored and GitHub committed 2022-05-17 10:38:46 +09:00
1 parent de16657ba0
commit 36c20c51bc
5 files changed
+61 -2

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
#### Support Speculation Rules API formatting in HTML (#12882 by @sosukesuzuki)
Please read https://web.dev/speculative-prerendering/ for about Speculation Rules API.
<!-- prettier-ignore -->
```html
<!-- Input -->
<script type="speculationrules">
{
"prerender": [
{"source": "list", "urls": ["https://a.test/foo"]}
]
}
</script>
<!-- Prettier stable -->
<script type="speculationrules">
{
"prerender": [
{"source": "list", "urls": ["https://a.test/foo"]}
]
}
</script>
<!-- Prettier main -->
<script type="speculationrules">
{
"prerender": [{ "source": "list", "urls": ["https://a.test/foo"] }]
}
</script>
```
+1
View File
@@ -304,6 +304,7 @@
"softlines",
"Sorin",
"Sosuke",
"speculationrules",
"srcset",
"Stachowiak",
"standalones",
+4 -1
View File
@@ -364,7 +364,10 @@ function _inferScriptParser(node) {
return "html";
}
if (type && (type.endsWith("json") || type.endsWith("importmap"))) {
if (
(type && (type.endsWith("json") || type.endsWith("importmap"))) ||
type === "speculationrules"
) {
return "json";
}
@@ -171,6 +171,15 @@ End Function
<script lang="unknown">
</script>
<script type="speculationrules">
{
"prerender": [
{"source": "list", "urls": ["https://a.test/foo"]}
]
}
</script>
=====================================output=====================================
<script type="application/ld+json">
{ "json": true }
@@ -208,5 +217,11 @@ End Function
<script lang="unknown"></script>
<script type="speculationrules">
{
"prerender": [{ "source": "list", "urls": ["https://a.test/foo"] }]
}
</script>
================================================================================
`;
+9 -1
View File
@@ -31,4 +31,12 @@ End Function
</script>
<script lang="unknown">
</script>
</script>
<script type="speculationrules">
{
"prerender": [
{"source": "list", "urls": ["https://a.test/foo"]}
]
}
</script>