fix(baoyu-post-to-wechat): decode HTML entities and strip tags from article summary

Add cleanSummaryText() to baoyu-md package: decodes HTML entities (&, <, &#x..., etc.)
and strips HTML tags before using frontmatter description/summary as WeChat article digest
This commit is contained in:
Jim Liu 宝玉
2026-04-12 20:16:53 -05:00
parent 517ff566a1
commit 990fea4f7b
7 changed files with 138 additions and 13 deletions
+17
View File
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
cleanSummaryText,
extractSummaryFromBody,
extractTitleFromMarkdown,
parseFrontmatter,
@@ -91,3 +92,19 @@ This is **the first paragraph** with [a link](https://example.com) and \`inline
"This is the first paragraph with a link and inline code that should...",
);
});
test("summary extraction normalizes raw HTML paragraphs to plain text", () => {
const summary = extractSummaryFromBody(
`
# Heading
<p style="font-size: 16px; color: #666; margin-bottom: 20px;">2026年初,一只“龙虾”搅动了整个科技圈。腾讯楼下排起近千人长队,只为让工程师领取一份福利。</p>
`,
120,
);
assert.equal(
summary,
"2026年初,一只“龙虾”搅动了整个科技圈。腾讯楼下排起近千人长队,只为让工程师领取一份福利。",
);
assert.equal(cleanSummaryText("<strong>Good&nbsp;text&#33;&apos;</strong>"), "Good text!'");
});