Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CDATA tag content should be not formatted with angular parser #16242

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/language-html/printer-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runFormatTest(import.meta, ["angular"]);
Loading