git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: fix hlint errors (#3764)
commitfa515e46f36fa3e73b26b89b721a2de1738cf4e3 authorAlexander Krotov <ilabdsf@gmail.com> dateMon 26 Jun 2017, 16:07 (9 years ago) parentb2fe009
2 files changed+15−19
src/Text/Pandoc/Writers/Muse.hs+13−17 test/Tests/Writers/Muse.hs+2−2
src/Text/Pandoc/Writers/Muse.hs+13−17
@@ -97,8 +97,7 @@ pandocToMuse (Pandoc meta blocks) = do
9797 body <- blockListToMuse blocks
9898 notes <- liftM (reverse . stNotes) get >>= notesToMuse
9999 let main = render colwidth $ body $+$ notes
100− let context = defField "body" main
101− $ metadata
100+ let context = defField "body" main metadata
102101 case writerTemplate opts of
103102 Nothing -> return main
104103 Just tpl -> renderTemplate' tpl context
@@ -129,14 +128,14 @@ blockToMuse (Para inlines) = do
129128blockToMuse (LineBlock lns) = do
130129 let splitStanza [] = []
131130 splitStanza xs = case break (== mempty) xs of
132− (l, []) -> l : []
131+ (l, []) -> [l]
133132 (l, _:r) -> l : splitStanza r
134133 let joinWithLinefeeds = nowrap . mconcat . intersperse cr
135134 let joinWithBlankLines = mconcat . intersperse blankline
136135 let prettyfyStanza ls = joinWithLinefeeds <$> mapM inlineListToMuse ls
137136 contents <- joinWithBlankLines <$> mapM prettyfyStanza (splitStanza lns)
138137 return $ blankline $$ "<verse>" $$ contents $$ "</verse>" <> blankline
139−blockToMuse (CodeBlock (_,_,_) str) = do
138+blockToMuse (CodeBlock (_,_,_) str) =
140139 return $ "<example>" $$ text str $$ "</example>" $$ blankline
141140blockToMuse (RawBlock (Format format) str) =
142141 return $ blankline $$ "<literal style=\"" <> text format <> "\">" $$
@@ -154,11 +153,10 @@ blockToMuse (OrderedList (start, style, _) items) = do
154153 let maxMarkerLength = maximum $ map length markers
155154 let markers' = map (\m -> let s = maxMarkerLength - length m
156155 in m ++ replicate s ' ') markers
157− contents <- mapM (\(item, num) -> orderedListItemToMuse item num) $
158− zip markers' items
156+ contents <- zipWithM orderedListItemToMuse markers' items
159157 -- ensure that sublists have preceding blank line
160158 topLevel <- gets stTopLevel
161− return $ cr $$ ((if topLevel then nest 1 else id) $ vcat contents) $$ blankline
159+ return $ cr $$ (if topLevel then nest 1 else id) (vcat contents) $$ blankline
162160 where orderedListItemToMuse :: PandocMonad m
163161 => String -- ^ marker for list item
164162 -> [Block] -- ^ list item (list of blocks)
@@ -170,7 +168,7 @@ blockToMuse (BulletList items) = do
170168 contents <- mapM bulletListItemToMuse items
171169 -- ensure that sublists have preceding blank line
172170 topLevel <- gets stTopLevel
173− return $ cr $$ ((if topLevel then nest 1 else id) $ vcat contents) $$ blankline
171+ return $ cr $$ (if topLevel then nest 1 else id) (vcat contents) $$ blankline
174172 where bulletListItemToMuse :: PandocMonad m
175173 => [Block]
176174 -> StateT WriterState m Doc
@@ -179,7 +177,7 @@ blockToMuse (BulletList items) = do
179177 return $ hang 2 "- " contents
180178blockToMuse (DefinitionList items) = do
181179 contents <- mapM definitionListItemToMuse items
182− return $ cr $$ (nest 1 $ vcat $ contents) $$ blankline
180+ return $ cr $$ nest 1 (vcat contents) $$ blankline
183181 where definitionListItemToMuse :: PandocMonad m
184182 => ([Inline], [[Block]])
185183 -> StateT WriterState m Doc
@@ -218,8 +216,8 @@ blockToMuse (Table caption _ _ headers rows) = do
218216 -- FIXME: Muse doesn't allow blocks with height more than 1.
219217 let hpipeBlocks sep blocks = hcat $ intersperse sep' blocks
220218 where h = maximum (1 : map height blocks)
221− sep' = lblock (length sep) $ vcat (map text $ replicate h sep)
222− let makeRow sep = (" " <>) . (hpipeBlocks sep . zipWith lblock widthsInChars)
219+ sep' = lblock (length sep) $ vcat (replicate h (text sep))
220+ let makeRow sep = (" " <>) . hpipeBlocks sep . zipWith lblock widthsInChars
223221 let head' = makeRow " || " headers'
224222 let rowSeparator = if noHeaders then " | " else " | "
225223 rows'' <- mapM (\row -> do cols <- mapM blockListToMuse row
@@ -236,9 +234,7 @@ blockToMuse Null = return empty
236234notesToMuse :: PandocMonad m
237235 => Notes
238236 -> StateT WriterState m Doc
239−notesToMuse notes =
240− mapM (\(num, note) -> noteToMuse num note) (zip [1..] notes) >>=
241− return . vsep
237+notesToMuse notes = liftM vsep (zipWithM noteToMuse [1 ..] notes)
242238
243239-- | Return Muse representation of a note.
244240noteToMuse :: PandocMonad m
@@ -268,7 +264,7 @@ conditionalEscapeString s
268264inlineListToMuse :: PandocMonad m
269265 => [Inline]
270266 -> StateT WriterState m Doc
271−inlineListToMuse lst = mapM inlineToMuse lst >>= return . hcat
267+inlineListToMuse lst = liftM hcat (mapM inlineToMuse lst)
272268
273269-- | Convert Pandoc inline element to Muse.
274270inlineToMuse :: PandocMonad m
@@ -316,7 +312,7 @@ inlineToMuse Space = return space
316312inlineToMuse SoftBreak = do
317313 wrapText <- gets $ writerWrapText . stOptions
318314 return $ if wrapText == WrapPreserve then cr else space
319−inlineToMuse (Link _ txt (src, _)) = do
315+inlineToMuse (Link _ txt (src, _)) =
320316 case txt of
321317 [Str x] | escapeURI x == src ->
322318 return $ "[[" <> text (escapeLink x) <> "]]"
@@ -340,7 +336,7 @@ inlineToMuse (Note contents) = do
340336 -- add to notes in state
341337 notes <- gets stNotes
342338 modify $ \st -> st { stNotes = contents:notes }
343− let ref = show $ (length notes) + 1
339+ let ref = show $ length notes + 1
344340 return $ "[" <> text ref <> "]"
345341inlineToMuse (Span (_,name:_,_) inlines) = do
346342 contents <- inlineListToMuse inlines
test/Tests/Writers/Muse.hs+2−2
@@ -31,14 +31,14 @@ tests = [ testGroup "block elements"
3131 , "Second paragraph."
3232 ]
3333 ]
34− , "line block" =: lineBlock ([text "Foo", text "bar", text "baz"])
34+ , "line block" =: lineBlock [text "Foo", text "bar", text "baz"]
3535 =?> unlines [ "<verse>"
3636 , "Foo"
3737 , "bar"
3838 , "baz"
3939 , "</verse>"
4040 ]
41− , "code block" =: codeBlock ("int main(void) {\n\treturn 0;\n}")
41+ , "code block" =: codeBlock "int main(void) {\n\treturn 0;\n}"
4242 =?> unlines [ "<example>"
4343 , "int main(void) {"
4444 , "\treturn 0;"