@@ -59,6 +59,7 @@ import qualified Data.Set as Set
59
59
type Notes = [[Block ]]
60
60
data WriterState =
61
61
WriterState { stNotes :: Notes
62
+ , stEndNotes :: Notes
62
63
, stOptions :: WriterOptions
63
64
, stTopLevel :: Bool
64
65
, stInsideBlock :: Bool
@@ -72,6 +73,7 @@ writeMuse :: PandocMonad m
72
73
-> m Text
73
74
writeMuse opts document =
74
75
let st = WriterState { stNotes = []
76
+ , stEndNotes = []
75
77
, stOptions = opts
76
78
, stTopLevel = True
77
79
, stInsideBlock = False
@@ -95,8 +97,9 @@ pandocToMuse (Pandoc meta blocks) = do
95
97
(fmap render' . inlineListToMuse)
96
98
meta
97
99
body <- blockListToMuse blocks
98
- notes <- liftM (reverse . stNotes) get >>= notesToMuse
99
- let main = render colwidth $ body $+$ notes
100
+ notes <- liftM (reverse . stNotes) get >>= notesToMuse (' [' , ' ]' )
101
+ endNotes <- liftM (reverse . stEndNotes) get >>= notesToMuse (' {' , ' }' )
102
+ let main = render colwidth $ body $+$ notes $+$ endNotes
100
103
let context = defField " body" main metadata
101
104
case writerTemplate opts of
102
105
Nothing -> return main
@@ -261,18 +264,20 @@ blockToMuse Null = return empty
261
264
262
265
-- | Return Muse representation of notes.
263
266
notesToMuse :: PandocMonad m
264
- => Notes
267
+ => (Char , Char )
268
+ -> Notes
265
269
-> StateT WriterState m Doc
266
- notesToMuse notes = liftM vsep (zipWithM noteToMuse [1 .. ] notes)
270
+ notesToMuse lr notes = liftM vsep (zipWithM ( noteToMuse lr) [1 .. ] notes)
267
271
268
272
-- | Return Muse representation of a note.
269
273
noteToMuse :: PandocMonad m
270
- => Int
274
+ => (Char , Char )
275
+ -> Int
271
276
-> [Block ]
272
277
-> StateT WriterState m Doc
273
- noteToMuse num note = do
278
+ noteToMuse (l, r) num note = do
274
279
contents <- blockListToMuse note
275
- let marker = " [ " ++ show num ++ " ] "
280
+ let marker = l : ( show num ++ (r : " " ))
276
281
return $ hang (length marker) (text marker) contents
277
282
278
283
-- | Escape special characters for Muse.
@@ -391,12 +396,19 @@ inlineToMuse (Image _ inlines (source, title)) = do
391
396
else " [" <> alt <> " ]"
392
397
else " [" <> text title <> " ]"
393
398
return $ " [[" <> text source <> " ]" <> title' <> " ]"
394
- inlineToMuse (Note _ contents) = do
399
+ inlineToMuse (Note notetype contents) = do
395
400
-- add to notes in state
396
401
notes <- gets stNotes
397
- modify $ \ st -> st { stNotes = contents: notes }
398
- let ref = show $ length notes + 1
399
- return $ " [" <> text ref <> " ]"
402
+ endNotes <- gets stEndNotes
403
+ modify $ case notetype of
404
+ EndNote -> \ st -> st { stEndNotes = contents: endNotes }
405
+ _ -> \ st -> st { stNotes = contents: notes }
406
+ let ref = show $ 1 + length (case notetype of
407
+ EndNote -> endNotes
408
+ _ -> notes)
409
+ case notetype of
410
+ EndNote -> return $ " {" <> text ref <> " }"
411
+ _ -> return $ " [" <> text ref <> " ]"
400
412
inlineToMuse (Span (_,name: _,_) inlines) = do
401
413
contents <- inlineListToMuse inlines
402
414
return $ " <class name=\" " <> text name <> " \" >" <> contents <> " </class>"
0 commit comments