@@ -120,6 +120,7 @@ defaultWriterEnv = WriterEnv{ envTextProperties = []
120
120
121
121
data WriterState = WriterState {
122
122
stFootnotes :: [Element ]
123
+ , stEndnotes :: [Element ]
123
124
, stComments :: [([(String ,String )], [Inline ])]
124
125
, stSectionIds :: Set. Set String
125
126
, stExternalLinks :: M. Map String String
@@ -137,6 +138,7 @@ data WriterState = WriterState{
137
138
defaultWriterState :: WriterState
138
139
defaultWriterState = WriterState {
139
140
stFootnotes = defaultFootnotes
141
+ , stEndnotes = []
140
142
, stComments = []
141
143
, stSectionIds = Set. empty
142
144
, stExternalLinks = M. empty
@@ -283,7 +285,7 @@ writeDocx opts doc@(Pandoc meta _) = do
283
285
}
284
286
285
287
286
- ((contents, footnotes, comments), st) <- runStateT
288
+ ((contents, footnotes, endnotes, comments), st) <- runStateT
287
289
(runReaderT
288
290
(writeOpenXML opts{writerWrapText = WrapNone } doc')
289
291
env)
@@ -352,6 +354,8 @@ writeDocx opts doc@(Pandoc meta _) = do
352
354
" application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" )
353
355
,(" /word/footnotes.xml" ,
354
356
" application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml" )
357
+ ,(" /word/endnotes.xml" ,
358
+ " application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml" )
355
359
] ++
356
360
map (\ x -> (maybe " " (" /word/" ++ ) $ extractTarget x,
357
361
" application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml" )) headers ++
@@ -396,8 +400,11 @@ writeDocx opts doc@(Pandoc meta _) = do
396
400
,(" http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" ,
397
401
" rId7" ,
398
402
" footnotes.xml" )
399
- ,(" http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments " ,
403
+ ,(" http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes " ,
400
404
" rId8" ,
405
+ " endnotes.xml" )
406
+ ,(" http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" ,
407
+ " rId9" ,
401
408
" comments.xml" )
402
409
]
403
410
@@ -436,14 +443,23 @@ writeDocx opts doc@(Pandoc meta _) = do
436
443
$ renderXml docContents
437
444
438
445
-- footnotes
439
- let notes = mknode " w:footnotes" stdAttributes footnotes
440
- let footnotesEntry = toEntry " word/footnotes.xml" epochtime $ renderXml notes
446
+ let footnotesNode = mknode " w:footnotes" stdAttributes footnotes
447
+ let footnotesEntry = toEntry " word/footnotes.xml" epochtime $ renderXml footnotesNode
441
448
442
449
-- footnote rels
443
450
let footnoteRelEntry = toEntry " word/_rels/footnotes.xml.rels" epochtime
444
451
$ renderXml $ mknode " Relationships" [(" xmlns" ," http://schemas.openxmlformats.org/package/2006/relationships" )]
445
452
linkrels
446
453
454
+ -- endnotes
455
+ let endnotesNode = mknode " w:endnotes" stdAttributes endnotes
456
+ let endnotesEntry = toEntry " word/endnotes.xml" epochtime $ renderXml endnotesNode
457
+
458
+ -- endnote rels
459
+ let endnoteRelEntry = toEntry " word/_rels/endnotes.xml.rels" epochtime
460
+ $ renderXml $ mknode " Relationships" [(" xmlns" ," http://schemas.openxmlformats.org/package/2006/relationships" )]
461
+ linkrels
462
+
447
463
-- comments
448
464
let commentsEntry = toEntry " word/comments.xml" epochtime
449
465
$ renderXml $ mknode " w:comments" stdAttributes comments
@@ -544,15 +560,16 @@ writeDocx opts doc@(Pandoc meta _) = do
544
560
, " word/_rels/" `isPrefixOf` (eRelativePath e)
545
561
, " .xml.rels" `isSuffixOf` (eRelativePath e)
546
562
, eRelativePath e /= " word/_rels/document.xml.rels"
547
- , eRelativePath e /= " word/_rels/footnotes.xml.rels" ]
563
+ , eRelativePath e /= " word/_rels/footnotes.xml.rels"
564
+ , eRelativePath e /= " word/_rels/endnotes.xml.rels" ]
548
565
let otherMediaEntries = [ e | e <- zEntries refArchive
549
566
, " word/media/" `isPrefixOf` eRelativePath e ]
550
567
551
568
-- Create archive
552
569
let archive = foldr addEntryToArchive emptyArchive $
553
570
contentTypesEntry : relsEntry : contentEntry : relEntry :
554
- footnoteRelEntry : numEntry : styleEntry : footnotesEntry :
555
- commentsEntry :
571
+ footnoteRelEntry : endnoteRelEntry : numEntry : styleEntry :
572
+ footnotesEntry : endnotesEntry : commentsEntry :
556
573
docPropsEntry : docPropsAppEntry : themeEntry :
557
574
fontTableEntry : settingsEntry : webSettingsEntry :
558
575
imageEntries ++ headerFooterEntries ++
@@ -751,7 +768,7 @@ makeTOC _ = return []
751
768
752
769
-- | Convert Pandoc document to two lists of
753
770
-- OpenXML elements (the main document and footnotes).
754
- writeOpenXML :: (PandocMonad m ) => WriterOptions -> Pandoc -> WS m ([Element ], [Element ],[Element ])
771
+ writeOpenXML :: (PandocMonad m ) => WriterOptions -> Pandoc -> WS m ([Element ], [Element ], [ Element ], [Element ])
755
772
writeOpenXML opts (Pandoc meta blocks) = do
756
773
let tit = docTitle meta
757
774
let auths = docAuthors meta
@@ -778,7 +795,8 @@ writeOpenXML opts (Pandoc meta blocks) = do
778
795
convertSpace xs = xs
779
796
let blocks' = bottomUp convertSpace blocks
780
797
doc' <- setFirstPara >> blocksToOpenXML opts blocks'
781
- notes' <- reverse <$> gets stFootnotes
798
+ footnotes' <- reverse <$> gets stFootnotes
799
+ endnotes' <- reverse <$> gets stEndnotes
782
800
comments <- reverse <$> gets stComments
783
801
let toComment (kvs, ils) = do
784
802
annotation <- inlinesToOpenXML opts ils
@@ -798,7 +816,7 @@ writeOpenXML opts (Pandoc meta blocks) = do
798
816
comments' <- mapM toComment comments
799
817
toc <- makeTOC opts
800
818
let meta' = title ++ subtitle ++ authors ++ date ++ abstract ++ toc
801
- return (meta' ++ doc', notes ', comments')
819
+ return (meta' ++ doc', footnotes', endnotes ', comments')
802
820
803
821
-- | Convert a list of Pandoc blocks to OpenXML.
804
822
blocksToOpenXML :: (PandocMonad m ) => WriterOptions -> [Block ] -> WS m [Element ]
@@ -1225,8 +1243,8 @@ inlineToOpenXML' opts (Code attrs str) = do
1225
1243
Left msg -> do
1226
1244
unless (null msg) $ report $ CouldNotHighlight msg
1227
1245
unhighlighted
1228
- inlineToOpenXML' opts (Note _ bs) = do
1229
- notes <- gets stFootnotes
1246
+ inlineToOpenXML' opts (Note FootNote bs) = do
1247
+ footnotes <- gets stFootnotes
1230
1248
notenum <- (lift . lift) getUniqueId
1231
1249
footnoteStyle <- rStyleM " Footnote Reference"
1232
1250
let notemarker = mknode " w:r" []
@@ -1243,10 +1261,32 @@ inlineToOpenXML' opts (Note _ bs) = do
1243
1261
(withParaPropM (pStyleM " Footnote Text" ) $ blocksToOpenXML opts
1244
1262
$ insertNoteRef bs)
1245
1263
let newnote = mknode " w:footnote" [(" w:id" , notenum)] contents
1246
- modify $ \ s -> s{ stFootnotes = newnote : notes }
1264
+ modify $ \ s -> s{ stFootnotes = newnote : footnotes }
1247
1265
return [ mknode " w:r" []
1248
1266
[ mknode " w:rPr" [] footnoteStyle
1249
1267
, mknode " w:footnoteReference" [(" w:id" , notenum)] () ] ]
1268
+ inlineToOpenXML' opts (Note EndNote bs) = do
1269
+ endnotes <- gets stEndnotes
1270
+ notenum <- (lift . lift) getUniqueId
1271
+ endnoteStyle <- rStyleM " Endnote Reference"
1272
+ let notemarker = mknode " w:r" []
1273
+ [ mknode " w:rPr" [] endnoteStyle
1274
+ , mknode " w:endnoteRef" [] () ]
1275
+ let notemarkerXml = RawInline (Format " openxml" ) $ ppElement notemarker
1276
+ let insertNoteRef (Plain ils : xs) = Plain (notemarkerXml : Space : ils) : xs
1277
+ insertNoteRef (Para ils : xs) = Para (notemarkerXml : Space : ils) : xs
1278
+ insertNoteRef xs = Para [notemarkerXml] : xs
1279
+
1280
+ contents <- local (\ env -> env{ envListLevel = - 1
1281
+ , envParaProperties = []
1282
+ , envTextProperties = [] })
1283
+ (withParaPropM (pStyleM " Endnote Text" ) $ blocksToOpenXML opts
1284
+ $ insertNoteRef bs)
1285
+ let newnote = mknode " w:endnote" [(" w:id" , notenum)] contents
1286
+ modify $ \ s -> s{ stEndnotes = newnote : endnotes }
1287
+ return [ mknode " w:r" []
1288
+ [ mknode " w:rPr" [] endnoteStyle
1289
+ , mknode " w:endnoteReference" [(" w:id" , notenum)] () ] ]
1250
1290
-- internal link:
1251
1291
inlineToOpenXML' opts (Link _ txt (' #' : xs,_)) = do
1252
1292
contents <- withTextPropM (rStyleM " Hyperlink" ) $ inlinesToOpenXML opts txt
0 commit comments