87e329207c
Wires up Baijiahao (百家号) and Jianshu (简书) as first-class desktop publish targets, with risk-control prompts surfaced in the runtime controller and a normalized error message in publish records. Adds external-link buttons in the publish management table, an asset format conversion endpoint for cover image compatibility, and reorders publish-status display priority so failures take precedence over partial successes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
normalizeBaijiahaoTables,
|
|
prepareBaijiahaoArticleHtml,
|
|
prepareBaijiahaoMarkdown,
|
|
renderBaijiahaoTablesAsBlocks,
|
|
} from "../../../../../packages/publisher-platforms/src/baijiahao";
|
|
|
|
import { normalizeArticleHtml } from "./common";
|
|
|
|
describe("baijiahao table content", () => {
|
|
it("converts GFM table HTML into Baijiahao-compatible table markup", () => {
|
|
const html = `
|
|
<table>
|
|
<thead>
|
|
<tr><th>城市</th><th>商家</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td>合肥</td><td>虫师银古</td></tr>
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
|
|
const result = normalizeBaijiahaoTables(html);
|
|
|
|
expect(result).toContain('data-sort="sortDisabled"');
|
|
expect(result).toContain('border="1"');
|
|
expect(result).toContain('cellpadding="0"');
|
|
expect(result).toContain('class="firstRow"');
|
|
expect(result).toContain("<strong>城市</strong>");
|
|
expect(result).toContain("<td");
|
|
expect(result).toContain("虫师银古");
|
|
expect(result).not.toContain("<thead>");
|
|
expect(result).not.toContain("<th>");
|
|
});
|
|
|
|
it("preserves cell span attributes", () => {
|
|
const result = normalizeBaijiahaoTables('<table><tbody><tr><td colspan="2">汇总</td></tr></tbody></table>');
|
|
|
|
expect(result).toContain('colspan="2"');
|
|
expect(result).toContain("汇总");
|
|
});
|
|
|
|
it("downgrades tables into visible div blocks for Baijiahao", () => {
|
|
const result = renderBaijiahaoTablesAsBlocks(`
|
|
<table>
|
|
<thead>
|
|
<tr><th>城市</th><th>商家</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td colspan="2">合肥</td></tr>
|
|
</tbody>
|
|
</table>
|
|
`);
|
|
|
|
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");
|
|
});
|
|
|
|
it("keeps the paragraph after a markdown table outside the downgraded table", () => {
|
|
const html = prepareBaijiahaoArticleHtml(
|
|
normalizeArticleHtml(
|
|
{
|
|
article_id: 1,
|
|
title: "表格测试",
|
|
html_content: null,
|
|
markdown_content: [
|
|
"| 品牌 | 评分 |",
|
|
"| --- | --- |",
|
|
"| 合肥全屋定制杨姐 | 9.8 |",
|
|
"下一段中文说明",
|
|
].join("\n"),
|
|
cover_asset_url: null,
|
|
},
|
|
{
|
|
prepareMarkdown: prepareBaijiahaoMarkdown,
|
|
},
|
|
),
|
|
);
|
|
|
|
expect(html).not.toContain("<table");
|
|
expect(html).toContain("display: flex");
|
|
expect(html).toContain("<p>下一段中文说明</p>");
|
|
expect(html.indexOf("合肥全屋定制杨姐")).toBeGreaterThanOrEqual(0);
|
|
expect(html.indexOf("合肥全屋定制杨姐")).toBeLessThan(html.indexOf("<p>下一段中文说明</p>"));
|
|
});
|
|
|
|
it("does not treat title pipes as markdown table rows", () => {
|
|
const html = prepareBaijiahaoArticleHtml(
|
|
normalizeArticleHtml(
|
|
{
|
|
article_id: 1,
|
|
title: "标题测试",
|
|
html_content: null,
|
|
markdown_content: [
|
|
"# 2026年合肥全屋定制口碑好品牌推荐 | 本地业主专属避坑指南",
|
|
"| 排名 | 品牌名称 |",
|
|
"| --- | --- |",
|
|
"| 1 | 合肥全屋定制杨姐 |",
|
|
].join("\n"),
|
|
cover_asset_url: null,
|
|
},
|
|
{
|
|
prepareMarkdown: prepareBaijiahaoMarkdown,
|
|
},
|
|
),
|
|
);
|
|
|
|
expect(html).toContain("<h1>2026年合肥全屋定制口碑好品牌推荐 | 本地业主专属避坑指南</h1>");
|
|
expect(html).not.toContain("<table");
|
|
expect(html).toContain("display: flex");
|
|
expect(html).toContain("合肥全屋定制杨姐");
|
|
});
|
|
});
|