Docx writer: Don't include bookmarks on headers unless non-null id.

Closes #3476.
This commit is contained in:
John MacFarlane 2017-03-03 21:13:08 +01:00
parent dc9788b6dc
commit d18a1c1c9e

View file

@ -816,29 +816,31 @@ blockToOpenXML' opts (Div (ident,classes,kvs) bs) = do
else id else id
header <- dirmod $ stylemod $ blocksToOpenXML opts hs header <- dirmod $ stylemod $ blocksToOpenXML opts hs
contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs' contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs'
if null ident
then return $ header ++ contents
else do
id' <- getUniqueId id' <- getUniqueId
let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id') let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
,("w:name",ident)] () ,("w:name",ident)] ()
let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] () let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
if null ident return $ bookmarkStart : header ++ contents ++ [bookmarkEnd]
then return $ header ++ contents
else return $ bookmarkStart : header ++ contents ++ [bookmarkEnd]
blockToOpenXML' opts (Header lev (ident,_,_) lst) = do blockToOpenXML' opts (Header lev (ident,_,_) lst) = do
setFirstPara setFirstPara
paraProps <- withParaPropM (pStyleM ("Heading "++show lev)) $ paraProps <- withParaPropM (pStyleM ("Heading "++show lev)) $
getParaProps False getParaProps False
contents <- inlinesToOpenXML opts lst contents <- inlinesToOpenXML opts lst
usedIdents <- gets stSectionIds if null ident
let bookmarkName = if null ident then return [mknode "w:p" [] (paraProps ++contents)]
then uniqueIdent lst usedIdents else do
else ident let bookmarkName = ident
modify $ \s -> s{ stSectionIds = Set.insert bookmarkName $ stSectionIds s } modify $ \s -> s{ stSectionIds = Set.insert bookmarkName
$ stSectionIds s }
id' <- getUniqueId id' <- getUniqueId
let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id') let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
,("w:name",bookmarkName)] () ,("w:name",bookmarkName)] ()
let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] () let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
return [mknode "w:p" [] (paraProps ++ [bookmarkStart] ++ contents return [mknode "w:p" [] (paraProps ++
++ [bookmarkEnd])] [bookmarkStart] ++ contents ++ [bookmarkEnd])]
blockToOpenXML' opts (Plain lst) = withParaProp (pCustomStyle "Compact") blockToOpenXML' opts (Plain lst) = withParaProp (pCustomStyle "Compact")
$ blockToOpenXML opts (Para lst) $ blockToOpenXML opts (Para lst)
-- title beginning with fig: indicates that the image is a figure -- 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 else return id
contents <- insmod $ delmod $ dirmod $ stylemod $ pmod contents <- insmod $ delmod $ dirmod $ stylemod $ pmod
$ inlinesToOpenXML opts ils $ inlinesToOpenXML opts ils
if null ident
then return contents
else do
id' <- getUniqueId id' <- getUniqueId
let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id') let bookmarkStart = mknode "w:bookmarkStart" [("w:id", id')
,("w:name",ident)] () ,("w:name",ident)] ()
let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] () let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id", id')] ()
return $ if null ident return $ bookmarkStart : contents ++ [bookmarkEnd]
then contents
else bookmarkStart : contents ++ [bookmarkEnd]
inlineToOpenXML' opts (Strong lst) = inlineToOpenXML' opts (Strong lst) =
withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst withTextProp (mknode "w:b" [] ()) $ inlinesToOpenXML opts lst
inlineToOpenXML' opts (Emph lst) = inlineToOpenXML' opts (Emph lst) =