Skip to content

Commit

Permalink
fix: fix script contains template nested interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Oct 24, 2024
1 parent 48c2604 commit 3e3e3de
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dprint_plugin/tests/integration/biome/indent.html.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,47 @@ source: dprint_plugin/tests/integration.rs
second line`;
}
</script>

<html lang="en">
<body>
<script type="module">
const data = await (await fetch("./monthly-visits.json")).json();
const { title, labels, datasets } = data;
const fmt = new Intl.NumberFormat();

new frappe.Chart(document.getElementById("chart"), {
title,
type: "bar",
height: 300,
data: {
labels,
datasets: datasets.map(({ name, values }) => {
return { name, values, chartType: "bar" };
}),
},
});
document.title = title;
document.getElementById("title").innerText = title;
const details = document.getElementById("details");
details.innerHTML = `
${datasets
.map(
({ name, values }) => `
<h2>${name}</h2>
<dl>
${labels
.map(
(label, index) => `
<dt>${label}</dt>
<dd>${fmt.format(values[index])}</dd>
`,
)
.join("")}
</dl>
`,
)
.join("")}
`;
</script>
</body>
</html>
43 changes: 43 additions & 0 deletions dprint_plugin/tests/integration/dprint_ts/indent.html.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,46 @@ source: dprint_plugin/tests/integration.rs
second line`;
}
</script>

<html lang="en">
<body>
<script type="module">
const data = await (await fetch("./monthly-visits.json")).json();
const { title, labels, datasets } = data;
const fmt = new Intl.NumberFormat();

new frappe.Chart(
document.getElementById("chart"),
{
title,
type: "bar",
height: 300,
data: {
labels,
datasets: datasets.map(({ name, values }) => {
return { name, values, chartType: "bar" };
}),
},
},
);
document.title = title;
document.getElementById("title").innerText = title;
const details = document.getElementById("details");
details.innerHTML = `
${
datasets.map(({ name, values }) => `
<h2>${name}</h2>
<dl>
${
labels.map((label, index) => `
<dt>${label}</dt>
<dd>${fmt.format(values[index])}</dd>
`).join("")
}
</dl>
`).join("")
}
`;
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions dprint_plugin/tests/integration/indent.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,42 @@
second line`;
}
</script>

<html lang="en">
<body>
<script type="module">
const data = await (await fetch("./monthly-visits.json")).json();
const { title, labels, datasets } = data;
const fmt = new Intl.NumberFormat();

new frappe.Chart(
document.getElementById("chart"),
{
title,
type: "bar",
height: 300,
data: {
labels,
datasets: datasets.map(({ name, values }) => {
return { name, values, chartType: "bar" };
}),
},
},
);
document.title = title;
document.getElementById("title").innerText = title;
const details = document.getElementById("details");
details.innerHTML = `
${datasets.map(({ name, values }) => `
<h2>${name}</h2>
<dl>
${labels.map((label, index) => `
<dt>${label}</dt>
<dd>${fmt.format(values[index])}</dd>
`).join("")}
</dl>
`).join("")}
`;
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,9 @@ fn reflow_with_indent<'i, 'o: 'i>(s: &'i str) -> impl Iterator<Item = Doc<'o>> +
pair_stack.push('$');
}
}
'{' => {
pair_stack.push('{');
}
'}' if matches!(pair_stack.last(), Some('$' | '{')) => {
pair_stack.pop();
}
Expand Down

0 comments on commit 3e3e3de

Please sign in to comment.