prettier / prettier/plugin-php

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

Offen
#2,403 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
PHP
Sterne
1.9k
Forks
139
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Description

For HTML specifically, this is probably related to better inline support, & https://github.com/prettier/plugin-php/issues/845#issuecomment-441405121 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;

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das bereitgestellte PHP-heredoc-Beispiel im Prettier PHP Playground zu reproduzieren, und vergleiche die aktuelle Ausgabe mit der erwarteten HTML-Formatierung. Verfolge, wie heredoc-Inhalte geparst und ausgegeben werden, und definiere den Abschluss als das Formatieren des eingebetteten HTML unter Beibehaltung der PHP-Interpolation und der heredoc-Syntax; die Unterstützung für andere eingebettete Sprachen bleibt ein weiter gefasster Bestandteil für spätere Arbeiten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.