forked from marko/svitak
improve chapter detection
This commit is contained in:
parent
d63c8c43c6
commit
4a55d773c6
1 changed files with 15 additions and 10 deletions
|
|
@ -120,16 +120,7 @@ embedImages arch bdir = map processTag
|
|||
b64 = TE.decodeUtf8 $ B64.encode rawData
|
||||
in "data:" <> getMimeType fullPath <> ";base64," <> b64
|
||||
|
||||
-- TODO: Implement this, as it's not called yet
|
||||
getChapterTitle :: [Tag T.Text] -> T.Text
|
||||
getChapterTitle tags =
|
||||
case dropWhile (not . isHeading) tags of
|
||||
(_ : TagText t : _) -> T.strip t
|
||||
_ -> "Untitled Chapter"
|
||||
where
|
||||
isHeading (TagOpen "h1" _) = True
|
||||
isHeading (TagOpen "h2" _) = True
|
||||
isHeading _ = False
|
||||
|
||||
|
||||
filterJunk :: [Tag T.Text] -> [Tag T.Text]
|
||||
filterJunk = go
|
||||
|
|
@ -142,3 +133,17 @@ filterJunk = go
|
|||
dropUntilClose _ [] = []
|
||||
dropUntilClose name (TagClose n : xs) | n == name = xs
|
||||
dropUntilClose name (_ : xs) = dropUntilClose name xs
|
||||
|
||||
-- TODO: Implement this, as it's not called yet
|
||||
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) -- The heading content, the outer tags will be detected such as h1 but this makes sure that every other inner tag is ignored yet the inner text will still be visible
|
||||
|
||||
_ -> "Untitled Chapter"
|
||||
|
||||
where
|
||||
ishding (TagOpen n _ ) = n `elem` ["h1", "h2", "h3"]
|
||||
ishding _ = False
|
||||
isclose n (TagClose n') = n == n'
|
||||
isclose _ _ = False
|
||||
|
|
|
|||
Loading…
Reference in a new issue