Empty source paragraphs lose their source identity

Đã đóng Phù hợp với người mới
#2,802 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #2808 của @chubes4 — đã merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
css, php
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu từ RichTextElementConverter::convertParagraph(), nơi một đoạn văn rỗng được chuyển đến helper convertText(trim($element->textContent)), helper này tạo ra một core/paragraph không có phần tử nguồn. Tái hiện lỗi bằng HTML trong issue và kiểm tra xem đầu ra <p> rỗng có mang dấu blocks-engine-source-p-* hay không. Hoàn thành khi đoạn văn nguồn rỗng được tạo từ phần tử nguồn của nó giống như đoạn không rỗng, để quy tắc p và các quy tắc lề theo từng thẻ áp dụng được cho nó.

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

Mô tả

Problem

An empty source <p></p> lowers to a bare core/paragraph with no source identity. Its box is still rendered, but author p rules (projected onto the blocks-engine-source-p-* tag marker) can no longer reach it, so it falls back to the UA margins of 1em top and bottom.

Reproduction (neutral)

<style>p{margin-top:0;margin-bottom:1rem}.desc p:empty{min-height:1em}</style>
<main><div class="card"><h3>Title</h3><div class="desc"><p></p></div></div>
<div class="card"><h3>Other</h3><div class="desc"><p>Text</p></div></div></main>

Output: <p></p> and <p class="blocks-engine-source-p-…">Text</p>. The empty paragraph gets no marker, so p{margin-top:0} and the per-card margin rules miss it.

On a real Next.js/Bootstrap capture (nostar2.com video list), each video description is an empty <p>. Every one picks up 32px of UA margin, and the page drifts 32px further per item.

Root cause

RichTextElementConverter::convertParagraph() handles an empty paragraph with convertText(trim($element->textContent)). That helper creates core/paragraph from a text string with no source element, so the source marker, classes and presentation attributes are all dropped.

Expected

An empty source paragraph that is kept as core/paragraph is created from its source element, exactly like a non-empty one, so the author cascade reaches it.


AI disclosure: found and reduced with Claude (Anthropic) in the Pi coding agent during the nostar2.com import parity loop.

Ngôn ngữ chính
PHP
Star
22
Fork
3
Merge trung bình
6 giờ 26 phút
Pull request đã merge (30 ngày)
879

Chuẩn bị môi trường

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.

Issue khác của Automattic/blocks-engine

Tất cả issue của Automattic/blocks-engine

Issue tương tự

Thêm issue về PHP

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.