- 添加MetadataModel.cs支持完整的元数据字段 - 更新FileMerger.cs从TXT文件读取元数据,从bkmk文件读取目录 - 支持所有元数据字段:title, Other titles, Volume, ISBN, creator等 - 修正书签连接符为14个短横线(---------------) - 添加UTF-8/GBK编码自动检测 - 更新ContentFormatter.cs支持元数据文档合并 现在程序能够: 1. 从TXT文件读取完整的元数据信息 2. 从FreePic2Pdf_bkmk.txt文件提取书签目录 3. 按照需求格式合并输出完整内容 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
101 lines
2.8 KiB
C#
101 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Linq;
|
|
|
|
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 FormatMetadataDocument(DocumentMetadata metadata)
|
|
{
|
|
if (metadata == null)
|
|
return string.Empty;
|
|
|
|
return metadata.ToFormattedString();
|
|
}
|
|
|
|
public static string CombineFormattedMetadataDocuments(List<DocumentMetadata> documents)
|
|
{
|
|
if (documents == null || documents.Count == 0)
|
|
return string.Empty;
|
|
|
|
var combined = new StringBuilder();
|
|
|
|
for (int i = 0; i < documents.Count; i++)
|
|
{
|
|
var doc = documents[i];
|
|
|
|
if (i > 0)
|
|
{
|
|
// 在不同文档内容之间用"<>"分隔
|
|
combined.AppendLine();
|
|
combined.AppendLine("<>");
|
|
combined.AppendLine();
|
|
}
|
|
|
|
combined.Append(doc.ToFormattedString());
|
|
}
|
|
|
|
return combined.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();
|
|
}
|
|
}
|
|
} |