diff --git a/Epub/KoeBook.Epub/Services/EpubCreateService.cs b/Epub/KoeBook.Epub/Services/EpubCreateService.cs index f96cac2..b34d590 100644 --- a/Epub/KoeBook.Epub/Services/EpubCreateService.cs +++ b/Epub/KoeBook.Epub/Services/EpubCreateService.cs @@ -8,7 +8,6 @@ namespace KoeBook.Epub.Services; public class EpubCreateService(IFileExtensionService fileExtensionService) : IEpubCreateService { private readonly IFileExtensionService _fileExtensionService = fileExtensionService; - private readonly StringBuilder _builder = new(); internal const string ContainerXml = """ @@ -113,10 +112,9 @@ public async ValueTask TryCreateEpubAsync(EpubDocument epubDocument, strin } } - internal string CreateNavXhtml(EpubDocument epubDocument) + internal static string CreateNavXhtml(EpubDocument epubDocument) { - _builder.Clear(); - _builder.AppendLine($""" + var builder = new StringBuilder($""" @@ -126,13 +124,13 @@ internal string CreateNavXhtml(EpubDocument epubDocument) """); - return _builder.ToString(); + return builder.ToString(); } - internal string CreateCssText(EpubDocument epubDocument) + internal static string CreateCssText(EpubDocument epubDocument) { - _builder.Clear(); + var builder = new StringBuilder(); foreach (var cssClass in epubDocument.CssClasses) { - _builder.AppendLine(cssClass.Text); + builder.AppendLine(cssClass.Text); } - return _builder.ToString(); + return builder.ToString(); } internal string CreateOpf(EpubDocument epubDocument) { - _builder.Clear(); - _builder.AppendLine($""" + var builder = new StringBuilder($""" {epubDocument.Title} @@ -196,6 +193,7 @@ internal string CreateOpf(EpubDocument epubDocument) {DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)} -epub-media-overlay-active -epub-media-overlay-unactive + """); var totalTime = TimeSpan.Zero; @@ -205,12 +203,12 @@ internal string CreateOpf(EpubDocument epubDocument) { var time = epubDocument.Chapters[i].Sections[j].GetTotalTime(); totalTime += time; - _builder.AppendLine($""" + builder.AppendLine($""" {time} """); } } - _builder.AppendLine($""" + builder.AppendLine($""" {totalTime} @@ -223,7 +221,7 @@ internal string CreateOpf(EpubDocument epubDocument) { for (var j = 0; j < epubDocument.Chapters[i].Sections.Count; j++) { - _builder.AppendLine($""" + builder.AppendLine($""" """); @@ -232,17 +230,17 @@ internal string CreateOpf(EpubDocument epubDocument) var element = epubDocument.Chapters[i].Sections[j].Elements[k]; if (element is Paragraph para && para.Audio != null) { - _builder.AppendLine(@$" "); + builder.AppendLine(@$" "); } else if (element is Picture pic && File.Exists(pic.PictureFilePath)) { - _builder.AppendLine(@$" "); + builder.AppendLine(@$" "); } } } } - _builder.AppendLine($""" + builder.AppendLine($""" """); @@ -251,23 +249,23 @@ internal string CreateOpf(EpubDocument epubDocument) { for (var j = 0; j < epubDocument.Chapters[i].Sections.Count; j++) { - _builder.AppendLine($""" + builder.AppendLine($""" """); } } - _builder.AppendLine($""" + builder.AppendLine($""" """); - return _builder.ToString(); + return builder.ToString(); } - internal string CreateSectionXhtml(Section section) + + internal static string CreateSectionXhtml(Section section) { - _builder.Clear(); - _builder.AppendLine($""" + var builder = new StringBuilder($""" @@ -281,7 +279,7 @@ internal string CreateSectionXhtml(Section section) { if (section.Elements[i] is Paragraph para) { - _builder.AppendLine($""" + builder.AppendLine($"""

{para.Text}

@@ -289,7 +287,7 @@ internal string CreateSectionXhtml(Section section) } else if (section.Elements[i] is Picture pic && File.Exists(pic.PictureFilePath)) { - _builder.AppendLine($""" + builder.AppendLine($"""

@@ -297,17 +295,16 @@ internal string CreateSectionXhtml(Section section) } } - _builder.AppendLine(""" + builder.AppendLine(""" """); - return _builder.ToString(); + return builder.ToString(); } - internal string CreateSectionSmil(Section section) + internal static string CreateSectionSmil(Section section) { - _builder.Clear(); - _builder.AppendLine($""" + var builder = new StringBuilder($""" @@ -317,7 +314,7 @@ internal string CreateSectionSmil(Section section) { if (section.Elements[i] is Paragraph para && para.Audio != null) { - _builder.AppendLine($""" + builder.AppendLine($""" """); - return _builder.ToString(); + return builder.ToString(); } }