git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: define Muse type
commit72527770783ac098e6ec9976eebcd3f8401700cc authorAlexander Krotov <ilabdsf@gmail.com> dateWed 28 Mar 2018, 14:53 (9 years ago) parentb379a29
1 file changed+18−16
src/Text/Pandoc/Writers/Muse.hs+18−16
src/Text/Pandoc/Writers/Muse.hs+18−16
@@ -69,6 +69,8 @@ data WriterState =
6969 , stIds :: Set.Set String
7070 }
7171
72+type Muse = StateT WriterState
73+
7274-- | Convert Pandoc to Muse.
7375writeMuse :: PandocMonad m
7476 => WriterOptions
@@ -86,7 +88,7 @@ writeMuse opts document =
8688-- | Return Muse representation of document.
8789pandocToMuse :: PandocMonad m
8890 => Pandoc
89− -> StateT WriterState m Text
91+ -> Muse m Text
9092pandocToMuse (Pandoc meta blocks) = do
9193 opts <- gets stOptions
9294 let colwidth = if writerWrapText opts == WrapAuto
@@ -111,7 +113,7 @@ pandocToMuse (Pandoc meta blocks) = do
111113catWithBlankLines :: PandocMonad m
112114 => [Block] -- ^ List of block elements
113115 -> Int -- ^ Number of blank lines
114− -> StateT WriterState m Doc
116+ -> Muse m Doc
115117catWithBlankLines (b : bs) n = do
116118 b' <- blockToMuse b
117119 bs' <- flatBlockListToMuse bs
@@ -122,7 +124,7 @@ catWithBlankLines _ _ = error "Expected at least one block"
122124-- | without setting stTopLevel.
123125flatBlockListToMuse :: PandocMonad m
124126 => [Block] -- ^ List of block elements
125− -> StateT WriterState m Doc
127+ -> Muse m Doc
126128flatBlockListToMuse bs@(BulletList _ : BulletList _ : _) = catWithBlankLines bs 2
127129flatBlockListToMuse bs@(OrderedList (_, style1, _) _ : OrderedList (_, style2, _) _ : _) =
128130 catWithBlankLines bs (if style1' == style2' then 2 else 0)
@@ -138,7 +140,7 @@ flatBlockListToMuse [] = return mempty
138140-- | Convert list of Pandoc block elements to Muse.
139141blockListToMuse :: PandocMonad m
140142 => [Block] -- ^ List of block elements
141− -> StateT WriterState m Doc
143+ -> Muse m Doc
142144blockListToMuse blocks = do
143145 oldState <- get
144146 modify $ \s -> s { stTopLevel = not $ stInsideBlock s
@@ -153,7 +155,7 @@ blockListToMuse blocks = do
153155-- | Convert Pandoc block element to Muse.
154156blockToMuse :: PandocMonad m
155157 => Block -- ^ Block element
156− -> StateT WriterState m Doc
158+ -> Muse m Doc
157159blockToMuse (Plain inlines) = inlineListToMuse' inlines
158160blockToMuse (Para inlines) = do
159161 contents <- inlineListToMuse' inlines
@@ -183,7 +185,7 @@ blockToMuse (OrderedList (start, style, _) items) = do
183185 where orderedListItemToMuse :: PandocMonad m
184186 => String -- ^ marker for list item
185187 -> [Block] -- ^ list item (list of blocks)
186− -> StateT WriterState m Doc
188+ -> Muse m Doc
187189 orderedListItemToMuse marker item = do
188190 contents <- blockListToMuse item
189191 return $ hang (length marker + 1) (text marker <> space) contents
@@ -194,7 +196,7 @@ blockToMuse (BulletList items) = do
194196 return $ cr $$ (if topLevel then nest 1 else id) (vcat contents) $$ blankline
195197 where bulletListItemToMuse :: PandocMonad m
196198 => [Block]
197− -> StateT WriterState m Doc
199+ -> Muse m Doc
198200 bulletListItemToMuse item = do
199201 contents <- blockListToMuse item
200202 return $ hang 2 "- " contents
@@ -205,7 +207,7 @@ blockToMuse (DefinitionList items) = do
205207 return $ cr $$ (if topLevel then nest 1 else id) (vcat contents) $$ blankline
206208 where definitionListItemToMuse :: PandocMonad m
207209 => ([Inline], [[Block]])
208− -> StateT WriterState m Doc
210+ -> Muse m Doc
209211 definitionListItemToMuse (label, defs) = do
210212 label' <- inlineListToMuse' label
211213 contents <- liftM vcat $ mapM descriptionToMuse defs
@@ -213,7 +215,7 @@ blockToMuse (DefinitionList items) = do
213215 return $ hang ind label' contents
214216 descriptionToMuse :: PandocMonad m
215217 => [Block]
216− -> StateT WriterState m Doc
218+ -> Muse m Doc
217219 descriptionToMuse desc = hang 4 " :: " <$> blockListToMuse desc
218220blockToMuse (Header level (ident,_,_) inlines) = do
219221 opts <- gets stOptions
@@ -261,14 +263,14 @@ blockToMuse Null = return empty
261263-- | Return Muse representation of notes.
262264notesToMuse :: PandocMonad m
263265 => Notes
264− -> StateT WriterState m Doc
266+ -> Muse m Doc
265267notesToMuse notes = liftM vsep (zipWithM noteToMuse [1 ..] notes)
266268
267269-- | Return Muse representation of a note.
268270noteToMuse :: PandocMonad m
269271 => Int
270272 -> [Block]
271− -> StateT WriterState m Doc
273+ -> Muse m Doc
272274noteToMuse num note = do
273275 contents <- blockListToMuse note
274276 let marker = "[" ++ show num ++ "] "
@@ -377,7 +379,7 @@ fixOrEscape _ = False
377379renderInlineList :: PandocMonad m
378380 => Bool
379381 -> [Inline]
380− -> StateT WriterState m Doc
382+ -> Muse m Doc
381383renderInlineList True [] = pure "<verbatim></verbatim>"
382384renderInlineList False [] = pure ""
383385renderInlineList start (x:xs) = do r <- inlineToMuse x
@@ -391,21 +393,21 @@ renderInlineList start (x:xs) = do r <- inlineToMuse x
391393inlineListToMuse'' :: PandocMonad m
392394 => Bool
393395 -> [Inline]
394− -> StateT WriterState m Doc
396+ -> Muse m Doc
395397inlineListToMuse'' start lst = do
396398 lst' <- (normalizeInlineList . fixNotes) <$> preprocessInlineList (map (removeKeyValues . replaceSmallCaps) lst)
397399 renderInlineList start lst'
398400
399−inlineListToMuse' :: PandocMonad m => [Inline] -> StateT WriterState m Doc
401+inlineListToMuse' :: PandocMonad m => [Inline] -> Muse m Doc
400402inlineListToMuse' = inlineListToMuse'' True
401403
402−inlineListToMuse :: PandocMonad m => [Inline] -> StateT WriterState m Doc
404+inlineListToMuse :: PandocMonad m => [Inline] -> Muse m Doc
403405inlineListToMuse = inlineListToMuse'' False
404406
405407-- | Convert Pandoc inline element to Muse.
406408inlineToMuse :: PandocMonad m
407409 => Inline
408− -> StateT WriterState m Doc
410+ -> Muse m Doc
409411inlineToMuse (Str str) = return $ text $ conditionalEscapeString str
410412inlineToMuse (Emph lst) = do
411413 contents <- inlineListToMuse lst