@@ -598,6 +598,33 @@ mkLvl marker lvl =
598getNumId :: WS Int
598getNumId :: WS Int
599getNumId = (((baseListId - 1) +) . length) `fmap` gets stLists
599getNumId = (((baseListId - 1) +) . length) `fmap` gets stLists
601+makeTOC :: WriterOptions -> WS [Element]
602+makeTOC opts | writerTableOfContents opts = do
603+ let depth = "1-"++(show (writerTOCDepth opts))
604+ let tocCmd = "TOC \\o \""++depth++"\" \\h \\z \\u"
605+ title <- withParaPropM (pStyleM "TOC Heading") (blocksToOpenXML opts [Para [Str "Table of Contents"]])
607+ [mknode "w:sdt" [] ([
608+ mknode "w:sdtPr" [] (
609+ mknode "w:docPartObj" [] (
610+ [mknode "w:docPartGallery" [("w:val","Table of Contents")] (),
611+ mknode "w:docPartUnique" [] ()]
614+ mknode "w:sdtContent" [] (title++[
617+ mknode "w:fldChar" [("w:fldCharType","begin"),("w:dirty","true")] (),
618+ mknode "w:instrText" [("xml:space","preserve")] tocCmd,
619+ mknode "w:fldChar" [("w:fldCharType","separate")] (),
620+ mknode "w:fldChar" [("w:fldCharType","end")] ()
625+makeTOC _ = return []
601-- | Convert Pandoc document to two lists of
628-- | Convert Pandoc document to two lists of
602-- OpenXML elements (the main document and footnotes).
629-- OpenXML elements (the main document and footnotes).
603writeOpenXML :: WriterOptions -> Pandoc -> WS ([Element], [Element])
630writeOpenXML :: WriterOptions -> Pandoc -> WS ([Element], [Element])
@@ -630,7 +657,8 @@ writeOpenXML opts (Pandoc meta blocks) = do
630 let blocks' = bottomUp convertSpace blocks
657 let blocks' = bottomUp convertSpace blocks
631 doc' <- (setFirstPara >> blocksToOpenXML opts blocks')
658 doc' <- (setFirstPara >> blocksToOpenXML opts blocks')
632 notes' <- reverse `fmap` gets stFootnotes
659 notes' <- reverse `fmap` gets stFootnotes
633− let meta' = title ++ subtitle ++ authors ++ date ++ abstract
661+ let meta' = title ++ subtitle ++ authors ++ date ++ abstract ++ toc
634 return (meta' ++ doc', notes')
662 return (meta' ++ doc', notes')
636-- | Convert a list of Pandoc blocks to OpenXML.
664-- | Convert a list of Pandoc blocks to OpenXML.