prettier / prettier/plugin-php

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

Đang mở
#2,403 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
PHP
Star
1.9k
Fork
139
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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;

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ PHP heredoc được cung cấp trong Prettier PHP playground và so sánh đầu ra hiện tại với định dạng HTML mong đợi. Theo dõi cách nội dung heredoc được phân tích cú pháp và in ra, sau đó xác định tiêu chí hoàn thành là định dạng HTML được nhúng trong khi vẫn bảo toàn phép nội suy PHP và cú pháp heredoc; việc hỗ trợ các ngôn ngữ nhúng khác vẫn thuộc phạm vi rộng hơn để thực hiện sau.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.