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
@@ -39,6 +39,22 @@ test("buildHtmlDocument includes optional meta tags and code theme CSS", () => {
assert.match(html, /<article>Hello<\/article>/);
});
test("buildHtmlDocument escapes head metadata attributes", () => {
const html = buildHtmlDocument(
{
title: `Doc <draft>`,
author: `Bao"yu`,
description: `<p style="color: red">Summary & notes</p>`,
},
"",
"",
);
assert.match(html, /<title>Doc &lt;draft&gt;<\/title>/);
assert.match(html, /meta name="author" content="Bao&quot;yu"/);
assert.match(html, /meta name="description" content="&lt;p style=&quot;color: red&quot;&gt;Summary &amp; notes&lt;\/p&gt;"/);
});
test("normalizeCssText and normalizeInlineCss replace variables and strip declarations", () => {
const rawCss = `
:root { --md-primary-color: #000; --md-font-size: 12px; --foreground: 0 0% 5%; }