refactor(publish): downgrade baijiahao tables to paragraph rows

Baijiahao does not consistently render the previous flex-based faux table
markup, so reduce tables to plain <p> rows separated by three nbsp gaps
to keep tabular content visible after publish.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 21:55:27 +08:00
parent 87e329207c
commit 2044e179e1
2 changed files with 50 additions and 87 deletions
@@ -5,6 +5,7 @@ import {
prepareBaijiahaoArticleHtml,
prepareBaijiahaoMarkdown,
renderBaijiahaoTablesAsBlocks,
renderTablesAsParagraphRows,
} from "../../../../../packages/publisher-platforms/src/baijiahao";
import { normalizeArticleHtml } from "./common";
@@ -42,8 +43,8 @@ describe("baijiahao table content", () => {
expect(result).toContain("汇总");
});
it("downgrades tables into visible div blocks for Baijiahao", () => {
const result = renderBaijiahaoTablesAsBlocks(`
it("downgrades tables into paragraph rows with three-space column separators", () => {
const result = renderTablesAsParagraphRows(`
<table>
<thead>
<tr><th>城市</th><th>商家</th></tr>
@@ -57,11 +58,14 @@ describe("baijiahao table content", () => {
expect(result).not.toContain("<table");
expect(result).not.toContain("<thead");
expect(result).not.toContain("<th");
expect(result).toContain("display: flex");
expect(result).toContain("城市");
expect(result).toContain("商家");
expect(result).toContain("合肥");
expect(result).toContain("flex: 2 2 0");
expect(result).toContain("<p>城市&nbsp;&nbsp;&nbsp;商家</p>");
expect(result).toContain("<p>合肥</p>");
});
it("keeps the legacy Baijiahao block renderer on the paragraph-row fallback", () => {
const result = renderBaijiahaoTablesAsBlocks("<table><tbody><tr><td>A</td><td>B</td></tr></tbody></table>");
expect(result).toBe("<p>A&nbsp;&nbsp;&nbsp;B</p>");
});
it("keeps the paragraph after a markdown table outside the downgraded table", () => {
@@ -86,7 +90,9 @@ describe("baijiahao table content", () => {
);
expect(html).not.toContain("<table");
expect(html).toContain("display: flex");
expect(html).not.toContain("display: flex");
expect(html).toContain("<p>品牌&nbsp;&nbsp;&nbsp;评分</p>");
expect(html).toContain("<p>合肥全屋定制杨姐&nbsp;&nbsp;&nbsp;9.8</p>");
expect(html).toContain("<p>下一段中文说明</p>");
expect(html.indexOf("合肥全屋定制杨姐")).toBeGreaterThanOrEqual(0);
expect(html.indexOf("合肥全屋定制杨姐")).toBeLessThan(html.indexOf("<p>下一段中文说明</p>"));
@@ -115,7 +121,8 @@ describe("baijiahao table content", () => {
expect(html).toContain("<h1>2026年合肥全屋定制口碑好品牌推荐 | 本地业主专属避坑指南</h1>");
expect(html).not.toContain("<table");
expect(html).toContain("display: flex");
expect(html).not.toContain("display: flex");
expect(html).toContain("<p>排名&nbsp;&nbsp;&nbsp;品牌名称</p>");
expect(html).toContain("合肥全屋定制杨姐");
});
});