支持公开用户主页、帖子图缩略图与编辑器图组排版。
新增用户签名与活动统计、图片灯箱;正文按需生成缩略图;TipTap 支持多图分组与环绕排版,并注入站点标题避免刷新闪烁。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -50,16 +50,50 @@ function splitParagraphBreaks(html: string): string {
|
||||
|
||||
/** 为 Turndown 注册通用正文规则(不含 members-only) */
|
||||
function addTurndownContentRules(service: TurndownService): void {
|
||||
service.addRule('imageGroup', {
|
||||
filter: (node) =>
|
||||
node.nodeName === 'DIV' && (node as HTMLElement).hasAttribute('data-image-group'),
|
||||
replacement: (_content, node) => {
|
||||
const el = node as HTMLElement;
|
||||
const layout = el.getAttribute('data-layout') || 'cols-2';
|
||||
const imgs = [...el.querySelectorAll(':scope > img, :scope .image-group__grid > img')]
|
||||
.map(img => {
|
||||
const src = img.getAttribute('src') || '';
|
||||
const alt = img.getAttribute('alt') || '';
|
||||
return src ? `<img src="${src}" alt="${alt}">` : '';
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join('');
|
||||
if (!imgs) return '';
|
||||
return `\n\n<div data-image-group data-layout="${layout}" class="image-group image-group--${layout}">${imgs}</div>\n\n`;
|
||||
},
|
||||
});
|
||||
|
||||
service.addRule('image', {
|
||||
filter: 'img',
|
||||
replacement: (_content, node) => {
|
||||
const el = node as HTMLImageElement;
|
||||
// 已由图组规则处理的子图跳过
|
||||
if (el.closest('[data-image-group]')) return '';
|
||||
const alt = el.getAttribute('alt') ?? '';
|
||||
const src = el.getAttribute('src') ?? '';
|
||||
return src ? `` : '';
|
||||
if (!src) return '';
|
||||
const display = el.getAttribute('data-display');
|
||||
if (display && display !== 'default') {
|
||||
return `\n\n<img src="${src}" alt="${alt}" data-display="${display}" class="article-img article-img--${display}">\n\n`;
|
||||
}
|
||||
return ``;
|
||||
},
|
||||
});
|
||||
|
||||
// 清浮动段落:保留为 HTML,避免空行被 Markdown 折叠后绕排失效
|
||||
service.addRule('clearFloatParagraph', {
|
||||
filter: (node) =>
|
||||
node.nodeName === 'P' && (node as HTMLElement).hasAttribute('data-clear-float'),
|
||||
replacement: (content) =>
|
||||
`\n\n<p data-clear-float class="article-clear-float">${content}</p>\n\n`,
|
||||
});
|
||||
|
||||
service.addRule('underline', {
|
||||
filter: ['u'],
|
||||
replacement: (content) => `<u>${content}</u>`,
|
||||
|
||||
Reference in New Issue
Block a user