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

Ignore CDATA in HTML or option to ignore it #16147

Open
muuvmuuv opened this issue Mar 12, 2024 · 5 comments · May be fixed by #16242
Open

Ignore CDATA in HTML or option to ignore it #16147

muuvmuuv opened this issue Mar 12, 2024 · 5 comments · May be fixed by #16242
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular)

Comments

@muuvmuuv
Copy link
Contributor

Prettier 3.2.5
Playground link

--parser angular
--print-width 90
--prose-wrap always
--html-whitespace-sensitivity strict

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>]]>

Expected output:

<![CDATA[<app-alert>
  Lorem ipsum dolor sit amet consectetur adipisicing elit.
</app-alert>]]>

Why?

We use CDATA to show a code example of how someone should use a component surrounded by pre/code tags. Prettier always formats it. Alternatively, handle it separately and do not try to indent it with the rest of the code.

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Apr 6, 2024

@muuvmuuv Thanks for the report. I am not familiar with CDATA so let me ask a question. Is this a matter of code style preference? Or is there some processor or other that cannot accept the current Prettier output?

If it is a matter of style preference, we would not accept this request.

@sosukesuzuki sosukesuzuki added status:awaiting response Issues that require answers to questions from maintainers before action can be taken lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) labels Apr 6, 2024
@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Apr 7, 2024

From MDN

used within XML to include extended portions of unescaped text
Since you cannot write HTML in HTML that is printed as “plain text” you need that unless you escape/ASCII the HTML tags yourself which is time-consuming.

It is a matter of style pref, but this isn't directly tied to Angular. CDATA is unformatted unescaped unstyled plain text. IMO, it should not get any formatting. You style the inner part of yourself.

Another quote: https://stackoverflow.com/questions/2784183/what-does-cdata-in-xml-mean

"a section of element content that is marked for the parser to interpret as only character data, not markup."

@github-actions github-actions bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Apr 7, 2024
@fisker
Copy link
Member

fisker commented Apr 10, 2024

I agree that CDATA should not be formatted.

@yanapeycheva
Copy link

Hi! I am working on this issue, can you please assign it to me? Thanks!

yanapeycheva pushed a commit to iuliaaai/prettier that referenced this issue Apr 29, 2024
yanapeycheva pushed a commit to iuliaaai/prettier that referenced this issue Apr 29, 2024
@muuvmuuv
Copy link
Contributor Author

Hey @yanapeycheva, great!

I wouldn't say this is only for Angular but any XML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants