Skip to content

Commit

Permalink
prettier#16147: do not format CDATA with angular parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Yana Peycheva committed Apr 29, 2024
1 parent 1264a4c commit 3597494
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/language-html/printer-html.js
Expand Up @@ -68,6 +68,10 @@ function genericPrint(path, options, print) {
printClosingTagEnd(node, options),
];
case "text": {
// CDATA should not be formatted
if (node.value.startsWith("<![CDATA") && node.value.endsWith("]>") && options.parser === "angular") {
return node.value
}
if (node.parent.type === "interpolation") {
// replace the trailing literalline with hardline for better readability
const trailingNewlineRegex = /\n[^\S\n]*$/;
Expand Down
19 changes: 19 additions & 0 deletions tests/format/angular/cdata/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`example.html format 1`] = `
====================================options=====================================
parsers: ["angular"]
printWidth: 80
| printWidth
=====================================input======================================
<![CDATA[<app-alert>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</app-alert>]]>
=====================================output=====================================
<![CDATA[<app-alert>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</app-alert>]]>
================================================================================
`;
3 changes: 3 additions & 0 deletions tests/format/angular/cdata/example.html
@@ -0,0 +1,3 @@
<![CDATA[<app-alert>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</app-alert>]]>
1 change: 1 addition & 0 deletions tests/format/angular/cdata/jsfmt.spec.js
@@ -0,0 +1 @@
runFormatTest(import.meta, ["angular"]);

0 comments on commit 3597494

Please sign in to comment.