Documentation

This commit is contained in:
Marko Andjelic 2026-02-04 02:12:28 +00:00
commit a53ef52902

View file

@ -121,6 +121,7 @@ getMimeFromManifest (DMan.Manifest items) relPath =
Just item -> T.pack $ DMan.mfiMediaType item
Nothing -> "image/jpeg"
-- Replace img tags with base64
embedImages :: EpubEnv -> [Tag T.Text] -> [Tag T.Text]
embedImages env = map processTag
where
@ -128,7 +129,7 @@ embedImages env = map processTag
processTag other = other
replaceSrc (name, value)
| name == "src" = ("src", findImage value)
| name == "src" = ("src", findImage value) -- guards to check for src otherwise output the argument it was given without changes
| otherwise = (name, value)
findImage path =
@ -145,7 +146,7 @@ filterJunk :: [Tag T.Text] -> [Tag T.Text]
filterJunk = go
where
go [] = []
go (TagOpen name _ : xs) | name `elem` ["script", "style", "head", "link", "meta"] =
go (TagOpen name _ : xs) | name `elem` ["script", "style", "head", "link", "meta"] = -- these are elems we want to filter out
go (dropUntilClose name xs)
go (x:xs) = x : go xs
@ -156,7 +157,7 @@ filterJunk = go
getChapterTitle :: [Tag T.Text] -> T.Text
getChapterTitle tags =
case dropWhile (not . ishding) tags of
(TagOpen x _ : xs ) -> T.strip $ innerText (takeWhile (not . isclose x) xs)
(TagOpen x _ : xs ) -> T.strip $ innerText (takeWhile (not . isclose x) xs) -- get the raw heading content, remove nested tags
_ -> "Untitled Chapter"
where
ishding (TagOpen n _ ) = n `elem` ["h1", "h2", "h3"]