Repository: prettier/prettier (JavaScript)
Date: 2018-12-15 15:17:36+00:00
Task type: Feature

Issue:
Handle "application/ld+json" type as script type in html formatting
**Prettier 1.15.3**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAeAzmATgSwA4wAEMAnnnALwA6IAhnngDY5i0w7QD0jAJgNQArdNBoA+KlEKFgEqVJoABSLDgAPGDSSEaACxgw8STp0w64AW1oA6CFgDmNADQTZcmpZxQAorBykA8gBmAAq0dnCa0q5y2iAKpOSRNADqcABGoeFO0W5xODxJIHoG6EacAO6VVuW06DqedjDQeBDoMFaQ5jQ5AL7OkrlmtDzMUBHIOfIgybX1UI3QhMGtMFoAQlhwtADWDYQAcnDl6I6Eyba8pwCqAMqnACIAwgdH6IQAZLTmeADchACCUFojBI6Bw6GyUBcUJhMRoPDgmFwBA4UImAzhIA2W1280IY2OhFoUB4RKBILBb0WLWY7DAJ0IaQArmCxugGeULqSgexoMD8a9Tgh4FgYLRPOZhYRzLY4FZCABJKAAWgRBB0hCepwAajh7J4cLRTgBZWhYEiMYnc16ESAANzgWDCcEInjAjCZPD2MCdgUCLFO5S2MDMWFO2BwkqFPCZrF5UFOmzatCZTtghE2dpwNqt0tlVkh0KLMJyNEjzsiAG1JrFinhSsZKuVqrMGk0oC02h0IOZOHg0hBVFY8Do8AB+VOMCh1hsVKo1Opt5orbu9-ucJMQVNgRGcSN2Tgwcp4ZXCMCGxinnRmuV4eafb4-coUACMABYABxvh+-CB4ChJjgABecA-j8f4wK+YH+owIoUMS7DAoa6BgZBABMAAML4AOwYQArDh3QYoQAC6-SliA4L-GAO7sjgaSMHAABithMZs4xaDQAAqWBMuM-SYte6ChKKkQyMRUzxGQHGxKkGTOl4jGSrAkIxFMVE0YiYIMcxrHsYUPF8apak0PS6A3HAjFgE0WCFMOtAkDUjCMERMR9NCmJ4EyDHgqGYk1ooCQyTQhzHMacBerQ-j2MSwFsKixmYkCkoGWYZytvM7ZLCsiW5HAIYsMJEDMGAJCFDOZRNi2i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ussion:
Shouldn’t it be the `json` parser?
Yes, you're right. 

Solution patch:
diff --git a/src/language-html/utils.js b/src/language-html/utils.js
index 5b263ecebc7d..ecbf5a139d8d 100644
--- a/src/language-html/utils.js
+++ b/src/language-html/utils.js
@@ -375,6 +375,10 @@ function inferScriptParser(node) {
     if (node.attrMap.type === "text/markdown") {
       return "markdown";
     }
+
+    if (node.attrMap.type === "application/ld+json") {
+      return "json";
+    }
   }
 
   if (node.name === "style") {


Test patch:
diff --git a/tests/html_script/__snapshots__/jsfmt.spec.js.snap b/tests/html_script/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 000000000000..18a5cad25c06
--- /dev/null
+++ b/tests/html_script/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,19 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`script.html 1`] = `
+====================================options=====================================
+parsers: ["html"]
+printWidth: 80
+                                                                                | printWidth
+=====================================input======================================
+<script type="application/ld+json">
+  {   "json":true  }
+</script>
+
+=====================================output=====================================
+<script type="application/ld+json">
+  { "json": true }
+</script>
+
+================================================================================
+`;
diff --git a/tests/html_script/jsfmt.spec.js b/tests/html_script/jsfmt.spec.js
new file mode 100644
index 000000000000..53763df9b20b
--- /dev/null
+++ b/tests/html_script/jsfmt.spec.js
@@ -0,0 +1,1 @@
+run_spec(__dirname, ["html"]);
diff --git a/tests/html_script/script.html b/tests/html_script/script.html
new file mode 100644
index 000000000000..5010a12a80e2
--- /dev/null
+++ b/tests/html_script/script.html
@@ -0,0 +1,3 @@
+<script type="application/ld+json">
+  {   "json":true  }
+</script>