diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/Opf.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/Opf.kt index 234fd5f9b..193ce26dc 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/Opf.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/Opf.kt @@ -21,7 +21,12 @@ fun Document.getManifest() = fun normalizeHref( opfDir: Path?, href: String, -) = (opfDir?.resolve(href)?.normalize() ?: Paths.get(href)).invariantSeparatorsPathString +): String { + val anchor = href.substringAfterLast("#", "") + val base = href.substringBeforeLast("#") + val resolvedPath = (opfDir?.resolve(base)?.normalize() ?: Paths.get(base)).invariantSeparatorsPathString + return resolvedPath + if (anchor.isNotBlank()) "#$anchor" else "" +} /** * Process an OPF document and extracts TOC entries