بنقرة واحدة
wenyan-xhs-pagination-debug
文言排版器小红书分页问题排查与修复
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
文言排版器小红书分页问题排查与修复
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
高德地图综合服务,支持POI搜索、路径规划、旅游规划、周边搜索和热力图数据可视化
Knowledge comic creator supporting multiple art styles and tones. Creates original educational comics with detailed panel layouts and sequential image generation. Use when user asks to create "知识漫画", "教育漫画", "biography comic", "tutorial comic", or "Logicomix-style comic".
Generate professional infographics with 21 layout types and 21 visual styles. Analyzes content, recommends layout×style combinations, and generates publication-ready infographics. Use when user asks to create "infographic", "visual summary", "信息图", "可视化", or "高密度信息大图".
Darwin Skill (达尔文.skill): autonomous skill optimizer inspired by Karpathy's autoresearch. Evaluates SKILL.md files using an 8-dimension rubric (structure + effectiveness), runs hill-climbing with git version control, validates improvements through test prompts, and generates visual result cards. Use when user mentions "优化skill", "skill评分", "自动优化", "auto optimize", "skill质量检查", "达尔文", "darwin", "帮我改改skill", "skill怎么样", "提升skill质量", "skill review", "skill打分".
从 DESIGN.md 生成预览图并截图的工作流 - 解决 Playwright 浏览器路径问题和 YAML 解析
Cron jobs auto-deliver final responses to configured targets — send_message to the same target gets deduplicated and skipped. Print report content directly as final response instead.
| name | wenyan-xhs-pagination-debug |
| description | 文言排版器小红书分页问题排查与修复 |
分页函数会执行两次:
所有 img: 0)横版 img: 5)移到下一页的图片在第二次 doSplit 时是第一个元素,offsetTop=0,之前的截断检测逻辑不适用。
// 问题代码:scaleCss 完全覆盖了 themeCss
const scaleCss = `
#wenyan { font-size: ...; line-height: ...; } // 这会覆盖 background-image!
`;
themeCss 中的 background-image 被完全覆盖。
doSplit 在隐藏的测量容器 (#wenyan-measure) 中执行,那里创建的 img 元素是新创建的,没有 landscape/portrait class。
// 问题:缩放比例 <40% 就移到下一页
if (scaleRatio >= 0.4) {
// 缩放
} else {
// 移到下一页 ← 导致很多图被错误分页
}
const scaleCss = `
:where(#wenyan) { font-size: ...; line-height: ...; }
:where(#wenyan) h1 { ... }
// ...
`;
在 renderMarkdown() 和小红书渲染时调用 detectAndApplyImageStyles():
function detectAndApplyImageStyles(container) {
const imgs = container.querySelectorAll('img');
imgs.forEach((img, idx) => {
if (img.classList.contains('landscape') || img.classList.contains('portrait')) {
return; // 已有 class 跳过
}
if (img.complete && img.naturalWidth > 0) {
applyImageOrientationStyle(img);
} else {
img.addEventListener('load', () => {
applyImageOrientationStyle(img);
});
img.addEventListener('error', () => {
img.classList.add('landscape'); // 失败默认横版
});
}
});
}
function detectImageOrientation(container, debug = false) {
imgs.forEach(img => {
// 新增:跳过已有 class
if (img.classList.contains('portrait') || img.classList.contains('landscape')) {
return;
}
// ... 检测逻辑 ...
// 强制重新计算布局
void img.offsetHeight;
});
}
#wenyan-measure img.landscape {
max-width:100% !important;
height:auto !important;
display:block !important;
}
const XHS_DIMENSIONS = {
'公众号宽度': { width: 700, height: 1000 },
'3:4': { width: 1080, height: 1440 },
'1:1': { width: 440, height: 440 },
};
if (hasLandscapeImg && targetImg) {
const remaining = maxContentH - currentH;
if (remaining > 0) {
// 强制缩放到剩余空间
const newHeight = Math.max(remaining, 50);
// 应用缩放...
continue;
}
}
在检测完图片方向后添加:
detectImageOrientation(measureContent, true);
void measureContent.offsetHeight; // 强制刷新布局
setTimeout(() => { ... }, 200);
关键发现:测量和渲染两阶段的尺寸比例完全不同:
| 阶段 | 容器宽度 | 字体计算 | 实际显示 |
|---|---|---|---|
| 测量 | 1080px | 16px × measureScale | 约 10px |
| 渲染 | 270px | 16px × (1080/440) ≈ 39px,然后 scale(0.25) | 约 10px |
但图片高度的问题更严重:
在 doSplit 函数中,把测量高度乘以 renderScale:
const renderScale = 270 / pageWidth; // 0.25 for 1080px
const actualBH = bH * renderScale; // 实际渲染高度
// 用 actualBH 替代 bH 进行分页计算
if (currentH + actualBH > maxContentH) {
pages.push(currentPage.map(b => b.outerHTML).join('\n'));
currentPage = [block];
currentH = padding + actualBH;
} else {
currentPage.push(block);
currentH += actualBH;
}
原默认值是「公众号宽度」(700×1000),应该是「3:4」(1080×1440)。
<select id="xhsRatio">
<option value="3:4" selected>3:4 (1080×1440)</option> <!-- 改为默认 -->
<option value="公众号宽度">公众号宽度 (700×1000)</option>
<option value="1:1">1:1 (440×440)</option>
</select>
正常工作的日志应该显示:
分页设置: pageWidth= 1080 pageHeight= 1440 PADDING= 59 MAX_CONTENT_H= 1263 measureScale= 0.614
图片 block 4 : tag= P height= 475 img.naturalHeight= 475
换页: currentH= 169 bH= 119 maxContentH= 1263 (换页高度应该是 119 左右,不是 475)
=== doSplit,total blocks: 58 所有 img: 5 横版 img: 5
分页结果: 共 5 页
注意图片 block 的 height 已经除以缩放比例了。
/opt/data/workspace/Projects/wenyan-editor/frontend/index.htmldoSplit(), splitContentIntoPages(), generateXhsPages(), detectAndApplyImageStyles(), detectImageOrientation():where(#wenyan) 避免覆盖背景图.landscape 添加 !important// 截图前临时移除 transform:scale
const origTransform = contentEl.style.transform;
contentEl.style.transform = 'none';
contentEl.style.width = dims.width + 'px';
await new Promise(r => setTimeout(r, 50));
// 使用实际渲染尺寸
const actualWidth = contentEl.offsetWidth;
const actualHeight = contentEl.offsetHeight;
const canvas = await html2canvas(contentEl, {
width: actualWidth,
height: actualHeight,
scale: 1,
useCORS: true,
allowTaint: true,
});
// 恢复原始样式
contentEl.style.transform = origTransform;
transform: scale(0.25) 让 html2canvas/html-to-image 测量尺寸时出错