From e79cd346c4165320e37ab6e165ff51a8511c5c25 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sat, 22 Apr 2023 15:52:37 +0200 Subject: [PATCH] fix toc --- internal/epub/epub_toc.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/epub/epub_toc.go b/internal/epub/epub_toc.go index 7c625b3..0824ca3 100644 --- a/internal/epub/epub_toc.go +++ b/internal/epub/epub_toc.go @@ -37,12 +37,18 @@ func (e *ePub) getToc(title string, images []*Image) string { link := t.CreateElement("a") link.CreateAttr("href", img.TextPath()) link.CreateText(path) - paths[currentPath] = t + paths[currentPath] = t.CreateElement("ol") } } if len(ol.ChildElements()) == 1 && e.StripFirstDirectoryFromToc { - ol = ol.ChildElements()[0] + ol = ol.FindElement("/li/ol") + } + + for _, v := range ol.FindElements("//ol") { + if len(v.ChildElements()) == 0 { + v.Parent().RemoveChild(v) + } } beginning := etree.NewElement("li")