Skip to content

Commit

Permalink
feat: support JSON-LD in <script> tag (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuapp authored Oct 14, 2024
1 parent 1983826 commit 2a2402e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dprint config add g-plane/malva
dprint config add typescript
```

If you also want to format JSON in `<script>` tag whose `"type"` is `"importmap"` or `"application/json"`,
If you also want to format JSON in `<script>` tag whose `"type"` is `"importmap"`, `"application/json"`, or `"application/ld+json"`,
you can add dprint-plugin-json:

```bash
Expand Down
3 changes: 3 additions & 0 deletions dprint_plugin/tests/integration/biome/json.html.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ source: dprint_plugin/tests/integration.rs
<script type="application/json">
{ "ssrData": { "items": [1, 2, 3] } }
</script>
<script type="application/ld+json">
{ "@context": "https://schema.org" }
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions dprint_plugin/tests/integration/dprint_ts/json.html.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ source: dprint_plugin/tests/integration.rs
<script type="application/json">
{ "ssrData": { "items": [1, 2, 3] } }
</script>
<script type="application/ld+json">
{ "@context": "https://schema.org" }
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions dprint_plugin/tests/integration/json.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
<script type="application/json">
{"ssrData":{"items":[1,2,3]}}
</script>
<script type="application/ld+json">
{"@context": "https://schema.org"}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl<'s> DocGen<'s> for Element<'s> {
&& native_attr
.value
.map(|(value, _)| {
value == "importmap" || value == "application/json"
value == "importmap" || value == "application/json" || value == "application/ld+json"
})
.unwrap_or_default()
} else {
Expand Down

0 comments on commit 2a2402e

Please sign in to comment.