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

Support formatting of heredoc with HTML (& potentially other embedded languages) #2403

Open
sxxov opened this issue Sep 15, 2024 · 0 comments

Comments

@sxxov
Copy link

sxxov commented Sep 15, 2024

Thanks for all the work on this project, Prettier team!

Description

For HTML specifically, this is probably related to better inline support, & #845 (comment) but I figured the implementation for this would be slightly more straight forward as the explicit marking of HTML may make it more likely a html node be fully represented in one string. Many editors (including VSCode) also already highlight these sections by default with their respective syntax highlightings. Whilst prettier's HTML parser is still too strict to deal with interpolated tags (e.g. <$foo></$foo>, other parsers (like the one used in VSCode's builtin HTML formatter), can handle it.

For other languages, I guess it would depend more on their parsers, but I foresee that we could probably either use some sort of placeholder-replacement system, or just pass the whole string as is & YOLO.

Prettier 1.16.4

PHP Plugin 0.10.2

# Options (if any):
--use-tabs --php-version 8.2 --brace-style 1tbs

Input:

<?php

function Component($foo) {
	echo <<<HTML
		<div data-this-should-break data-bruh data-intersection>foo: $foo</div>
	HTML;
}

echo <<<HTML
	<main>
		{${Component(foo: "bar")}}
		{${Component(foo: "baz")}}
	</main>
HTML;

Output:
(The same)

<?php

function Component($foo) {
	echo <<<HTML
		<div data-this-should-break data-bruh data-intersection>foo: $foo</div>
	HTML;
}

echo <<<HTML
	<main>
		{${Component(foo: "bar")}}
		{${Component(foo: "baz")}}
	</main>
HTML;

Expected behavior:
The HTML should be formatted.

<?php

function Component($foo) {
	echo <<<HTML
		<div
			data-this-should-break
			data-bruh
			data-intersection
		>
			foo: $foo
		</div>
	HTML;
}

echo <<<HTML
	<main>
		{${Component(foo: "bar")}}
		{${Component(foo: "baz")}}
	</main>
HTML;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant