From 02bb0f051aee08e2b8a3aa1d8fba2d9f7398279c Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Tue, 2 Oct 2012 19:20:51 -0700
Subject: [PATCH] Use integer ids for bookmarks.

Closes #626.
---
 src/Text/Pandoc/Writers/Docx.hs | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index f8e3370e4..e44f77497 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -50,6 +50,7 @@ import Text.XML.Light
 import Text.TeXMath
 import Control.Monad.State
 import Text.Highlighting.Kate
+import Data.Unique (hashUnique, newUnique)
 
 data WriterState = WriterState{
          stTextProperties :: [Element]
@@ -333,11 +334,12 @@ blockToOpenXML opts (Header lev lst) = do
   contents <- withParaProp (pStyle $ "Heading" ++ show lev) $
                blockToOpenXML opts (Para lst)
   usedIdents <- gets stSectionIds
-  let ident = uniqueIdent lst usedIdents
-  modify $ \s -> s{ stSectionIds = ident : stSectionIds s }
-  let bookmarkStart = mknode "w:bookmarkStart" [("w:id",ident)
-                                               ,("w:name",ident)] ()
-  let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id",ident)] ()
+  let bookmarkName = uniqueIdent lst usedIdents
+  modify $ \s -> s{ stSectionIds = bookmarkName : stSectionIds s }
+  id' <- liftIO $ hashUnique `fmap` newUnique
+  let bookmarkStart = mknode "w:bookmarkStart" [("w:id",show id')
+                                               ,("w:name",bookmarkName)] ()
+  let bookmarkEnd = mknode "w:bookmarkEnd" [("w:id",show id')] ()
   return $ [bookmarkStart] ++ contents ++ [bookmarkEnd]
 blockToOpenXML opts (Plain lst) = blockToOpenXML opts (Para lst)
 blockToOpenXML opts (Para x@[Image alt _]) = do
@@ -574,7 +576,7 @@ inlineToOpenXML _ (Code attrs str) =
                                      , mknode "w:t" [("xml:space","preserve")] tok ]
 inlineToOpenXML opts (Note bs) = do
   notes <- gets stFootnotes
-  let notenum = length notes + 1
+  notenum <- liftIO $ hashUnique `fmap` newUnique
   let notemarker = mknode "w:r" []
                    [ mknode "w:rPr" [] (rStyle "FootnoteReference")
                    , mknode "w:footnoteRef" [] () ]