prettier / prettier/plugin-php

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

オープン
#2,403 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
PHP
スター
1.9k
フォーク
139
PR マージ指標
30日以内にマージされた PR はありません

説明

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;

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された PHP heredoc の例を Prettier PHP playground で再現し、現在の出力を期待される HTML のフォーマットと比較します。heredoc の内容がどのように解析され、出力されるかを追跡し、PHP の補間と heredoc 構文を維持したまま埋め込み HTML をフォーマットできることを完了条件として定義します。その他の埋め込み言語への対応は、より広い範囲の後続作業とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。