From 09f405445e24ec0bc08005642375a992f12b8708 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sat, 26 Apr 2025 09:01:46 -0500 Subject: [PATCH] Fixed a bug where body-level classes weren't being transferred to Kavita's epub html in some cases. --- API/Services/BookService.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/API/Services/BookService.cs b/API/Services/BookService.cs index 2eee99891..99fdd1400 100644 --- a/API/Services/BookService.cs +++ b/API/Services/BookService.cs @@ -399,11 +399,14 @@ public class BookService : IBookService { // Check if any classes on the html node (some r2l books do this) and move them to body tag for scoping var htmlNode = doc.DocumentNode.SelectSingleNode("//html"); - if (htmlNode == null || !htmlNode.Attributes.Contains("class")) return body.InnerHtml; + if (htmlNode == null) return body.InnerHtml; var bodyClasses = body.Attributes.Contains("class") ? body.Attributes["class"].Value : string.Empty; - var classes = htmlNode.Attributes["class"].Value + " " + bodyClasses; - body.Attributes.Add("class", $"{classes}"); + var htmlClasses = htmlNode.Attributes.Contains("class") ? htmlNode.Attributes["class"].Value : string.Empty; + + body.Attributes.Add("class", $"{htmlClasses} {bodyClasses}"); + + // I actually need the body tag itself for the classes, so i will create a div and put the body stuff there. return $"
{body.InnerHtml}
"; }