Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): preserve WeChat copy styles and adaptive directory cards

tianma-iffa1921570e4d
diff --git a/apps/web/src/components/editor/EditorMagazineHeader.tsx b/apps/web/src/components/editor/EditorMagazineHeader.tsx
index e31108c2..b1e92396 100644
--- a/apps/web/src/components/editor/EditorMagazineHeader.tsx
+++ b/apps/web/src/components/editor/EditorMagazineHeader.tsx
@@ -328,6 +328,11 @@ export const EditorMagazineHeader = ({
useSolidAccent
? {
width: "146px",
+ boxSizing: "border-box",
+ flexShrink: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "stretch",
textAlign: "left",
background: "linear-gradient(135deg, var(--note-palette-accent, #374151), color-mix(in srgb, var(--note-palette-accent, #374151) 80%, #ffffff))",
border: "1px solid transparent",
@@ -337,6 +342,11 @@ export const EditorMagazineHeader = ({
}
: {
width: "146px",
+ boxSizing: "border-box",
+ flexShrink: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "stretch",
textAlign: "left",
background: isHighlighted ? "#f3f4f6" : "#ffffff",
border: "1px solid #e5e7eb",
@@ -350,6 +360,7 @@ export const EditorMagazineHeader = ({
<div
style={{
fontSize: "9px",
+ lineHeight: 1.4,
fontWeight: 700,
color: useSolidAccent ? "rgba(255, 255, 255, 0.72)" : "#6b7280",
letterSpacing: "1px",
@@ -377,9 +388,7 @@ export const EditorMagazineHeader = ({
fontSize: "10px",
color: useSolidAccent ? "rgba(255, 255, 255, 0.75)" : "#6b7280",
lineHeight: 1.4,
- overflow: "hidden",
- textOverflow: "ellipsis",
- whiteSpace: "nowrap",
+ wordBreak: "break-word",
}}
>
{section.subTitle}
diff --git a/apps/web/src/lib/wechat-copy.test.mjs b/apps/web/src/lib/wechat-copy.test.mjs
index 13f1f5d9..60f0c0eb 100644
--- a/apps/web/src/lib/wechat-copy.test.mjs
+++ b/apps/web/src/lib/wechat-copy.test.mjs
@@ -112,6 +112,41 @@ describe("preparePublishArticle", () => {
}
});
+ test("keeps nested editor table paragraphs compact and header text readable", () => {
+ const container = document.createElement("div");
+ container.dataset.notePalette = "violet";
+ const previous = globalThis.getComputedStyle;
+ globalThis.getComputedStyle = () => ({
+ getPropertyValue: (name) => ({
+ "--note-palette-light-accent": "#7351CF",
+ "--note-palette-text": "#27272a",
+ })[name] ?? "",
+ });
+ try {
+ for (const palette of ["violet", "native"]) {
+ container.dataset.notePalette = palette;
+ const root = preparePublishArticle(
+ '<p>正文</p><table><tbody><tr><th><p>表头 <strong>重点</strong></p></th></tr>' +
+ '<tr><td><p>内容 <strong>重点</strong></p><p>第二段</p></td></tr></tbody></table>', container,
+ );
+ const header = root.querySelector("th p");
+ expect(css(header)).toContain(`color:${palette === "violet" ? "#ffffff" : "#111827"}`);
+ expect(css(header)).toContain("font-size:13.44px");
+ expect(css(header.querySelector("strong"))).toContain(`color:${palette === "violet" ? "#ffffff" : "#111827"}`);
+ for (const paragraph of root.querySelectorAll("th p, td p")) {
+ expect(css(paragraph)).toContain("margin:0");
+ expect(css(paragraph)).toContain("line-height:1.45");
+ }
+ expect(css(root.querySelector("td p"))).toContain("font-size:16px");
+ expect(css(root.querySelector("td strong"))).toContain("color:#111827");
+ expect(css(root.firstElementChild)).toContain("color:#27272a");
+ expect(css(root.firstElementChild)).not.toContain("margin:0;");
+ }
+ } finally {
+ globalThis.getComputedStyle = previous;
+ }
+ });
+
test("matches the light editor instead of the old rose-and-green paste", () => {
const root = preparePublishArticle([
"<blockquote><p>引用</p></blockquote>",
@@ -241,15 +276,29 @@ describe("preparePublishArticle", () => {
});
try {
const root = preparePublishArticle([
- "<h2>第一章</h2>",
+ "<h2>效率工具箱:斜杠指令、双链与数学公式</h2>",
"<p>内容一</p>",
- "<h2>第二章</h2>",
+ "<h2>多媒体管理、无损备份与零成本自建</h2>",
"<p>内容二</p>",
].join(""), container);
expect(root.querySelector("[data-ee-cover-card]")).not.toBeNull();
expect(root.querySelector("[data-ee-cover-card]")?.textContent).toContain("深度评测文章");
expect(root.querySelector("[data-ee-toc-cards]")).not.toBeNull();
expect(root.querySelector("[data-ee-toc-cards]")?.textContent).toContain("2 PARTS");
+ const card = root.querySelector('[data-ee-toc-cards] section[style*="width: 136px"]');
+ expect(css(card)).toContain("background-color:#059669");
+ expect(css(card)).toContain("linear-gradient(135deg,");
+ expect(css(card)).not.toContain("color-mix");
+ const cards = root.querySelectorAll('[data-ee-toc-cards] section[style*="width: 136px"]');
+ expect(cards.length).toBe(2);
+ for (const item of cards) {
+ expect(css(item)).not.toContain("height:");
+ expect(css(item.parentElement)).toContain("display:flex");
+ expect(css(item.parentElement)).toContain("align-items:stretch");
+ expect(css(item)).toContain("box-sizing:border-box");
+ expect(css(item)).toContain("border:1px solid");
+ expect(css(item.querySelector("p"))).toContain("line-height:1.4");
+ }
} finally {
globalThis.getComputedStyle = previous;
}
diff --git a/apps/web/src/lib/wechat-copy.ts b/apps/web/src/lib/wechat-copy.ts
index 2e8968ec..6f31f151 100644
--- a/apps/web/src/lib/wechat-copy.ts
+++ b/apps/web/src/lib/wechat-copy.ts
@@ -101,7 +101,10 @@ const applyLegacyWeChatStyles = (
const preStyle = proseStyle.quoteStyle === "dashed"
? `margin: 0 0 20px; padding: 14px 18px; overflow: hidden; border: 0; border-left: 3px solid ${accent}; border-radius: 0 8px 8px 0; background: #f9fafb; color: #0f172a; font-family: ${PUBLISH_MONO}; font-size: ${codeSize}; line-height: 1.75; text-align: left; white-space: pre-wrap;`
: `margin: 0 0 16px; padding: 14px 16px; overflow: hidden; border: 1px solid #e4e4e4; border-radius: 8px; background: #fafafa; color: #0f172a; font-family: ${PUBLISH_MONO}; font-size: ${codeSize}; line-height: 1.6; text-align: left; white-space: pre-wrap;`;
- const thStyle = `padding: 8px 13px; border: 1px solid #e5e5e5; background: ${thBackground}; color: ${thColor}; font-weight: 700; font-size: 13px; text-align: left;`;
+ // Match the editor header size and keep paragraph defaults out of table cells.
+ const tableHeaderSize = "13.44px";
+ const accentGradient = `background-color: ${accent}; background-image: linear-gradient(135deg, rgba(255,255,255,0), rgba(255,255,255,0.2));`;
+ const thStyle = `padding: 8px 13px; border: 1px solid #e5e5e5; background: ${thBackground}; color: ${thColor}; font-weight: 700; font-size: ${tableHeaderSize}; text-align: left; vertical-align: top;`;
const imgStyle =
"display: block; max-width: 100%; height: auto; margin: 16px 0; padding: 6px; box-sizing: border-box; background: #ffffff; border: 1px solid #e5e7eb; border-radius: 12px; box-shadow: 0 4px 12px -2px rgba(0,0,0,0.08);";
const paragraphBottom = proseStyle.headingStyle === "numbered" ? "16px" : PARAGRAPH_SPACING;
@@ -135,7 +138,7 @@ const applyLegacyWeChatStyles = (
: "margin: 24px 0; border: 0; border-top: 1px solid #1a1d21;",
table: `width: 100%; margin: 20px 0; border-collapse: collapse; font-size: ${fontSize}; line-height: 1.45;`,
th: thStyle,
- td: `padding: 8px 13px; border: 1px solid #e5e5e5; color: ${BODY_COLOR}; text-align: left;`,
+ td: `padding: 8px 13px; border: 1px solid #e5e5e5; color: ${BODY_COLOR}; text-align: left; vertical-align: top;`,
img: imgStyle,
};
@@ -148,7 +151,10 @@ const applyLegacyWeChatStyles = (
const isMergeDivider =
tagName === "hr" && element.matches("[data-edgeever-merge-divider], .edgeever-merge-divider");
const quoted = (tagName === "p" || tagName === "li") && element.closest("blockquote");
- const baseStyle = styles[tagName] || "";
+ const cell = tagName === "p" ? element.closest("th, td") : null;
+ const baseStyle = cell
+ ? `margin: 0; padding: 0; font-family: ${PUBLISH_FONT}; font-size: ${cell.tagName.toLowerCase() === "th" ? tableHeaderSize : fontSize}; line-height: 1.45; letter-spacing: inherit; color: ${cell.tagName.toLowerCase() === "th" ? thColor : BODY_COLOR};`
+ : styles[tagName] || "";
// One color declaration. A second `color` later in the attribute is easy for WeChat to drop.
const style = isMergeDivider
? "margin: 24px 0; border: 0; border-top: 2px solid #1a1d21;"
@@ -182,7 +188,7 @@ const applyLegacyWeChatStyles = (
`<p data-ee-publish-chrome="true" style="font-size: 23px; font-weight: 900; color: #111827; margin: 0 0 14px; line-height: 1.2; letter-spacing: -0.5px;">${titleHtml}</p>`,
`<section data-ee-publish-chrome="true" style="width: 48px; height: 3px; background: ${accent}; border-radius: 2px;"><span leaf=""><br></span></section>`,
`</section>`,
- `<section data-ee-publish-chrome="true" style="background: ${colors ? accent : "#f3f4f6"}; padding: 10px 24px; font-size: 0;">`,
+ `<section data-ee-publish-chrome="true" style="${colors ? accentGradient : "background: #f3f4f6;"} padding: 10px 24px; font-size: 0;">`,
`<span data-ee-publish-chrome="true" style="display: inline-block; font-size: 11px; color: ${colors ? "rgba(255,255,255,0.92)" : "#374151"}; font-weight: 600; letter-spacing: 0.8px; vertical-align: middle;">EDGEEVER · 精选笔记</span>`,
`</section>`,
].join("");
@@ -202,21 +208,21 @@ const applyLegacyWeChatStyles = (
const shortTitle = rawText.slice(0, 6) || `章节 ${num}`;
const subTitle = rawText.length > 6 ? rawText.slice(6, 18) : `PART ${num}`;
const isHighlighted = index < h2ListForToc.length - 1 || h2ListForToc.length === 2 && index === 0;
- const useSolidAccent = isHighlighted && Boolean(colors);
- if (useSolidAccent) {
+ const useAccentGradient = isHighlighted && Boolean(colors);
+ if (useAccentGradient) {
return [
- `<section data-ee-publish-chrome="true" style="display: inline-block; vertical-align: top; width: 136px; box-sizing: border-box; background: ${accent}; border-radius: 12px; padding: 12px; margin: 0 8px 8px 0;">`,
- `<p data-ee-publish-chrome="true" style="font-size: 9px; font-weight: 700; color: rgba(255,255,255,0.72); letter-spacing: 1px; margin: 0 0 5px;">${num}</p>`,
+ `<section data-ee-publish-chrome="true" style="display: inline-block; vertical-align: top; width: 136px; flex-shrink: 0; box-sizing: border-box; border: 1px solid transparent; ${accentGradient} border-radius: 12px; padding: 12px; margin: 0 8px 8px 0;">`,
+ `<p data-ee-publish-chrome="true" style="font-size: 9px; line-height: 1.4; font-weight: 700; color: rgba(255,255,255,0.72); letter-spacing: 1px; margin: 0 0 5px;">${num}</p>`,
`<p data-ee-publish-chrome="true" style="font-size: 13px; font-weight: 800; color: #ffffff; margin: 0 0 3px; line-height: 1.3;">${shortTitle}</p>`,
- `<p data-ee-publish-chrome="true" style="font-size: 10px; color: rgba(255,255,255,0.75); margin: 0; line-height: 1.4;">${subTitle}</p>`,
+ `<p data-ee-publish-chrome="true" style="font-size: 10px; color: rgba(255,255,255,0.75); margin: 0; line-height: 1.4; word-break: break-word;">${subTitle}</p>`,
`</section>`,
].join("");
}
return [
- `<section data-ee-publish-chrome="true" style="display: inline-block; vertical-align: top; width: 136px; box-sizing: border-box; background: ${isHighlighted ? "#f3f4f6" : "#ffffff"}; border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px; margin: 0 8px 8px 0;">`,
- `<p data-ee-publish-chrome="true" style="font-size: 9px; font-weight: 700; color: #6b7280; letter-spacing: 1px; margin: 0 0 5px;">${num}</p>`,
+ `<section data-ee-publish-chrome="true" style="display: inline-block; vertical-align: top; width: 136px; flex-shrink: 0; box-sizing: border-box; background: ${isHighlighted ? "#f3f4f6" : "#ffffff"}; border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px; margin: 0 8px 8px 0;">`,
+ `<p data-ee-publish-chrome="true" style="font-size: 9px; line-height: 1.4; font-weight: 700; color: #6b7280; letter-spacing: 1px; margin: 0 0 5px;">${num}</p>`,
`<p data-ee-publish-chrome="true" style="font-size: 13px; font-weight: 800; color: #111827; margin: 0 0 3px; line-height: 1.3;">${shortTitle}</p>`,
- `<p data-ee-publish-chrome="true" style="font-size: 10px; color: #6b7280; margin: 0; line-height: 1.4;">${subTitle}</p>`,
+ `<p data-ee-publish-chrome="true" style="font-size: 10px; color: #6b7280; margin: 0; line-height: 1.4; word-break: break-word;">${subTitle}</p>`,
`</section>`,
].join("");
}).join("");
@@ -224,7 +230,7 @@ const applyLegacyWeChatStyles = (
`<section data-ee-publish-chrome="true" style="margin-bottom: 10px;">`,
`<p data-ee-publish-chrome="true" style="font-size: 10px; color: #9ca3af; margin: 0; text-transform: uppercase; letter-spacing: 2px; font-weight: 600;">${h2ListForToc.length} PARTS · 全文导览</p>`,
`</section>`,
- `<section data-ee-publish-chrome="true" style="font-size: 0;">${cardsHtml}</section>`,
+ `<section data-ee-publish-chrome="true" style="display: flex; flex-wrap: wrap; align-items: stretch; font-size: 0;">${cardsHtml}</section>`,
].join("");
h2ListForToc[0].parentElement?.insertBefore(toc, h2ListForToc[0]);
}