aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-01-11 17:07:25 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2013-01-11 17:07:25 -0800
commit98bc0d17ab3c31f53d7d133e3dc589fc93756c7b (patch)
tree08ca66fc0b7a54a2f4d624401f755bb1619ee6f6 /src
parentf3f3638f21a5f9ca1c1933a969bdfc1aef1a2eb4 (diff)
downloadpandoc-98bc0d17ab3c31f53d7d133e3dc589fc93756c7b.tar.gz
Revised EPUB writer given changes in header attributes.
We need to ensure that all headers have attributes, since this is no longer guaranteed by hierarchicalize. Explicitly given headers remain the same.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 20b9f190d..389589e9a 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -119,7 +119,8 @@ writeEPUB opts doc@(Pandoc meta _) = do
-- body pages
-- add level 1 header to beginning if none there
- let blocks' = case blocks of
+ let blocks' = addIdentifiers
+ $ case blocks of
(Header 1 _ _ : _) -> blocks
_ -> Header 1 ("",[],[]) (docTitle meta) : blocks
@@ -431,6 +432,18 @@ data IdentState = IdentState{
showChapter :: Int -> String
showChapter = printf "ch%03d.xhtml"
+-- Add identifiers to any headers without them.
+addIdentifiers :: [Block] -> [Block]
+addIdentifiers bs = evalState (mapM go bs) []
+ where go (Header n (ident,classes,kvs) ils) = do
+ ids <- get
+ let ident' = if null ident
+ then uniqueIdent ils ids
+ else ident
+ put $ ident' : ids
+ return $ Header n (ident',classes,kvs) ils
+ go x = return x
+
-- Go through a block list and construct a table
-- correlating the automatically constructed references
-- that would be used in a normal pandoc document with
@@ -444,21 +457,19 @@ correlateRefs chapterHeaderLevel bs =
, chapterIdents = []
, identTable = [] }
where go :: Block -> State IdentState ()
- go (Header n _ ils) = do
+ go (Header n (ident,_,_) ils) = do
when (n <= chapterHeaderLevel) $
modify $ \s -> s{ chapterNumber = chapterNumber s + 1
, chapterIdents = [] }
st <- get
- let runningid = uniqueIdent ils (runningIdents st)
let chapterid = showChapter (chapterNumber st) ++
if n <= chapterHeaderLevel
then ""
else '#' : uniqueIdent ils (chapterIdents st)
- modify $ \s -> s{ runningIdents = runningid : runningIdents st
+ modify $ \s -> s{ runningIdents = ident : runningIdents st
, chapterIdents = chapterid : chapterIdents st
- , identTable = (runningid, chapterid) :
- identTable st
- }
+ , identTable = (ident, chapterid) : identTable st
+ }
go _ = return ()
-- Replace internal link references using the table produced