Merge pull request #5 from rebill/main

This commit is contained in:
ZhangJia
2026-02-05 12:01:59 +08:00
committed by GitHub
5 changed files with 45 additions and 23 deletions

View File

@@ -58,7 +58,8 @@
flex: 1;
display: flex;
align-items: flex-start;
word-break: break-all;
word-break: normal;
overflow-wrap: break-word;
}
.cover-subtitle {

View File

@@ -70,7 +70,8 @@ body {
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: auto;
word-break: break-all;
word-break: normal;
overflow-wrap: break-word;
}
.cover-subtitle {
@@ -199,7 +200,9 @@ body {
overflow-x: visible;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: normal;
white-space: pre-wrap;
font-size: 36px;
line-height: 1.5;

View File

@@ -2,9 +2,9 @@
"name": "md2redbook",
"version": "2.0.0",
"description": "小红书笔记素材创作工具 - 支持多种排版样式和智能分页",
"main": "scripts/render_xhs.js",
"main": "scripts/render_xhs_v2.js",
"scripts": {
"render": "node scripts/render_xhs.js",
"render": "node scripts/render_xhs_v2.js",
"install-browsers": "npx playwright install chromium"
},
"keywords": [
@@ -16,8 +16,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"js-yaml": "^4.1.0",
"marked": "^11.0.0",
"yaml": "^2.3.0",
"playwright": "^1.40.0"
"playwright": "^1.58.0"
}
}

View File

@@ -148,11 +148,19 @@ def generate_cover_html(metadata: dict, theme: str, width: int, height: int) ->
title = metadata.get('title', '标题')
subtitle = metadata.get('subtitle', '')
# 限制标题和副标题长度
if len(title) > 15:
title = title[:15]
if len(subtitle) > 15:
subtitle = subtitle[:15]
# 动态调整标题字体大小
title_len = len(title)
if title_len <= 6:
title_size = int(width * 0.14) # 极大
elif title_len <= 10:
title_size = int(width * 0.12) # 大
elif title_len <= 18:
title_size = int(width * 0.09) # 中
elif title_len <= 30:
title_size = int(width * 0.07) # 小
else:
title_size = int(width * 0.055) # 极小
# 获取主题背景色
theme_backgrounds = {
@@ -231,7 +239,7 @@ def generate_cover_html(metadata: dict, theme: str, width: int, height: int) ->
.cover-title {{
font-weight: 900;
font-size: {int(width * 0.12)}px;
font-size: {title_size}px;
line-height: 1.4;
background: {title_bg};
-webkit-background-clip: text;

View File

@@ -295,11 +295,19 @@ def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
title = metadata.get('title', '标题')
subtitle = metadata.get('subtitle', '')
# 限制标题和副标题长度
if len(title) > 15:
title = title[:15]
if len(subtitle) > 15:
subtitle = subtitle[:15]
# 动态调整标题字体大小
title_len = len(title)
if title_len <= 6:
title_size = 150 # 极大 (width * 0.14)
elif title_len <= 10:
title_size = 130 # 大 (width * 0.12)
elif title_len <= 18:
title_size = 100 # 中 (width * 0.09)
elif title_len <= 30:
title_size = 80 # 小 (width * 0.07)
else:
title_size = 60 # 极小 (width * 0.055)
# 暗黑模式特殊处理
is_dark = style_key == "dark"
@@ -335,14 +343,15 @@ def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
}}
.cover-emoji {{ font-size: 180px; line-height: 1.2; margin-bottom: 50px; }}
.cover-title {{
font-weight: 900; font-size: 130px; line-height: 1.4;
font-weight: 900; font-size: {title_size}px; line-height: 1.4;
background: {title_gradient};
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
flex: 1;
display: flex; align-items: flex-start;
word-break: break-all;
word-break: normal;
overflow-wrap: break-word;
}}
.cover-subtitle {{
font-weight: 350; font-size: 72px; line-height: 1.4;
@@ -463,7 +472,8 @@ def generate_card_html(content: str, page_number: int = 1, total_pages: int = 1,
overflow-x: visible;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: normal;
overflow-wrap: break-word;
white-space: pre-wrap;
font-size: 36px; line-height: 1.5;
}}