Skip to content

Commit

Permalink
fix: improve fallback content printint
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 24, 2024
1 parent 2559fa8 commit c2e2995
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script nonce=$global.cspNonce type="speculationrules"
--
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
8 changes: 8 additions & 0 deletions src/__tests__/fixtures/script-with-type.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script nonce=$global.cspNonce type="speculationrules">
{
"prerender": [{
"where": { "href_matches": "/*" },
"eagerness": "moderate"
}]
}
</script>
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ export const printers: Record<string, Printer<types.Node>> = {
: b.ifBreak("--", " --", { groupId }),
opts.markoSyntax === "html" ? "" : b.line,
replaceEmbeddedPlaceholders(
await toDoc(embeddedCode, { parser: scriptParser }),
await toDoc(embeddedCode, {
parser: scriptParser,
}).catch(() => embeddedCode.trim()),
placeholders,
),
opts.markoSyntax === "html"
Expand Down Expand Up @@ -781,7 +783,12 @@ export const printers: Record<string, Printer<types.Node>> = {
"style",
!lang || lang === ".css" ? "" : lang,
" {",
b.indent([b.line, await toDoc(code, { parser })]),
b.indent([
b.line,
await toDoc(code, { parser }).catch(() =>
code.trim(),
),
]),
b.line,
"}",
]),
Expand Down Expand Up @@ -888,14 +895,15 @@ export const printers: Record<string, Printer<types.Node>> = {
: b.ifBreak("--", " --", { groupId }),
opts.markoSyntax === "html" ? "" : b.line,
replaceEmbeddedPlaceholders(
await toDoc(embeddedCode, { parser }),
await toDoc(embeddedCode, { parser }).catch(() =>
embeddedCode.trim(),
),
placeholders,
),
opts.markoSyntax === "html"
? ""
: b.ifBreak([b.softline, "--"]),
]);

doc.push(b.indent([wrapSep, bodyDoc]));

if (opts.markoSyntax === "html") {
Expand Down

0 comments on commit c2e2995

Please sign in to comment.