SlideCombine/ContentFormatter.cs
yuuko 505715c05e 实现PDF书签合并功能
- 添加BookmarkExtractor类用于从FreePic2Pdf_bkmk文件提取书签内容
- 添加ContentFormatter类实现内容格式化处理
- 添加FileMerger类实现文件智能合并功能
- 更新主界面支持路径选择和处理进度显示
- 支持按文件名前缀自动合并(如CH-875 1-3和CH-875 4-6合并为CH-875.txt)
- 输出格式符合需求:tableOfContents与subject之间插入格式化内容
- 支持UTF-8和GBK编码自动检测
- 添加详细的使用说明文档

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 15:44:37 +08:00

67 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.Text;
namespace SlideCombine
{
public class ContentFormatter
{
public static string FormatBookmarks(List<BookmarkItem> bookmarks)
{
if (bookmarks == null || bookmarks.Count == 0)
return string.Empty;
var sb = new StringBuilder();
// 添加tableOfContents标记
sb.AppendLine("tableOfContents:");
foreach (var bookmark in bookmarks)
{
if (!string.IsNullOrEmpty(bookmark.Title))
{
// 每行内容顶格
sb.Append(bookmark.Title.Trim());
// 单词和页码之间加"----------"
if (!string.IsNullOrEmpty(bookmark.Page))
{
sb.Append("----------");
sb.Append(bookmark.Page);
}
// 页码后加"<br/>"
sb.Append("<br/>");
}
}
// 添加subject标记
sb.AppendLine();
sb.Append("subject:");
return sb.ToString();
}
public static string CombineFormattedContents(List<string> formattedContents)
{
if (formattedContents == null || formattedContents.Count == 0)
return string.Empty;
var combined = new StringBuilder();
for (int i = 0; i < formattedContents.Count; i++)
{
if (i > 0)
{
// 在不同文件内容之间用"<>"分隔
combined.AppendLine();
combined.AppendLine("<>");
combined.AppendLine();
}
combined.Append(formattedContents[i]);
}
return combined.ToString();
}
}
}