@@ -110,6 +110,7 @@ data WriterState = WriterState{
110 , stPrintWidth :: Integer
110 , stPrintWidth :: Integer
111 , stStyleMaps :: StyleMaps
111 , stStyleMaps :: StyleMaps
112 , stFirstPara :: Bool
112 , stFirstPara :: Bool
113+ , stTocTitle :: [Inline]
115defaultWriterState :: WriterState
116defaultWriterState :: WriterState
@@ -131,6 +132,7 @@ defaultWriterState = WriterState{
131 , stPrintWidth = 1
132 , stPrintWidth = 1
132 , stStyleMaps = defaultStyleMaps
133 , stStyleMaps = defaultStyleMaps
133 , stFirstPara = False
134 , stFirstPara = False
135+ , stTocTitle = normalizeInlines [Str "Table of Contents"]
136type WS a = StateT WriterState IO a
138type WS a = StateT WriterState IO a
@@ -193,6 +195,13 @@ isValidChar (ord -> c)
193 | 0x10000 <= c && c <= 0x10FFFF = True
195 | 0x10000 <= c && c <= 0x10FFFF = True
194 | otherwise = False
196 | otherwise = False
198+metaValueToInlines :: MetaValue -> [Inline]
199+metaValueToInlines (MetaString s) = normalizeInlines [Str s]
200+metaValueToInlines (MetaInlines ils) = ils
201+metaValueToInlines (MetaBlocks bs) = query return bs
202+metaValueToInlines (MetaBool b) = [Str $ show b]
203+metaValueToInlines _ = []
196-- | Produce an Docx file from a Pandoc document.
205-- | Produce an Docx file from a Pandoc document.
197writeDocx :: WriterOptions -- ^ Writer options
206writeDocx :: WriterOptions -- ^ Writer options
198 -> Pandoc -- ^ Document to convert
207 -> Pandoc -- ^ Document to convert
@@ -235,11 +244,15 @@ writeDocx opts doc@(Pandoc meta _) = do
235 -- parse styledoc for heading styles
244 -- parse styledoc for heading styles
236 let styleMaps = getStyleMaps styledoc
245 let styleMaps = getStyleMaps styledoc
247+ let tocTitle = fromMaybe (stTocTitle defaultWriterState) $
248+ metaValueToInlines <$> lookupMeta "toc-title" meta
238 ((contents, footnotes), st) <- runStateT (writeOpenXML opts{writerWrapText = False} doc')
250 ((contents, footnotes), st) <- runStateT (writeOpenXML opts{writerWrapText = False} doc')
239 defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
251 defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
240 , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
252 , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
241 , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
253 , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
242 , stStyleMaps = styleMaps
254 , stStyleMaps = styleMaps
255+ , stTocTitle = tocTitle
244 let epochtime = floor $ utcTimeToPOSIXSeconds utctime
257 let epochtime = floor $ utcTimeToPOSIXSeconds utctime
245 let imgs = M.elems $ stImages st
258 let imgs = M.elems $ stImages st
@@ -626,7 +639,8 @@ makeTOC :: WriterOptions -> WS [Element]
626makeTOC opts | writerTableOfContents opts = do
639makeTOC opts | writerTableOfContents opts = do
627 let depth = "1-"++(show (writerTOCDepth opts))
640 let depth = "1-"++(show (writerTOCDepth opts))
628 let tocCmd = "TOC \\o \""++depth++"\" \\h \\z \\u"
641 let tocCmd = "TOC \\o \""++depth++"\" \\h \\z \\u"
642+ tocTitle <- gets stTocTitle
629− title <- withParaPropM (pStyleM "TOC Heading") (blocksToOpenXML opts [Para [Str "Table of Contents"]])
643+ title <- withParaPropM (pStyleM "TOC Heading") (blocksToOpenXML opts [Para tocTitle])
631 [mknode "w:sdt" [] ([
645 [mknode "w:sdt" [] ([
632 mknode "w:sdtPr" [] (
646 mknode "w:sdtPr" [] (