aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-03 21:13:08 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-03 21:13:08 +0100
commitd18a1c1c9e6ebd83b1ce3b24a639c9478b4b62cb (patch)
tree883c977c49b93948471bca969c7bfc8d369051f9 /src/Text
parentdc9788b6dc00b96be7f67c6d072b23420dc05dec (diff)
downloadpandoc-d18a1c1c9e6ebd83b1ce3b24a639c9478b4b62cb.tar.gz
Docx writer: Don't include bookmarks on headers unless non-null id.
Closes #3476.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 3636a94ba..26b1cfdf6 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -816,29 +816,31 @@ blockToOpenXML' opts (Div (ident,classes,kvs) bs) = do
else id
header <- dirmod $ stylemod $ blocksToOpenXML opts hs
contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs'
- id' <- getUniqueId
- let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
- ,("w:name",ident)] ()
- let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
if null ident
then return $ header ++ contents
- else return $ bookmarkStart : header ++ contents ++ [bookmarkEnd]
+ else do
+ id' <- getUniqueId
+ let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
+ ,("w:name",ident)] ()
+ let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
+ return $ bookmarkStart : header ++ contents ++ [bookmarkEnd]
blockToOpenXML' opts (Header lev (ident,_,_) lst) = do
setFirstPara
paraProps <- withParaPropM (pStyleM ("Heading "++show lev)) $
getParaProps False
contents <- inlinesToOpenXML opts lst
- usedIdents <- gets stSectionIds
- let bookmarkName = if null ident
- then uniqueIdent lst usedIdents
- else ident
- modify $ \s -> s{ stSectionIds = Set.insert bookmarkName $ stSectionIds s }
- id' <- getUniqueId
- let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
+ if null ident
+ then return [mknode "w:p" [] (paraProps ++contents)]
+ else do
+ let bookmarkName = ident
+ modify $ \s -> s{ stSectionIds = Set.insert bookmarkName
+ $ stSectionIds s }
+ id' <- getUniqueId
+ let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
,("w:name",bookmarkName)] ()
- let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
- return [mknode "w:p" [] (paraProps ++ [bookmarkStart] ++ contents
- ++ [bookmarkEnd])]
+ let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
+ return [mknode "w:p" [] (paraProps ++
+ [bookmarkStart] ++ contents ++ [bookmarkEnd])]
blockToOpenXML' opts (Plain lst) = withParaProp (pCustomStyle "Compact")
$ blockToOpenXML opts (Para lst)
-- title beginning with fig: indicates that the image is a figure
@@ -1100,13 +1102,14 @@ inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do
else return id
contents <- insmod $ delmod $ dirmod $ stylemod $ pmod
$ inlinesToOpenXML opts ils
- id' <- getUniqueId
- let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
- ,("w:name",ident)] ()
- let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
- return $ if null ident
- then contents
- else bookmarkStart : contents ++ [bookmarkEnd]
+ if null ident
+ then return contents
+ else do
+ id' <- getUniqueId
+ let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
+ ,("w:name",ident)] ()
+ let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
+ return $ bookmarkStart : contents ++ [bookmarkEnd]
inlineToOpenXML' opts (Strong lst) =
withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst
inlineToOpenXML' opts (Emph lst) =