chore: migrate repository to standard knowledge base layout

This commit is contained in:
tukuaiai
2026-05-02 03:29:06 +08:00
parent fb3bd75473
commit a23de97460
565 changed files with 687 additions and 711 deletions
Vendored Submodule
+1
Submodule tools/external/.tmux added at 87dcd13a28
+54
View File
@@ -0,0 +1,54 @@
# tools/external/ 目录 Agent 指南
本目录用于收纳 **外部工具/第三方项目**(含 Git submodule),保持“主仓库资产”和“外部依赖”边界清晰、可审计、可更新。
## 目录结构(约定)
```text
tools/external/
├── AGENTS.md # 本文件(目录级行为准则)
├── README.md # 外部工具索引
├── .tmux/ # submoduleoh-my-tmux 配置
├── tmux/ # submoduletmux 源码
├── claude-official-skills/ # submoduleClaude 官方 skills 仓库
├── Skill_Seekers-development/ # submoduleSkill Seekers 工具来源
├── html-tools-main/ # 普通目录:HTML 工具集
├── my-nvim/ # 普通目录:Neovim 配置
├── MCPlayerTransfer/ # 普通目录:MC 玩家迁移工具
└── XHS-image-to-PDF-conversion/ # 普通目录:图片合并 PDF 工具
```
## 当前软链接显示
```text
skills/claude-official-skills -> ../tools/external/claude-official-skills
skills/tmux-autopilot/assets/oh-my-tmux -> ../../../tools/external/.tmux
skills/tmux-autopilot/assets/tmux-src -> ../../../tools/external/tmux
skills/auto-skill/scripts/Skill_Seekers-development -> ../../../tools/external/Skill_Seekers-development
skills/auto-skill/scripts/skill-seekers-configs -> Skill_Seekers-development/configs
skills/auto-skill/scripts/skill-seekers-src -> Skill_Seekers-development/src
```
## 操作规范
### 允许
- 新增外部依赖(优先 Git submodule,确保可复现)
- 更新 submodule 指针(明确记录上游来源与用途)
- 用相对软链接把 `tools/external/` 下的事实来源暴露到其它目录,软链接目标必须仍在仓库内
- 为已复制进主仓库的外部源码建立清退计划:上游 URL、保留理由、迁移方式、验证命令
### 禁止 / 不推荐
- 直接复制粘贴大型第三方仓库内容到主仓库(优先 submodule)
- 将 submodule 替换为本地绝对路径软链接(会导致他人环境不可用)
- 提交第三方仓库的构建产物、生成物、运行时二进制或缓存目录
- 在主仓库直接魔改第三方源码快照;需要改造时先 fork,再以 submodule 指向 fork
## 仓库表达决策
1. **完整外部仓库**:优先使用 `git submodule`,主仓库只记录 commit 指针。
2. **同仓多入口展示**:使用相对软链接,例如 `skills/<name> -> ../tools/external/<name>`
3. **项目内小工具**:只有在无上游、体量小、与本项目强耦合时才直接追踪源码。
4. **生成输出**:默认不跟踪;若必须保留样例,只提交最小样例和生成说明。
5. **历史备份**`scripts/backups/` 按项目资产处理,不套用外部仓库清退规则。
+52
View File
@@ -0,0 +1,52 @@
# MC Player Transfer
Minecraft 基岩版角色转移工具 - 像泰拉瑞亚一样转移角色
## 项目结构
```
MCPlayerTransfer/
├── main.py # 主入口
├── requirements.txt # 依赖
├── README.md
├── src/
│ ├── __init__.py
│ ├── extract_player.py # 提取模块
│ └── import_player.py # 导入模块
├── input/ # 放入 .mcworld 文件
└── output/ # 输出 .dat 角色文件
```
## 安装
```bash
pip install -r requirements.txt
```
## 使用
### 提取角色
```bash
python main.py extract "input/World.mcworld"
```
### 导入角色
```bash
python main.py import "input/另一个世界.mcworld" "output/player.dat"
```
## 数据说明
提取的 `.dat` 文件包含角色全部数据:
- 背包物品
- 末影箱物品
- 潜影盒及内容
- 装备栏
- 经验等级
- 生命/饥饿值
- 位置坐标
## 注意事项
- 操作前备份存档
- 关闭游戏后操作
+243
View File
@@ -0,0 +1,243 @@
# MC Player Transfer 使用文档
## 简介
MC Player Transfer 是一个 Minecraft 基岩版角色转移工具,可以像泰拉瑞亚一样,将角色从一个世界完整转移到另一个世界。
### 支持转移的数据
- ✅ 背包全部物品
- ✅ 末影箱全部物品
- ✅ 潜影盒及其内部物品
- ✅ 装备栏(头盔、胸甲、护腿、靴子)
- ✅ 副手物品
- ✅ 经验等级
- ✅ 生命值 / 饥饿值
- ✅ 玩家坐标位置
- ✅ 游戏模式
- ✅ 物品附魔、耐久度等 NBT 数据
---
## 环境要求
- Python 3.8 或更高版本
- Windows 10/11WSL 环境)
---
## 安装步骤
### 1. 安装 Python 依赖
打开命令行,进入项目目录,执行:
```bash
pip install -r requirements.txt
```
或手动安装:
```bash
pip install amulet-core
```
### 2. 验证安装
```bash
python main.py
```
如果显示帮助信息,说明安装成功。
---
## 使用方法
### 方法一:提取角色数据
`.mcworld` 文件中的角色数据提取为独立的 `.dat` 文件。
**步骤:**
1. 将你的 `.mcworld` 存档文件放入 `input/` 文件夹
2. 执行命令:
```bash
python main.py extract "input/你的世界.mcworld"
```
3. 提取的角色数据会保存到 `output/` 文件夹,文件名格式:`世界名_时间戳.dat`
**示例:**
```bash
python main.py extract "input/World (2).mcworld"
```
输出:
```
正在解压: input/World (2).mcworld
找到数据库: /tmp/xxx/db
✓ 提取成功!
世界名称: World (2)
数据大小: 50617 bytes
输出文件: output/World (2)_20251216_084843.dat
```
---
### 方法二:导入角色数据
将 `.dat` 角色文件导入到另一个 `.mcworld` 存档中。
**步骤:**
1. 准备好目标世界的 `.mcworld` 文件
2. 准备好之前提取的 `.dat` 角色文件
3. 执行命令:
```bash
python main.py import "目标世界.mcworld" "output/角色数据.dat"
```
4. 生成的新存档文件名为 `目标世界_imported.mcworld`
**示例:**
```bash
python main.py import "我的世界.mcworld" "output/World (2)_20251216_084843.dat"
```
输出:
```
读取角色数据: 50617 bytes
正在解压: 我的世界.mcworld
✓ 角色数据已写入
正在打包: 我的世界_imported.mcworld
✓ 导入成功!
输出文件: 我的世界_imported.mcworld
```
---
## 完整使用流程示例
### 场景:将角色从「生存世界」转移到「新世界」
```bash
# 第一步:提取生存世界的角色
python main.py extract "input/生存世界.mcworld"
# 第二步:导入到新世界
python main.py import "input/新世界.mcworld" "output/生存世界_20251216_120000.dat"
# 第三步:将生成的 新世界_imported.mcworld 导入游戏
```
---
## 如何获取 .mcworld 文件
### 方法一:从游戏导出
1. 打开 Minecraft 基岩版
2. 进入「设置」→「存储」
3. 选择要导出的世界
4. 点击「导出世界」
5. 选择保存位置,得到 `.mcworld` 文件
### 方法二:从存档文件夹打包
Windows 存档位置:
```
C:\Users\用户名\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds\
```
将整个世界文件夹压缩为 `.zip`,然后改后缀为 `.mcworld`。
---
## 如何导入 .mcworld 文件到游戏
1. 双击 `.mcworld` 文件,游戏会自动导入
2. 或者将文件拖入游戏窗口
3. 或者手动解压到存档目录
---
## 项目目录结构
```
MCPlayerTransfer/
├── main.py # 主程序入口
├── requirements.txt # Python 依赖
├── README.md # 简要说明
├── src/ # 源代码
│ ├── __init__.py
│ ├── extract_player.py # 提取模块
│ └── import_player.py # 导入模块
├── docs/ # 文档
│ └── 使用文档.md
├── input/ # 输入文件夹(放 .mcworld 文件)
└── output/ # 输出文件夹(生成 .dat 文件)
```
---
## 常见问题
### Q: 提示找不到 leveldb 模块?
A: 执行 `pip install amulet-core`,这个包包含了所需的 leveldb 支持。
### Q: 提示找不到本地玩家数据?
A: 确保 `.mcworld` 文件是有效的基岩版存档,且曾经在单人模式下游玩过。
### Q: 导入后角色位置不对?
A: 角色数据包含坐标信息,导入后会保留原来的位置。如果新世界该位置是虚空,角色可能会掉落。建议先在新世界创建一个安全的出生点。
### Q: 可以转移多人服务器的角色吗?
A: 本工具只支持本地玩家(`~local_player`)。服务器玩家数据存储方式不同,暂不支持。
### Q: 原存档会被修改吗?
A: 不会。提取操作只读取数据,导入操作会生成新的 `_imported.mcworld` 文件,不修改原文件。
---
## 注意事项
⚠️ **重要提醒:**
1. **操作前务必备份存档**
2. **关闭游戏后再进行操作**
3. **导入会完全覆盖目标存档的本地玩家数据**
4. **建议先在测试存档上验证**
---
## 技术原理
Minecraft 基岩版使用 LevelDB 数据库存储世界数据。玩家数据存储在 key 为 `~local_player` 的条目中,格式为 NBT 二进制数据。
本工具的工作原理:
1. 解压 `.mcworld` 文件(本质是 ZIP 压缩包)
2. 打开 `db/` 目录中的 LevelDB 数据库
3. 读取或写入 `~local_player` 数据
4. 重新打包为 `.mcworld` 文件
---
## 更新日志
### v1.0.0 (2024-12-16)
- 初始版本
- 支持提取和导入本地玩家数据
- 支持 .mcworld 文件格式
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""
Minecraft 基岩版角色转移工具
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from extract_player import extract_player
from import_player import import_player
def main():
if len(sys.argv) < 2:
print("""
Minecraft 基岩版角色转移工具
============================
用法:
python main.py extract <.mcworld文件>
python main.py import <.mcworld文件> <.dat角色文件>
示例:
python main.py extract "input/World.mcworld"
python main.py import "input/World.mcworld" "output/player.dat"
""")
return
cmd = sys.argv[1].lower()
if cmd == 'extract':
if len(sys.argv) < 3:
print("错误: 请提供 .mcworld 文件路径")
return
extract_player(sys.argv[2], "output")
elif cmd == 'import':
if len(sys.argv) < 4:
print("错误: 请提供 .mcworld 文件和 .dat 角色文件")
return
import_player(sys.argv[2], sys.argv[3])
else:
print(f"未知命令: {cmd}")
if __name__ == '__main__':
main()
+1
View File
@@ -0,0 +1 @@
amulet-core>=1.9.0
+1
View File
@@ -0,0 +1 @@
# MC Player Transfer
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""
Minecraft 基岩版角色提取工具
输入: .mcworld 文件
输出: 角色数据文件 (.dat)
"""
import os
import sys
import zipfile
import tempfile
import shutil
from datetime import datetime
def extract_player(mcworld_path, output_dir="output"):
"""从 .mcworld 文件提取角色数据"""
if not os.path.exists(mcworld_path):
print(f"错误: 文件不存在 - {mcworld_path}")
return None
if not mcworld_path.endswith('.mcworld'):
print("错误: 请提供 .mcworld 文件")
return None
# 创建输出目录
os.makedirs(output_dir, exist_ok=True)
# 获取世界名称
world_name = os.path.splitext(os.path.basename(mcworld_path))[0]
# 创建临时目录解压
temp_dir = tempfile.mkdtemp()
try:
print(f"正在解压: {mcworld_path}")
with zipfile.ZipFile(mcworld_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# 查找 db 目录
db_path = os.path.join(temp_dir, 'db')
if not os.path.exists(db_path):
# 可能在子目录里
for root, dirs, files in os.walk(temp_dir):
if 'db' in dirs:
db_path = os.path.join(root, 'db')
break
if not os.path.exists(db_path):
print("错误: 找不到 db 目录")
return None
print(f"找到数据库: {db_path}")
# 打开 LevelDB
import leveldb
db = leveldb.LevelDB(db_path)
# 提取玩家数据
player_data = db.get(b'~local_player')
if not player_data:
print("错误: 找不到本地玩家数据")
return None
# 保存到输出目录
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = os.path.join(output_dir, f"{world_name}_{timestamp}.dat")
with open(output_file, 'wb') as f:
f.write(player_data)
print(f"\n✓ 提取成功!")
print(f" 世界名称: {world_name}")
print(f" 数据大小: {len(player_data)} bytes")
print(f" 输出文件: {output_file}")
del db
return output_file
finally:
# 清理临时目录
shutil.rmtree(temp_dir, ignore_errors=True)
def main():
if len(sys.argv) < 2:
print("""
Minecraft 基岩版角色提取工具
============================
用法:
python extract_player.py <.mcworld文件> [输出目录]
示例:
python extract_player.py "World.mcworld"
python extract_player.py "World.mcworld" ./output
输出:
角色数据文件 (.dat),可导入到其他存档
""")
return
mcworld_path = sys.argv[1]
output_dir = sys.argv[2] if len(sys.argv) > 2 else "output"
extract_player(mcworld_path, output_dir)
if __name__ == '__main__':
main()
+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
"""
Minecraft 基岩版角色导入工具
输入: .mcworld 文件 + .dat 角色文件
输出: 新的 .mcworld 文件
"""
import os
import sys
import zipfile
import tempfile
import shutil
from datetime import datetime
def import_player(mcworld_path, player_dat, output_path=None):
"""将角色数据导入到 .mcworld 文件"""
if not os.path.exists(mcworld_path):
print(f"错误: 文件不存在 - {mcworld_path}")
return None
if not os.path.exists(player_dat):
print(f"错误: 角色文件不存在 - {player_dat}")
return None
# 读取角色数据
with open(player_dat, 'rb') as f:
player_data = f.read()
print(f"读取角色数据: {len(player_data)} bytes")
# 默认输出路径
if output_path is None:
base = os.path.splitext(mcworld_path)[0]
output_path = f"{base}_imported.mcworld"
# 创建临时目录
temp_dir = tempfile.mkdtemp()
try:
print(f"正在解压: {mcworld_path}")
with zipfile.ZipFile(mcworld_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
# 查找 db 目录
db_path = os.path.join(temp_dir, 'db')
world_root = temp_dir
if not os.path.exists(db_path):
for root, dirs, files in os.walk(temp_dir):
if 'db' in dirs:
db_path = os.path.join(root, 'db')
world_root = root
break
if not os.path.exists(db_path):
print("错误: 找不到 db 目录")
return None
# 写入玩家数据
import leveldb
db = leveldb.LevelDB(db_path)
db.put(b'~local_player', player_data)
del db
print("✓ 角色数据已写入")
# 重新打包
print(f"正在打包: {output_path}")
with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(world_root):
for file in files:
file_path = os.path.join(root, file)
arc_name = os.path.relpath(file_path, world_root)
zipf.write(file_path, arc_name)
print(f"\n✓ 导入成功!")
print(f" 输出文件: {output_path}")
return output_path
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
def main():
if len(sys.argv) < 3:
print("""
Minecraft 基岩版角色导入工具
============================
用法:
python import_player.py <.mcworld文件> <.dat角色文件> [输出文件]
示例:
python import_player.py "World.mcworld" "player.dat"
python import_player.py "World.mcworld" "player.dat" "NewWorld.mcworld"
""")
return
mcworld_path = sys.argv[1]
player_dat = sys.argv[2]
output_path = sys.argv[3] if len(sys.argv) > 3 else None
import_player(mcworld_path, player_dat, output_path)
if __name__ == '__main__':
main()
+65
View File
@@ -0,0 +1,65 @@
# 🔌 tools/external:外部仓库与第三方工具
`tools/external/` 用来收纳第三方工具、外部依赖与 Git submodule。核心原则是:
- **尽量原样保留**:避免“魔改后不可升级”
- **隔离依赖与风险**:外部工具的依赖不要污染主仓库
- **可追溯**:来源、许可证、用法要写清楚
## 目录结构
```text
tools/external/
├── AGENTS.md # 本目录的 Agent 行为准则
├── README.md # 本文件(外部工具索引)
├── .tmux/ # submoduleoh-my-tmux 配置
├── tmux/ # submoduletmux 源码
├── claude-official-skills/ # submoduleClaude 官方 skills 仓库
├── Skill_Seekers-development/ # submoduleSkills 制作器
├── html-tools-main/ # HTML 工具集
├── my-nvim/ # Neovim 配置
├── MCPlayerTransfer/ # MC 玩家迁移工具
└── XHS-image-to-PDF-conversion/ # 图片合并 PDF 工具
```
## 工具清单
- `Skill_Seekers-development/`:以 submodule 引入的 Skills 抓取/制作器
- `.tmux/`:以 submodule 引入的 oh-my-tmux 配置来源
- `tmux/`:以 submodule 引入的 tmux 上游源码
- `claude-official-skills/`:以 submodule 引入的 Claude 官方 skills 仓库
- `html-tools-main/`HTML 工具集
- `my-nvim/`:个人 Neovim 配置
- `MCPlayerTransfer/`MC 玩家迁移工具
- `XHS-image-to-PDF-conversion/`:图片合并 PDF 工具
## 相关迁移
- 提示词转换工具已迁移到 `tools/prompts-library/`
- AI 聊天记录保存工具已迁移到 `tools/chat-vault/`
- 备份脚本已迁移到 `scripts/backups/`
- 技能库入口已迁移到 `skills/`
## 当前软链接显示
| 事实来源 | 展示入口 | 说明 |
|:---|:---|:---|
| `tools/external/.tmux/` | `skills/tmux-autopilot/assets/oh-my-tmux` | oh-my-tmux 配置来源 |
| `tools/external/tmux/` | `skills/tmux-autopilot/assets/tmux-src` | tmux 上游源码入口 |
| `tools/external/claude-official-skills/` | `skills/claude-official-skills` | Claude 官方 skills 仓库 |
| `tools/external/Skill_Seekers-development/` | `skills/auto-skill/scripts/Skill_Seekers-development` | `auto-skill` 的 Skill Seekers 工具来源 |
## 表达规则
- 完整外部仓库:优先 `git submodule add <url> tools/external/<name>`
- 跨目录展示入口:使用相对软链接,例如 `skills/<name> -> ../tools/external/<name>`
- 不允许:软链接到本机绝对路径、复制大型上游源码、提交构建产物/生成物、提交二进制运行时。
- 需要本地改造第三方工具时:优先 fork 后以 submodule 指向 fork;不要在主仓库直接魔改一份不可升级的源码快照。
## 新增外部工具(最小清单)
1. 优先新增 submodule`git submodule add <url> tools/external/<tool-name>`
2. 只在没有上游仓库、且体量小/与本项目强耦合时,才创建普通目录:`tools/external/<tool-name>/`
3. 必备文件:`README.md`(用途/入口/依赖/输入输出)、许可证与来源说明(如 `LICENSE` / `SOURCE.md`)。
4. 依赖约束:尽量使用工具自带的虚拟环境/容器化方式,不影响仓库其他部分。
5. 文档同步:在本 README 增加一行工具说明,保证可发现性。
@@ -0,0 +1,10 @@
# 贡献指南
欢迎贡献!
## 如何贡献
1. 修复 Bug / 改进功能:请在 `README.md` 的“快速开始/使用方式”验证脚本可运行。
2. 新增功能:请同时补充最小示例与必要的依赖说明。
3. 提交 PR:描述改动内容、使用方式与验证步骤。
+176
View File
@@ -0,0 +1,176 @@
<div align="center">
# 📚 小红书图文批量转 PDF
### Batch Convert XHS Images to PDF
**一个智能 Python 脚本,用于将从小红书批量下载的 ZIP 压缩包,按顺序自动拼接为清晰的 PDF 文件。**
*A smart Python script that automatically converts ZIP archives from Xiaohongshu into well-ordered PDF files.*
---
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![Status: Active](https://img.shields.io/badge/Status-Active-success.svg?style=for-the-badge)]()
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=for-the-badge)]()
[![Language: Python](https://img.shields.io/badge/Language-Python-orange.svg?style=for-the-badge)]()
[✨ 功能特性](#-功能特性) • [⚙️ 工作流程](#-工作流程) • [🚀 快速开始](#-快速开始) • [🗂️ 项目结构](#-项目结构) • [🤝 参与贡献](#-参与贡献)
</div>
---
## ✨ 功能特性
| 特性 | 描述 |
|:---:|:---|
| 📦 **全自动处理** | 无需手动解压,脚本自动处理 `.zip` 压缩包。 |
| 🔢 **智能自然排序** | 完美处理 `1, 2, ... 10, 11` 这样的文件名排序,确保图片顺序正确。 |
| 🚀 **批量转换** | 支持一次性转换文件夹内的所有 `.zip` 文件,省时省力。 |
| 🗑️ **自动清理** | 转换成功后,自动删除原始的 `.zip` 文件和临时文件,保持目录整洁。 |
| 📖 **PDF 优化** | 生成的 PDF 文件经过优化,保证清晰度的同时控制文件大小。 |
| 💻 **跨平台兼容** | 依赖的 `Pillow` 库和 Python 脚本可在 Windows, macOS, Linux 上运行。 |
---
## ⚙️ 工作流程
<table>
<tr>
<td width="50%">
脚本的核心逻辑非常简单直接:监控并处理文件夹内的 ZIP 文件,通过一系列自动化步骤输出 PDF。
### 核心步骤
1. **扫描**: 查找当前目录下的所有 `.zip` 文件。
2. **解压**: 将找到的 `.zip` 文件解压到临时目录。
3. **排序**: 智能地对所有图片文件进行“自然排序”。
4. **合并**: 将排序后的图片合并成一个 PDF 文件。
5. **清理**: 删除原始的 `.zip` 文件和临时文件夹。
</td>
<td width="50%">
```mermaid
graph TD
A[📁 放置 .zip 文件] --> B{运行 pdf.py 脚本};
B --> C[🔄 解压到临时目录];
C --> D[🔢 按文件名自然排序];
D --> E[🖼️ 合并图片为 PDF];
E --> F[📄 生成 output.pdf];
F --> G[🗑️ 删除原 .zip 文件];
G --> H[✅ 完成];
```
</td>
</tr>
</table>
---
## 🚀 快速开始
### 1. 环境准备
首先,确保你的电脑上安装了 **Python 3**
然后,将本项目克隆到你的本地:
```bash
git clone https://github.com/tukuaiai/XHS-image-to-PDF-conversion.git
cd XHS-image-to-PDF-conversion
```
### 2. 安装依赖
本项目依赖 `Pillow` 库来处理图片。运行以下命令安装它:
```bash
pip install -r requirements.txt
```
或者,你也可以使用 `Makefile` (如果你的系统支持 `make`):
```bash
make install
```
### 3. 下载图文
使用你喜欢的浏览器扩展(如推荐的 **小地瓜**)从小红书下载图文,并确保它们是 `.zip` 格式。
- **小地瓜 - 小红书图片视频下载助手**: [Firefox 扩展](https://addons.mozilla.org/zh-CN/firefox/addon/%E5%B0%8F%E5%9C%B0%E7%93%9C-%E5%B0%8F%E7%BA%A2%E4%B9%A6%E5%9B%BE%E7%89%87%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD%E5%8A%A9%E6%89%8B/)
### 4. 运行脚本
<details>
<summary><b>模式一:批量处理所有 ZIP 文件 (推荐)</b></summary>
1. 将所有下载的 `.zip` 文件移动到本项目文件夹中。
2. 直接运行 `pdf.bat` (Windows) 或在终端中运行以下命令:
```bash
python pdf.py
```
或者使用 `make`:
```bash
make run
```
3. 脚本会自动处理文件夹内所有的 `.zip` 文件。
</details>
<details>
<summary><b>模式二:处理单个 ZIP 文件</b></summary>
如果你只想处理一个文件,可以使用拖放或命令行参数:
1. **拖放 (Windows)**: 将一个 `.zip` 文件直接拖到 `pdf.bat` 图标上。
2. **命令行**:
```bash
python pdf.py "你的文件路径.zip"
```
</details>
---
## 🗂️ 项目结构
```
XHS-image-to-PDF-conversion/
├── .git/
├── docs/ # (未来可能添加的文档)
├── 📚...pdf # (示例文件)
├── pdf.bat # Windows 批处理脚本
├── pdf.py # 核心 Python 脚本
├── Makefile # 自动化命令
├── requirements.txt # Python 依赖
├── README.md # 你正在阅读的这个文件
├── LICENSE # MIT 许可证
├── CODE_OF_CONDUCT.md # 社区行为准则
└── CONTRIBUTING.md # 贡献指南
```
---
## 🤝 参与贡献
我们欢迎任何形式的贡献!无论是报告 Bug、提出功能建议还是直接贡献代码。
请参考我们的 [**贡献指南 (CONTRIBUTING.md)**](CONTRIBUTING.md) 来了解如何参与。
---
## 📜 许可证
本项目采用 [MIT](https://opensource.org/licenses/MIT) 许可证。
---
<div align="center">
**如果这个项目对你有帮助,请给一个 Star ⭐!**
[![Star History Chart](https://api.star-history.com/svg?repos=tukuaiai/XHS-image-to-PDF-conversion&type=Date)](https://star-history.com/#tukuaiai/XHS-image-to-PDF-conversion&Date)
---
**Made with 🐍 & ❤️ by tukuaiai**
[⬆ 回到顶部](#-小红书图文批量转-pdf)
</div>
+2
View File
@@ -0,0 +1,2 @@
python pdf.py
pause
+195
View File
@@ -0,0 +1,195 @@
#!/usr/bin/env python3
"""
图片ZIP转PDF脚本
将ZIP文件中的图片按序号排序并拼接成PDF文件
"""
import zipfile
import os
import re
from PIL import Image
import shutil
def 自然排序键(文件名):
"""将文件名转换为自然排序键,支持数字排序"""
return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', 文件名)]
def zip转pdf(zip路径):
"""
将ZIP文件中的图片排序后转换为PDF
Args:
zip路径: ZIP文件的完整路径
Returns:
成功返回PDF路径,失败返回None
"""
try:
# 获取ZIP文件名(不含扩展名)
zip目录, zip文件名 = os.path.split(zip路径)
pdf名称 = os.path.splitext(zip文件名)[0] + '.pdf'
pdf路径 = os.path.join(zip目录, pdf名称)
print(f"正在处理: {zip文件名}")
# 创建临时目录解压文件
临时目录 = os.path.join(zip目录, 'temp_extract')
if os.path.exists(临时目录):
shutil.rmtree(临时目录)
os.makedirs(临时目录)
# 解压ZIP文件
with zipfile.ZipFile(zip路径, 'r') as zip文件:
zip文件.extractall(临时目录)
# 获取所有图片文件
支持的格式 = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp'}
图片文件 = []
for 根目录, 目录, 文件列表 in os.walk(临时目录):
for 文件 in 文件列表:
if any(文件.lower().endswith(格式) for 格式 in 支持的格式):
完整路径 = os.path.join(根目录, 文件)
图片文件.append(完整路径)
if not 图片文件:
print("错误: ZIP文件中没有找到图片文件")
shutil.rmtree(临时目录)
return None
# 按文件名自然排序
图片文件.sort(key=lambda x: 自然排序键(os.path.basename(x)))
print(f"找到 {len(图片文件)} 张图片,开始转换...")
# 打开第一张图片作为基础
图片对象列表 = []
for 图片路径 in 图片文件:
try:
图片 = Image.open(图片路径)
# 转换为RGB模式(确保兼容性)
if 图片.mode != 'RGB':
图片 = 图片.convert('RGB')
图片对象列表.append(图片)
except Exception as e:
print(f"警告: 无法打开图片 {图片路径}: {e}")
continue
if not 图片对象列表:
print("错误: 没有成功加载任何图片")
shutil.rmtree(临时目录)
return None
# 保存为PDF(第一张作为主图,其余附加)
图片对象列表[0].save(
pdf路径,
"PDF",
quality=95,
optimize=True,
save_all=True,
append_images=图片对象列表[1:]
)
# 关闭所有图片对象
for 图片 in 图片对象列表:
图片.close()
# 清理临时文件
shutil.rmtree(临时目录)
# 删除原ZIP文件
os.remove(zip路径)
print(f"✓ 成功创建PDF: {pdf名称}")
print(f"✓ 已删除原ZIP文件: {zip文件名}")
return pdf路径
except zipfile.BadZipFile:
print(f"错误: {zip路径} 不是有效的ZIP文件")
return None
except Exception as e:
print(f"处理过程中出错: {e}")
# 清理临时文件
if '临时目录' in locals() and os.path.exists(临时目录):
shutil.rmtree(临时目录)
return None
def 批量处理当前目录():
"""批量处理当前目录下所有ZIP文件"""
当前目录 = os.getcwd()
zip文件列表 = []
# 扫描当前目录所有ZIP文件
for 文件 in os.listdir(当前目录):
if 文件.lower().endswith('.zip'):
zip文件列表.append(os.path.join(当前目录, 文件))
if not zip文件列表:
print("当前目录下没有找到ZIP文件")
return
print(f"发现 {len(zip文件列表)} 个ZIP文件,开始批量处理...")
print("-" * 50)
成功计数 = 0
失败计数 = 0
for zip路径 in zip文件列表:
print(f"\n[{zip文件列表.index(zip路径) + 1}/{len(zip文件列表)}] 处理: {os.path.basename(zip路径)}")
# 执行转换
结果 = zip转pdf(zip路径)
if 结果:
成功计数 += 1
else:
失败计数 += 1
print("-" * 50)
print(f"批量处理完成!成功: {成功计数} 个,失败: {失败计数}")
def 处理指定文件(zip路径):
"""处理指定的单个ZIP文件"""
if not os.path.exists(zip路径):
print(f"错误: 找不到文件 {zip路径}")
return False
if not zip路径.lower().endswith('.zip'):
print("错误: 请提供ZIP格式的文件")
return False
# 执行转换
结果 = zip转pdf(zip路径)
if 结果:
print(f"\n🎉 任务完成!PDF文件已保存为: {结果}")
return True
else:
print("\n❌ 任务失败,请检查错误信息")
return False
def 主函数():
"""主函数:智能处理模式"""
import sys
# 优先处理指定文件(如果存在)
指定文件路径 = r"C:\Users\lenovo\Desktop\新建文件夹\剥头皮量化策略全拆解:低延迟、高频的底层.zip"
# 检查是否有命令行参数
if len(sys.argv) > 1:
# 命令行指定了ZIP文件路径
zip路径 = sys.argv[1]
print(f"通过命令行参数指定文件: {zip路径}")
处理指定文件(zip路径)
elif os.path.exists(指定文件路径):
# 处理默认指定文件
print(f"处理默认指定文件: {os.path.basename(指定文件路径)}")
处理指定文件(指定文件路径)
else:
# 自动扫描当前目录所有ZIP文件
print("开始扫描当前目录所有ZIP文件...")
批量处理当前目录()
if __name__ == "__main__":
主函数()
@@ -0,0 +1 @@
Pillow
+74
View File
@@ -0,0 +1,74 @@
# HTML Tools
**HTML 工具集:集成多种独立 HTML 工具,涵盖单一或多功能设计,致力于一键高效完成任务。**
## 项目简介
HTML Tools 是一个集合各种 HTML 工具的项目,旨在帮助开发者快速、高效地完成 HTML 页面相关的任务。无论是单一功能的小工具,还是集成多种功能的工具,这个项目都能够满足您的需求。
---
## 功能特色
- **多种工具集成**:提供从简单到复杂 HTML 操作的工具。
- **高效便捷**:一键式操作,快速完成目标任务。
- **模块化设计**:工具独立,便于扩展和维护。
- **开源免费**:完全开源,欢迎贡献。
---
## 安装与使用
### 1. 克隆仓库
```bash
git clone https://github.com/fud114514/html-tools.git
cd html-tools
```
### 2. 打开工具
- 将工具直接部署在浏览器中运行,或者在本地 HTML 文件中打开。
- 无需安装额外依赖。
### 3. 贡献代码
如果您有兴趣为项目贡献代码,请按照以下步骤进行:
1. Fork 本仓库。
2. 创建自己的分支:`git checkout -b feature/your-feature`
3. 提交更改:`git commit -m 'Add some feature'`
4. 推送分支到 GitHub`git push origin feature/your-feature`
5. 提交 Pull Request。
---
## 文件结构
```plaintext
html-tools/
├── index.html # 主页面
├── tools/ # 各种独立工具文件
├── assets/ # 静态资源 (如图片、样式表)
└── README.md # 项目文档
```
---
## 参与贡献
欢迎大家为 HTML Tools 项目贡献自己的力量!无论是修复问题、添加新功能或改进文档,您的每一个贡献都对我们非常重要。
### 提交 Issue
如果您在使用过程中遇到问题,可以通过 [Issue 页面](https://github.com/fud114514/html-tools/issues) 提交问题。
### 提交 Pull Request
详细步骤请参考上文的“贡献代码”部分。
---
## 开发者
该项目由 [fud114514](https://github.com/fud114514) 开发和维护。
---
## 许可证
本项目采用 [MIT 许可证](https://opensource.org/licenses/MIT) 开源,详情请参阅 [LICENSE 文件](https://github.com/fud114514/html-tools/blob/main/LICENSE)。
+424
View File
@@ -0,0 +1,424 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EPUB CSS 清理工具 (Web版)</title>
<style>
body {
font-family: sans-serif;
line-height: 1.6;
padding: 20px;
max-width: 600px;
margin: 20px auto;
background-color: #f4f4f4;
border: 1px solid #ccc;
border-radius: 8px;
}
h1 {
text-align: center;
color: #333;
}
#drop-area {
border: 2px dashed #ccc;
border-radius: 5px;
padding: 30px;
text-align: center;
background-color: #fff;
margin-bottom: 20px;
cursor: pointer;
}
#drop-area.highlight {
border-color: dodgerblue;
}
#drop-area p {
margin: 0;
color: #555;
}
#fileInput {
display: none; /* Hide default input, use drop area or label */
}
label.file-label {
display: inline-block;
padding: 10px 15px;
background-color: dodgerblue;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
transition: background-color 0.2s;
}
label.file-label:hover {
background-color: #007ae5;
}
#status {
margin-top: 15px;
padding: 10px;
background-color: #eee;
border-radius: 4px;
min-height: 40px; /* Ensure space for messages */
text-align: center;
font-weight: bold;
}
.status-details {
font-size: 0.9em;
color: #555;
margin-top: 5px;
}
.warning {
color: #a00;
font-weight: bold;
text-align: center;
margin-top: 20px;
padding: 10px;
background-color: #fdd;
border: 1px solid #fbb;
border-radius: 4px;
}
progress {
width: 100%;
margin-top: 10px;
display: none; /* Hidden by default */
}
</style>
<!-- Include JSZip library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<!-- Include FileSaver.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
</head>
<body>
<h1>EPUB CSS 清理工具 (Web版)</h1>
<p>将单个 EPUB 文件或包含多个 EPUB 的 ZIP 文件拖拽到下方区域,或点击按钮选择文件,即可移除指定的 CSS 样式。</p>
<div id="drop-area">
<!-- Accept both .epub and .zip -->
<input type="file" id="fileInput" accept=".epub,.zip">
<p>将 EPUB 或 ZIP 文件拖拽到这里</p>
<label for="fileInput" class="file-label">或者选择文件</label>
</div>
<progress id="progressBar" value="0" max="100"></progress>
<div id="status">请选择或拖拽一个 EPUB 或 ZIP 文件。</div>
<div id="statusDetails" class="status-details"></div>
<div class="warning">
<strong>重要提示:</strong> 此工具在你的浏览器中处理文件,不会上传到服务器。处理后的文件需要你手动下载。建议在处理前备份原始文件!处理 ZIP 文件时,会生成一个包含所有处理后(或原始)EPUB 的新 ZIP 文件。
</div>
<script>
// --- Check if libraries loaded ---
if (typeof JSZip === 'undefined' || typeof saveAs === 'undefined') {
const errorMsg = '错误:无法加载必需的库 (JSZip 或 FileSaver)。请检查您的网络连接,并确保没有浏览器插件(如广告拦截器)阻止从 cdnjs.cloudflare.com 加载脚本。然后请刷新页面重试。';
document.getElementById('status').textContent = errorMsg;
document.getElementById('status').style.color = '#a00';
document.getElementById('drop-area').style.display = 'none';
document.querySelector('.warning').textContent = errorMsg;
} else {
// --- Global Variables & Constants ---
const dropArea = document.getElementById('drop-area');
const fileInput = document.getElementById('fileInput');
const statusDiv = document.getElementById('status');
const statusDetailsDiv = document.getElementById('statusDetails');
const progressBar = document.getElementById('progressBar');
const CSS_REMOVE_PATTERN = /((text-indent|line-height|font-size|height|font-family|color)\s*:\s*[^;]*;|display\s*:\s*block\s*;)/ig;
// --- Event Handlers ---
setupDragDropHandlers();
fileInput.addEventListener('change', handleFileSelect, false);
function setupDragDropHandlers() {
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, () => dropArea.classList.add('highlight'), false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, () => dropArea.classList.remove('highlight'), false);
});
dropArea.addEventListener('drop', handleDrop, false);
}
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function handleDrop(e) {
handleFiles(e.dataTransfer.files);
}
function handleFileSelect(e) {
handleFiles(e.target.files);
}
// --- Main File Handling Logic ---
function handleFiles(files) {
if (files.length === 0) return;
const file = files[0]; // Process only the first file
// Check file type
const isEpub = file.name.toLowerCase().endsWith('.epub');
const isZip = file.name.toLowerCase().endsWith('.zip');
if (!isEpub && !isZip) {
updateStatus('错误:请选择一个 .epub 或 .zip 文件。', true);
resetInput();
return;
}
updateStatus(`正在读取文件: ${file.name}...`);
clearStatusDetails();
progressBar.style.display = 'block';
progressBar.value = 0;
const reader = new FileReader();
reader.onload = async (e) => {
const fileContent = e.target.result; // ArrayBuffer
try {
if (isEpub) {
updateStatus(`正在处理 EPUB 文件: ${file.name}...`);
const result = await processEpub(fileContent, file.name);
if (result.blob) {
saveAs(result.blob, result.filename);
updateStatus(`处理完成!已生成 ${result.filename}`);
} else if (result.modified === false) {
updateStatus('信息:文件无需修改。');
}
resetInput();
} else if (isZip) {
updateStatus(`正在处理 ZIP 压缩包: ${file.name}...`);
await processZipArchive(fileContent, file.name);
}
} catch (error) {
console.error("处理失败:", error);
updateStatus(`处理失败:${error.message}`, true);
resetInput();
}
};
reader.onprogress = updateReadProgress;
reader.onerror = handleReadError;
reader.readAsArrayBuffer(file);
}
function updateReadProgress(e) {
if (e.lengthComputable) {
progressBar.value = Math.round((e.loaded / e.total) * 10); // Reading is ~10%
}
}
function handleReadError() {
updateStatus('错误:读取文件时出错。', true);
resetInput();
}
// --- ZIP Archive Processing ---
async function processZipArchive(zipFileContent, zipFilename) {
let outputZip = new JSZip();
let processedCount = 0;
let failedCount = 0;
let foundCount = 0;
let modifiedCount = 0;
let filePromises = [];
updateStatus(`正在打开 ZIP 压缩包...`);
progressBar.value = 15;
const inputZip = await JSZip.loadAsync(zipFileContent);
const totalFilesInZip = Object.keys(inputZip.files).length;
updateStatus(`在 ZIP 中查找 EPUB 文件...`);
inputZip.forEach((relativePath, zipEntry) => {
if (!zipEntry.dir && relativePath.toLowerCase().endsWith('.epub')) {
foundCount++;
updateStatusDetails(`找到 EPUB: ${relativePath}`);
// Add a promise to process this EPUB entry
const promise = zipEntry.async('arraybuffer')
.then(async (innerEpubContent) => {
try {
// Process the inner EPUB
const result = await processEpub(innerEpubContent, relativePath);
if (result.blob) {
// Add modified EPUB to output ZIP
outputZip.file(result.filename, result.blob);
modifiedCount++;
console.log(`Added cleaned ${result.filename} to output zip.`);
} else {
// Add original EPUB back if not modified
outputZip.file(relativePath, innerEpubContent);
console.log(`Added original ${relativePath} (no changes needed) to output zip.`);
}
processedCount++;
} catch (epubError) {
// Add original EPUB back if processing failed
console.error(`Error processing inner EPUB ${relativePath}:`, epubError);
updateStatusDetails(`处理 ${relativePath} 时出错,将保留原文件。`);
outputZip.file(relativePath, innerEpubContent); // Add original back
failedCount++;
}
})
.catch(extractError => {
// Handle error extracting the inner EPUB content
console.error(`Error extracting inner EPUB ${relativePath} from zip:`, extractError);
updateStatusDetails(`无法从 ZIP 中提取 ${relativePath},已跳过。`);
failedCount++;
})
.finally(() => {
// Update progress based on entries processed (success or fail)
const progress = 15 + Math.round(((processedCount + failedCount) / foundCount) * 60); // Processing EPUBs is ~60%
progressBar.value = Math.min(progress, 75); // Cap at 75 before final packing
});
filePromises.push(promise);
}
// We are currently NOT adding non-EPUB files from the source ZIP to the output ZIP.
// To do so, handle the 'else' case here and add zipEntry data to outputZip.
});
// Wait for all inner EPUB processing promises to complete
await Promise.all(filePromises);
progressBar.value = 80; // Done processing files inside zip
if (foundCount === 0) {
updateStatus('错误:在 ZIP 文件中未找到任何 EPUB 文件。', true);
resetInput();
return;
}
updateStatus(`处理了 ${foundCount} 个 EPUB 文件。正在生成输出 ZIP...`);
statusDetailsDiv.innerHTML += `<br>成功: ${processedCount}, 修改: ${modifiedCount}, 失败/跳过: ${failedCount}`;
progressBar.value = 90;
const outputZipBlob = await outputZip.generateAsync({
type: "blob",
compression: "DEFLATE",
platform: "browser"
}, (metadata) => {
progressBar.value = 90 + Math.round(metadata.percent * 0.1);
});
progressBar.value = 100;
const baseName = zipFilename.substring(0, zipFilename.lastIndexOf('.')) || zipFilename;
const outputZipFilename = `${baseName}_cleaned.zip`;
saveAs(outputZipBlob, outputZipFilename);
updateStatus(`处理完成!已生成包含处理后 EPUB 的 ${outputZipFilename}`);
resetInput();
}
// --- Single EPUB Processing (Modified to return result) ---
async function processEpub(fileContent, originalFilename) {
// This function now returns an object:
// { blob: Blob, filename: string } if modified
// { modified: false } if no modification needed
// Throws error if processing fails critically
console.log(`Processing EPUB: ${originalFilename}`);
// Note: Progress bar updates inside this function are less meaningful now,
// as the overall progress is handled by the caller (handleFiles or processZipArchive).
// We could pass a progress callback if detailed inner progress is needed.
const zip = await JSZip.loadAsync(fileContent);
const newZip = new JSZip();
let cssFilesFound = false;
let modified = false;
let filePromises = [];
zip.forEach((relativePath, zipEntry) => {
if (zipEntry.dir) { newZip.folder(relativePath); return; }
const options = {
date: zipEntry.date,
unixPermissions: zipEntry.unixPermissions,
dosPermissions: zipEntry.dosPermissions,
comment: zipEntry.comment,
dir: zipEntry.dir,
compression: zipEntry.options?.compression === "STORE" ? "STORE" : "DEFLATE"
};
if (relativePath.toLowerCase() === 'mimetype') {
const promise = zipEntry.async('uint8array').then(data => {
newZip.file(relativePath, data, { ...options, compression: "STORE" });
});
filePromises.push(promise);
} else if (relativePath.toLowerCase().endsWith('.css')) {
cssFilesFound = true;
const promise = zipEntry.async('string').then(originalCss => {
const cleanedCss = originalCss.replace(CSS_REMOVE_PATTERN, '');
let contentToAdd = originalCss;
if (cleanedCss !== originalCss) {
modified = true;
contentToAdd = cleanedCss;
console.log(` Cleaned CSS: ${relativePath}`);
}
newZip.file(relativePath, contentToAdd, options);
}).catch(err => {
console.warn(` Could not process CSS ${relativePath} as text, keeping original. Error: ${err}`);
return zipEntry.async('uint8array').then(originalData => {
newZip.file(relativePath, originalData, options);
});
});
filePromises.push(promise);
} else {
const promise = zipEntry.async('uint8array').then(data => {
newZip.file(relativePath, data, options);
});
filePromises.push(promise);
}
});
await Promise.all(filePromises);
if (!modified) {
console.log(` EPUB ${originalFilename} - No modifications needed.`);
return { modified: false }; // Indicate no changes were made
}
console.log(` Repacking modified EPUB: ${originalFilename}`);
const newEpubBlob = await newZip.generateAsync({
type: "blob",
mimeType: "application/epub+zip",
compression: "DEFLATE",
platform: "browser"
});
const baseName = originalFilename.substring(0, originalFilename.lastIndexOf('.')) || originalFilename;
const newFilename = `${baseName}_cleaned.epub`;
return { blob: newEpubBlob, filename: newFilename }; // Return data for the caller
} // end of processEpub function
// --- UI Update Functions ---
function updateStatus(message, isError = false) {
statusDiv.textContent = message;
statusDiv.style.color = isError ? '#a00' : '#000';
if (isError) {
progressBar.style.display = 'none';
clearStatusDetails();
}
}
function updateStatusDetails(message) {
statusDetailsDiv.innerHTML += message + "<br>";
}
function clearStatusDetails() {
statusDetailsDiv.innerHTML = "";
}
function resetInput() {
fileInput.value = '';
// Hide progress bar after a delay
setTimeout(() => { progressBar.style.display = 'none'; progressBar.value = 0; }, 5000);
}
} // End of the 'else' block for library check
</script>
</body>
</html>
+303
View File
@@ -0,0 +1,303 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Editor</title>
<style>
:root {
--border-color: #eee;
--bg-color: #fafafa;
--text-color: #333;
--btn-border: #ddd;
--code-bg: #f5f5f5;
--scrollbar-color: #ccc;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
overflow: hidden;
}
.header {
padding: 8px 20px;
background: var(--bg-color);
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: flex-end;
align-items: center;
font-size: 14px;
color: var(--text-color);
}
.toolbar {
display: flex;
gap: 8px;
}
.btn {
border: 1px solid var(--btn-border);
background: white;
padding: 4px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
color: var(--text-color);
min-width: 80px;
text-align: center;
transition: background-color 0.2s ease;
}
.btn:hover {
background: var(--code-bg);
}
.content {
display: flex;
flex: 1;
overflow: hidden;
}
#preview, #editor {
width: 50%;
height: 100%;
padding: 20px;
line-height: 1.6;
}
#preview {
color: var(--text-color);
border-right: 1px solid var(--border-color);
overflow-y: auto;
}
#editor {
font-family: monospace;
font-size: 14px;
border: none;
outline: none;
resize: none;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: var(--scrollbar-color) transparent;
}
#editor::-webkit-scrollbar {
width: 8px;
}
#editor::-webkit-scrollbar-thumb {
background-color: var(--scrollbar-color);
border-radius: 4px;
}
#editor::-webkit-scrollbar-track {
background-color: transparent;
}
.preview-content {
height: auto;
min-height: 100%;
padding-right: 8px;
}
#preview h1, #preview h2, #preview h3 {
margin: 16px 0;
font-weight: 500;
}
#preview h1:first-child {
margin-top: 0;
}
#preview p {
margin: 12px 0;
}
#preview ul, #preview ol {
padding-left: 24px;
margin: 12px 0;
}
#preview code {
background-color: var(--code-bg);
padding: 2px 4px;
border-radius: 3px;
font-size: 0.9em;
}
#preview pre code {
display: block;
padding: 12px;
overflow-x: auto;
line-height: 1.45;
}
.toast {
position: fixed;
top: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 8px 16px;
border-radius: 4px;
font-size: 14px;
display: none;
z-index: 1000;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<div class="header">
<div class="toolbar">
<button class="btn" id="copyBtn">一键复制</button>
<button class="btn" id="exportBtn">导出文本</button>
</div>
</div>
<div class="content">
<div id="preview">
<div class="preview-content"></div>
</div>
<textarea id="editor" placeholder="在这里输入 Markdown 文本..."></textarea>
</div>
<div id="toast" class="toast"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const editor = document.getElementById('editor');
const preview = document.getElementById('preview');
const previewContent = preview.querySelector('.preview-content');
const toast = document.getElementById('toast');
const copyBtn = document.getElementById('copyBtn');
const exportBtn = document.getElementById('exportBtn');
// Initialize marked with safe options
marked.setOptions({
breaks: true,
gfm: true,
headerIds: true,
sanitize: false,
highlight: function(code, lang) {
return code;
}
});
function showToast(message, duration = 2000) {
toast.textContent = message;
toast.style.display = 'block';
setTimeout(() => {
toast.style.display = 'none';
}, duration);
}
function updatePreview() {
try {
const markdownText = editor.value;
const htmlContent = marked.parse(markdownText);
previewContent.innerHTML = htmlContent;
} catch (error) {
console.error('Markdown parsing error:', error);
previewContent.innerHTML = '<p style="color: red;">Error parsing markdown</p>';
}
}
function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
const debouncedUpdate = debounce(updatePreview, 150);
async function copyText() {
try {
await navigator.clipboard.writeText(editor.value);
showToast('已复制到剪贴板');
} catch (err) {
console.error('Copy failed:', err);
showToast('复制失败');
}
}
function exportTxt() {
try {
const text = editor.value;
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const timestamp = new Date().toISOString().slice(0,19).replace(/[-:]/g, '');
a.href = url;
a.download = `markdown_${timestamp}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
showToast('已导出为文本文件');
} catch (err) {
console.error('Export failed:', err);
showToast('导出失败');
}
}
// Event Listeners
editor.addEventListener('input', debouncedUpdate);
copyBtn.addEventListener('click', copyText);
exportBtn.addEventListener('click', exportTxt);
// Sync scroll
editor.addEventListener('scroll', () => {
const percentage = editor.scrollTop / (editor.scrollHeight - editor.clientHeight);
preview.scrollTop = percentage * (preview.scrollHeight - preview.clientHeight);
});
// Initial content
const initialText = `# Markdown 编辑器
## 欢迎使用!
这是一个简单的 Markdown 编辑器。
### 主要功能:
1. 实时预览
2. 一键复制内容
3. 导出文本文件
4. 支持常用 Markdown 语法
### 快速开始:
- 在右侧输入 Markdown 文本
- 在左侧查看实时预览
- 使用顶部按钮进行操作
\`\`\`markdown
# 示例代码
**粗体** 和 *斜体*
- 列表项
- 另一个列表项
\`\`\``;
editor.value = initialText;
updatePreview();
});
</script>
</body>
</html>
+289
View File
@@ -0,0 +1,289 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>任务卡片生成器</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: flex-start; /* 从顶部开始排列 */
align-items: center;
min-height: 100vh;
background: #121212; /* 深色背景,让卡片在预览时效果更一致 */
margin: 0;
font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif; /* 更现代的字体栈 */
padding: 30px 20px; /* 给body一些padding */
box-sizing: border-box;
}
.export-container {
background: #282828; /* 图片中外部容器的深灰色 */
padding: 20px; /* 容器内边距 */
border-radius: 8px;
display: inline-block;
box-shadow: 0 8px 20px rgba(0,0,0,0.3); /* 给容器一些阴影 */
}
.card {
width: 370px; /* 调整宽度以适应两列布局和间距 */
background: #000000; /* 卡片纯黑背景 */
padding: 25px;
box-sizing: border-box;
color: #ffffff;
border-radius: 6px; /* 给卡片本身也加一点圆角 */
}
.card-header {
border-bottom: 1px solid #444444; /* 更细、颜色更深的分割线 */
padding-bottom: 15px;
margin-bottom: 20px;
}
.task-id {
font-size: 14px;
color: #888888; /* 灰色ID文字 */
margin-bottom: 8px; /* ID和标题间距 */
min-height: 1.2em; /* 确保空的时候也有高度,placeholder可以显示 */
}
.task-title {
font-size: 24px;
font-weight: bold;
color: #ffffff;
word-wrap: break-word;
min-height: 1.2em;
}
.task-description {
font-size: 15px;
color: #e0e0e0;
line-height: 1.6;
word-wrap: break-word;
margin-top: 15px;
margin-bottom: 25px;
min-height: 45px; /* 描述区域最小高度 */
padding: 5px 2px; /* 轻微内边距 */
}
.task-details {
display: grid;
grid-template-columns: 1fr 1fr; /* 固定两列 */
gap: 15px;
font-size: 14px;
margin-top: 20px;
}
.detail-item {
background-color: #1c1c1c; /* 详情项的背景色,比卡片黑底亮一点 */
padding: 12px;
border-radius: 6px;
}
/* 如果最后一个元素是奇数个中的最后一个(例如第3个),则让它占据整行 */
.detail-item:last-child:nth-child(odd) {
grid-column: 1 / -1; /* 跨越所有列 */
}
.detail-item label {
font-weight: normal;
color: #aaaaaa; /* 标签文字颜色 */
display: block;
margin-bottom: 8px;
font-size: 13px;
}
.detail-item .value.editable,
.detail-item input[type="date"].value {
color: #ffffff;
background-color: #000000; /* 值区域纯黑背景 */
border: 1px solid #333333; /* 值区域的细边框 */
width: 100%;
padding: 8px 10px; /* 值区域内边距 */
min-height: 1.5em; /* 确保有高度 */
border-radius: 4px;
font-size: 15px;
line-height: 1.4;
box-sizing: border-box; /* padding和border不增加额外宽度 */
}
.detail-item input[type="date"].value {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
position: relative;
}
.detail-item input[type="date"].value::-webkit-calendar-picker-indicator {
filter: invert(0.8) brightness(0.8);
cursor: pointer;
opacity: 0.7;
}
.detail-item .value.editable {
position: relative;
}
.detail-item .value.editable:empty::before {
content: attr(data-placeholder);
color: #555555;
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
width: calc(100% - 20px);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.editable {
position: relative;
min-height: 1.2em;
}
.editable:empty:not(:focus)::before {
content: attr(data-placeholder);
color: #666666;
position: absolute;
left: 0;
top: 0;
pointer-events: none;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.task-id.editable:empty:not(:focus)::before,
.task-title.editable:empty:not(:focus)::before,
.task-description.editable:empty:not(:focus)::before {
left: 2px;
top: 2px;
}
.editable:focus {
outline: 1px dashed #777777;
background-color: #0a0a0a;
}
[contenteditable] {
-webkit-user-select: text;
user-select: text;
}
[contenteditable]:focus {
background-color: #0a0a0a !important;
}
::selection {
background-color: #444444;
color: #ffffff;
}
.button-container {
margin-top: 25px;
text-align: center;
}
.export-btn {
padding: 12px 25px;
background: #1c1c1c;
color: #ffffff;
border: 1px solid #444444;
cursor: pointer;
font-size: 16px;
border-radius: 6px;
transition: background-color 0.2s ease, border-color 0.2s ease;
}
.export-btn:hover {
background: #282828;
border-color: #555555;
}
</style>
</head>
<body>
<div class="export-container" id="export-container">
<div id="taskCard" class="card">
<div class="card-header">
<div class="task-id editable" contenteditable="true" data-placeholder="任务ID (可选)"></div>
<div class="task-title editable" contenteditable="true" data-placeholder="点击输入任务标题"></div>
</div>
<div class="task-description editable" contenteditable="true" data-placeholder="点击输入任务详细描述..."></div>
<div class="task-details">
<div class="detail-item">
<label for="assignee-value">负责人:</label>
<div id="assignee-value" class="value editable" contenteditable="true" data-placeholder="未分配"></div>
</div>
<!-- 标签现在是第二个 -->
<div class="detail-item">
<label for="tags-value">标签:</label>
<div id="tags-value" class="value editable" contenteditable="true" data-placeholder="例如: 项目A, Bug"></div>
</div>
<!-- 截止日期现在是第三个,会自动占据整行 -->
<div class="detail-item">
<label for="dueDate-value">截止日期:</label>
<input type="date" id="dueDate-value" class="value">
</div>
</div>
</div>
</div>
<div class="button-container">
<button class="export-btn" onclick="exportToPng()">导出为PNG</button>
</div>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
function sanitizeFilename(name) {
return name.replace(/[^a-z0-9_\-.\u4e00-\u9fa5\s]/gi, '').replace(/\s+/g, '_');
}
function exportToPng() {
if (window.getSelection) {
if (window.getSelection().empty) { window.getSelection().empty(); }
else if (window.getSelection().removeAllRanges) { window.getSelection().removeAllRanges(); }
} else if (document.selection) { document.selection.empty(); }
const container = document.getElementById('export-container');
// const card = document.getElementById('taskCard'); // card variable not strictly needed here
const originalDueDate = document.getElementById('dueDate-value').value;
html2canvas(container, {
backgroundColor: null,
scale: 2,
useCORS: true,
logging: false, // Changed to false to reduce console noise unless debugging
onclone: (documentClone) => {
// const clonedCard = documentClone.getElementById('taskCard'); // clonedCard not strictly needed
const dueDateInputClone = documentClone.getElementById('dueDate-value');
if (dueDateInputClone) {
dueDateInputClone.value = originalDueDate;
if (!originalDueDate) {
dueDateInputClone.style.color = '#555555';
} else {
dueDateInputClone.style.color = '#ffffff';
}
}
const editables = documentClone.querySelectorAll('.editable');
editables.forEach(el => {
// Placeholder handling is mostly done by CSS (:empty::before)
// If specific adjustments needed for clone, add here.
// For example, ensuring text color if content exists:
// if (el.textContent.trim() !== '' && el.classList.contains('value')) {
// el.style.color = '#ffffff';
// }
});
}
}).then(canvas => {
const link = document.createElement('a');
const taskTitleElement = document.getElementById('task-title');
let filename = '任务卡片.png';
if (taskTitleElement && taskTitleElement.textContent.trim() !== '') {
const sanitizedTitle = sanitizeFilename(taskTitleElement.textContent.trim());
if (sanitizedTitle) { // Ensure title isn't just invalid chars
filename = sanitizedTitle + '.png';
}
}
link.download = filename;
link.href = canvas.toDataURL('image/png');
link.click();
}).catch(err => {
console.error("导出PNG失败:", err);
alert("导出PNG失败,请查看控制台获取更多信息。");
});
}
document.querySelectorAll('.editable').forEach(element => {
element.addEventListener('focus', function() {
// CSS handles placeholder via :not(:focus)::before
});
element.addEventListener('blur', function() {
// CSS handles placeholder
});
});
</script>
</body>
</html>
@@ -0,0 +1,320 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown 编辑与预览 (带同步滚动和滑块)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
background: #f0f0f0;
margin: 0;
font-family: 'Arial', sans-serif;
padding-top: 20px;
overflow: hidden; /* Prevent body scrollbars if editor is full height */
}
.editor-container {
display: flex;
width: 90%; /* Use percentage for better responsiveness */
max-width: 1200px; /* Max width for large screens */
height: calc(100vh - 100px); /* Adjust height to fill more of the viewport */
background: #333333;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
position: relative; /* For resizer positioning if needed */
}
.markdown-editor, .preview-pane {
padding: 20px;
box-sizing: border-box;
overflow-y: auto;
height: 100%; /* Fill the container height */
}
.markdown-editor {
/* flex: 1; Will be set by JS */
background: #222222;
color: #e0e0e0;
border: none;
resize: none;
font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
font-size: 14px;
line-height: 1.6;
outline: none;
}
.resizer {
flex: 0 0 10px; /* Don't grow, don't shrink, base width 10px */
background: #555555;
cursor: col-resize;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
user-select: none; /* Prevent text selection during drag */
}
.resizer::before { /* Optional: visual indicator for dragging */
content: '⋮';
color: #aaa;
font-size: 18px;
line-height: 0;
}
.preview-pane {
/* flex: 1; Will be set by JS */
background: #000000;
color: #ffffff;
/* border-left: 2px solid #666666; /* Replaced by resizer */
word-wrap: break-word;
}
/* Styling for rendered Markdown elements in preview-pane */
.preview-pane h1, .preview-pane h2, .preview-pane h3, .preview-pane h4, .preview-pane h5, .preview-pane h6 {
color: #ffffff;
border-bottom: 1px solid #444444;
padding-bottom: 5px;
margin-top: 1em;
margin-bottom: 0.5em;
}
.preview-pane h1 { font-size: 24px; font-weight: bold; border-bottom: 2px solid #666666; padding-bottom: 10px; margin-bottom: 15px;}
.preview-pane p {
font-size: 16px;
line-height: 1.5;
margin-bottom: 1em;
}
.preview-pane ul, .preview-pane ol {
margin-left: 20px;
margin-bottom: 1em;
}
.preview-pane li {
margin-bottom: 0.5em;
}
.preview-pane blockquote {
border-left: 4px solid #555555;
padding-left: 10px;
color: #aaaaaa;
margin-left: 0;
margin-right: 0;
margin-bottom: 1em;
}
.preview-pane pre {
background-color: #1e1e1e;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}
.preview-pane code {
font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
background-color: #282c34;
padding: 2px 4px;
border-radius: 3px;
font-size: 0.9em;
}
.preview-pane pre code {
background-color: transparent;
padding: 0;
border-radius: 0;
}
.preview-pane table {
border-collapse: collapse;
width: 100%;
margin-bottom: 1em;
}
.preview-pane th, .preview-pane td {
border: 1px solid #666666;
padding: 8px;
text-align: left;
}
.preview-pane th {
background-color: #1a1a1a;
}
.preview-pane img {
max-width: 100%;
height: auto;
border-radius: 4px;
}
.button-container {
margin-top: 20px;
text-align: center;
}
.export-btn {
padding: 10px 20px;
background: #000000;
color: #ffffff;
border: 2px solid #666666;
cursor: pointer;
font-size: 16px;
}
.export-btn:hover {
background: #333333;
}
</style>
</head>
<body>
<div class="editor-container">
<textarea id="markdown-input" class="markdown-editor" placeholder="在此输入 Markdown... 例如:\n# 标题\n\n- 列表项1\n- 列表项2\n\n**加粗文本**"></textarea>
<div id="resizer" class="resizer"></div>
<div id="preview-output" class="preview-pane"></div>
</div>
<div class="button-container">
<button class="export-btn" onclick="exportToPng()">导出为PNG</button>
</div>
<script>
const markdownInput = document.getElementById('markdown-input');
const previewOutput = document.getElementById('preview-output');
const resizer = document.getElementById('resizer');
const editorContainer = document.querySelector('.editor-container');
// Initial flex distribution
markdownInput.style.flex = '1';
previewOutput.style.flex = '1';
const converter = new showdown.Converter({
tables: true,
strikethrough: true,
tasklists: true,
ghCompatibleHeaderId: true,
simpleLineBreaks: true
});
converter.setFlavor('github');
function renderMarkdown() {
const markdownText = markdownInput.value;
const html = converter.makeHtml(markdownText);
previewOutput.innerHTML = html;
}
markdownInput.addEventListener('input', renderMarkdown);
renderMarkdown(); // Initial render
// --- Resizer Logic ---
let isResizing = false;
let startX, startEditorWidth, startPreviewWidth;
resizer.addEventListener('mousedown', (e) => {
e.preventDefault(); // Prevent text selection, etc.
isResizing = true;
startX = e.clientX;
startEditorWidth = markdownInput.offsetWidth;
startPreviewWidth = previewOutput.offsetWidth;
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', stopResize);
});
function handleMouseMove(e) {
if (!isResizing) return;
const dx = e.clientX - startX;
let newEditorWidth = startEditorWidth + dx;
let newPreviewWidth = startPreviewWidth - dx;
const minWidth = 50; // Minimum width for panes
if (newEditorWidth < minWidth) {
newEditorWidth = minWidth;
newPreviewWidth = startEditorWidth + startPreviewWidth - minWidth;
} else if (newPreviewWidth < minWidth) {
newPreviewWidth = minWidth;
newEditorWidth = startEditorWidth + startPreviewWidth - minWidth;
}
const totalWidth = editorContainer.offsetWidth - resizer.offsetWidth;
markdownInput.style.flex = `0 0 ${newEditorWidth}px`;
previewOutput.style.flex = `0 0 ${newPreviewWidth}px`;
}
function stopResize() {
isResizing = false;
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', stopResize);
}
// --- Synchronized Scrolling ---
let scrollTimeout;
let isSyncingEditor = false;
let isSyncingPreview = false;
markdownInput.addEventListener('scroll', () => {
if (isSyncingEditor) {
isSyncingEditor = false; // Reset for next manual scroll
return;
}
if (isResizing) return; // Don't sync scroll while resizing
isSyncingPreview = true; // Prevent preview scroll from triggering editor scroll
const scrollPercentage = markdownInput.scrollTop / (markdownInput.scrollHeight - markdownInput.clientHeight);
if (isNaN(scrollPercentage)) return; // Avoid NaN if scrollHeight equals clientHeight
previewOutput.scrollTop = scrollPercentage * (previewOutput.scrollHeight - previewOutput.clientHeight);
// Clear any existing timeout to avoid race conditions
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
isSyncingPreview = false;
}, 100); // Adjust delay as needed
});
previewOutput.addEventListener('scroll', () => {
if (isSyncingPreview) {
isSyncingPreview = false; // Reset for next manual scroll
return;
}
if (isResizing) return; // Don't sync scroll while resizing
isSyncingEditor = true; // Prevent editor scroll from triggering preview scroll
const scrollPercentage = previewOutput.scrollTop / (previewOutput.scrollHeight - previewOutput.clientHeight);
if (isNaN(scrollPercentage)) return;
markdownInput.scrollTop = scrollPercentage * (markdownInput.scrollHeight - markdownInput.clientHeight);
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
isSyncingEditor = false;
}, 100); // Adjust delay as needed
});
function exportToPng() {
const previewPane = document.getElementById('preview-output');
const originalHeight = previewPane.style.height;
const originalOverflowY = previewPane.style.overflowY;
previewPane.style.height = previewPane.scrollHeight + 'px';
previewPane.style.overflowY = 'visible';
previewPane.style.backgroundColor = '#000000';
html2canvas(previewPane, {
backgroundColor: '#000000',
scale: 2,
useCORS: true,
logging: false,
onclone: (documentClone) => {
const clonedPreviewPane = documentClone.getElementById('preview-output');
if (clonedPreviewPane) {
clonedPreviewPane.style.backgroundColor = '#000000';
clonedPreviewPane.style.color = '#ffffff';
clonedPreviewPane.style.height = clonedPreviewPane.scrollHeight + 'px';
clonedPreviewPane.style.overflowY = 'visible';
}
}
}).then(canvas => {
const link = document.createElement('a');
link.download = 'markdown_card.png';
link.href = canvas.toDataURL('image/png');
link.click();
}).finally(() => {
previewPane.style.height = originalHeight;
previewPane.style.overflowY = originalOverflowY;
});
}
</script>
</body>
</html>
@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小红书内容卡片</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f0f0f0;
margin: 0;
font-family: 'Arial', sans-serif;
}
.export-container {
background: #333333;
padding: 10px;
border-radius: 8px;
}
.card {
width: 320px;
background: #000000;
border: 2px solid #666666; /* 改为灰色边框 */
box-shadow: 4px 4px 0 #666666; /* 改为灰色阴影 */
padding: 20px;
box-sizing: border-box;
}
.title {
font-size: 24px;
font-weight: bold;
color: #ffffff;
border-bottom: 2px solid #666666; /* 改为灰色边框 */
padding-bottom: 10px;
margin-bottom: 15px;
word-wrap: break-word;
background-color: #000000;
}
.content {
font-size: 16px;
color: #ffffff;
line-height: 1.5;
word-wrap: break-word;
background-color: #000000;
}
.editable {
position: relative;
min-height: 1em;
}
.editable:empty:before {
content: attr(data-placeholder);
color: #666666;
position: absolute;
pointer-events: none;
}
.editable:focus {
outline: none;
background-color: #000000;
}
[contenteditable] {
-webkit-user-select: text;
user-select: text;
background-color: #000000 !important;
}
[contenteditable]:focus {
background-color: #000000 !important;
}
::selection {
background-color: #333333;
color: #ffffff;
}
.button-container {
margin-top: 20px;
text-align: center;
}
.export-btn {
padding: 10px 20px;
background: #000000;
color: #ffffff;
border: 2px solid #666666; /* 添加灰色边框保持一致性 */
cursor: pointer;
font-size: 16px;
}
.export-btn:hover {
background: #333333;
}
</style>
</head>
<body>
<div class="export-container" id="export-container">
<div id="card" class="card">
<div class="title editable" contenteditable="true" data-placeholder="点击输入标题"></div>
<div class="content editable" contenteditable="true" data-placeholder="点击输入内容"></div>
</div>
</div>
<div class="button-container">
<button class="export-btn" onclick="exportToPng()">导出为PNG</button>
</div>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
function exportToPng() {
// 清除选中状态
window.getSelection().removeAllRanges();
const container = document.getElementById('export-container');
html2canvas(container, {
backgroundColor: '#333333',
scale: 2,
useCORS: true,
logging: false,
removeContainer: true,
foreignObjectRendering: false,
onclone: (document) => {
const editables = document.querySelectorAll('.editable');
editables.forEach(el => {
// 确保克隆的元素保持相同的样式
el.style.backgroundColor = '#000000';
if (el.classList.contains('title')) {
el.style.borderBottom = '2px solid #666666';
}
});
// 确保卡片样式在克隆中保持一致
const card = document.querySelector('.card');
card.style.border = '2px solid #666666';
card.style.boxShadow = '4px 4px 0 #666666';
}
}).then(canvas => {
const link = document.createElement('a');
link.download = 'xiaohongshu_card.png';
link.href = canvas.toDataURL('image/png');
link.click();
});
}
// 监听编辑事件,保持样式一致性
document.querySelectorAll('.editable').forEach(element => {
element.addEventListener('input', function() {
this.style.backgroundColor = '#000000';
});
});
</script>
</body>
</html>
+200
View File
@@ -0,0 +1,200 @@
# 🚀 Perfect Neovim Configuration with LazyVim
## 系统配置文档
### 📋 配置概述
- **Neovim 版本**: v0.11.5 (最新版)
- **配置框架**: LazyVim (标准原生方案)
- **主题**: tokyonight (默认主题)
- **状态**: 经过全面测试,无任何问题或报错
### 📦 包含内容
- ✅ 最新版 Neovim v0.11.5 AppImage 可执行文件
- ✅ 标准 LazyVim 配置框架
- ✅ 修复的 Neotree 配置(无重复问题)
- ✅ 默认 tokyonight 主题
- ✅ 自动侧边栏和顶部标签配置
- ✅ 经过全面测试验证
## 🎯 快速开始
### 1. 克隆仓库
```bash
git clone https://github.com/tukuaiai/vim.git
cd vim
```
### 2. 安装配置
```bash
# 复制配置文件
cp -r nvim-config/* ~/.config/
# 复制可执行文件
cp nvim-config/nvim ~/.local/bin/
chmod +x ~/.local/bin/nvim
# 确保路径在 PATH 中
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```
### 3. 启动使用
```bash
# 直接启动
~/.local/bin/nvim
# 或使用别名(推荐)
alias n='~/.local/bin/nvim'
n
```
## 🎨 主题配置
### 当前主题:tokyonight(默认)
- 深色护眼主题
- 现代化配色方案
- 高对比度,适合长时间使用
### 切换主题(可选)
```vim
:Telescope colorscheme " 使用 Telescope 选择主题
```
## ⚙️ 核心功能
### 1. 文件浏览器(Neotree
- **快捷键**`<leader>e`(空格+e
- **功能**:侧边栏文件浏览器
- **特点**:无重复窗口问题(已修复)
### 2. 顶部标签页(Bufferline
- **功能**:显示打开的缓冲区
- **特点**:始终显示,美观实用
### 3. 模糊查找(Telescope
- **快捷键**`<leader>f`(空格+f
- **功能**:快速查找文件、符号等
### 4. Git 集成
- **快捷键**`<leader>g`(空格+g
- **功能**:Git 状态、提交、差异查看
## ⌨️ 快捷键速查
| 快捷键 | 功能 |
|--------|------|
| `<leader>e` | 打开文件浏览器 |
| `<leader>f` | 模糊查找 |
| `<leader>g` | Git 相关 |
| `<leader>b` | 缓冲区管理 |
| `<leader>w` | 保存文件 |
| `<leader>q` | 退出 |
| `<leader>/` | 搜索当前文件 |
| `<leader>?` | 查看所有快捷键 |
## 🔧 高级配置
### 自动命令(autocmds
位于 `~/.config/nvim/lua/config/autocmds.lua`
```lua
-- 自动打开 Neotree(延迟 50ms 确保插件加载)
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
vim.defer_fn(function()
vim.cmd("Neotree show")
end, 50)
end,
})
```
### 插件配置
位于 `~/.config/nvim/lua/plugins/`
- `ui.lua` - UI 相关插件配置
- `colorscheme.lua` - 主题配置
- `example.lua` - 示例插件配置
## 🧪 测试验证
### 启动测试
```bash
# 基础启动测试
~/.local/bin/nvim --headless -c "echo 'OK'" -c "qa"
# 配置加载测试
~/.local/bin/nvim --headless -c "lua print('Config OK')" -c "qa"
```
### 健康检查
```vim
:checkhealth " 在 nvim 中运行健康检查
```
## 📁 文件结构
```
nvim-config/
├── init.lua # 入口文件
├── lazy-lock.json # 插件锁文件
├── lazyvim.json # LazyVim 配置
├── nvim # Neovim v0.11.5 AppImage
├── lua/
│ ├── config/
│ │ ├── autocmds.lua # 自动命令
│ │ ├── keymaps.lua # 键位映射
│ │ ├── lazy.lua # Lazy.nvim 配置
│ │ └── options.lua # 选项设置
│ └── plugins/
│ ├── colorscheme.lua # 主题配置
│ ├── ui.lua # UI 插件配置
│ └── example.lua # 示例配置
└── stylua.toml # 代码格式化配置
```
## 🚀 高级使用技巧
### 1. 快速文件操作
```vim
" 在当前行下方新建文件
:enew
" 保存文件
:w
" 退出
:qa
```
### 2. 窗口管理
```vim
" 水平分割
:sp filename
" 垂直分割
:vs filename
" 在分割间移动
Ctrl+w h/j/k/l
```
### 3. 搜索和替换
```vim
" 当前文件搜索
/
" 全局搜索
:Telescope live_grep
" 替换
:%s/old/new/g
```
## 📚 学习资源
1. **内置教程**`:Tutor`
2. **帮助系统**`:help 主题`
3. **LazyVim 文档**:按 `<leader>?`
4. **GitHub 仓库**https://github.com/tukuaiai/vim
## 🎉 结论
这份配置提供了:
- ✅ 最新稳定的 Neovim 版本
- ✅ 标准的 LazyVim 配置框架
- ✅ 修复的所有已知问题
- ✅ 美观实用的界面设计
- ✅ 经过全面测试验证
**确定没有任何问题和报错** - 你可以放心使用这份完美配置!
+29
View File
@@ -0,0 +1,29 @@
# Neovim 配置(LazyVim)说明
本目录是一套可直接复制到 `~/.config/nvim/` 的 Neovim 配置,基于 LazyVim + lazy.nvim。
## 目录结构
```text
nvim-config/
├── init.lua # 入口:加载 config.lazy
├── lazy-lock.json # 插件锁定版本
├── lazyvim.json # LazyVim 元数据(extras/install_version
└── lua/
├── config/ # options/keymaps/autocmds/lazy 基础配置
└── plugins/ # 以“文件为单位”的插件/覆盖配置
├── ui.lua # UIneo-tree/bufferline 等)覆盖
└── snacks.lua # Snacks 默认策略(显示隐藏/被忽略文件)
```
## 关键约定
- 对人可见文本(注释/日志/文档)用中文;代码符号(变量/函数/模块名)用英文。
- 插件覆盖优先放在 `lua/plugins/*.lua`,避免在 `config/*` 里堆逻辑。
- “默认显示隐藏文件”的入口在 `lua/plugins/snacks.lua`
- `picker.sources.files/explorer/grep`: `hidden=true``ignored=true`
## 变更记录
- 2026-02-20:新增 `lua/plugins/snacks.lua`,让 Snacks Explorer/Picker 默认显示隐藏与被忽略文件。
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+200
View File
@@ -0,0 +1,200 @@
# 🚀 Perfect Neovim Configuration with LazyVim
## 系统配置文档
### 📋 配置概述
- **Neovim 版本**: v0.11.5 (最新版)
- **配置框架**: LazyVim (标准原生方案)
- **主题**: tokyonight (默认主题)
- **状态**: 经过全面测试,无任何问题或报错
### 📦 包含内容
- ✅ 最新版 Neovim v0.11.5 AppImage 可执行文件
- ✅ 标准 LazyVim 配置框架
- ✅ 修复的 Neotree 配置(无重复问题)
- ✅ 默认 tokyonight 主题
- ✅ 自动侧边栏和顶部标签配置
- ✅ 经过全面测试验证
## 🎯 快速开始
### 1. 克隆仓库
```bash
git clone https://github.com/tukuaiai/vim.git
cd vim
```
### 2. 安装配置
```bash
# 复制配置文件
cp -r nvim-config/* ~/.config/
# 复制可执行文件
cp nvim-config/nvim ~/.local/bin/
chmod +x ~/.local/bin/nvim
# 确保路径在 PATH 中
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```
### 3. 启动使用
```bash
# 直接启动
~/.local/bin/nvim
# 或使用别名(推荐)
alias n='~/.local/bin/nvim'
n
```
## 🎨 主题配置
### 当前主题:tokyonight(默认)
- 深色护眼主题
- 现代化配色方案
- 高对比度,适合长时间使用
### 切换主题(可选)
```vim
:Telescope colorscheme " 使用 Telescope 选择主题
```
## ⚙️ 核心功能
### 1. 文件浏览器(Neotree
- **快捷键**`<leader>e`(空格+e
- **功能**:侧边栏文件浏览器
- **特点**:无重复窗口问题(已修复)
### 2. 顶部标签页(Bufferline
- **功能**:显示打开的缓冲区
- **特点**:始终显示,美观实用
### 3. 模糊查找(Telescope
- **快捷键**`<leader>f`(空格+f
- **功能**:快速查找文件、符号等
### 4. Git 集成
- **快捷键**`<leader>g`(空格+g
- **功能**:Git 状态、提交、差异查看
## ⌨️ 快捷键速查
| 快捷键 | 功能 |
|--------|------|
| `<leader>e` | 打开文件浏览器 |
| `<leader>f` | 模糊查找 |
| `<leader>g` | Git 相关 |
| `<leader>b` | 缓冲区管理 |
| `<leader>w` | 保存文件 |
| `<leader>q` | 退出 |
| `<leader>/` | 搜索当前文件 |
| `<leader>?` | 查看所有快捷键 |
## 🔧 高级配置
### 自动命令(autocmds
位于 `~/.config/nvim/lua/config/autocmds.lua`
```lua
-- 自动打开 Neotree(延迟 50ms 确保插件加载)
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
vim.defer_fn(function()
vim.cmd("Neotree show")
end, 50)
end,
})
```
### 插件配置
位于 `~/.config/nvim/lua/plugins/`
- `ui.lua` - UI 相关插件配置
- `colorscheme.lua` - 主题配置
- `example.lua` - 示例插件配置
## 🧪 测试验证
### 启动测试
```bash
# 基础启动测试
~/.local/bin/nvim --headless -c "echo 'OK'" -c "qa"
# 配置加载测试
~/.local/bin/nvim --headless -c "lua print('Config OK')" -c "qa"
```
### 健康检查
```vim
:checkhealth " 在 nvim 中运行健康检查
```
## 📁 文件结构
```
nvim-config/
├── init.lua # 入口文件
├── lazy-lock.json # 插件锁文件
├── lazyvim.json # LazyVim 配置
├── nvim # Neovim v0.11.5 AppImage
├── lua/
│ ├── config/
│ │ ├── autocmds.lua # 自动命令
│ │ ├── keymaps.lua # 键位映射
│ │ ├── lazy.lua # Lazy.nvim 配置
│ │ └── options.lua # 选项设置
│ └── plugins/
│ ├── colorscheme.lua # 主题配置
│ ├── ui.lua # UI 插件配置
│ └── example.lua # 示例配置
└── stylua.toml # 代码格式化配置
```
## 🚀 高级使用技巧
### 1. 快速文件操作
```vim
" 在当前行下方新建文件
:enew
" 保存文件
:w
" 退出
:qa
```
### 2. 窗口管理
```vim
" 水平分割
:sp filename
" 垂直分割
:vs filename
" 在分割间移动
Ctrl+w h/j/k/l
```
### 3. 搜索和替换
```vim
" 当前文件搜索
/
" 全局搜索
:Telescope live_grep
" 替换
:%s/old/new/g
```
## 📚 学习资源
1. **内置教程**`:Tutor`
2. **帮助系统**`:help 主题`
3. **LazyVim 文档**:按 `<leader>?`
4. **GitHub 仓库**https://github.com/tukuaiai/vim
## 🎉 结论
这份配置提供了:
- ✅ 最新稳定的 Neovim 版本
- ✅ 标准的 LazyVim 配置框架
- ✅ 修复的所有已知问题
- ✅ 美观实用的界面设计
- ✅ 经过全面测试验证
**确定没有任何问题和报错** - 你可以放心使用这份完美配置!
+2
View File
@@ -0,0 +1,2 @@
-- bootstrap lazy.nvim, LazyVim and your plugins
require("config.lazy")
+36
View File
@@ -0,0 +1,36 @@
{
"LazyVim": { "branch": "main", "commit": "c64a61734fc9d45470a72603395c02137802bc6f" },
"blink.cmp": { "branch": "main", "commit": "b19413d214068f316c78978b08264ed1c41830ec" },
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
"catppuccin": { "branch": "main", "commit": "193e123cdbc4dd3e86db883d55349e9587f0ded6" },
"conform.nvim": { "branch": "master", "commit": "ffe26e8df8115c9665d24231f8a49fadb2d611ce" },
"dracula": { "branch": "main", "commit": "ae752c13e95fb7c5f58da4b5123cb804ea7568ee" },
"flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" },
"friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },
"gitsigns.nvim": { "branch": "main", "commit": "5813e4878748805f1518cee7abb50fd7205a3a48" },
"grug-far.nvim": { "branch": "main", "commit": "b58b2d65863f4ebad88b10a1ddd519e5380466e0" },
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
"lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" },
"lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "c55bd8a8fb191e24176c206a7af1dd51ce7276a5" },
"mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" },
"mini.ai": { "branch": "main", "commit": "bfb26d9072670c3aaefab0f53024b2f3729c8083" },
"mini.icons": { "branch": "main", "commit": "ff2e4f1d29f659cc2bad0f9256f2f6195c6b2428" },
"mini.pairs": { "branch": "main", "commit": "472ec50092a3314ec285d2db2baa48602d71fe93" },
"neo-tree.nvim": { "branch": "main", "commit": "7a6f14c6edde0921333005cd738309b70138964b" },
"noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" },
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
"nvim-lint": { "branch": "master", "commit": "897f7771c1ca4b11659dfe372d9376acd9fe3097" },
"nvim-lspconfig": { "branch": "master", "commit": "7af6f57d517d8cc68f249e0d27364c188a097812" },
"nvim-treesitter": { "branch": "main", "commit": "2979e048b356cfd32dc419d5803dc356b9832adf" },
"nvim-treesitter-textobjects": { "branch": "main", "commit": "76deedf0f1cec4496ef8d49b6d1f020f6d0c6ec9" },
"nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" },
"persistence.nvim": { "branch": "main", "commit": "b20b2a7887bd39c1a356980b45e03250f3dce49c" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"snacks.nvim": { "branch": "main", "commit": "fe7cfe9800a182274d0f868a74b7263b8c0c020b" },
"todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" },
"tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" },
"trouble.nvim": { "branch": "main", "commit": "bd67efe408d4816e25e8491cc5ad4088e708a69a" },
"ts-comments.nvim": { "branch": "main", "commit": "123a9fb12e7229342f807ec9e6de478b1102b041" },
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
}
+10
View File
@@ -0,0 +1,10 @@
{
"extras": [
],
"install_version": 8,
"news": {
"NEWS.md": "11866"
},
"version": 8
}
@@ -0,0 +1,25 @@
-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
--
-- Add any additional autocmds here
-- with `vim.api.nvim_create_autocmd`
--
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
-- 自动打开Neotree(使用标准LazyVim方式)
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
-- 延迟执行,确保插件加载完成
vim.defer_fn(function()
vim.cmd("Neotree show")
end, 50)
end,
})
-- 确保bufferline始终显示
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
vim.o.showtabline = 2
end,
})
@@ -0,0 +1,15 @@
-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
-- ==================== 文件搜索:包含隐藏/被忽略文件 ====================
-- 说明:
-- - LazyVim 默认 <leader>ff 通常不包含 .gitignore 忽略的文件
-- - 这个快捷键用于“真的找不到文件时”兜底(例如 .env)
vim.keymap.set("n", "<leader>fF", function()
require("telescope.builtin").find_files({
hidden = true,
no_ignore = true,
no_ignore_parent = true,
})
end, { desc = "Find All Files (hidden + ignored)" })
+55
View File
@@ -0,0 +1,55 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
spec = {
-- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
-- import/override with your plugins
{ import = "plugins" },
},
defaults = {
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
-- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
lazy = false,
-- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
-- have outdated releases, which may break your Neovim install.
version = false, -- always use the latest git commit
-- version = "*", -- try installing the latest stable version for plugins that support semver
},
install = { colorscheme = { "tokyonight", "habamax" } },
checker = {
enabled = true, -- check for plugin updates periodically
notify = false, -- notify on update
}, -- automatically check for plugin updates
performance = {
rtp = {
-- disable some rtp plugins
disabled_plugins = {
"gzip",
-- "matchit",
-- "matchparen",
-- "netrwPlugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
-- 使用默认的tokyonight主题(LazyVim默认主题)
-- 不需要手动设置,LazyVim会自动加载
@@ -0,0 +1,3 @@
-- Options are automatically loaded before lazy.nvim startup
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
-- Add any additional options here
@@ -0,0 +1,13 @@
-- 默认使用 LazyVim 自带的 tokyonight 主题
-- 如果需要其他主题,可以在这里添加
return {
-- 可以在这里添加其他主题插件
-- 例如:
-- {
-- "folke/tokyonight.nvim",
-- opts = {
-- style = "moon", -- 可选: night, storm, moon, day
-- },
-- },
}
@@ -0,0 +1,34 @@
-- Dracula 主题插件配置
return {
{
'Mofiqul/dracula.nvim',
name = 'dracula',
lazy = false,
priority = 1000,
config = function()
-- 获取主题配置
local dracula_config = require('themes.dracula')
-- 从环境变量或默认值获取样式
local style = vim.env.NVIM_THEME_STYLE or 'dracula'
-- 设置主题
require('dracula').setup(dracula_config.config(style))
-- 应用主题
vim.cmd.colorscheme('dracula')
end,
},
-- Lualine 主题集成
{
'nvim-lualine/lualine.nvim',
dependencies = { 'dracula' },
opts = {
options = {
theme = 'dracula-nvim'
}
}
}
}
@@ -0,0 +1,197 @@
-- since this is just an example spec, don't actually load anything here and return an empty spec
-- stylua: ignore
if true then return {} end
-- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim
--
-- In your plugin files, you can:
-- * add extra plugins
-- * disable/enabled LazyVim plugins
-- * override the configuration of LazyVim plugins
return {
-- add gruvbox
{ "ellisonleao/gruvbox.nvim" },
-- Configure LazyVim to load gruvbox
{
"LazyVim/LazyVim",
opts = {
colorscheme = "gruvbox",
},
},
-- change trouble config
{
"folke/trouble.nvim",
-- opts will be merged with the parent spec
opts = { use_diagnostic_signs = true },
},
-- disable trouble
{ "folke/trouble.nvim", enabled = false },
-- override nvim-cmp and add cmp-emoji
{
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-emoji" },
---@param opts cmp.ConfigSchema
opts = function(_, opts)
table.insert(opts.sources, { name = "emoji" })
end,
},
-- change some telescope options and a keymap to browse plugin files
{
"nvim-telescope/telescope.nvim",
keys = {
-- add a keymap to browse plugin files
-- stylua: ignore
{
"<leader>fp",
function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
desc = "Find Plugin File",
},
},
-- change some options
opts = {
defaults = {
layout_strategy = "horizontal",
layout_config = { prompt_position = "top" },
sorting_strategy = "ascending",
winblend = 0,
},
},
},
-- add pyright to lspconfig
{
"neovim/nvim-lspconfig",
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- pyright will be automatically installed with mason and loaded with lspconfig
pyright = {},
},
},
},
-- add tsserver and setup with typescript.nvim instead of lspconfig
{
"neovim/nvim-lspconfig",
dependencies = {
"jose-elias-alvarez/typescript.nvim",
init = function()
require("lazyvim.util").lsp.on_attach(function(_, buffer)
-- stylua: ignore
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
end)
end,
},
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- tsserver will be automatically installed with mason and loaded with lspconfig
tsserver = {},
},
-- you can do any additional lsp server setup here
-- return true if you don't want this server to be setup with lspconfig
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
setup = {
-- example to setup with typescript.nvim
tsserver = function(_, opts)
require("typescript").setup({ server = opts })
return true
end,
-- Specify * to use this function as a fallback for any server
-- ["*"] = function(server, opts) end,
},
},
},
-- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
-- treesitter, mason and typescript.nvim. So instead of the above, you can use:
{ import = "lazyvim.plugins.extras.lang.typescript" },
-- add more treesitter parsers
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"bash",
"html",
"javascript",
"json",
"lua",
"markdown",
"markdown_inline",
"python",
"query",
"regex",
"tsx",
"typescript",
"vim",
"yaml",
},
},
},
-- since `vim.tbl_deep_extend`, can only merge tables and not lists, the code above
-- would overwrite `ensure_installed` with the new value.
-- If you'd rather extend the default config, use the code below instead:
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
-- add tsx and treesitter
vim.list_extend(opts.ensure_installed, {
"tsx",
"typescript",
})
end,
},
-- the opts function can also be used to change the default opts:
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, {
function()
return "😄"
end,
})
end,
},
-- or you can return new options to override all the defaults
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function()
return {
--[[add your custom lualine config here]]
}
end,
},
-- use mini.starter instead of alpha
{ import = "lazyvim.plugins.extras.ui.mini-starter" },
-- add jsonls and schemastore packages, and setup treesitter for json, json5 and jsonc
{ import = "lazyvim.plugins.extras.lang.json" },
-- add any tools you want to have installed below
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"stylua",
"shellcheck",
"shfmt",
"flake8",
},
},
},
}
@@ -0,0 +1,28 @@
return {
{
"folke/snacks.nvim",
opts = function(_, opts)
-- ==================== 默认显示隐藏/被忽略文件 ====================
-- LazyVim install_version=8 默认 picker/explorer 都优先走 Snacks,这里统一打开 hidden/ignored。
opts.picker = opts.picker or {}
opts.picker.sources = opts.picker.sources or {}
local sources = opts.picker.sources
sources.files = vim.tbl_deep_extend("force", sources.files or {}, {
hidden = true,
ignored = true,
})
sources.explorer = vim.tbl_deep_extend("force", sources.explorer or {}, {
hidden = true,
ignored = true,
})
sources.grep = vim.tbl_deep_extend("force", sources.grep or {}, {
hidden = true,
ignored = true,
})
end,
},
}
+93
View File
@@ -0,0 +1,93 @@
return {
{
"nvim-neo-tree/neo-tree.nvim",
opts = {
filesystem = {
filtered_items = {
hide_dotfiles = false,
hide_gitignored = false,
-- 避免被默认规则额外隐藏(例如 .git 等)
hide_by_name = {},
hide_by_pattern = {},
},
},
window = {
position = "left",
width = 30,
mapping_options = {
noremap = true,
nowait = true,
},
},
},
config = function(_, opts)
require("neo-tree").setup(opts)
-- Neotree 打开逻辑已移到 autocmds.lua,这里不再重复
end,
},
-- Telescope 默认不展示 dotfiles(以及可能被 .gitignore 忽略的文件),这里统一打开
{
"nvim-telescope/telescope.nvim",
opts = function(_, opts)
opts.pickers = opts.pickers or {}
opts.pickers.find_files = vim.tbl_deep_extend("force", opts.pickers.find_files or {}, {
hidden = true,
no_ignore = true,
no_ignore_parent = true,
})
-- live_grep / grep_string 默认也包含 dotfiles(但仍遵循 ignore 规则,避免把 node_modules 等全扫进来)
opts.defaults = opts.defaults or {}
local telescope_defaults = require("telescope.config").values
opts.defaults.vimgrep_arguments = vim.deepcopy(opts.defaults.vimgrep_arguments or telescope_defaults.vimgrep_arguments)
if not vim.tbl_contains(opts.defaults.vimgrep_arguments, "--hidden") then
table.insert(opts.defaults.vimgrep_arguments, "--hidden")
end
end,
},
{
"akinsho/bufferline.nvim",
event = "VeryLazy",
opts = {
options = {
mode = "buffers", -- set to "tabs" to only show tabpages instead
numbers = "ordinal",
close_command = function(bufnr) vim.api.nvim_buf_delete(bufnr, { force = true }) end,
right_mouse_command = function(bufnr) vim.api.nvim_buf_delete(bufnr, { force = true }) end,
left_mouse_command = "buffer",
middle_mouse_command = nil,
indicator = {
style = "icon",
icon = "",
},
buffer_close_icon = "󰅖",
modified_icon = "",
close_icon = "",
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 18,
max_prefix_length = 15,
tab_size = 18,
truncate_names = true,
color_icons = true,
show_buffer_icons = true,
show_buffer_close_icons = true,
show_close_icon = true,
show_tab_indicators = true,
persist_buffer_sort = true,
separator_style = "thin",
enforce_regular_tabs = false,
always_show_bufferline = true,
hover = {
enabled = true,
delay = 200,
reveal = {'close'}
},
sort_by = 'insert_after_current',
},
},
config = function(_, opts)
require("bufferline").setup(opts)
end,
},
}
@@ -0,0 +1,60 @@
-- Dracula 主题配置
-- 支持多种变体: dracula, dracula-soft, day
local M = {}
M.config = function(style)
local opts = {
-- 主题变体: dracula, dracula-soft, day
theme = style or 'dracula',
-- 透明背景
transparent_bg = false,
-- 斜体注释
italic_comment = true,
-- 显示文件末尾的 ~ 符号
show_end_of_buffer = true,
-- Lualine 背景色
lualine_bg_color = '#44475a',
}
-- 高级自定义选项(可选)
if style == 'soft' then
opts.colors = {
-- 更柔和的背景色
bg = '#21222c',
fg = '#f8f8f2',
}
elseif style == 'day' then
opts.colors = {
-- 浅色主题配色
bg = '#f8f8f2',
fg = '#282a36',
}
end
return opts
end
-- 主题信息
M.info = {
name = 'dracula',
plugin = 'Mofiqul/dracula.nvim',
variants = {
{ name = 'dracula', desc = '经典深色主题' },
{ name = 'dracula-soft', desc = '柔和深色主题' },
{ name = 'day', desc = '浅色主题' },
},
features = {
'支持透明背景',
'斜体注释',
'完整的 LSP 和 Treesitter 支持',
'Lualine 主题集成',
'多插件支持(Telescope, NvimTree 等)',
}
}
return M
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
indent_type = "Spaces"
indent_width = 2
column_width = 120
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env lua
-- 主题预览器 - 简化版
-- 用法: nvim -u theme-previewer.lua
-- 临时配置目录
local tmp_dir = "/tmp/nvim-theme-preview"
os.execute("mkdir -p " .. tmp_dir)
-- 写入基础配置
local init_lua = tmp_dir .. "/init.lua"
local file = io.open(init_lua, "w")
if not file then
print("无法创建临时配置")
os.exit(1)
end
file:write([[
-- 最小化主题预览配置
vim.opt.termguicolors = true
vim.opt.background = "dark"
-- 主题列表
local themes = {
dracula = function()
package.path = package.path .. ";" .. vim.fn.stdpath("config") .. "/lua/?.lua"
require('plugins.dracula')
end,
onedark = function()
vim.cmd [[colorscheme onedark]]
end,
tokyonight = function()
require('tokyonight').setup({style = 'night'})
vim.cmd.colorscheme('tokyonight')
end,
catppuccin = function()
require('catppuccin').setup({flavour = 'mocha'})
vim.cmd.colorscheme('catppuccin')
end,
gruvbox = function()
require('gruvbox').setup({contrast = 'hard'})
vim.cmd.colorscheme('gruvbox')
end,
}
-- 获取主题参数
local theme = arg[1] or 'dracula'
-- 应用主题
if themes[theme] then
themes[theme]()
else
print("未知主题: " .. theme)
print("可用主题: " .. table.concat(vim.tbl_keys(themes), ", "))
end
-- 预览内容
vim.api.nvim_buf_set_lines(0, 0, -1, false, {
"🎨 " .. theme .. " 主题预览",
"",
"-- Lua 代码示例",
"local function hello_world()",
" print('Hello, World!') -- 注释",
" local dracula = '🧛'",
" return dracula",
"end",
"",
"-- JavaScript 代码示例",
"function hello() {",
" console.log('Hello, World!');",
" const theme = '" .. theme .. "';",
" return theme;",
"}",
"",
"快捷键: q 退出预览",
})
-- 设置快捷键
vim.keymap.set('n', 'q', ':qa!<CR>', {noremap = true, silent = true})
vim.keymap.set('n', '<Esc>', ':qa!<CR>', {noremap = true, silent = true})
print("🎨 预览 " .. theme .. " 主题")
print("按 q 退出预览")
]])
file:close()
-- 启动 nvim
local cmd = string.format("nvim -u %s", init_lua)
os.execute(cmd)
-- 清理
os.execute("rm -rf " .. tmp_dir)
+159
View File
@@ -0,0 +1,159 @@
#!/usr/bin/env lua
-- Neovim 主题切换脚本
-- 用法: nvim -l theme-switcher.lua <主题名> [样式]
local themes = {
dracula = {
plugin = 'Mofiqul/dracula.nvim',
setup = function(style)
local opts = {
theme = style or 'dracula', -- dracula, dracula-soft, day
transparent_bg = false,
italic_comment = true,
show_end_of_buffer = true,
}
require('dracula').setup(opts)
end
},
catppuccin = {
plugin = 'catppuccin/nvim',
setup = function(style)
local flavours = { 'mocha', 'macchiato', 'frappe', 'latte' }
local flavour = style and flavours[tonumber(style)] or 'mocha'
require('catppuccin').setup({ flavour = flavour })
end
},
tokyonight = {
plugin = 'folke/tokyonight.nvim',
setup = function(style)
local opts = {
style = style or 'night', -- night, storm, day, moon
transparent = false,
terminal_colors = true,
}
require('tokyonight').setup(opts)
end
},
gruvbox = {
plugin = 'ellisonleao/gruvbox.nvim',
setup = function(style)
local opts = {
contrast = style or 'hard', -- soft, medium, hard
transparent_mode = false,
}
require('gruvbox').setup(opts)
end
},
onedark = {
plugin = 'navarasu/onedark.nvim',
setup = function(style)
local opts = {
style = style or 'dark', -- dark, darker, cool, deep, warm, warmer
transparent = false,
}
require('onedark').setup(opts)
end
}
}
-- 解析命令行参数
local theme_name = arg[1]
local style = arg[2]
if not theme_name then
print("\n🎨 Neovim 主题切换器")
print("用法: nvim -l theme-switcher.lua <主题> [样式]")
print("\n可用主题:")
for name, info in pairs(themes) do
print(string.format(" %-12s %s", name, info.plugin))
end
print("\n示例:")
print(" nvim -l theme-switcher.lua dracula dracula-soft")
print(" nvim -l theme-switcher.lua catppuccin 1 (1=mocha,2=macchiato,3=frappe,4=latte)")
print(" nvim -l theme-switcher.lua tokyonight storm")
os.exit(0)
end
-- 检查主题是否存在
if not themes[theme_name] then
print("❌ 未知主题: " .. theme_name)
print("可用主题: " .. table.concat(vim.tbl_keys(themes), ", "))
os.exit(1)
end
-- 生成临时配置文件
local config_content = string.format([[
-- 临时主题配置 - %s
vim.cmd [[set runtimepath+=~/.config/nvim]]
-- 安装主题插件
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{ "%s", priority = 1000 },
})
-- 设置主题
%s
vim.cmd.colorscheme("%s")
-- 打开一个新文件查看效果
vim.cmd [[enew]]
vim.api.nvim_buf_set_lines(0, 0, -1, false, {
"🎨 主题预览: %s",
"",
"function hello() {",
" console.log('Hello, World!');",
" // This is a comment",
" const dracula = '🧛';",
" return dracula;",
"}",
"",
"local themes = {",
" dracula = 'dark',",
" catppuccin = 'soft',",
"}",
})
-- 设置快捷键
vim.keymap.set('n', 'q', ':qa!<CR>', { noremap = true, silent = true })
vim.keymap.set('n', '<Esc>', ':qa!<CR>', { noremap = true, silent = true })
print("\n🎨 主题预览: %s (%s)")
print("按 q 或 Esc 退出预览")
]],
theme_name,
themes[theme_name].plugin,
themes[theme_name].setup(style),
theme_name,
theme_name,
theme_name,
style or "default"
)
-- 写入临时配置
local tmp_config = "/tmp/nvim-theme-preview.lua"
local file = io.open(tmp_config, "w")
if file then
file:write(config_content)
file:close()
-- 启动 neovim 预览
local cmd = string.format("nvim -u %s", tmp_config)
print(string.format("\n🎨 启动 %s 主题预览 (%s)...", theme_name, style or "default"))
os.execute(cmd)
-- 清理临时文件
os.remove(tmp_config)
else
print("❌ 无法创建临时配置文件")
os.exit(1)
end
Vendored Submodule
+1
Submodule tools/external/tmux added at 615c27c117