Support Speculation Rules API formatting in HTML (#12882)
* Add script formatting for `speculationrules` * Fix lint problems
This commit is contained in:
1 parent
de16657ba0
commit
36c20c51bc
5 files changed
+60
-1
No files matched your search
@@ -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>
|
||||
```
|
||||
@@ -304,6 +304,7 @@
|
||||
"softlines",
|
||||
"Sorin",
|
||||
"Sosuke",
|
||||
"speculationrules",
|
||||
"srcset",
|
||||
"Stachowiak",
|
||||
"standalones",
|
||||
|
||||
@@ -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>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -32,3 +32,11 @@ End Function
|
||||
|
||||
<script lang="unknown">
|
||||
</script>
|
||||
|
||||
<script type="speculationrules">
|
||||
{
|
||||
"prerender": [
|
||||
{"source": "list", "urls": ["https://a.test/foo"]}
|
||||
]
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user