git.iko.soy/typeable/pandoc
on master help sign in
hlint suggestions.
cbcb9b3John MacFarlane
pandoc.hs−1
@@ -36,4 +36,3 @@ import Text.Pandoc.Error (handleError)
36main :: IO ()
36main :: IO ()
37main = E.catch (parseOptions options defaultOpts >>= convertWithOpts)
37main = E.catch (parseOptions options defaultOpts >>= convertWithOpts)
38 (handleError . Left)
38 (handleError . Left)
39−
src/Text/Pandoc/CSV.hs−1
@@ -100,4 +100,3 @@ endline :: Parser ()
100endline = do
100endline = do
101 optional (void $ char '\r')
101 optional (void $ char '\r')
102 void $ char '\n'
102 void $ char '\n'
103−
src/Text/Pandoc/Class.hs−1
@@ -997,4 +997,3 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
997 else "")
997 else "")
998 (return ())
998 (return ())
999 logOutput = lift . logOutput
999 logOutput = lift . logOutput
1000−
src/Text/Pandoc/Emoji.hs−1
@@ -903,4 +903,3 @@ emojis = M.fromList
903 ,("zero","0\65039\8419")
903 ,("zero","0\65039\8419")
904 ,("zzz","\128164")
904 ,("zzz","\128164")
905 ]
905 ]
906−
src/Text/Pandoc/ImageSize.hs−1
@@ -602,4 +602,3 @@ tagTypeTable = M.fromList
602 , (0xa300, FileSource)
602 , (0xa300, FileSource)
603 , (0xa301, SceneType)
603 , (0xa301, SceneType)
604 ]
604 ]
605−
src/Text/Pandoc/Lua/StackInstances.hs+10−10
@@ -208,18 +208,18 @@ peekBlock idx = do
208 case tag of
208 case tag of
209 "BlockQuote" -> BlockQuote <$> elementContent
209 "BlockQuote" -> BlockQuote <$> elementContent
210 "BulletList" -> BulletList <$> elementContent
210 "BulletList" -> BulletList <$> elementContent
211− "CodeBlock" -> (withAttr CodeBlock) <$> elementContent
211+ "CodeBlock" -> withAttr CodeBlock <$> elementContent
212 "DefinitionList" -> DefinitionList <$> elementContent
212 "DefinitionList" -> DefinitionList <$> elementContent
213− "Div" -> (withAttr Div) <$> elementContent
213+ "Div" -> withAttr Div <$> elementContent
214 "Header" -> (\(lvl, LuaAttr attr, lst) -> Header lvl attr lst)
214 "Header" -> (\(lvl, LuaAttr attr, lst) -> Header lvl attr lst)
215 <$> elementContent
215 <$> elementContent
216 "HorizontalRule" -> return HorizontalRule
216 "HorizontalRule" -> return HorizontalRule
217 "LineBlock" -> LineBlock <$> elementContent
217 "LineBlock" -> LineBlock <$> elementContent
218− "OrderedList" -> (uncurry OrderedList) <$> elementContent
218+ "OrderedList" -> uncurry OrderedList <$> elementContent
219 "Null" -> return Null
219 "Null" -> return Null
220 "Para" -> Para <$> elementContent
220 "Para" -> Para <$> elementContent
221 "Plain" -> Plain <$> elementContent
221 "Plain" -> Plain <$> elementContent
222− "RawBlock" -> (uncurry RawBlock) <$> elementContent
222+ "RawBlock" -> uncurry RawBlock <$> elementContent
223 "Table" -> (\(capt, aligns, widths, headers, body) ->
223 "Table" -> (\(capt, aligns, widths, headers, body) ->
224 Table capt aligns widths headers body)
224 Table capt aligns widths headers body)
225 <$> elementContent
225 <$> elementContent
@@ -257,8 +257,8 @@ peekInline :: StackIndex -> Lua Inline
257peekInline idx = do
257peekInline idx = do
258 tag <- getTag idx
258 tag <- getTag idx
259 case tag of
259 case tag of
260− "Cite" -> (uncurry Cite) <$> elementContent
260+ "Cite" -> uncurry Cite <$> elementContent
261− "Code" -> (withAttr Code) <$> elementContent
261+ "Code" -> withAttr Code <$> elementContent
262 "Emph" -> Emph <$> elementContent
262 "Emph" -> Emph <$> elementContent
263 "Image" -> (\(LuaAttr attr, lst, tgt) -> Image attr lst tgt)
263 "Image" -> (\(LuaAttr attr, lst, tgt) -> Image attr lst tgt)
264 <$> elementContent
264 <$> elementContent
@@ -266,13 +266,13 @@ peekInline idx = do
266 <$> elementContent
266 <$> elementContent
267 "LineBreak" -> return LineBreak
267 "LineBreak" -> return LineBreak
268 "Note" -> Note <$> elementContent
268 "Note" -> Note <$> elementContent
269− "Math" -> (uncurry Math) <$> elementContent
269+ "Math" -> uncurry Math <$> elementContent
270− "Quoted" -> (uncurry Quoted) <$> elementContent
270+ "Quoted" -> uncurry Quoted <$> elementContent
271− "RawInline" -> (uncurry RawInline) <$> elementContent
271+ "RawInline" -> uncurry RawInline <$> elementContent
272 "SmallCaps" -> SmallCaps <$> elementContent
272 "SmallCaps" -> SmallCaps <$> elementContent
273 "SoftBreak" -> return SoftBreak
273 "SoftBreak" -> return SoftBreak
274 "Space" -> return Space
274 "Space" -> return Space
275− "Span" -> (withAttr Span) <$> elementContent
275+ "Span" -> withAttr Span <$> elementContent
276 "Str" -> Str <$> elementContent
276 "Str" -> Str <$> elementContent
277 "Strikeout" -> Strikeout <$> elementContent
277 "Strikeout" -> Strikeout <$> elementContent
278 "Strong" -> Strong <$> elementContent
278 "Strong" -> Strong <$> elementContent
src/Text/Pandoc/MIME.hs−1
@@ -525,4 +525,3 @@ mimeTypesList = -- List borrowed from happstack-server.
525 ,("zip","application/zip")
525 ,("zip","application/zip")
526 ,("zmt","chemical/x-mopac-input")
526 ,("zmt","chemical/x-mopac-input")
527 ]
527 ]
528−
src/Text/Pandoc/PDF.hs−1
@@ -438,4 +438,3 @@ context2pdf verbosity tmpDir source = inDirectory tmpDir $ do
438 return $ Left logmsg
438 return $ Left logmsg
439 (ExitSuccess, Nothing) -> return $ Left ""
439 (ExitSuccess, Nothing) -> return $ Left ""
440 (ExitSuccess, Just pdf) -> return $ Right pdf
440 (ExitSuccess, Just pdf) -> return $ Right pdf
441−
src/Text/Pandoc/Readers/Creole.hs+1−1
@@ -282,7 +282,7 @@ placeholder = B.text <$> try (string "<<<" >> manyTill anyChar (string ">>>")
282 >> return "")
282 >> return "")
283
283
284whitespace :: PandocMonad m => CRLParser m B.Inlines
284whitespace :: PandocMonad m => CRLParser m B.Inlines
285−whitespace = (lb <|> regsp)
285+whitespace = lb <|> regsp
286 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
286 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
287 regsp = try $ skipMany1 spaceChar >> return B.space
287 regsp = try $ skipMany1 spaceChar >> return B.space
288
288
src/Text/Pandoc/Readers/Docx.hs+37−38
@@ -139,7 +139,7 @@ instance Default DEnv where
139type DocxContext m = ReaderT DEnv (StateT DState m)
139type DocxContext m = ReaderT DEnv (StateT DState m)
140
140
141evalDocxContext :: PandocMonad m => DocxContext m a -> DEnv -> DState -> m a
141evalDocxContext :: PandocMonad m => DocxContext m a -> DEnv -> DState -> m a
142−evalDocxContext ctx env st = flip evalStateT st $ flip runReaderT env $ ctx
142+evalDocxContext ctx env st = flip evalStateT st $flip runReaderT env ctx
143
143
144-- This is empty, but we put it in for future-proofing.
144-- This is empty, but we put it in for future-proofing.
145spansToKeep :: [String]
145spansToKeep :: [String]
@@ -156,7 +156,7 @@ metaStyles = M.fromList [ ("Title", "title")
156 , ("Abstract", "abstract")]
156 , ("Abstract", "abstract")]
157
157
158sepBodyParts :: [BodyPart] -> ([BodyPart], [BodyPart])
158sepBodyParts :: [BodyPart] -> ([BodyPart], [BodyPart])
159−sepBodyParts = span (\bp -> (isMetaPar bp || isEmptyPar bp))
159+sepBodyParts = span (\bp -> isMetaPar bp || isEmptyPar bp)
160
160
161isMetaPar :: BodyPart -> Bool
161isMetaPar :: BodyPart -> Bool
162isMetaPar (Paragraph pPr _) =
162isMetaPar (Paragraph pPr _) =
@@ -183,7 +183,7 @@ bodyPartsToMeta' (bp : bps)
183 remaining <- bodyPartsToMeta' bps
183 remaining <- bodyPartsToMeta' bps
184 let
184 let
185 f (MetaInlines ils) (MetaInlines ils') = MetaBlocks [Para ils, Para ils']
185 f (MetaInlines ils) (MetaInlines ils') = MetaBlocks [Para ils, Para ils']
186− f (MetaInlines ils) (MetaBlocks blks) = MetaBlocks ((Para ils) : blks)
186+ f (MetaInlines ils) (MetaBlocks blks) = MetaBlocks (Para ils : blks)
187 f m (MetaList mv) = MetaList (m : mv)
187 f m (MetaList mv) = MetaList (m : mv)
188 f m n = MetaList [m, n]
188 f m n = MetaList [m, n]
189 return $ M.insertWith f metaField (MetaInlines (toList inlines)) remaining
189 return $ M.insertWith f metaField (MetaInlines (toList inlines)) remaining
@@ -215,17 +215,17 @@ codeDivs = ["SourceCode"]
215
215
216runElemToInlines :: RunElem -> Inlines
216runElemToInlines :: RunElem -> Inlines
217runElemToInlines (TextRun s) = text s
217runElemToInlines (TextRun s) = text s
218−runElemToInlines (LnBrk) = linebreak
218+runElemToInlines LnBrk = linebreak
219−runElemToInlines (Tab) = space
219+runElemToInlines Tab = space
220−runElemToInlines (SoftHyphen) = text "\xad"
220+runElemToInlines SoftHyphen = text "\xad"
221−runElemToInlines (NoBreakHyphen) = text "\x2011"
221+runElemToInlines NoBreakHyphen = text "\x2011"
222
222
223runElemToString :: RunElem -> String
223runElemToString :: RunElem -> String
224runElemToString (TextRun s) = s
224runElemToString (TextRun s) = s
225−runElemToString (LnBrk) = ['\n']
225+runElemToString LnBrk = ['\n']
226−runElemToString (Tab) = ['\t']
226+runElemToString Tab = ['\t']
227−runElemToString (SoftHyphen) = ['\xad']
227+runElemToString SoftHyphen = ['\xad']
228−runElemToString (NoBreakHyphen) = ['\x2011']
228+runElemToString NoBreakHyphen = ['\x2011']
229
229
230runToString :: Run -> String
230runToString :: Run -> String
231runToString (Run _ runElems) = concatMap runElemToString runElems
231runToString (Run _ runElems) = concatMap runElemToString runElems
@@ -274,21 +274,21 @@ runStyleToTransform rPr
274 , s `elem` spansToKeep =
274 , s `elem` spansToKeep =
275 let rPr' = rPr{rStyle = Nothing}
275 let rPr' = rPr{rStyle = Nothing}
276 in
276 in
277− (spanWith ("", [s], [])) . (runStyleToTransform rPr')
277+ spanWith ("", [s], []) . runStyleToTransform rPr'
278 | Just True <- isItalic rPr =
278 | Just True <- isItalic rPr =
279− emph . (runStyleToTransform rPr {isItalic = Nothing})
279+ emph . runStyleToTransform rPr {isItalic = Nothing}
280 | Just True <- isBold rPr =
280 | Just True <- isBold rPr =
281− strong . (runStyleToTransform rPr {isBold = Nothing})
281+ strong . runStyleToTransform rPr {isBold = Nothing}
282 | Just True <- isSmallCaps rPr =
282 | Just True <- isSmallCaps rPr =
283− smallcaps . (runStyleToTransform rPr {isSmallCaps = Nothing})
283+ smallcaps . runStyleToTransform rPr {isSmallCaps = Nothing}
284 | Just True <- isStrike rPr =
284 | Just True <- isStrike rPr =
285− strikeout . (runStyleToTransform rPr {isStrike = Nothing})
285+ strikeout . runStyleToTransform rPr {isStrike = Nothing}
286 | Just SupScrpt <- rVertAlign rPr =
286 | Just SupScrpt <- rVertAlign rPr =
287− superscript . (runStyleToTransform rPr {rVertAlign = Nothing})
287+ superscript . runStyleToTransform rPr {rVertAlign = Nothing}
288 | Just SubScrpt <- rVertAlign rPr =
288 | Just SubScrpt <- rVertAlign rPr =
289− subscript . (runStyleToTransform rPr {rVertAlign = Nothing})
289+ subscript . runStyleToTransform rPr {rVertAlign = Nothing}
290 | Just "single" <- rUnderline rPr =
290 | Just "single" <- rUnderline rPr =
291− underlineSpan . (runStyleToTransform rPr {rUnderline = Nothing})
291+ underlineSpan . runStyleToTransform rPr {rUnderline = Nothing}
292 | otherwise = id
292 | otherwise = id
293
293
294runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
294runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
@@ -306,10 +306,10 @@ runToInlines (Run rs runElems)
306 let ils = smushInlines (map runElemToInlines runElems)
306 let ils = smushInlines (map runElemToInlines runElems)
307 return $ (runStyleToTransform $ resolveDependentRunStyle rs) ils
307 return $ (runStyleToTransform $ resolveDependentRunStyle rs) ils
308runToInlines (Footnote bps) = do
308runToInlines (Footnote bps) = do
309− blksList <- smushBlocks <$> (mapM bodyPartToBlocks bps)
309+ blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
310 return $ note blksList
310 return $ note blksList
311runToInlines (Endnote bps) = do
311runToInlines (Endnote bps) = do
312− blksList <- smushBlocks <$> (mapM bodyPartToBlocks bps)
312+ blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
313 return $ note blksList
313 return $ note blksList
314runToInlines (InlineDrawing fp title alt bs ext) = do
314runToInlines (InlineDrawing fp title alt bs ext) = do
315 (lift . lift) $ P.insertMedia fp Nothing bs
315 (lift . lift) $ P.insertMedia fp Nothing bs
@@ -330,7 +330,7 @@ blocksToInlinesWarn cmtId blks = do
330 notParaOrPlain (Para _) = False
330 notParaOrPlain (Para _) = False
331 notParaOrPlain (Plain _) = False
331 notParaOrPlain (Plain _) = False
332 notParaOrPlain _ = True
332 notParaOrPlain _ = True
333− when (not $ null $ filter notParaOrPlain blkList) $
333+ unless (null $ filter notParaOrPlain blkList) $
334 lift $ P.report $ DocxParserWarning $
334 lift $ P.report $ DocxParserWarning $
335 "Docx comment " ++ cmtId ++ " will not retain formatting"
335 "Docx comment " ++ cmtId ++ " will not retain formatting"
336 return $ fromList $ blocksToInlines blkList
336 return $ fromList $ blocksToInlines blkList
@@ -390,7 +390,7 @@ parPartToInlines (BookMark _ anchor) =
390 -- are not defined in pandoc, it seems like a necessary evil to
390 -- are not defined in pandoc, it seems like a necessary evil to
391 -- avoid an extra pass.
391 -- avoid an extra pass.
392 let newAnchor =
392 let newAnchor =
393− if not inHdrBool && anchor `elem` (M.elems anchorMap)
393+ if not inHdrBool && anchor `elem` M.elems anchorMap
394 then uniqueIdent [Str anchor] (Set.fromList $ M.elems anchorMap)
394 then uniqueIdent [Str anchor] (Set.fromList $ M.elems anchorMap)
395 else anchor
395 else anchor
396 unless inHdrBool
396 unless inHdrBool
@@ -399,7 +399,7 @@ parPartToInlines (BookMark _ anchor) =
399parPartToInlines (Drawing fp title alt bs ext) = do
399parPartToInlines (Drawing fp title alt bs ext) = do
400 (lift . lift) $ P.insertMedia fp Nothing bs
400 (lift . lift) $ P.insertMedia fp Nothing bs
401 return $ imageWith (extentToAttr ext) fp title $ text alt
401 return $ imageWith (extentToAttr ext) fp title $ text alt
402−parPartToInlines Chart = do
402+parPartToInlines Chart =
403 return $ spanWith ("", ["chart"], []) $ text "[CHART]"
403 return $ spanWith ("", ["chart"], []) $ text "[CHART]"
404parPartToInlines (InternalHyperLink anchor runs) = do
404parPartToInlines (InternalHyperLink anchor runs) = do
405 ils <- smushInlines <$> mapM runToInlines runs
405 ils <- smushInlines <$> mapM runToInlines runs
@@ -407,11 +407,10 @@ parPartToInlines (InternalHyperLink anchor runs) = do
407parPartToInlines (ExternalHyperLink target runs) = do
407parPartToInlines (ExternalHyperLink target runs) = do
408 ils <- smushInlines <$> mapM runToInlines runs
408 ils <- smushInlines <$> mapM runToInlines runs
409 return $ link target "" ils
409 return $ link target "" ils
410−parPartToInlines (PlainOMath exps) = do
410+parPartToInlines (PlainOMath exps) =
411 return $ math $ writeTeX exps
411 return $ math $ writeTeX exps
412parPartToInlines (SmartTag runs) = do
412parPartToInlines (SmartTag runs) = do
413− ils <- smushInlines <$> mapM runToInlines runs
413+ smushInlines <$> mapM runToInlines runs
414− return ils
415
414
416isAnchorSpan :: Inline -> Bool
415isAnchorSpan :: Inline -> Bool
417isAnchorSpan (Span (_, classes, kvs) _) =
416isAnchorSpan (Span (_, classes, kvs) _) =
@@ -454,7 +453,7 @@ makeHeaderAnchor' blk = return blk
454-- Rewrite a standalone paragraph block as a plain
453-- Rewrite a standalone paragraph block as a plain
455singleParaToPlain :: Blocks -> Blocks
454singleParaToPlain :: Blocks -> Blocks
456singleParaToPlain blks
455singleParaToPlain blks
457− | (Para (ils) :< seeq) <- viewl $ unMany blks
456+ | (Para ils :< seeq) <- viewl $ unMany blks
458 , Seq.null seeq =
457 , Seq.null seeq =
459 singleton $ Plain ils
458 singleton $ Plain ils
460singleParaToPlain blks = blks
459singleParaToPlain blks = blks
@@ -471,7 +470,7 @@ rowToBlocksList (Row cells) = do
471
470
472-- like trimInlines, but also take out linebreaks
471-- like trimInlines, but also take out linebreaks
473trimSps :: Inlines -> Inlines
472trimSps :: Inlines -> Inlines
474−trimSps (Many ils) = Many $ Seq.dropWhileL isSp $ Seq.dropWhileR isSp $ ils
473+trimSps (Many ils) = Many $ Seq.dropWhileL isSp $Seq.dropWhileR isSp ils
475 where isSp Space = True
474 where isSp Space = True
476 isSp SoftBreak = True
475 isSp SoftBreak = True
477 isSp LineBreak = True
476 isSp LineBreak = True
@@ -483,17 +482,17 @@ parStyleToTransform pPr
483 , c `elem` divsToKeep =
482 , c `elem` divsToKeep =
484 let pPr' = pPr { pStyle = cs }
483 let pPr' = pPr { pStyle = cs }
485 in
484 in
486− (divWith ("", [c], [])) . (parStyleToTransform pPr')
485+ divWith ("", [c], []) . parStyleToTransform pPr'
487 | (c:cs) <- pStyle pPr,
486 | (c:cs) <- pStyle pPr,
488 c `elem` listParagraphDivs =
487 c `elem` listParagraphDivs =
489 let pPr' = pPr { pStyle = cs, indentation = Nothing}
488 let pPr' = pPr { pStyle = cs, indentation = Nothing}
490 in
489 in
491− (divWith ("", [c], [])) . (parStyleToTransform pPr')
490+ divWith ("", [c], []) . parStyleToTransform pPr'
492 | (_:cs) <- pStyle pPr
491 | (_:cs) <- pStyle pPr
493 , Just True <- pBlockQuote pPr =
492 , Just True <- pBlockQuote pPr =
494 let pPr' = pPr { pStyle = cs }
493 let pPr' = pPr { pStyle = cs }
495 in
494 in
496− blockQuote . (parStyleToTransform pPr')
495+ blockQuote . parStyleToTransform pPr'
497 | (_:cs) <- pStyle pPr =
496 | (_:cs) <- pStyle pPr =
498 let pPr' = pPr { pStyle = cs}
497 let pPr' = pPr { pStyle = cs}
499 in
498 in
@@ -523,7 +522,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
523 $ codeBlock
522 $ codeBlock
524 $ concatMap parPartToString parparts
523 $ concatMap parPartToString parparts
525 | Just (style, n) <- pHeading pPr = do
524 | Just (style, n) <- pHeading pPr = do
526− ils <- local (\s-> s{docxInHeaderBlock=True}) $
525+ ils <-local (\s-> s{docxInHeaderBlock=True})
527 (smushInlines <$> mapM parPartToInlines parparts)
526 (smushInlines <$> mapM parPartToInlines parparts)
528 makeHeaderAnchor $
527 makeHeaderAnchor $
529 headerWith ("", delete style (pStyle pPr), []) n ils
528 headerWith ("", delete style (pStyle pPr), []) n ils
@@ -545,7 +544,7 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
545 , ("num-id", numId)
544 , ("num-id", numId)
546 , ("format", fmt)
545 , ("format", fmt)
547 , ("text", txt)
546 , ("text", txt)
548− , ("start", (show start))
547+ , ("start", show start)
549 ]
548 ]
550
549
551 (_, fmt, txt, Nothing) -> [ ("level", lvl)
550 (_, fmt, txt, Nothing) -> [ ("level", lvl)
@@ -556,7 +555,7 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
556 blks <- bodyPartToBlocks (Paragraph pPr parparts)
555 blks <- bodyPartToBlocks (Paragraph pPr parparts)
557 return $ divWith ("", ["list-item"], kvs) blks
556 return $ divWith ("", ["list-item"], kvs) blks
558bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
557bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
559− let pPr' = pPr {pStyle = "ListParagraph": (pStyle pPr)}
558+ let pPr' = pPr {pStyle = "ListParagraph": pStyle pPr}
560 in
559 in
561 bodyPartToBlocks $ Paragraph pPr' parparts
560 bodyPartToBlocks $ Paragraph pPr' parparts
562bodyPartToBlocks (Tbl _ _ _ []) =
561bodyPartToBlocks (Tbl _ _ _ []) =
@@ -588,7 +587,7 @@ bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
588 widths = replicate width 0 :: [Double]
587 widths = replicate width 0 :: [Double]
589
588
590 return $ table caption (zip alignments widths) hdrCells cells
589 return $ table caption (zip alignments widths) hdrCells cells
591−bodyPartToBlocks (OMathPara e) = do
590+bodyPartToBlocks (OMathPara e) =
592 return $ para $ displayMath (writeTeX e)
591 return $ para $ displayMath (writeTeX e)
593
592
594
593
@@ -597,7 +596,7 @@ rewriteLink' :: PandocMonad m => Inline -> DocxContext m Inline
597rewriteLink' l@(Link attr ils ('#':target, title)) = do
596rewriteLink' l@(Link attr ils ('#':target, title)) = do
598 anchorMap <- gets docxAnchorMap
597 anchorMap <- gets docxAnchorMap
599 return $ case M.lookup target anchorMap of
598 return $ case M.lookup target anchorMap of
600− Just newTarget -> (Link attr ils ('#':newTarget, title))
599+ Just newTarget -> Link attr ils ('#':newTarget, title)
601 Nothing -> l
600 Nothing -> l
602rewriteLink' il = return il
601rewriteLink' il = return il
603
602
@@ -610,7 +609,7 @@ bodyToOutput (Body bps) = do
610 meta <- bodyPartsToMeta metabps
609 meta <- bodyPartsToMeta metabps
611 blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
610 blks <- smushBlocks <$> mapM bodyPartToBlocks blkbps
612 blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
611 blks' <- rewriteLinks $ blocksToDefinitions $ blocksToBullets $ toList blks
613− return $ (meta, blks')
612+ return (meta, blks')
614
613
615docxToOutput :: PandocMonad m
614docxToOutput :: PandocMonad m
616 => ReaderOptions
615 => ReaderOptions
src/Text/Pandoc/Readers/Docx/Lists.hs+1−1
@@ -156,7 +156,7 @@ flatToBullets :: [Block] -> [Block]
156flatToBullets elems = flatToBullets' (-1) elems
156flatToBullets elems = flatToBullets' (-1) elems
157
157
158singleItemHeaderToHeader :: Block -> Block
158singleItemHeaderToHeader :: Block -> Block
159−singleItemHeaderToHeader (OrderedList _ [[h@(Header{})]]) = h
159+singleItemHeaderToHeader (OrderedList _ [[h@Header{}]]) = h
160singleItemHeaderToHeader blk = blk
160singleItemHeaderToHeader blk = blk
161
161
162
162
src/Text/Pandoc/Readers/Docx/Parse.hs+10−16
@@ -303,8 +303,7 @@ archiveToDocument zf = do
303
303
304elemToBody :: NameSpaces -> Element -> D Body
304elemToBody :: NameSpaces -> Element -> D Body
305elemToBody ns element | isElem ns "w" "body" element =
305elemToBody ns element | isElem ns "w" "body" element =
306− mapD (elemToBodyPart ns) (elChildren element) >>=
306+ fmap Body (mapD (elemToBodyPart ns) (elChildren element))
307− (return . Body)
308elemToBody _ _ = throwError WrongElem
307elemToBody _ _ = throwError WrongElem
309
308
310archiveToStyles :: Archive -> (CharStyleMap, ParStyleMap)
309archiveToStyles :: Archive -> (CharStyleMap, ParStyleMap)
@@ -374,7 +373,7 @@ buildBasedOnList ns element rootStyle =
374 case getStyleChildren ns element rootStyle of
373 case getStyleChildren ns element rootStyle of
375 [] -> []
374 [] -> []
376 stys -> stys ++
375 stys -> stys ++
377− concatMap (\s -> buildBasedOnList ns element (Just s)) stys
376+ concatMap (buildBasedOnList ns element . Just) stys
378
377
379archiveToNotes :: Archive -> Notes
378archiveToNotes :: Archive -> Notes
380archiveToNotes zf =
379archiveToNotes zf =
@@ -577,7 +576,7 @@ testBitMask :: String -> Int -> Bool
577testBitMask bitMaskS n =
576testBitMask bitMaskS n =
578 case (reads ("0x" ++ bitMaskS) :: [(Int, String)]) of
577 case (reads ("0x" ++ bitMaskS) :: [(Int, String)]) of
579 [] -> False
578 [] -> False
580− ((n', _) : _) -> ((n' .|. n) /= 0)
579+ ((n', _) : _) -> (n' .|. n) /= 0
581
580
582stringToInteger :: String -> Maybe Integer
581stringToInteger :: String -> Maybe Integer
583stringToInteger s = listToMaybe $ map fst (reads s :: [(Integer, String)])
582stringToInteger s = listToMaybe $ map fst (reads s :: [(Integer, String)])
@@ -654,12 +653,8 @@ getTitleAndAlt :: NameSpaces -> Element -> (String, String)
654getTitleAndAlt ns element =
653getTitleAndAlt ns element =
655 let mbDocPr = findChildByName ns "wp" "inline" element >>=
654 let mbDocPr = findChildByName ns "wp" "inline" element >>=
656 findChildByName ns "wp" "docPr"
655 findChildByName ns "wp" "docPr"
657− title = case mbDocPr >>= findAttrByName ns "" "title" of
656+ title = fromMaybe "" (mbDocPr >>= findAttrByName ns "" "title")
658− Just title' -> title'
659− Nothing -> ""
660− alt = case mbDocPr >>= findAttrByName ns "" "descr" of
657+ alt = fromMaybe "" (mbDocPr >>= findAttrByName ns "" "descr")
661− Just alt' -> alt'
662− Nothing -> ""
663 in (title, alt)
658 in (title, alt)
664
659
665elemToParPart :: NameSpaces -> Element -> D ParPart
660elemToParPart :: NameSpaces -> Element -> D ParPart
@@ -727,7 +722,7 @@ elemToParPart ns element
727 runs <- mapD (elemToRun ns) (elChildren element)
722 runs <- mapD (elemToRun ns) (elChildren element)
728 rels <- asks envRelationships
723 rels <- asks envRelationships
729 case lookupRelationship location relId rels of
724 case lookupRelationship location relId rels of
730− Just target -> do
725+ Just target ->
731 case findAttrByName ns "w" "anchor" element of
726 case findAttrByName ns "w" "anchor" element of
732 Just anchor -> return $ ExternalHyperLink (target ++ '#':anchor) runs
727 Just anchor -> return $ ExternalHyperLink (target ++ '#':anchor) runs
733 Nothing -> return $ ExternalHyperLink target runs
728 Nothing -> return $ ExternalHyperLink target runs
@@ -750,7 +745,7 @@ elemToParPart ns element
750 return $ CommentEnd cmtId
745 return $ CommentEnd cmtId
751elemToParPart ns element
746elemToParPart ns element
752 | isElem ns "m" "oMath" element =
747 | isElem ns "m" "oMath" element =
753− (eitherToD $ readOMML $ showElement element) >>= (return . PlainOMath)
748+ fmap PlainOMath (eitherToD $ readOMML $ showElement element)
754elemToParPart _ _ = throwError WrongElem
749elemToParPart _ _ = throwError WrongElem
755
750
756elemToCommentStart :: NameSpaces -> Element -> D ParPart
751elemToCommentStart :: NameSpaces -> Element -> D ParPart
@@ -764,10 +759,10 @@ elemToCommentStart ns element
764elemToCommentStart _ _ = throwError WrongElem
759elemToCommentStart _ _ = throwError WrongElem
765
760
766lookupFootnote :: String -> Notes -> Maybe Element
761lookupFootnote :: String -> Notes -> Maybe Element
767−lookupFootnote s (Notes _ fns _) = fns >>= (M.lookup s)
762+lookupFootnote s (Notes _ fns _) = fns >>= M.lookup s
768
763
769lookupEndnote :: String -> Notes -> Maybe Element
764lookupEndnote :: String -> Notes -> Maybe Element
770−lookupEndnote s (Notes _ _ ens) = ens >>= (M.lookup s)
765+lookupEndnote s (Notes _ _ ens) = ens >>= M.lookup s
771
766
772elemToExtent :: Element -> Extent
767elemToExtent :: Element -> Extent
773elemToExtent drawingElem =
768elemToExtent drawingElem =
@@ -1035,11 +1030,10 @@ elemToRunElems ns element
1035 let font = do
1030 let font = do
1036 fontElem <- findElement (qualName "rFonts") element
1031 fontElem <- findElement (qualName "rFonts") element
1037 stringToFont =<<
1032 stringToFont =<<
1038− (foldr (<|>) Nothing $
1033+ foldr (<|>) Nothing (
1039 map (flip findAttr fontElem . qualName) ["ascii", "hAnsi"])
1034 map (flip findAttr fontElem . qualName) ["ascii", "hAnsi"])
1040 local (setFont font) (mapD (elemToRunElem ns) (elChildren element))
1035 local (setFont font) (mapD (elemToRunElem ns) (elChildren element))
1041elemToRunElems _ _ = throwError WrongElem
1036elemToRunElems _ _ = throwError WrongElem
1042
1037
1043setFont :: Maybe Font -> ReaderEnv -> ReaderEnv
1038setFont :: Maybe Font -> ReaderEnv -> ReaderEnv
1044setFont f s = s{envFont = f}
1039setFont f s = s{envFont = f}
1045−
src/Text/Pandoc/Readers/Docx/Util.hs−1
@@ -44,4 +44,3 @@ findAttrByName :: NameSpaces -> String -> String -> Element -> Maybe String
44findAttrByName ns pref name el =
44findAttrByName ns pref name el =
45 let ns' = ns ++ elemToNameSpaces el
45 let ns' = ns ++ elemToNameSpaces el
46 in findAttr (elemName ns' pref name) el
46 in findAttr (elemName ns' pref name) el
47−
src/Text/Pandoc/Readers/EPUB.hs+11−11
@@ -1,5 +1,5 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2−{-# LANGUAGE StandaloneDeriving #-}
2+
3{-# LANGUAGE TupleSections #-}
3{-# LANGUAGE TupleSections #-}
4{-# LANGUAGE ViewPatterns #-}
4{-# LANGUAGE ViewPatterns #-}
5
5
@@ -39,7 +39,7 @@ type Items = M.Map String (FilePath, MimeType)
39
39
40readEPUB :: PandocMonad m => ReaderOptions -> BL.ByteString -> m Pandoc
40readEPUB :: PandocMonad m => ReaderOptions -> BL.ByteString -> m Pandoc
41readEPUB opts bytes = case toArchiveOrFail bytes of
41readEPUB opts bytes = case toArchiveOrFail bytes of
42− Right archive -> archiveToEPUB opts $ archive
42+ Right archive -> archiveToEPUB opts archive
43 Left _ -> throwError $ PandocParseError "Couldn't extract ePub file"
43 Left _ -> throwError $ PandocParseError "Couldn't extract ePub file"
44
44
45-- runEPUB :: Except PandocError a -> Either PandocError a
45-- runEPUB :: Except PandocError a -> Either PandocError a
@@ -61,7 +61,7 @@ archiveToEPUB os archive = do
61 Pandoc _ bs <-
61 Pandoc _ bs <-
62 foldM' (\a b -> ((a <>) . walk (prependHash escapedSpine))
62 foldM' (\a b -> ((a <>) . walk (prependHash escapedSpine))
63 `liftM` parseSpineElem root b) mempty spine
63 `liftM` parseSpineElem root b) mempty spine
64− let ast = coverDoc <> (Pandoc meta bs)
64+ let ast = coverDoc <> Pandoc meta bs
65 fetchImages (M.elems items) root archive ast
65 fetchImages (M.elems items) root archive ast
66 return ast
66 return ast
67 where
67 where
@@ -79,7 +79,7 @@ archiveToEPUB os archive = do
79 return $ fixInternalReferences path html
79 return $ fixInternalReferences path html
80 mimeToReader s _ (unEscapeString -> path)
80 mimeToReader s _ (unEscapeString -> path)
81 | s `elem` imageMimes = return $ imageToPandoc path
81 | s `elem` imageMimes = return $ imageToPandoc path
82− | otherwise = return $ mempty
82+ | otherwise = return mempty
83
83
84-- paths should be absolute when this function is called
84-- paths should be absolute when this function is called
85-- renameImages should do this
85-- renameImages should do this
@@ -122,7 +122,7 @@ parseManifest content = do
122 let items = findChildren (dfName "item") manifest
122 let items = findChildren (dfName "item") manifest
123 r <- mapM parseItem items
123 r <- mapM parseItem items
124 let cover = findAttr (emptyName "href") =<< filterChild findCover manifest
124 let cover = findAttr (emptyName "href") =<< filterChild findCover manifest
125− return (cover, (M.fromList r))
125+ return (cover, M.fromList r)
126 where
126 where
127 findCover e = maybe False (isInfixOf "cover-image")
127 findCover e = maybe False (isInfixOf "cover-image")
128 (findAttr (emptyName "properties") e)
128 (findAttr (emptyName "properties") e)
@@ -136,7 +136,7 @@ parseSpine :: PandocMonad m => Items -> Element -> m [(FilePath, MimeType)]
136parseSpine is e = do
136parseSpine is e = do
137 spine <- findElementE (dfName "spine") e
137 spine <- findElementE (dfName "spine") e
138 let itemRefs = findChildren (dfName "itemref") spine
138 let itemRefs = findChildren (dfName "itemref") spine
139− mapM (mkE "parseSpine" . (flip M.lookup is)) $ mapMaybe parseItemRef itemRefs
139+ mapM (mkE "parseSpine" . flip M.lookup is) $ mapMaybe parseItemRef itemRefs
140 where
140 where
141 parseItemRef ref = do
141 parseItemRef ref = do
142 let linear = maybe True (== "yes") (findAttr (emptyName "linear") ref)
142 let linear = maybe True (== "yes") (findAttr (emptyName "linear") ref)
@@ -167,21 +167,21 @@ getManifest archive = do
167 docElem <- (parseXMLDocE . UTF8.toStringLazy . fromEntry) metaEntry
167 docElem <- (parseXMLDocE . UTF8.toStringLazy . fromEntry) metaEntry
168 let namespaces = mapMaybe attrToNSPair (elAttribs docElem)
168 let namespaces = mapMaybe attrToNSPair (elAttribs docElem)
169 ns <- mkE "xmlns not in namespaces" (lookup "xmlns" namespaces)
169 ns <- mkE "xmlns not in namespaces" (lookup "xmlns" namespaces)
170− as <- liftM ((map attrToPair) . elAttribs)
170+ as <- fmap (map attrToPair . elAttribs)
171 (findElementE (QName "rootfile" (Just ns) Nothing) docElem)
171 (findElementE (QName "rootfile" (Just ns) Nothing) docElem)
172 manifestFile <- mkE "Root not found" (lookup "full-path" as)
172 manifestFile <- mkE "Root not found" (lookup "full-path" as)
173 let rootdir = dropFileName manifestFile
173 let rootdir = dropFileName manifestFile
174 --mime <- lookup "media-type" as
174 --mime <- lookup "media-type" as
175 manifest <- findEntryByPathE manifestFile archive
175 manifest <- findEntryByPathE manifestFile archive
176− liftM ((,) rootdir) (parseXMLDocE . UTF8.toStringLazy . fromEntry $ manifest)
176+ fmap ((,) rootdir) (parseXMLDocE . UTF8.toStringLazy . fromEntry $ manifest)
177
177
178-- Fixup
178-- Fixup
179
179
180fixInternalReferences :: FilePath -> Pandoc -> Pandoc
180fixInternalReferences :: FilePath -> Pandoc -> Pandoc
181fixInternalReferences pathToFile =
181fixInternalReferences pathToFile =
182− (walk $ renameImages root)
182+ walk (renameImages root)
183− . (walk $ fixBlockIRs filename)
183+ . walk (fixBlockIRs filename)
184− . (walk $ fixInlineIRs filename)
184+ . walk (fixInlineIRs filename)
185 where
185 where
186 (root, escapeURI -> filename) = splitFileName pathToFile
186 (root, escapeURI -> filename) = splitFileName pathToFile
187
187
src/Text/Pandoc/Readers/Haddock.hs+1−1
@@ -142,7 +142,7 @@ makeExample prompt expression result =
142 <> B.space
142 <> B.space
143 <> B.codeWith ([], ["haskell","expr"], []) (trim expression)
143 <> B.codeWith ([], ["haskell","expr"], []) (trim expression)
144 <> B.linebreak
144 <> B.linebreak
145− <> (mconcat $ intersperse B.linebreak $ map coder result')
145+ <> mconcat (intersperse B.linebreak $ map coder result')
146 where
146 where
147 -- 1. drop trailing whitespace from the prompt, remember the prefix
147 -- 1. drop trailing whitespace from the prompt, remember the prefix
148 prefix = takeWhile (`elem` " \t") prompt
148 prefix = takeWhile (`elem` " \t") prompt
src/Text/Pandoc/Readers/LaTeX.hs+34−34
@@ -107,7 +107,7 @@ parseLaTeX = do
107 (if bottomLevel < 1
107 (if bottomLevel < 1
108 then walk (adjustHeaders (1 - bottomLevel))
108 then walk (adjustHeaders (1 - bottomLevel))
109 else id) $
109 else id) $
110− walk (resolveRefs (sLabels st)) $ doc'
110+ walk (resolveRefs (sLabels st)) doc'
111 return $ Pandoc meta bs'
111 return $ Pandoc meta bs'
112
112
113resolveRefs :: M.Map String [Inline] -> Inline -> Inline
113resolveRefs :: M.Map String [Inline] -> Inline -> Inline
@@ -246,7 +246,7 @@ rawLaTeXParser parser = do
246 case res of
246 case res of
247 Left _ -> mzero
247 Left _ -> mzero
248 Right (raw, st) -> do
248 Right (raw, st) -> do
249− updateState (updateMacros ((sMacros st) <>))
249+ updateState (updateMacros (sMacros st <>))
250 takeP (T.length (untokenize raw))
250 takeP (T.length (untokenize raw))
251
251
252applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
252applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
@@ -333,7 +333,7 @@ totoks pos t =
333 : totoks (incSourceColumn pos
333 : totoks (incSourceColumn pos
334 (1 + T.length ws + T.length ss)) rest'''
334 (1 + T.length ws + T.length ss)) rest'''
335 | d == '\t' || d == '\n' ->
335 | d == '\t' || d == '\n' ->
336− Tok pos Symbol ("\\")
336+ Tok pos Symbol "\\"
337 : totoks (incSourceColumn pos 1) rest
337 : totoks (incSourceColumn pos 1) rest
338 | otherwise ->
338 | otherwise ->
339 Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
339 Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
@@ -403,7 +403,7 @@ satisfyTok f =
403doMacros :: PandocMonad m => Int -> LP m ()
403doMacros :: PandocMonad m => Int -> LP m ()
404doMacros n = do
404doMacros n = do
405 verbatimMode <- sVerbatimMode <$> getState
405 verbatimMode <- sVerbatimMode <$> getState
406− when (not verbatimMode) $ do
406+ unless verbatimMode $ do
407 inp <- getInput
407 inp <- getInput
408 case inp of
408 case inp of
409 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
409 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
@@ -543,7 +543,7 @@ bgroup = try $ do
543 symbol '{' <|> controlSeq "bgroup" <|> controlSeq "begingroup"
543 symbol '{' <|> controlSeq "bgroup" <|> controlSeq "begingroup"
544
544
545egroup :: PandocMonad m => LP m Tok
545egroup :: PandocMonad m => LP m Tok
546−egroup = (symbol '}' <|> controlSeq "egroup" <|> controlSeq "endgroup")
546+egroup = symbol '}' <|> controlSeq "egroup" <|> controlSeq "endgroup"
547
547
548grouped :: (PandocMonad m, Monoid a) => LP m a -> LP m a
548grouped :: (PandocMonad m, Monoid a) => LP m a -> LP m a
549grouped parser = try $ do
549grouped parser = try $ do
@@ -577,7 +577,7 @@ dimenarg :: PandocMonad m => LP m Text
577dimenarg = try $ do
577dimenarg = try $ do
578 ch <- option False $ True <$ symbol '='
578 ch <- option False $ True <$ symbol '='
579 Tok _ _ s <- satisfyTok isWordTok
579 Tok _ _ s <- satisfyTok isWordTok
580− guard $ (T.take 2 (T.reverse s)) `elem`
580+ guard $ T.take 2 (T.reverse s) `elem`
581 ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
581 ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
582 let num = T.take (T.length s - 2) s
582 let num = T.take (T.length s - 2) s
583 guard $ T.length num > 0
583 guard $ T.length num > 0
@@ -633,7 +633,7 @@ mkImage options src = do
633 _ -> return $ imageWith attr src "" alt
633 _ -> return $ imageWith attr src "" alt
634
634
635doxspace :: PandocMonad m => LP m Inlines
635doxspace :: PandocMonad m => LP m Inlines
636−doxspace = do
636+doxspace =
637 (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
637 (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
638 where startsWithLetter (Tok _ Word t) =
638 where startsWithLetter (Tok _ Word t) =
639 case T.uncons t of
639 case T.uncons t of
@@ -662,22 +662,22 @@ lit = pure . str
662
662
663removeDoubleQuotes :: Text -> Text
663removeDoubleQuotes :: Text -> Text
664removeDoubleQuotes t =
664removeDoubleQuotes t =
665− maybe t id $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
665+ Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
666
666
667doubleQuote :: PandocMonad m => LP m Inlines
667doubleQuote :: PandocMonad m => LP m Inlines
668−doubleQuote = do
668+doubleQuote =
669 quoted' doubleQuoted (try $ count 2 $ symbol '`')
669 quoted' doubleQuoted (try $ count 2 $ symbol '`')
670− (void $ try $ count 2 $ symbol '\'')
670+ (void $ try $ count 2 $ symbol '\'')
671 <|> quoted' doubleQuoted ((:[]) <$> symbol '“') (void $ symbol '”')
671 <|> quoted' doubleQuoted ((:[]) <$> symbol '“') (void $ symbol '”')
672 -- the following is used by babel for localized quotes:
672 -- the following is used by babel for localized quotes:
673 <|> quoted' doubleQuoted (try $ sequence [symbol '"', symbol '`'])
673 <|> quoted' doubleQuoted (try $ sequence [symbol '"', symbol '`'])
674 (void $ try $ sequence [symbol '"', symbol '\''])
674 (void $ try $ sequence [symbol '"', symbol '\''])
675
675
676singleQuote :: PandocMonad m => LP m Inlines
676singleQuote :: PandocMonad m => LP m Inlines
677−singleQuote = do
677+singleQuote =
678 quoted' singleQuoted ((:[]) <$> symbol '`')
678 quoted' singleQuoted ((:[]) <$> symbol '`')
679− (try $ symbol '\'' >>
679+ (try $ symbol '\'' >>
680− notFollowedBy (satisfyTok startsWithLetter))
680+ notFollowedBy (satisfyTok startsWithLetter))
681 <|> quoted' singleQuoted ((:[]) <$> symbol '‘')
681 <|> quoted' singleQuoted ((:[]) <$> symbol '‘')
682 (try $ symbol '’' >>
682 (try $ symbol '’' >>
683 notFollowedBy (satisfyTok startsWithLetter))
683 notFollowedBy (satisfyTok startsWithLetter))
@@ -726,8 +726,8 @@ doAcronymPlural form = do
726 acro <- braced
726 acro <- braced
727 plural <- lit "s"
727 plural <- lit "s"
728 return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
728 return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
729− ("acronym-form", "plural+" ++ form)]) $ mconcat
729+ ("acronym-form", "plural+" ++ form)]) $
730− $ [str $ toksToString acro, plural]]
730+ mconcat [str $ toksToString acro, plural]]
731
731
732doverb :: PandocMonad m => LP m Inlines
732doverb :: PandocMonad m => LP m Inlines
733doverb = do
733doverb = do
@@ -748,7 +748,7 @@ verbTok stopchar = do
748 let (t1, t2) = T.splitAt i txt
748 let (t1, t2) = T.splitAt i txt
749 inp <- getInput
749 inp <- getInput
750 setInput $ Tok (incSourceColumn pos i) Symbol (T.singleton stopchar)
750 setInput $ Tok (incSourceColumn pos i) Symbol (T.singleton stopchar)
751− : (totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2)) ++ inp
751+ : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
752 return $ Tok pos toktype t1
752 return $ Tok pos toktype t1
753
753
754dolstinline :: PandocMonad m => LP m Inlines
754dolstinline :: PandocMonad m => LP m Inlines
@@ -773,8 +773,8 @@ keyval = try $ do
773 val <- option [] $ do
773 val <- option [] $ do
774 symbol '='
774 symbol '='
775 optional sp
775 optional sp
776− braced <|> (many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
776+ braced <|> many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
777− <|> anyControlSeq))
777+ <|> anyControlSeq)
778 optional sp
778 optional sp
779 optional (symbol ',')
779 optional (symbol ',')
780 optional sp
780 optional sp
@@ -1020,10 +1020,10 @@ dollarsMath = do
1020 contents <- trim . toksToString <$>
1020 contents <- trim . toksToString <$>
1021 many (notFollowedBy (symbol '$') >> anyTok)
1021 many (notFollowedBy (symbol '$') >> anyTok)
1022 if display
1022 if display
1023− then do
1023+ then
1024 mathDisplay contents <$ try (symbol '$' >> symbol '$')
1024 mathDisplay contents <$ try (symbol '$' >> symbol '$')
1025− <|> (guard (null contents) >> return (mathInline ""))
1025+ <|> (guard (null contents) >> return (mathInline ""))
1026− else mathInline contents <$ (symbol '$')
1026+ else mathInline contents <$ symbol '$'
1027
1027
1028-- citations
1028-- citations
1029
1029
@@ -1041,7 +1041,7 @@ simpleCiteArgs :: PandocMonad m => LP m [Citation]
1041simpleCiteArgs = try $ do
1041simpleCiteArgs = try $ do
1042 first <- optionMaybe $ toList <$> opt
1042 first <- optionMaybe $ toList <$> opt
1043 second <- optionMaybe $ toList <$> opt
1043 second <- optionMaybe $ toList <$> opt
1044− keys <- try $ bgroup *> (manyTill citationLabel egroup)
1044+ keys <- try $ bgroup *> manyTill citationLabel egroup
1045 let (pre, suf) = case (first , second ) of
1045 let (pre, suf) = case (first , second ) of
1046 (Just s , Nothing) -> (mempty, s )
1046 (Just s , Nothing) -> (mempty, s )
1047 (Just s , Just t ) -> (s , t )
1047 (Just s , Just t ) -> (s , t )
@@ -1080,7 +1080,7 @@ cites mode multi = try $ do
1080citation :: PandocMonad m => String -> CitationMode -> Bool -> LP m Inlines
1080citation :: PandocMonad m => String -> CitationMode -> Bool -> LP m Inlines
1081citation name mode multi = do
1081citation name mode multi = do
1082 (c,raw) <- withRaw $ cites mode multi
1082 (c,raw) <- withRaw $ cites mode multi
1083− return $ cite c (rawInline "latex" $ "\\" ++ name ++ (toksToString raw))
1083+ return $ cite c (rawInline "latex" $ "\\" ++ name ++ toksToString raw)
1084
1084
1085handleCitationPart :: Inlines -> [Citation]
1085handleCitationPart :: Inlines -> [Citation]
1086handleCitationPart ils =
1086handleCitationPart ils =
@@ -1139,7 +1139,7 @@ singleChar = try $ do
1139 then do
1139 then do
1140 let (t1, t2) = (T.take 1 t, T.drop 1 t)
1140 let (t1, t2) = (T.take 1 t, T.drop 1 t)
1141 inp <- getInput
1141 inp <- getInput
1142− setInput $ (Tok (incSourceColumn pos 1) toktype t2) : inp
1142+ setInput $ Tok (incSourceColumn pos 1) toktype t2 : inp
1143 return $ Tok pos toktype t1
1143 return $ Tok pos toktype t1
1144 else return $ Tok pos toktype t
1144 else return $ Tok pos toktype t
1145
1145
@@ -1606,7 +1606,7 @@ getRawCommand name txt = do
1606 void braced
1606 void braced
1607 skipopts
1607 skipopts
1608 void $ count 4 braced
1608 void $ count 4 braced
1609− "def" -> do
1609+ "def" ->
1610 void $ manyTill anyTok braced
1610 void $ manyTill anyTok braced
1611 _ -> do
1611 _ -> do
1612 skipangles
1612 skipangles
@@ -1715,14 +1715,14 @@ inlines = mconcat <$> many inline
1715-- block elements:
1715-- block elements:
1716
1716
1717begin_ :: PandocMonad m => Text -> LP m ()
1717begin_ :: PandocMonad m => Text -> LP m ()
1718−begin_ t = (try $ do
1718+begin_ t = try (do
1719 controlSeq "begin"
1719 controlSeq "begin"
1720 spaces
1720 spaces
1721 txt <- untokenize <$> braced
1721 txt <- untokenize <$> braced
1722 guard (t == txt)) <?> ("\\begin{" ++ T.unpack t ++ "}")
1722 guard (t == txt)) <?> ("\\begin{" ++ T.unpack t ++ "}")
1723
1723
1724end_ :: PandocMonad m => Text -> LP m ()
1724end_ :: PandocMonad m => Text -> LP m ()
1725−end_ t = (try $ do
1725+end_ t = try (do
1726 controlSeq "end"
1726 controlSeq "end"
1727 spaces
1727 spaces
1728 txt <- untokenize <$> braced
1728 txt <- untokenize <$> braced
@@ -1766,7 +1766,7 @@ insertIncluded :: PandocMonad m
1766insertIncluded dirs f = do
1766insertIncluded dirs f = do
1767 pos <- getPosition
1767 pos <- getPosition
1768 containers <- getIncludeFiles <$> getState
1768 containers <- getIncludeFiles <$> getState
1769− when (f `elem` containers) $ do
1769+ when (f `elem` containers) $
1770 throwError $ PandocParseError $ "Include file loop at " ++ show pos
1770 throwError $ PandocParseError $ "Include file loop at " ++ show pos
1771 updateState $ addIncludeFile f
1771 updateState $ addIncludeFile f
1772 mbcontents <- readFileFromDirs dirs f
1772 mbcontents <- readFileFromDirs dirs f
@@ -1800,7 +1800,7 @@ authors = try $ do
1800 addMeta "author" (map trimInlines auths)
1800 addMeta "author" (map trimInlines auths)
1801
1801
1802macroDef :: PandocMonad m => LP m Blocks
1802macroDef :: PandocMonad m => LP m Blocks
1803−macroDef = do
1803+macroDef =
1804 mempty <$ ((commandDef <|> environmentDef) <* doMacros 0)
1804 mempty <$ ((commandDef <|> environmentDef) <* doMacros 0)
1805 where commandDef = do
1805 where commandDef = do
1806 (name, macro') <- newcommand <|> letmacro <|> defmacro
1806 (name, macro') <- newcommand <|> letmacro <|> defmacro
@@ -2177,9 +2177,9 @@ fancyverbEnv name = do
2177 codeBlockWith attr <$> verbEnv name
2177 codeBlockWith attr <$> verbEnv name
2178
2178
2179obeylines :: PandocMonad m => LP m Blocks
2179obeylines :: PandocMonad m => LP m Blocks
2180−obeylines = do
2180+obeylines =
2181 para . fromList . removeLeadingTrailingBreaks .
2181 para . fromList . removeLeadingTrailingBreaks .
2182− walk softBreakToHard . toList <$> env "obeylines" inlines
2182+ walk softBreakToHard . toList <$> env "obeylines" inlines
2183 where softBreakToHard SoftBreak = LineBreak
2183 where softBreakToHard SoftBreak = LineBreak
2184 softBreakToHard x = x
2184 softBreakToHard x = x
2185 removeLeadingTrailingBreaks = reverse . dropWhile isLineBreak .
2185 removeLeadingTrailingBreaks = reverse . dropWhile isLineBreak .
@@ -2368,7 +2368,7 @@ splitWordTok :: PandocMonad m => LP m ()
2368splitWordTok = do
2368splitWordTok = do
2369 inp <- getInput
2369 inp <- getInput
2370 case inp of
2370 case inp of
2371− (Tok spos Word t : rest) -> do
2371+ (Tok spos Word t : rest) ->
2372 setInput $ map (Tok spos Symbol . T.singleton) (T.unpack t) ++ rest
2372 setInput $ map (Tok spos Symbol . T.singleton) (T.unpack t) ++ rest
2373 _ -> return ()
2373 _ -> return ()
2374
2374
@@ -2433,9 +2433,9 @@ parseTableRow envname prefsufs = do
2433 suffpos <- getPosition
2433 suffpos <- getPosition
2434 option [] (count 1 amp)
2434 option [] (count 1 amp)
2435 return $ map (setpos prefpos) pref ++ contents ++ map (setpos suffpos) suff
2435 return $ map (setpos prefpos) pref ++ contents ++ map (setpos suffpos) suff
2436− rawcells <- sequence (map celltoks prefsufs)
2436+ rawcells <- mapM celltoks prefsufs
2437 oldInput <- getInput
2437 oldInput <- getInput
2438− cells <- sequence $ map (\ts -> setInput ts >> parseTableCell) rawcells
2438+ cells <- mapM (\ts -> setInput ts >> parseTableCell) rawcells
2439 setInput oldInput
2439 setInput oldInput
2440 spaces
2440 spaces
2441 let numcells = length cells
2441 let numcells = length cells
src/Text/Pandoc/Readers/LaTeX/Types.hs−1
@@ -49,4 +49,3 @@ data ExpansionPoint = ExpandWhenDefined | ExpandWhenUsed
49
49
50data Macro = Macro ExpansionPoint Int (Maybe [Tok]) [Tok]
50data Macro = Macro ExpansionPoint Int (Maybe [Tok]) [Tok]
51 deriving Show
51 deriving Show
52−
src/Text/Pandoc/Readers/Markdown.hs+33−37
@@ -74,7 +74,7 @@ readMarkdown :: PandocMonad m
74 -> Text -- ^ String to parse (assuming @'\n'@ line endings)
74 -> Text -- ^ String to parse (assuming @'\n'@ line endings)
75 -> m Pandoc
75 -> m Pandoc
76readMarkdown opts s = do
76readMarkdown opts s = do
77− parsed <- (readWithM parseMarkdown) def{ stateOptions = opts }
77+ parsed <- readWithM parseMarkdown def{ stateOptions = opts }
78 (T.unpack (crFilter s) ++ "\n\n")
78 (T.unpack (crFilter s) ++ "\n\n")
79 case parsed of
79 case parsed of
80 Right result -> return result
80 Right result -> return result
@@ -162,7 +162,7 @@ charsInBalancedBrackets openBrackets =
162 (char '[' >> charsInBalancedBrackets (openBrackets + 1))
162 (char '[' >> charsInBalancedBrackets (openBrackets + 1))
163 <|> (char ']' >> charsInBalancedBrackets (openBrackets - 1))
163 <|> (char ']' >> charsInBalancedBrackets (openBrackets - 1))
164 <|> (( (() <$ code)
164 <|> (( (() <$ code)
165− <|> (() <$ (escapedChar'))
165+ <|> (() <$ escapedChar')
166 <|> (newline >> notFollowedBy blankline)
166 <|> (newline >> notFollowedBy blankline)
167 <|> skipMany1 (noneOf "[]`\n\\")
167 <|> skipMany1 (noneOf "[]`\n\\")
168 <|> (() <$ count 1 (oneOf "`\\"))
168 <|> (() <$ count 1 (oneOf "`\\"))
@@ -241,7 +241,7 @@ yamlMetaBlock = try $ do
241 case Yaml.decodeEither' $ UTF8.fromString rawYaml of
241 case Yaml.decodeEither' $ UTF8.fromString rawYaml of
242 Right (Yaml.Object hashmap) -> do
242 Right (Yaml.Object hashmap) -> do
243 let alist = H.toList hashmap
243 let alist = H.toList hashmap
244− mapM_ (\(k, v) -> do
244+ mapM_ (\(k, v) ->
245 if ignorable k
245 if ignorable k
246 then return ()
246 then return ()
247 else do
247 else do
@@ -320,7 +320,7 @@ yamlToMeta (Yaml.Array xs) = do
320 return $ B.toMetaValue xs''
320 return $ B.toMetaValue xs''
321yamlToMeta (Yaml.Object o) = do
321yamlToMeta (Yaml.Object o) = do
322 let alist = H.toList o
322 let alist = H.toList o
323− foldM (\m (k,v) -> do
323+ foldM (\m (k,v) ->
324 if ignorable k
324 if ignorable k
325 then return m
325 then return m
326 else do
326 else do
@@ -353,7 +353,7 @@ kvPair allowEmpty = try $ do
353 (try $ newline >> lookAhead (blankline <|> nonspaceChar))
353 (try $ newline >> lookAhead (blankline <|> nonspaceChar))
354 guard $ allowEmpty || not (null val)
354 guard $ allowEmpty || not (null val)
355 let key' = concat $ words $ map toLower key
355 let key' = concat $ words $ map toLower key
356− let val' = MetaBlocks $ B.toList $ B.plain $ B.text $ val
356+ let val' = MetaBlocks $ B.toList $ B.plain $B.text val
357 return (key',val')
357 return (key',val')
358
358
359parseMarkdown :: PandocMonad m => MarkdownParser m Pandoc
359parseMarkdown :: PandocMonad m => MarkdownParser m Pandoc
@@ -364,8 +364,7 @@ parseMarkdown = do
364 -- check for notes with no corresponding note references
364 -- check for notes with no corresponding note references
365 let notesUsed = stateNoteRefs st
365 let notesUsed = stateNoteRefs st
366 let notesDefined = M.keys (stateNotes' st)
366 let notesDefined = M.keys (stateNotes' st)
367− mapM_ (\n -> unless (n `Set.member` notesUsed) $ do
367+ mapM_ (\n -> unless (n `Set.member` notesUsed) $
368− -- lookup to get sourcepos
369 case M.lookup n (stateNotes' st) of
368 case M.lookup n (stateNotes' st) of
370 Just (pos, _) -> report (NoteDefinedButNotUsed n pos)
369 Just (pos, _) -> report (NoteDefinedButNotUsed n pos)
371 Nothing -> throwError $
370 Nothing -> throwError $
@@ -384,7 +383,7 @@ referenceKey = try $ do
384 (_,raw) <- reference
383 (_,raw) <- reference
385 char ':'
384 char ':'
386 skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
385 skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
387− let sourceURL = liftM unwords $ many $ try $ do
386+ let sourceURL = fmap unwords $ many $ try $ do
388 skipMany spaceChar
387 skipMany spaceChar
389 notFollowedBy' referenceTitle
388 notFollowedBy' referenceTitle
390 notFollowedBy' $ guardEnabled Ext_link_attributes >> attributes
389 notFollowedBy' $ guardEnabled Ext_link_attributes >> attributes
@@ -533,7 +532,7 @@ atxChar = do
533
532
534atxHeader :: PandocMonad m => MarkdownParser m (F Blocks)
533atxHeader :: PandocMonad m => MarkdownParser m (F Blocks)
535atxHeader = try $ do
534atxHeader = try $ do
536− level <- atxChar >>= many1 . char >>= return . length
535+ level <- fmap length (atxChar >>= many1 . char)
537 notFollowedBy $ guardEnabled Ext_fancy_lists >>
536 notFollowedBy $ guardEnabled Ext_fancy_lists >>
538 (char '.' <|> char ')') -- this would be a list
537 (char '.' <|> char ')') -- this would be a list
539 guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
538 guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
@@ -588,7 +587,7 @@ setextHeader = try $ do
588 underlineChar <- oneOf setextHChars
587 underlineChar <- oneOf setextHChars
589 many (char underlineChar)
588 many (char underlineChar)
590 blanklines
589 blanklines
591− let level = (fromMaybe 0 $ findIndex (== underlineChar) setextHChars) + 1
590+ let level = fromMaybe 0 (findIndex (== underlineChar) setextHChars) + 1
592 attr' <- registerHeader attr (runF text defaultParserState)
591 attr' <- registerHeader attr (runF text defaultParserState)
593 guardDisabled Ext_implicit_header_references
592 guardDisabled Ext_implicit_header_references
594 <|> registerImplicitHeader raw attr'
593 <|> registerImplicitHeader raw attr'
@@ -629,8 +628,7 @@ blockDelimiter f len = try $ do
629 c <- lookAhead (satisfy f)
628 c <- lookAhead (satisfy f)
630 case len of
629 case len of
631 Just l -> count l (char c) >> many (char c) >> return l
630 Just l -> count l (char c) >> many (char c) >> return l
632− Nothing -> count 3 (char c) >> many (char c) >>=
631+ Nothing -> fmap ((+ 3) . length) (count 3 (char c) >> many (char c))
633− return . (+ 3) . length
634
632
635attributes :: PandocMonad m => MarkdownParser m Attr
633attributes :: PandocMonad m => MarkdownParser m Attr
636attributes = try $ do
634attributes = try $ do
@@ -794,7 +792,7 @@ blockQuote :: PandocMonad m => MarkdownParser m (F Blocks)
794blockQuote = do
792blockQuote = do
795 raw <- emailBlockQuote
793 raw <- emailBlockQuote
796 -- parse the extracted block, which may contain various block elements:
794 -- parse the extracted block, which may contain various block elements:
797− contents <- parseFromString' parseBlocks $ (intercalate "\n" raw) ++ "\n\n"
795+ contents <- parseFromString' parseBlocks $ intercalate "\n" raw ++ "\n\n"
798 return $ B.blockQuote <$> contents
796 return $ B.blockQuote <$> contents
799
797
800--
798--
@@ -840,7 +838,7 @@ orderedListStart mbstydelim = try $ do
840 return (num, style, delim))
838 return (num, style, delim))
841
839
842listStart :: PandocMonad m => MarkdownParser m ()
840listStart :: PandocMonad m => MarkdownParser m ()
843−listStart = bulletListStart <|> (orderedListStart Nothing >> return ())
841+listStart = bulletListStart <|> (Control.Monad.void (orderedListStart Nothing))
844
842
845listLine :: PandocMonad m => Int -> MarkdownParser m String
843listLine :: PandocMonad m => Int -> MarkdownParser m String
846listLine continuationIndent = try $ do
844listLine continuationIndent = try $ do
@@ -854,7 +852,7 @@ listLine continuationIndent = try $ do
854listLineCommon :: PandocMonad m => MarkdownParser m String
852listLineCommon :: PandocMonad m => MarkdownParser m String
855listLineCommon = concat <$> manyTill
853listLineCommon = concat <$> manyTill
856 ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
854 ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
857− <|> liftM snd (htmlTag isCommentTag)
855+ <|> fmap snd (htmlTag isCommentTag)
858 <|> count 1 anyChar
856 <|> count 1 anyChar
859 ) newline
857 ) newline
860
858
@@ -973,7 +971,7 @@ defRawBlock compact = try $ do
973 <|> notFollowedBy defListMarker
971 <|> notFollowedBy defListMarker
974 anyLine )
972 anyLine )
975 rawlines <- many dline
973 rawlines <- many dline
976− cont <- liftM concat $ many $ try $ do
974+ cont <- fmap concat $ many $ try $ do
977 trailing <- option "" blanklines
975 trailing <- option "" blanklines
978 ln <- indentSpaces >> notFollowedBy blankline >> anyLine
976 ln <- indentSpaces >> notFollowedBy blankline >> anyLine
979 lns <- many dline
977 lns <- many dline
@@ -984,7 +982,7 @@ defRawBlock compact = try $ do
984definitionList :: PandocMonad m => MarkdownParser m (F Blocks)
982definitionList :: PandocMonad m => MarkdownParser m (F Blocks)
985definitionList = try $ do
983definitionList = try $ do
986 lookAhead (anyLine >>
984 lookAhead (anyLine >>
987− optional (blankline >> notFollowedBy (table >> return ())) >>
985+ optional (blankline >> notFollowedBy (Control.Monad.void table)) >>
988 -- don't capture table caption as def list!
986 -- don't capture table caption as def list!
989 defListMarker)
987 defListMarker)
990 compactDefinitionList <|> normalDefinitionList
988 compactDefinitionList <|> normalDefinitionList
@@ -1052,7 +1050,7 @@ plain = fmap B.plain . trimInlinesF <$> inlines1
1052htmlElement :: PandocMonad m => MarkdownParser m String
1050htmlElement :: PandocMonad m => MarkdownParser m String
1053htmlElement = rawVerbatimBlock
1051htmlElement = rawVerbatimBlock
1054 <|> strictHtmlBlock
1052 <|> strictHtmlBlock
1055− <|> liftM snd (htmlTag isBlockTag)
1053+ <|> fmap snd (htmlTag isBlockTag)
1056
1054
1057htmlBlock :: PandocMonad m => MarkdownParser m (F Blocks)
1055htmlBlock :: PandocMonad m => MarkdownParser m (F Blocks)
1058htmlBlock = do
1056htmlBlock = do
@@ -1183,17 +1181,17 @@ simpleTableHeader headless = try $ do
1183 let (lengths, lines') = unzip dashes
1181 let (lengths, lines') = unzip dashes
1184 let indices = scanl (+) (length initSp) lines'
1182 let indices = scanl (+) (length initSp) lines'
1185 -- If no header, calculate alignment on basis of first row of text
1183 -- If no header, calculate alignment on basis of first row of text
1186− rawHeads <- liftM (tail . splitStringByIndices (init indices)) $
1184+ rawHeads <- fmap (tail . splitStringByIndices (init indices)) $
1187 if headless
1185 if headless
1188 then lookAhead anyLine
1186 then lookAhead anyLine
1189 else return rawContent
1187 else return rawContent
1190− let aligns = zipWith alignType (map (\a -> [a]) rawHeads) lengths
1188+ let aligns = zipWith alignType (map ((: [])) rawHeads) lengths
1191 let rawHeads' = if headless
1189 let rawHeads' = if headless
1192 then replicate (length dashes) ""
1190 then replicate (length dashes) ""
1193 else rawHeads
1191 else rawHeads
1194 heads <- fmap sequence
1192 heads <- fmap sequence
1193+ $
1195− $ mapM (parseFromString' (mconcat <$> many plain))
1194+ mapM ((parseFromString' (mconcat <$> many plain)).trim) rawHeads'
1196− $ map trim rawHeads'
1197 return (heads, aligns, indices)
1195 return (heads, aligns, indices)
1198
1196
1199-- Returns an alignment type for a table, based on a list of strings
1197-- Returns an alignment type for a table, based on a list of strings
@@ -1295,7 +1293,7 @@ multilineTableHeader headless = try $ do
1295 let (lengths, lines') = unzip dashes
1293 let (lengths, lines') = unzip dashes
1296 let indices = scanl (+) (length initSp) lines'
1294 let indices = scanl (+) (length initSp) lines'
1297 rawHeadsList <- if headless
1295 rawHeadsList <- if headless
1298− then liftM (map (:[]) . tail .
1296+ then fmap (map (:[]) . tail .
1299 splitStringByIndices (init indices)) $ lookAhead anyLine
1297 splitStringByIndices (init indices)) $ lookAhead anyLine
1300 else return $ transpose $ map
1298 else return $ transpose $ map
1301 (tail . splitStringByIndices (init indices))
1299 (tail . splitStringByIndices (init indices))
@@ -1305,8 +1303,7 @@ multilineTableHeader headless = try $ do
1305 then replicate (length dashes) ""
1303 then replicate (length dashes) ""
1306 else map (unlines . map trim) rawHeadsList
1304 else map (unlines . map trim) rawHeadsList
1307 heads <- fmap sequence $
1305 heads <- fmap sequence $
1308− mapM (parseFromString' (mconcat <$> many plain)) $
1306+ mapM ((parseFromString' (mconcat <$> many plain)).trim) rawHeads
1309− map trim rawHeads
1310 return (heads, aligns, indices)
1307 return (heads, aligns, indices)
1311
1308
1312-- Parse a grid table: starts with row of '-' on top, then header
1309-- Parse a grid table: starts with row of '-' on top, then header
@@ -1345,7 +1342,7 @@ pipeTable = try $ do
1345 fromIntegral (len + 1) / fromIntegral numColumns)
1342 fromIntegral (len + 1) / fromIntegral numColumns)
1346 seplengths
1343 seplengths
1347 else replicate (length aligns) 0.0
1344 else replicate (length aligns) 0.0
1348− return $ (aligns, widths, heads', sequence lines'')
1345+ return (aligns, widths, heads', sequence lines'')
1349
1346
1350sepPipe :: PandocMonad m => MarkdownParser m ()
1347sepPipe :: PandocMonad m => MarkdownParser m ()
1351sepPipe = try $ do
1348sepPipe = try $ do
@@ -1363,7 +1360,7 @@ pipeTableRow = try $ do
1363 <|> void (noneOf "|\n\r")
1360 <|> void (noneOf "|\n\r")
1364 let cellContents = ((trim . snd) <$> withRaw (many chunk)) >>=
1361 let cellContents = ((trim . snd) <$> withRaw (many chunk)) >>=
1365 parseFromString' pipeTableCell
1362 parseFromString' pipeTableCell
1366− cells <- cellContents `sepEndBy1` (char '|')
1363+ cells <- cellContents `sepEndBy1` char '|'
1367 -- surrounding pipes needed for a one-column table:
1364 -- surrounding pipes needed for a one-column table:
1368 guard $ not (length cells == 1 && not openPipe)
1365 guard $ not (length cells == 1 && not openPipe)
1369 blankline
1366 blankline
@@ -1383,7 +1380,7 @@ pipeTableHeaderPart = try $ do
1383 right <- optionMaybe (char ':')
1380 right <- optionMaybe (char ':')
1384 skipMany spaceChar
1381 skipMany spaceChar
1385 let len = length pipe + maybe 0 (const 1) left + maybe 0 (const 1) right
1382 let len = length pipe + maybe 0 (const 1) left + maybe 0 (const 1) right
1386− return $
1383+ return
1387 ((case (left,right) of
1384 ((case (left,right) of
1388 (Nothing,Nothing) -> AlignDefault
1385 (Nothing,Nothing) -> AlignDefault
1389 (Just _,Nothing) -> AlignLeft
1386 (Just _,Nothing) -> AlignLeft
@@ -1412,10 +1409,10 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
1412 lines' <- fmap sequence $ rowParser indices `sepEndBy1` lineParser
1409 lines' <- fmap sequence $ rowParser indices `sepEndBy1` lineParser
1413 footerParser
1410 footerParser
1414 numColumns <- getOption readerColumns
1411 numColumns <- getOption readerColumns
1415− let widths = if (indices == [])
1412+ let widths = if indices == []
1416 then replicate (length aligns) 0.0
1413 then replicate (length aligns) 0.0
1417 else widthsFromIndices numColumns indices
1414 else widthsFromIndices numColumns indices
1418− return $ (aligns, widths, heads, lines')
1415+ return (aligns, widths, heads, lines')
1419
1416
1420table :: PandocMonad m => MarkdownParser m (F Blocks)
1417table :: PandocMonad m => MarkdownParser m (F Blocks)
1421table = try $ do
1418table = try $ do
@@ -1573,7 +1570,7 @@ enclosure c = do
1573 <|> (guard =<< notAfterString)
1570 <|> (guard =<< notAfterString)
1574 cs <- many1 (char c)
1571 cs <- many1 (char c)
1575 (return (B.str cs) <>) <$> whitespace
1572 (return (B.str cs) <>) <$> whitespace
1576− <|> do
1573+ <|>
1577 case length cs of
1574 case length cs of
1578 3 -> three c
1575 3 -> three c
1579 2 -> two c mempty
1576 2 -> two c mempty
@@ -1723,7 +1720,7 @@ source = do
1723 skipSpaces
1720 skipSpaces
1724 let urlChunk =
1721 let urlChunk =
1725 try parenthesizedChars
1722 try parenthesizedChars
1726− <|> (notFollowedBy (oneOf " )") >> (count 1 litChar))
1723+ <|> (notFollowedBy (oneOf " )") >> count 1 litChar)
1727 <|> try (many1 spaceChar <* notFollowedBy (oneOf "\"')"))
1724 <|> try (many1 spaceChar <* notFollowedBy (oneOf "\"')"))
1728 let sourceURL = (unwords . words . concat) <$> many urlChunk
1725 let sourceURL = (unwords . words . concat) <$> many urlChunk
1729 let betweenAngles = try $
1726 let betweenAngles = try $
@@ -1892,8 +1889,8 @@ rawConTeXtEnvironment :: PandocMonad m => ParserT [Char] st m String
1892rawConTeXtEnvironment = try $ do
1889rawConTeXtEnvironment = try $ do
1893 string "\\start"
1890 string "\\start"
1894 completion <- inBrackets (letter <|> digit <|> spaceChar)
1891 completion <- inBrackets (letter <|> digit <|> spaceChar)
1895− <|> (many1 letter)
1892+ <|> many1 letter
1896− contents <- manyTill (rawConTeXtEnvironment <|> (count 1 anyChar))
1893+ contents <- manyTill (rawConTeXtEnvironment <|> count 1 anyChar)
1897 (try $ string "\\stop" >> string completion)
1894 (try $ string "\\stop" >> string completion)
1898 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1895 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1899
1896
@@ -1999,10 +1996,9 @@ emoji = try $ do
1999cite :: PandocMonad m => MarkdownParser m (F Inlines)
1996cite :: PandocMonad m => MarkdownParser m (F Inlines)
2000cite = do
1997cite = do
2001 guardEnabled Ext_citations
1998 guardEnabled Ext_citations
2002− citations <- textualCite
1999+ textualCite
2003 <|> do (cs, raw) <- withRaw normalCite
2000 <|> do (cs, raw) <- withRaw normalCite
2004 return $ (flip B.cite (B.text raw)) <$> cs
2001 return $ (flip B.cite (B.text raw)) <$> cs
2005− return citations
2006
2002
2007textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
2003textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
2008textualCite = try $ do
2004textualCite = try $ do
@@ -2076,7 +2072,7 @@ suffix = try $ do
2076
2072
2077prefix :: PandocMonad m => MarkdownParser m (F Inlines)
2073prefix :: PandocMonad m => MarkdownParser m (F Inlines)
2078prefix = trimInlinesF . mconcat <$>
2074prefix = trimInlinesF . mconcat <$>
2079− manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
2075+ manyTill inline (char ']' <|> fmap (const ']') (lookAhead citeKey))
2080
2076
2081citeList :: PandocMonad m => MarkdownParser m (F [Citation])
2077citeList :: PandocMonad m => MarkdownParser m (F [Citation])
2082citeList = fmap sequence $ sepBy1 citation (try $ char ';' >> spnl)
2078citeList = fmap sequence $ sepBy1 citation (try $ char ';' >> spnl)
src/Text/Pandoc/Readers/Muse.hs+9−9
@@ -137,7 +137,7 @@ parseHtmlContentWithAttrs tag parser = do
137 endOfContent = try $ skipMany blankline >> skipSpaces >> eof
137 endOfContent = try $ skipMany blankline >> skipSpaces >> eof
138
138
139parseHtmlContent :: PandocMonad m => String -> MuseParser m a -> MuseParser m [a]
139parseHtmlContent :: PandocMonad m => String -> MuseParser m a -> MuseParser m [a]
140−parseHtmlContent tag p = liftM snd (parseHtmlContentWithAttrs tag p)
140+parseHtmlContent tag p = fmap snd (parseHtmlContentWithAttrs tag p)
141
141
142--
142--
143-- directive parsers
143-- directive parsers
@@ -213,7 +213,7 @@ header = try $ do
213 st <- stateParserContext <$> getState
213 st <- stateParserContext <$> getState
214 q <- stateQuoteContext <$> getState
214 q <- stateQuoteContext <$> getState
215 getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1)
215 getPosition >>= \pos -> guard (st == NullState && q == NoQuote && sourceColumn pos == 1)
216− level <- liftM length $ many1 $ char '*'
216+ level <- fmap length $ many1 $ char '*'
217 guard $ level <= 5
217 guard $ level <= 5
218 spaceChar
218 spaceChar
219 content <- trimInlinesF . mconcat <$> manyTill inline eol
219 content <- trimInlinesF . mconcat <$> manyTill inline eol
@@ -240,7 +240,7 @@ exampleTag = do
240 chop = lchop . rchop
240 chop = lchop . rchop
241
241
242literal :: PandocMonad m => MuseParser m (F Blocks)
242literal :: PandocMonad m => MuseParser m (F Blocks)
243−literal = liftM (return . rawBlock) $ htmlElement "literal"
243+literal = fmap (return . rawBlock) $ htmlElement "literal"
244 where
244 where
245 format (_, _, kvs) = fromMaybe "html" $ lookup "format" kvs
245 format (_, _, kvs) = fromMaybe "html" $ lookup "format" kvs
246 rawBlock (attrs, content) = B.rawBlock (format attrs) content
246 rawBlock (attrs, content) = B.rawBlock (format attrs) content
@@ -268,7 +268,7 @@ quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
268divTag :: PandocMonad m => MuseParser m (F Blocks)
268divTag :: PandocMonad m => MuseParser m (F Blocks)
269divTag = do
269divTag = do
270 (attrs, content) <- parseHtmlContentWithAttrs "div" block
270 (attrs, content) <- parseHtmlContentWithAttrs "div" block
271− return $ (B.divWith attrs) <$> mconcat content
271+ return $ B.divWith attrs <$> mconcat content
272
272
273verseLine :: PandocMonad m => MuseParser m String
273verseLine :: PandocMonad m => MuseParser m String
274verseLine = do
274verseLine = do
@@ -296,7 +296,7 @@ para :: PandocMonad m => MuseParser m (F Blocks)
296para = do
296para = do
297 indent <- length <$> many spaceChar
297 indent <- length <$> many spaceChar
298 let f = if indent >= 2 && indent < 6 then B.blockQuote else id
298 let f = if indent >= 2 && indent < 6 then B.blockQuote else id
299− liftM (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
299+ fmap (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
300 where
300 where
301 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
301 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
302 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
302 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
@@ -481,7 +481,7 @@ museAppendElement tbl element =
481 return tbl{ museTableCaption = inlines' }
481 return tbl{ museTableCaption = inlines' }
482
482
483tableCell :: PandocMonad m => MuseParser m (F Blocks)
483tableCell :: PandocMonad m => MuseParser m (F Blocks)
484−tableCell = try $ liftM B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
484+tableCell = try $ fmap B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
485 where cellEnd = try $ void (many1 spaceChar >> char '|') <|> eol
485 where cellEnd = try $ void (many1 spaceChar >> char '|') <|> eol
486
486
487tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
487tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
@@ -575,7 +575,7 @@ footnote = try $ do
575 return $ B.note contents'
575 return $ B.note contents'
576
576
577whitespace :: PandocMonad m => MuseParser m (F Inlines)
577whitespace :: PandocMonad m => MuseParser m (F Inlines)
578−whitespace = liftM return (lb <|> regsp)
578+whitespace = fmap return (lb <|> regsp)
579 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
579 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
580 regsp = try $ skipMany1 spaceChar >> return B.space
580 regsp = try $ skipMany1 spaceChar >> return B.space
581
581
@@ -655,10 +655,10 @@ codeTag = do
655 return $ return $ B.codeWith attrs $ fromEntities content
655 return $ return $ B.codeWith attrs $ fromEntities content
656
656
657str :: PandocMonad m => MuseParser m (F Inlines)
657str :: PandocMonad m => MuseParser m (F Inlines)
658−str = liftM (return . B.str) (many1 alphaNum <|> count 1 characterReference)
658+str = fmap (return . B.str) (many1 alphaNum <|> count 1 characterReference)
659
659
660symbol :: PandocMonad m => MuseParser m (F Inlines)
660symbol :: PandocMonad m => MuseParser m (F Inlines)
661−symbol = liftM (return . B.str) $ count 1 nonspaceChar
661+symbol = fmap (return . B.str) $ count 1 nonspaceChar
662
662
663link :: PandocMonad m => MuseParser m (F Inlines)
663link :: PandocMonad m => MuseParser m (F Inlines)
664link = try $ do
664link = try $ do
src/Text/Pandoc/Readers/Native.hs−1
@@ -69,4 +69,3 @@ readInlines s = maybe ((:[]) <$> readInline s) Right (safeRead (unpack s))
69
69
70readInline :: Text -> Either PandocError Inline
70readInline :: Text -> Either PandocError Inline
71readInline s = maybe (Left . PandocParseError $ "Could not read: " ++ unpack s) Right (safeRead (unpack s))
71readInline s = maybe (Left . PandocParseError $ "Could not read: " ++ unpack s) Right (safeRead (unpack s))
72−
src/Text/Pandoc/Readers/OPML.hs+7−8
@@ -4,6 +4,7 @@ import Control.Monad.State.Strict
4import Data.Char (toUpper)
4import Data.Char (toUpper)
5import Data.Default
5import Data.Default
6import Data.Generics
6import Data.Generics
7+import Data.Maybe (fromMaybe)
7import Data.Text (Text, pack, unpack)
8import Data.Text (Text, pack, unpack)
8import Text.HTML.TagSoup.Entity (lookupEntity)
9import Text.HTML.TagSoup.Entity (lookupEntity)
9import Text.Pandoc.Builder
10import Text.Pandoc.Builder
@@ -32,9 +33,9 @@ instance Default OPMLState where
32
33
33readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
34readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
34readOPML _ inp = do
35readOPML _ inp = do
35− (bs, st') <- flip runStateT def
36+ (bs, st') <- runStateT
36 (mapM parseBlock $ normalizeTree $
37 (mapM parseBlock $ normalizeTree $
37− parseXML (unpack (crFilter inp)))
38+ parseXML (unpack (crFilter inp))) def
38 return $
39 return $
39 setTitle (opmlDocTitle st') $
40 setTitle (opmlDocTitle st') $
40 setAuthors (opmlDocAuthors st') $
41 setAuthors (opmlDocAuthors st') $
@@ -62,9 +63,7 @@ convertEntity e = maybe (map toUpper e) id (lookupEntity e)
62-- convenience function to get an attribute value, defaulting to ""
63-- convenience function to get an attribute value, defaulting to ""
63attrValue :: String -> Element -> String
64attrValue :: String -> Element -> String
64attrValue attr elt =
65attrValue attr elt =
65− case lookupAttrBy (\x -> qName x == attr) (elAttribs elt) of
66+ fromMaybe "" (lookupAttrBy (\x -> qName x == attr) (elAttribs elt))
66− Just z -> z
67− Nothing -> ""
68
67
69-- exceptT :: PandocMonad m => Either PandocError a -> OPML m a
68-- exceptT :: PandocMonad m => Either PandocError a -> OPML m a
70-- exceptT = either throwError return
69-- exceptT = either throwError return
@@ -73,13 +72,13 @@ asHtml :: PandocMonad m => String -> OPML m Inlines
73asHtml s =
72asHtml s =
74 (\(Pandoc _ bs) -> case bs of
73 (\(Pandoc _ bs) -> case bs of
75 [Plain ils] -> fromList ils
74 [Plain ils] -> fromList ils
76− _ -> mempty) <$> (lift $ readHtml def (pack s))
75+ _ -> mempty) <$> lift (readHtml def (pack s))
77
76
78asMarkdown :: PandocMonad m => String -> OPML m Blocks
77asMarkdown :: PandocMonad m => String -> OPML m Blocks
79−asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> (lift $ readMarkdown def (pack s))
78+asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> lift (readMarkdown def (pack s))
80
79
81getBlocks :: PandocMonad m => Element -> OPML m Blocks
80getBlocks :: PandocMonad m => Element -> OPML m Blocks
82−getBlocks e = mconcat <$> (mapM parseBlock $ elContent e)
81+getBlocks e = mconcat <$> mapM parseBlock (elContent e)
83
82
84parseBlock :: PandocMonad m => Content -> OPML m Blocks
83parseBlock :: PandocMonad m => Content -> OPML m Blocks
85parseBlock (Elem e) =
84parseBlock (Elem e) =
src/Text/Pandoc/Readers/Odt/Arrows/State.hs+3−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE Arrows #-}
1+
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE TupleSections #-}
3{-# LANGUAGE TupleSections #-}
4{-
4{-
@@ -139,7 +139,7 @@ iterateS :: (Foldable f, MonadPlus m)
139 => ArrowState s x y
139 => ArrowState s x y
140 -> ArrowState s (f x) (m y)
140 -> ArrowState s (f x) (m y)
141iterateS a = ArrowState $ \(s,f) -> foldr a' (s,mzero) f
141iterateS a = ArrowState $ \(s,f) -> foldr a' (s,mzero) f
142− where a' x (s',m) = second ((mplus m).return) $ runArrowState a (s',x)
142+ where a' x (s',m) = second (mplus m.return) $ runArrowState a (s',x)
143
143
144-- | Fold a state arrow through something 'Foldable'. Collect the results in a
144-- | Fold a state arrow through something 'Foldable'. Collect the results in a
145-- 'MonadPlus'.
145-- 'MonadPlus'.
@@ -147,7 +147,7 @@ iterateSL :: (Foldable f, MonadPlus m)
147 => ArrowState s x y
147 => ArrowState s x y
148 -> ArrowState s (f x) (m y)
148 -> ArrowState s (f x) (m y)
149iterateSL a = ArrowState $ \(s,f) -> foldl a' (s,mzero) f
149iterateSL a = ArrowState $ \(s,f) -> foldl a' (s,mzero) f
150− where a' (s',m) x = second ((mplus m).return) $ runArrowState a (s',x)
150+ where a' (s',m) x = second (mplus m.return) $ runArrowState a (s',x)
151
151
152
152
153-- | Fold a fallible state arrow through something 'Foldable'.
153-- | Fold a fallible state arrow through something 'Foldable'.
src/Text/Pandoc/Readers/Odt/Base.hs+1−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards #-}
1+
2
2
3{-
3{-
4Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
4Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
@@ -40,4 +40,3 @@ type OdtConverterState s = XMLConverterState Namespace s
40type XMLReader s a b = FallibleXMLConverter Namespace s a b
40type XMLReader s a b = FallibleXMLConverter Namespace s a b
41
41
42type XMLReaderSafe s a b = XMLConverter Namespace s a b
42type XMLReaderSafe s a b = XMLConverter Namespace s a b
43−
src/Text/Pandoc/Readers/Odt/Generic/Fallible.hs+2−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1+
2
2
3{-
3{-
4Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
4Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>
@@ -121,6 +121,6 @@ newtype SuccessList a = SuccessList { collectNonFailing :: [a] }
121 deriving ( Eq, Ord, Show )
121 deriving ( Eq, Ord, Show )
122
122
123instance ChoiceVector SuccessList where
123instance ChoiceVector SuccessList where
124− spreadChoice = Right . SuccessList . (foldr unTagRight []) . collectNonFailing
124+ spreadChoice = Right . SuccessList . foldr unTagRight [] . collectNonFailing
125 where unTagRight (Right x) = (x:)
125 where unTagRight (Right x) = (x:)
126 unTagRight _ = id
126 unTagRight _ = id
src/Text/Pandoc/Readers/Odt/Generic/Utils.hs+2−2
@@ -1,5 +1,5 @@
1−{-# LANGUAGE PatternGuards #-}
1+
2−{-# LANGUAGE TupleSections #-}
2+
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE ViewPatterns #-}
4{-# LANGUAGE ViewPatterns #-}
5
5
src/Text/Pandoc/Readers/Textile.hs+1−1
@@ -110,7 +110,7 @@ noteBlock = try $ do
110 startPos <- getPosition
110 startPos <- getPosition
111 ref <- noteMarker
111 ref <- noteMarker
112 optional blankline
112 optional blankline
113− contents <- liftM unlines $ many1Till anyLine (blanklines <|> noteBlock)
113+ contents <- fmap unlines $ many1Till anyLine (blanklines <|> noteBlock)
114 endPos <- getPosition
114 endPos <- getPosition
115 let newnote = (ref, contents ++ "\n")
115 let newnote = (ref, contents ++ "\n")
116 st <- getState
116 st <- getState
src/Text/Pandoc/Readers/TikiWiki.hs+50−54
@@ -22,7 +22,6 @@ module Text.Pandoc.Readers.TikiWiki ( readTikiWiki
22import Control.Monad
22import Control.Monad
23import Control.Monad.Except (throwError)
23import Control.Monad.Except (throwError)
24import qualified Data.Foldable as F
24import qualified Data.Foldable as F
25−import Data.List (intercalate)
26import Data.Maybe (fromMaybe)
25import Data.Maybe (fromMaybe)
27import Data.Text (Text)
26import Data.Text (Text)
28import qualified Data.Text as T
27import qualified Data.Text as T
@@ -58,7 +57,7 @@ tryMsg :: PandocMonad m => String -> TikiWikiParser m a -> TikiWikiParser m a
58tryMsg msg p = try p <?> msg
57tryMsg msg p = try p <?> msg
59
58
60skip :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m ()
59skip :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m ()
61−skip parser = parser >> return ()
60+skip parser = Control.Monad.void parser
62
61
63nested :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m a
62nested :: PandocMonad m => TikiWikiParser m a -> TikiWikiParser m a
64nested p = do
63nested p = do
@@ -88,7 +87,7 @@ block = do
88 <|> blockElements
87 <|> blockElements
89 <|> para
88 <|> para
90 skipMany blankline
89 skipMany blankline
91− when (verbosity >= INFO) $ do
90+ when (verbosity >= INFO) $
92 trace (printf "line %d: %s" (sourceLine pos) (take 60 $ show $ B.toList res))
91 trace (printf "line %d: %s" (sourceLine pos) (take 60 $ show $ B.toList res))
93 return res
92 return res
94
93
@@ -112,7 +111,7 @@ hr = try $ do
112 string "----"
111 string "----"
113 many (char '-')
112 many (char '-')
114 newline
113 newline
115− return $ B.horizontalRule
114+ return B.horizontalRule
116
115
117-- ! header
116-- ! header
118--
117--
@@ -122,18 +121,18 @@ hr = try $ do
122--
121--
123header :: PandocMonad m => TikiWikiParser m B.Blocks
122header :: PandocMonad m => TikiWikiParser m B.Blocks
124header = tryMsg "header" $ do
123header = tryMsg "header" $ do
125− level <- many1 (char '!') >>= return . length
124+ level <- fmap length (many1 (char '!'))
126 guard $ level <= 6
125 guard $ level <= 6
127 skipSpaces
126 skipSpaces
128 content <- B.trimInlines . mconcat <$> manyTill inline newline
127 content <- B.trimInlines . mconcat <$> manyTill inline newline
129 attr <- registerHeader nullAttr content
128 attr <- registerHeader nullAttr content
130− return $ B.headerWith attr level $ content
129+ return $B.headerWith attr level content
131
130
132tableRow :: PandocMonad m => TikiWikiParser m [B.Blocks]
131tableRow :: PandocMonad m => TikiWikiParser m [B.Blocks]
133tableRow = try $ do
132tableRow = try $ do
134-- row <- sepBy1 (many1Till inline $ oneOf "\n|") (try $ string "|" <* notFollowedBy (oneOf "|\n"))
133-- row <- sepBy1 (many1Till inline $ oneOf "\n|") (try $ string "|" <* notFollowedBy (oneOf "|\n"))
135-- return $ map (B.plain . mconcat) row
134-- return $ map (B.plain . mconcat) row
136− row <- sepBy1 ((many1 $ noneOf "\n|") >>= parseColumn) (try $ string "|" <* notFollowedBy (oneOf "|\n"))
135+ row <- sepBy1 (many1 (noneOf "\n|") >>= parseColumn) (try $ string "|" <* notFollowedBy (oneOf "|\n"))
137 return $ map B.plain row
136 return $ map B.plain row
138 where
137 where
139 parseColumn x = do
138 parseColumn x = do
@@ -165,14 +164,14 @@ table = try $ do
165 string "||"
164 string "||"
166 newline
165 newline
167 -- return $ B.simpleTable (headers rows) $ trace ("rows: " ++ (show rows)) rows
166 -- return $ B.simpleTable (headers rows) $ trace ("rows: " ++ (show rows)) rows
168− return $ B.simpleTable (headers rows) $ rows
167+ return $B.simpleTable (headers rows) rows
169 where
168 where
170 -- The headers are as many empty srings as the number of columns
169 -- The headers are as many empty srings as the number of columns
171 -- in the first row
170 -- in the first row
172− headers rows = map (B.plain . B.str) $ take (length $ rows !! 0) $ repeat ""
171+ headers rows = map (B.plain . B.str) $replicate (length $ rows !! 0) ""
173
172
174para :: PandocMonad m => TikiWikiParser m B.Blocks
173para :: PandocMonad m => TikiWikiParser m B.Blocks
175−para = many1Till inline endOfParaElement >>= return . result . mconcat
174+para = fmap (result . mconcat) ( many1Till inline endOfParaElement)
176 where
175 where
177 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
176 endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
178 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
177 endOfInput = try $ skipMany blankline >> skipSpaces >> eof
@@ -189,7 +188,7 @@ para = many1Till inline endOfParaElement >>= return . result . mconcat
189--
188--
190definitionList :: PandocMonad m => TikiWikiParser m B.Blocks
189definitionList :: PandocMonad m => TikiWikiParser m B.Blocks
191definitionList = tryMsg "definitionList" $ do
190definitionList = tryMsg "definitionList" $ do
192− elements <- many1 $ parseDefinitionListItem
191+ elements <-many1 parseDefinitionListItem
193 return $ B.definitionList elements
192 return $ B.definitionList elements
194 where
193 where
195 parseDefinitionListItem :: PandocMonad m => TikiWikiParser m (B.Inlines, [B.Blocks])
194 parseDefinitionListItem :: PandocMonad m => TikiWikiParser m (B.Inlines, [B.Blocks])
@@ -197,7 +196,7 @@ definitionList = tryMsg "definitionList" $ do
197 skipSpaces >> char ';' <* skipSpaces
196 skipSpaces >> char ';' <* skipSpaces
198 term <- many1Till inline $ char ':' <* skipSpaces
197 term <- many1Till inline $ char ':' <* skipSpaces
199 line <- listItemLine 1
198 line <- listItemLine 1
200− return $ (mconcat term, [B.plain line])
199+ return (mconcat term, [B.plain line])
201
200
202data ListType = None | Numbered | Bullet deriving (Ord, Eq, Show)
201data ListType = None | Numbered | Bullet deriving (Ord, Eq, Show)
203
202
@@ -233,15 +232,15 @@ mixedList = try $ do
233-- figre out a fold or something.
232-- figre out a fold or something.
234fixListNesting :: [B.Blocks] -> [B.Blocks]
233fixListNesting :: [B.Blocks] -> [B.Blocks]
235fixListNesting [] = []
234fixListNesting [] = []
236−fixListNesting (first:[]) = [recurseOnList first]
235+fixListNesting [first] = [recurseOnList first]
237-- fixListNesting nestall | trace ("\n\nfixListNesting: " ++ (show nestall)) False = undefined
236-- fixListNesting nestall | trace ("\n\nfixListNesting: " ++ (show nestall)) False = undefined
238-- fixListNesting nestall@(first:second:rest) =
237-- fixListNesting nestall@(first:second:rest) =
239fixListNesting (first:second:rest) =
238fixListNesting (first:second:rest) =
240 let secondBlock = head $ B.toList second in
239 let secondBlock = head $ B.toList second in
241 case secondBlock of
240 case secondBlock of
242− BulletList _ -> fixListNesting $ [(mappend (recurseOnList first) (recurseOnList second))] ++ rest
241+ BulletList _ -> fixListNesting $ (mappend (recurseOnList first) (recurseOnList second)) : rest
243− OrderedList _ _ -> fixListNesting $ [(mappend (recurseOnList first) (recurseOnList second))] ++ rest
242+ OrderedList _ _ -> fixListNesting $ (mappend (recurseOnList first) (recurseOnList second)) : rest
244− _ -> [recurseOnList first] ++ fixListNesting (second:rest)
243+ _ -> recurseOnList first : fixListNesting (second:rest)
245
244
246-- This function walks the Block structure for fixListNesting,
245-- This function walks the Block structure for fixListNesting,
247-- because it's a bit complicated, what with converting to and from
246-- because it's a bit complicated, what with converting to and from
@@ -249,7 +248,7 @@ fixListNesting (first:second:rest) =
249recurseOnList :: B.Blocks -> B.Blocks
248recurseOnList :: B.Blocks -> B.Blocks
250-- recurseOnList item | trace ("rOL: " ++ (show $ length $ B.toList item) ++ ", " ++ (show $ B.toList item)) False = undefined
249-- recurseOnList item | trace ("rOL: " ++ (show $ length $ B.toList item) ++ ", " ++ (show $ B.toList item)) False = undefined
251recurseOnList items
250recurseOnList items
252− | (length $ B.toList items) == 1 =
251+ | length (B.toList items) == 1 =
253 let itemBlock = head $ B.toList items in
252 let itemBlock = head $ B.toList items in
254 case itemBlock of
253 case itemBlock of
255 BulletList listItems -> B.bulletList $ fixListNesting $ map B.fromList listItems
254 BulletList listItems -> B.bulletList $ fixListNesting $ map B.fromList listItems
@@ -272,11 +271,11 @@ recurseOnList items
272-- sections.
271-- sections.
273spanFoldUpList :: ListNesting -> [(ListNesting, B.Blocks)] -> [B.Blocks]
272spanFoldUpList :: ListNesting -> [(ListNesting, B.Blocks)] -> [B.Blocks]
274spanFoldUpList _ [] = []
273spanFoldUpList _ [] = []
275−spanFoldUpList ln (first:[]) =
274+spanFoldUpList ln [first] =
276 listWrap ln (fst first) [snd first]
275 listWrap ln (fst first) [snd first]
277spanFoldUpList ln (first:rest) =
276spanFoldUpList ln (first:rest) =
278 let (span1, span2) = span (splitListNesting (fst first)) rest
277 let (span1, span2) = span (splitListNesting (fst first)) rest
279− newTree1 = listWrap ln (fst first) $ [snd first] ++ spanFoldUpList (fst first) span1
278+ newTree1 = listWrap ln (fst first) $ snd first : spanFoldUpList (fst first) span1
280 newTree2 = spanFoldUpList ln span2
279 newTree2 = spanFoldUpList ln span2
281 in
280 in
282 newTree1 ++ newTree2
281 newTree1 ++ newTree2
@@ -285,14 +284,13 @@ spanFoldUpList ln (first:rest) =
285-- item, which is true if the second item is at a deeper nesting
284-- item, which is true if the second item is at a deeper nesting
286-- level and of the same type.
285-- level and of the same type.
287splitListNesting :: ListNesting -> (ListNesting, B.Blocks) -> Bool
286splitListNesting :: ListNesting -> (ListNesting, B.Blocks) -> Bool
288−splitListNesting ln1 (ln2, _) =
287+splitListNesting ln1 (ln2, _)
289− if (lnnest ln1) < (lnnest ln2) then
288+ | (lnnest ln1) < (lnnest ln2) =
290− True
289+ True
291− else
292− if ln1 == ln2 then
290+ | ln1 == ln2 =
293− True
291+ True
294− else
292+ | otherwise =
295− False
293+ False
296
294
297-- If we've moved to a deeper nesting level, wrap the new level in
295-- If we've moved to a deeper nesting level, wrap the new level in
298-- the appropriate type of list.
296-- the appropriate type of list.
@@ -323,7 +321,7 @@ bulletItem = try $ do
323 prefix <- many1 $ char '*'
321 prefix <- many1 $ char '*'
324 many1 $ char ' '
322 many1 $ char ' '
325 content <- listItemLine (length prefix)
323 content <- listItemLine (length prefix)
326− return $ (LN Bullet (length prefix), B.plain content)
324+ return (LN Bullet (length prefix), B.plain content)
327
325
328-- # Start each line
326-- # Start each line
329-- # with a number (1.).
327-- # with a number (1.).
@@ -335,17 +333,17 @@ numberedItem = try $ do
335 prefix <- many1 $ char '#'
333 prefix <- many1 $ char '#'
336 many1 $ char ' '
334 many1 $ char ' '
337 content <- listItemLine (length prefix)
335 content <- listItemLine (length prefix)
338− return $ (LN Numbered (length prefix), B.plain content)
336+ return (LN Numbered (length prefix), B.plain content)
339
337
340listItemLine :: PandocMonad m => Int -> TikiWikiParser m B.Inlines
338listItemLine :: PandocMonad m => Int -> TikiWikiParser m B.Inlines
341−listItemLine nest = lineContent >>= parseContent >>= return
339+listItemLine nest = lineContent >>= parseContent
342 where
340 where
343 lineContent = do
341 lineContent = do
344 content <- anyLine
342 content <- anyLine
345 continuation <- optionMaybe listContinuation
343 continuation <- optionMaybe listContinuation
346− return $ filterSpaces content ++ "\n" ++ (maybe "" id continuation)
344+ return $ filterSpaces content ++ "\n" ++ maybe "" id continuation
347 filterSpaces = reverse . dropWhile (== ' ') . reverse
345 filterSpaces = reverse . dropWhile (== ' ') . reverse
348− listContinuation = string (take nest (repeat '+')) >> lineContent
346+ listContinuation = string (replicate nest '+') >> lineContent
349 parseContent x = do
347 parseContent x = do
350 parsed <- parseFromString (many1 inline) x
348 parsed <- parseFromString (many1 inline) x
351 return $ mconcat parsed
349 return $ mconcat parsed
@@ -373,7 +371,7 @@ codeMacro = try $ do
373 string ")}"
371 string ")}"
374 body <- manyTill anyChar (try (string "{CODE}"))
372 body <- manyTill anyChar (try (string "{CODE}"))
375 newline
373 newline
376− if length rawAttrs > 0
374+ if not (null rawAttrs)
377 then
375 then
378 return $ B.codeBlockWith (mungeAttrs rawAttrs) body
376 return $ B.codeBlockWith (mungeAttrs rawAttrs) body
379 else
377 else
@@ -412,7 +410,7 @@ inline = choice [ whitespace
412 ] <?> "inline"
410 ] <?> "inline"
413
411
414whitespace :: PandocMonad m => TikiWikiParser m B.Inlines
412whitespace :: PandocMonad m => TikiWikiParser m B.Inlines
415−whitespace = (lb <|> regsp) >>= return
413+whitespace = (lb <|> regsp)
416 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
414 where lb = try $ skipMany spaceChar >> linebreak >> return B.space
417 regsp = try $ skipMany1 spaceChar >> return B.space
415 regsp = try $ skipMany1 spaceChar >> return B.space
418
416
@@ -452,7 +450,7 @@ enclosed sep p = between sep (try $ sep <* endMarker) p
452nestedInlines :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m B.Inlines
450nestedInlines :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m B.Inlines
453nestedInlines end = innerSpace <|> nestedInline
451nestedInlines end = innerSpace <|> nestedInline
454 where
452 where
455− innerSpace = try $ whitespace <* (notFollowedBy end)
453+ innerSpace = try $ whitespace <* notFollowedBy end
456 nestedInline = notFollowedBy whitespace >> nested inline
454 nestedInline = notFollowedBy whitespace >> nested inline
457
455
458-- {img attId="39" imalign="right" link="http://info.tikiwiki.org" alt="Panama Hat"}
456-- {img attId="39" imalign="right" link="http://info.tikiwiki.org" alt="Panama Hat"}
@@ -470,13 +468,13 @@ image = try $ do
470 let title = fromMaybe src $ lookup "desc" rawAttrs
468 let title = fromMaybe src $ lookup "desc" rawAttrs
471 let alt = fromMaybe title $ lookup "alt" rawAttrs
469 let alt = fromMaybe title $ lookup "alt" rawAttrs
472 let classes = map fst $ filter (\(_,b) -> b == "" || b == "y") rawAttrs
470 let classes = map fst $ filter (\(_,b) -> b == "" || b == "y") rawAttrs
473− if length src > 0
471+ if not (null src)
474 then
472 then
475 return $ B.imageWith ("", classes, rawAttrs) src title (B.str alt)
473 return $ B.imageWith ("", classes, rawAttrs) src title (B.str alt)
476 else
474 else
477− return $ B.str $ " NOT SUPPORTED: image without src attribute BEGIN: {img " ++ (printAttrs rawAttrs) ++ "} :END "
475+ return $ B.str $ " NOT SUPPORTED: image without src attribute BEGIN: {img " ++ printAttrs rawAttrs ++ "} :END "
478 where
476 where
479− printAttrs attrs = intercalate " " $ map (\(a, b) -> a ++ "=\"" ++ b ++ "\"") attrs
477+ printAttrs attrs = unwords $ map (\(a, b) -> a ++ "=\"" ++ b ++ "\"") attrs
480
478
481imageAttr :: PandocMonad m => TikiWikiParser m (String, String)
479imageAttr :: PandocMonad m => TikiWikiParser m (String, String)
482imageAttr = try $ do
480imageAttr = try $ do
@@ -491,11 +489,11 @@ imageAttr = try $ do
491
489
492-- __strong__
490-- __strong__
493strong :: PandocMonad m => TikiWikiParser m B.Inlines
491strong :: PandocMonad m => TikiWikiParser m B.Inlines
494−strong = try $ enclosed (string "__") nestedInlines >>= return . B.strong
492+strong = try $ fmap B.strong (enclosed (string "__") nestedInlines)
495
493
496-- ''emph''
494-- ''emph''
497emph :: PandocMonad m => TikiWikiParser m B.Inlines
495emph :: PandocMonad m => TikiWikiParser m B.Inlines
498−emph = try $ enclosed (string "''") nestedInlines >>= return . B.emph
496+emph = try $ fmap B.emph (enclosed (string "''") nestedInlines)
499
497
500-- ~246~
498-- ~246~
501escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
499escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -503,7 +501,7 @@ escapedChar = try $ do
503 string "~"
501 string "~"
504 inner <- many1 $ oneOf "0123456789"
502 inner <- many1 $ oneOf "0123456789"
505 string "~"
503 string "~"
506− return $ B.str $ [(toEnum ((read inner) :: Int)) :: Char]
504+ return $B.str [(toEnum ((read inner) :: Int)) :: Char]
507
505
508-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
506-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
509-- for this
507-- for this
@@ -543,10 +541,10 @@ boxed = try $ do
543
541
544-- --text--
542-- --text--
545strikeout :: PandocMonad m => TikiWikiParser m B.Inlines
543strikeout :: PandocMonad m => TikiWikiParser m B.Inlines
546−strikeout = try $ enclosed (string "--") nestedInlines >>= return . B.strikeout
544+strikeout = try $ fmap B.strikeout (enclosed (string "--") nestedInlines)
547
545
548nestedString :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m String
546nestedString :: (Show a, PandocMonad m) => TikiWikiParser m a -> TikiWikiParser m String
549−nestedString end = innerSpace <|> (count 1 nonspaceChar)
547+nestedString end = innerSpace <|> count 1 nonspaceChar
550 where
548 where
551 innerSpace = try $ many1 spaceChar <* notFollowedBy end
549 innerSpace = try $ many1 spaceChar <* notFollowedBy end
552
550
@@ -555,7 +553,7 @@ breakChars = try $ string "%%%" >> return B.linebreak
555
553
556-- superscript: foo{TAG(tag=>sup)}super{TAG}foo / bar{SUP()}super2{SUP}bar
554-- superscript: foo{TAG(tag=>sup)}super{TAG}foo / bar{SUP()}super2{SUP}bar
557superTag :: PandocMonad m => TikiWikiParser m B.Inlines
555superTag :: PandocMonad m => TikiWikiParser m B.Inlines
558−superTag = try $ between (string "{TAG(tag=>sup)}") (string "{TAG}") nestedString >>= return . B.superscript . B.text . fromEntities
556+superTag = try $ fmap (B.superscript . B.text . fromEntities) ( between (string "{TAG(tag=>sup)}") (string "{TAG}") nestedString)
559
557
560superMacro :: PandocMonad m => TikiWikiParser m B.Inlines
558superMacro :: PandocMonad m => TikiWikiParser m B.Inlines
561superMacro = try $ do
559superMacro = try $ do
@@ -566,7 +564,7 @@ superMacro = try $ do
566
564
567-- subscript: baz{TAG(tag=>sub)}sub{TAG}qux / qux{SUB()}sub2{SUB}qux
565-- subscript: baz{TAG(tag=>sub)}sub{TAG}qux / qux{SUB()}sub2{SUB}qux
568subTag :: PandocMonad m => TikiWikiParser m B.Inlines
566subTag :: PandocMonad m => TikiWikiParser m B.Inlines
569−subTag = try $ between (string "{TAG(tag=>sub)}") (string "{TAG}") nestedString >>= return . B.subscript . B.text . fromEntities
567+subTag = try $ fmap (B.subscript . B.text . fromEntities) ( between (string "{TAG(tag=>sub)}") (string "{TAG}") nestedString)
570
568
571subMacro :: PandocMonad m => TikiWikiParser m B.Inlines
569subMacro :: PandocMonad m => TikiWikiParser m B.Inlines
572subMacro = try $ do
570subMacro = try $ do
@@ -577,7 +575,7 @@ subMacro = try $ do
577
575
578-- -+text+-
576-- -+text+-
579code :: PandocMonad m => TikiWikiParser m B.Inlines
577code :: PandocMonad m => TikiWikiParser m B.Inlines
580−code = try $ between (string "-+") (string "+-") nestedString >>= return . B.code . fromEntities
578+code = try $ fmap (B.code . fromEntities) ( between (string "-+") (string "+-") nestedString)
581
579
582macroAttr :: PandocMonad m => TikiWikiParser m (String, String)
580macroAttr :: PandocMonad m => TikiWikiParser m (String, String)
583macroAttr = try $ do
581macroAttr = try $ do
@@ -590,8 +588,7 @@ macroAttr = try $ do
590
588
591macroAttrs :: PandocMonad m => TikiWikiParser m [(String, String)]
589macroAttrs :: PandocMonad m => TikiWikiParser m [(String, String)]
592macroAttrs = try $ do
590macroAttrs = try $ do
593− attrs <- sepEndBy macroAttr spaces
591+ sepEndBy macroAttr spaces
594− return attrs
595
592
596-- ~np~ __not bold__ ~/np~
593-- ~np~ __not bold__ ~/np~
597noparse :: PandocMonad m => TikiWikiParser m B.Inlines
594noparse :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -601,10 +598,10 @@ noparse = try $ do
601 return $ B.str body
598 return $ B.str body
602
599
603str :: PandocMonad m => TikiWikiParser m B.Inlines
600str :: PandocMonad m => TikiWikiParser m B.Inlines
604−str = (many1 alphaNum <|> count 1 characterReference) >>= return . B.str
601+str = fmap B.str (many1 alphaNum <|> count 1 characterReference)
605
602
606symbol :: PandocMonad m => TikiWikiParser m B.Inlines
603symbol :: PandocMonad m => TikiWikiParser m B.Inlines
607−symbol = count 1 nonspaceChar >>= return . B.str
604+symbol = fmap B.str (count 1 nonspaceChar)
608
605
609-- [[not a link]
606-- [[not a link]
610notExternalLink :: PandocMonad m => TikiWikiParser m B.Inlines
607notExternalLink :: PandocMonad m => TikiWikiParser m B.Inlines
@@ -627,7 +624,7 @@ makeLink start middle end = try $ do
627 (url, title, anchor) <- wikiLinkText start middle end
624 (url, title, anchor) <- wikiLinkText start middle end
628 parsedTitle <- parseFromString (many1 inline) title
625 parsedTitle <- parseFromString (many1 inline) title
629 setState $ st{ stateAllowLinks = True }
626 setState $ st{ stateAllowLinks = True }
630− return $ B.link (url++anchor) "" $ mconcat $ parsedTitle
627+ return $ B.link (url++anchor) "" $mconcat parsedTitle
631
628
632wikiLinkText :: PandocMonad m => String -> String -> String -> TikiWikiParser m (String, String, String)
629wikiLinkText :: PandocMonad m => String -> String -> String -> TikiWikiParser m (String, String, String)
633wikiLinkText start middle end = do
630wikiLinkText start middle end = do
@@ -643,9 +640,9 @@ wikiLinkText start middle end = do
643 return (url, seg1, "")
640 return (url, seg1, "")
644 where
641 where
645 linkContent = do
642 linkContent = do
646− (char '|')
643+ char '|'
647 mystr <- many (noneOf middle)
644 mystr <- many (noneOf middle)
648− return $ mystr
645+ return mystr
649
646
650externalLink :: PandocMonad m => TikiWikiParser m B.Inlines
647externalLink :: PandocMonad m => TikiWikiParser m B.Inlines
651externalLink = makeLink "[" "]|" "]"
648externalLink = makeLink "[" "]|" "]"
@@ -657,4 +654,3 @@ externalLink = makeLink "[" "]|" "]"
657-- [see also this other post](My Other Page) is perfectly valid.
654-- [see also this other post](My Other Page) is perfectly valid.
658wikiLink :: PandocMonad m => TikiWikiParser m B.Inlines
655wikiLink :: PandocMonad m => TikiWikiParser m B.Inlines
659wikiLink = makeLink "((" ")|" "))"
656wikiLink = makeLink "((" ")|" "))"
660−
src/Text/Pandoc/Readers/Vimwiki.hs+64−65
@@ -91,14 +91,13 @@ import Text.Pandoc.Parsing (F, ParserState, ParserT, blanklines, emailAddress,
91 registerHeader, runF, spaceChar, stateMeta',
91 registerHeader, runF, spaceChar, stateMeta',
92 stateOptions, uri)
92 stateOptions, uri)
93import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast)
93import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast)
94+import Text.Parsec.Char
94−import Text.Parsec.Char (alphaNum, anyChar, char, newline, noneOf, spaces,
95+ (alphaNum, anyChar, char, newline, noneOf, spaces, string, oneOf,
95− string)
96+ space)
96−import Text.Parsec.Char (oneOf, space)
97−import Text.Parsec.Combinator (choice, count, eof, many1, manyTill,
97+import Text.Parsec.Combinator
98− notFollowedBy, option, skipMany1)
98+ (choice, count, eof, many1, manyTill, notFollowedBy, option,
99−import Text.Parsec.Combinator (between, lookAhead)
99+ skipMany1, between, lookAhead)
100−import Text.Parsec.Prim (getState, many, try, updateState)
100+import Text.Parsec.Prim (getState, many, try, updateState, (<|>))
101−import Text.Parsec.Prim ((<|>))
102
101
103readVimwiki :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
102readVimwiki :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
104readVimwiki opts s = do
103readVimwiki opts s = do
@@ -161,9 +160,9 @@ header = try $ do
161 let lev = length eqs
160 let lev = length eqs
162 guard $ lev <= 6
161 guard $ lev <= 6
163 contents <- trimInlines . mconcat <$> manyTill inline (try $ spaceChar
162 contents <- trimInlines . mconcat <$> manyTill inline (try $ spaceChar
164− >> (string eqs) >> many spaceChar >> newline)
163+ >> string eqs >> many spaceChar >> newline)
165 attr <- registerHeader (makeId contents,
164 attr <- registerHeader (makeId contents,
166− (if sp == "" then [] else ["justcenter"]), []) contents
165+ if sp == "" then [] else ["justcenter"], []) contents
167 return $ B.headerWith attr lev contents
166 return $ B.headerWith attr lev contents
168
167
169para :: PandocMonad m => VwParser m Blocks
168para :: PandocMonad m => VwParser m Blocks
@@ -191,22 +190,22 @@ blockQuote = try $ do
191
190
192definitionList :: PandocMonad m => VwParser m Blocks
191definitionList :: PandocMonad m => VwParser m Blocks
193definitionList = try $
192definitionList = try $
194− B.definitionList <$> (many1 (dlItemWithDT <|> dlItemWithoutDT))
193+ B.definitionList <$> many1 (dlItemWithDT <|> dlItemWithoutDT)
195
194
196dlItemWithDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
195dlItemWithDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
197dlItemWithDT = do
196dlItemWithDT = do
198 dt <- definitionTerm
197 dt <- definitionTerm
199 dds <- many definitionDef
198 dds <- many definitionDef
200− return $ (dt, dds)
199+ return (dt, dds)
201
200
202dlItemWithoutDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
201dlItemWithoutDT :: PandocMonad m => VwParser m (Inlines, [Blocks])
203dlItemWithoutDT = do
202dlItemWithoutDT = do
204 dds <- many1 definitionDef
203 dds <- many1 definitionDef
205− return $ (mempty, dds)
204+ return (mempty, dds)
206
205
207definitionDef :: PandocMonad m => VwParser m Blocks
206definitionDef :: PandocMonad m => VwParser m Blocks
208definitionDef = try $
207definitionDef = try $
209− (notFollowedBy definitionTerm) >> many spaceChar
208+ notFollowedBy definitionTerm >> many spaceChar
210 >> (definitionDef1 <|> definitionDef2)
209 >> (definitionDef1 <|> definitionDef2)
211
210
212definitionDef1 :: PandocMonad m => VwParser m Blocks
211definitionDef1 :: PandocMonad m => VwParser m Blocks
@@ -220,16 +219,16 @@ definitionDef2 = try $ B.plain <$>
220definitionTerm :: PandocMonad m => VwParser m Inlines
219definitionTerm :: PandocMonad m => VwParser m Inlines
221definitionTerm = try $ do
220definitionTerm = try $ do
222 x <- definitionTerm1 <|> definitionTerm2
221 x <- definitionTerm1 <|> definitionTerm2
223− guard $ (stringify x /= "")
222+ guard (stringify x /= "")
224 return x
223 return x
225
224
226definitionTerm1 :: PandocMonad m => VwParser m Inlines
225definitionTerm1 :: PandocMonad m => VwParser m Inlines
227definitionTerm1 = try $
226definitionTerm1 = try $
228− trimInlines . mconcat <$> manyTill inline' (try $ defMarkerE)
227+ trimInlines . mconcat <$> manyTill inline' (try defMarkerE)
229
228
230definitionTerm2 :: PandocMonad m => VwParser m Inlines
229definitionTerm2 :: PandocMonad m => VwParser m Inlines
231definitionTerm2 = try $ trimInlines . mconcat <$> manyTill inline'
230definitionTerm2 = try $ trimInlines . mconcat <$> manyTill inline'
232− (try $ lookAhead $ (defMarkerM >> notFollowedBy hasDefMarkerM))
231+ (try $lookAhead (defMarkerM >> notFollowedBy hasDefMarkerM))
233
232
234defMarkerM :: PandocMonad m => VwParser m Char
233defMarkerM :: PandocMonad m => VwParser m Char
235defMarkerM = string "::" >> spaceChar
234defMarkerM = string "::" >> spaceChar
@@ -247,14 +246,14 @@ preformatted = try $ do
247 lookAhead newline
246 lookAhead newline
248 contents <- manyTill anyChar (try (char '\n' >> many spaceChar >> string "}}}"
247 contents <- manyTill anyChar (try (char '\n' >> many spaceChar >> string "}}}"
249 >> many spaceChar >> newline))
248 >> many spaceChar >> newline))
250− if (not $ contents == "") && (head contents == '\n')
249+ if not (contents == "") && (head contents == '\n')
251 then return $ B.codeBlockWith (makeAttr attrText) (tail contents)
250 then return $ B.codeBlockWith (makeAttr attrText) (tail contents)
252 else return $ B.codeBlockWith (makeAttr attrText) contents
251 else return $ B.codeBlockWith (makeAttr attrText) contents
253
252
254makeAttr :: String -> Attr
253makeAttr :: String -> Attr
255makeAttr s =
254makeAttr s =
256 let xs = splitBy (`elem` " \t") s in
255 let xs = splitBy (`elem` " \t") s in
257− ("", [], catMaybes $ map nameValue xs)
256+ ("", [], mapMaybe nameValue xs)
258
257
259nameValue :: String -> Maybe (String, String)
258nameValue :: String -> Maybe (String, String)
260nameValue s =
259nameValue s =
@@ -262,7 +261,7 @@ nameValue s =
262 if length t /= 2
261 if length t /= 2
263 then Nothing
262 then Nothing
264 else let (a, b) = (head t, last t) in
263 else let (a, b) = (head t, last t) in
265− if ((length b) < 2) || ((head b, last b) /= ('"', '"'))
264+ if (length b < 2) || ((head b, last b) /= ('"', '"'))
266 then Nothing
265 then Nothing
267 else Just (a, stripFirstAndLast b)
266 else Just (a, stripFirstAndLast b)
268
267
@@ -317,12 +316,12 @@ mixedList' prevInd = do
317 if lowInd >= curInd
316 if lowInd >= curInd
318 then do
317 then do
319 (sameIndList, endInd) <- (mixedList' lowInd)
318 (sameIndList, endInd) <- (mixedList' lowInd)
320− let curList = (combineList curLine subList) ++ sameIndList
319+ let curList = combineList curLine subList ++ sameIndList
321 if curInd > prevInd
320 if curInd > prevInd
322 then return ([listBuilder curList], endInd)
321 then return ([listBuilder curList], endInd)
323 else return (curList, endInd)
322 else return (curList, endInd)
324 else do
323 else do
325− let (curList, endInd) = ((combineList curLine subList),
324+ let (curList, endInd) = (combineList curLine subList,
326 lowInd)
325 lowInd)
327 if curInd > prevInd
326 if curInd > prevInd
328 then return ([listBuilder curList], endInd)
327 then return ([listBuilder curList], endInd)
@@ -335,7 +334,7 @@ plainInlineML' w = do
335 return $ B.plain $ trimInlines $ mconcat $ w:xs
334 return $ B.plain $ trimInlines $ mconcat $ w:xs
336
335
337plainInlineML :: PandocMonad m => VwParser m Blocks
336plainInlineML :: PandocMonad m => VwParser m Blocks
338−plainInlineML = (notFollowedBy listStart) >> spaceChar >> plainInlineML' mempty
337+plainInlineML = notFollowedBy listStart >> spaceChar >> plainInlineML' mempty
339
338
340
339
341listItemContent :: PandocMonad m => VwParser m Blocks
340listItemContent :: PandocMonad m => VwParser m Blocks
@@ -372,9 +371,9 @@ makeListMarkerSpan x =
372
371
373combineList :: Blocks -> [Blocks] -> [Blocks]
372combineList :: Blocks -> [Blocks] -> [Blocks]
374combineList x [y] = case toList y of
373combineList x [y] = case toList y of
375− [BulletList z] -> [fromList $ (toList x)
374+ [BulletList z] -> [fromList $ toList x
376 ++ [BulletList z]]
375 ++ [BulletList z]]
377− [OrderedList attr z] -> [fromList $ (toList x)
376+ [OrderedList attr z] -> [fromList $ toList x
378 ++ [OrderedList attr z]]
377 ++ [OrderedList attr z]]
379 _ -> x:[y]
378 _ -> x:[y]
380combineList x xs = x:xs
379combineList x xs = x:xs
@@ -391,7 +390,7 @@ bulletListMarkers = "ul" <$ (char '*' <|> char '-')
391
390
392orderedListMarkers :: PandocMonad m => VwParser m String
391orderedListMarkers :: PandocMonad m => VwParser m String
393orderedListMarkers =
392orderedListMarkers =
394− ("ol" <$ (choice $ (orderedListMarker Decimal Period):(($OneParen)
393+ ("ol" <$choice ((orderedListMarker Decimal Period):(($OneParen)
395 <$> orderedListMarker
394 <$> orderedListMarker
396 <$> [Decimal, LowerRoman, UpperRoman, LowerAlpha, UpperAlpha])))
395 <$> [Decimal, LowerRoman, UpperRoman, LowerAlpha, UpperAlpha])))
397 <|> ("ol" <$ char '#')
396 <|> ("ol" <$ char '#')
@@ -418,11 +417,11 @@ table1 = try $ do
418table2 :: PandocMonad m => VwParser m ([Blocks], [[Blocks]])
417table2 :: PandocMonad m => VwParser m ([Blocks], [[Blocks]])
419table2 = try $ do
418table2 = try $ do
420 trs <- many1 tableRow
419 trs <- many1 tableRow
421− return (take (length $ head trs) $ repeat mempty, trs)
420+ return (replicate (length $ head trs) mempty, trs)
422
421
423tableHeaderSeparator :: PandocMonad m => VwParser m ()
422tableHeaderSeparator :: PandocMonad m => VwParser m ()
424tableHeaderSeparator = try $ do
423tableHeaderSeparator = try $ do
425− many spaceChar >> char '|' >> many1 ((many1 $ char '-') >> char '|')
424+ many spaceChar >> char '|' >> many1 (many1 (char '-') >> char '|')
426 >> many spaceChar >> newline
425 >> many spaceChar >> newline
427 return ()
426 return ()
428
427
@@ -438,16 +437,16 @@ tableRow = try $ do
438
437
439tableCell :: PandocMonad m => VwParser m Blocks
438tableCell :: PandocMonad m => VwParser m Blocks
440tableCell = try $
439tableCell = try $
441− B.plain <$> trimInlines . mconcat <$> (manyTill inline' (char '|'))
440+ B.plain . trimInlines . mconcat <$> (manyTill inline' (char '|'))
442
441
443placeholder :: PandocMonad m => VwParser m ()
442placeholder :: PandocMonad m => VwParser m ()
444placeholder = try $
443placeholder = try $
445− (choice (ph <$> ["title", "date"])) <|> noHtmlPh <|> templatePh
444+ choice (ph <$> ["title", "date"]) <|> noHtmlPh <|> templatePh
446
445
447ph :: PandocMonad m => String -> VwParser m ()
446ph :: PandocMonad m => String -> VwParser m ()
448ph s = try $ do
447ph s = try $ do
449− many spaceChar >> (string $ '%':s) >> spaceChar
448+ many spaceChar >>string ('%':s) >> spaceChar
450− contents <- (trimInlines . mconcat <$> (manyTill inline (lookAhead newline)))
449+ contents <- trimInlines . mconcat <$> (manyTill inline (lookAhead newline))
451 --use lookAhead because of placeholder in the whitespace parser
450 --use lookAhead because of placeholder in the whitespace parser
452 let meta' = return $ B.setMeta s contents nullMeta :: F Meta
451 let meta' = return $ B.setMeta s contents nullMeta :: F Meta
453 updateState $ \st -> st { stateMeta' = stateMeta' st <> meta' }
452 updateState $ \st -> st { stateMeta' = stateMeta' st <> meta' }
@@ -455,17 +454,17 @@ ph s = try $ do
455noHtmlPh :: PandocMonad m => VwParser m ()
454noHtmlPh :: PandocMonad m => VwParser m ()
456noHtmlPh = try $
455noHtmlPh = try $
457 () <$ (many spaceChar >> string "%nohtml" >> many spaceChar
456 () <$ (many spaceChar >> string "%nohtml" >> many spaceChar
458− >> (lookAhead newline))
457+ >> lookAhead newline)
459
458
460templatePh :: PandocMonad m => VwParser m ()
459templatePh :: PandocMonad m => VwParser m ()
461templatePh = try $
460templatePh = try $
462− () <$ (many spaceChar >> string "%template" >> (many $ noneOf "\n")
461+ () <$ (many spaceChar >> string "%template" >>many (noneOf "\n")
463− >> (lookAhead newline))
462+ >> lookAhead newline)
464
463
465-- inline parser
464-- inline parser
466
465
467inline :: PandocMonad m => VwParser m Inlines
466inline :: PandocMonad m => VwParser m Inlines
468−inline = choice $ (whitespace endlineP):inlineList
467+inline = choice $ whitespace endlineP:inlineList
469
468
470inlineList :: PandocMonad m => [VwParser m Inlines]
469inlineList :: PandocMonad m => [VwParser m Inlines]
471inlineList = [ bareURL
470inlineList = [ bareURL
@@ -490,18 +489,18 @@ inline' = choice $ whitespace':inlineList
490
489
491-- inline parser for blockquotes
490-- inline parser for blockquotes
492inlineBQ :: PandocMonad m => VwParser m Inlines
491inlineBQ :: PandocMonad m => VwParser m Inlines
493−inlineBQ = choice $ (whitespace endlineBQ):inlineList
492+inlineBQ = choice $ whitespace endlineBQ:inlineList
494
493
495-- inline parser for mixedlists
494-- inline parser for mixedlists
496inlineML :: PandocMonad m => VwParser m Inlines
495inlineML :: PandocMonad m => VwParser m Inlines
497−inlineML = choice $ (whitespace endlineML):inlineList
496+inlineML = choice $ whitespace endlineML:inlineList
498
497
499str :: PandocMonad m => VwParser m Inlines
498str :: PandocMonad m => VwParser m Inlines
500−str = B.str <$> (many1 $ noneOf $ spaceChars ++ specialChars)
499+str = B.str <$>many1 (noneOf $ spaceChars ++ specialChars)
501
500
502whitespace :: PandocMonad m => VwParser m () -> VwParser m Inlines
501whitespace :: PandocMonad m => VwParser m () -> VwParser m Inlines
503whitespace endline = B.space <$ (skipMany1 spaceChar <|>
502whitespace endline = B.space <$ (skipMany1 spaceChar <|>
504− (try (newline >> (comment <|> placeholder))))
503+ try (newline >> (comment <|> placeholder)))
505 <|> B.softbreak <$ endline
504 <|> B.softbreak <$ endline
506
505
507whitespace' :: PandocMonad m => VwParser m Inlines
506whitespace' :: PandocMonad m => VwParser m Inlines
@@ -518,31 +517,31 @@ bareURL = try $ do
518strong :: PandocMonad m => VwParser m Inlines
517strong :: PandocMonad m => VwParser m Inlines
519strong = try $ do
518strong = try $ do
520 s <- lookAhead $ between (char '*') (char '*') (many1 $ noneOf "*")
519 s <- lookAhead $ between (char '*') (char '*') (many1 $ noneOf "*")
521− guard $ (not $ (head s) `elem` spaceChars)
520+ guard $ not ((head s) `elem` spaceChars)
522− && (not $ (last s) `elem` spaceChars)
521+ &&not ((last s) `elem` spaceChars)
523 char '*'
522 char '*'
524− contents <- mconcat <$> (manyTill inline' $ char '*'
523+ contents <- mconcat <$>manyTill inline' (char '*'
525 >> notFollowedBy alphaNum)
524 >> notFollowedBy alphaNum)
526− return $ (B.spanWith ((makeId contents), [], []) mempty)
525+ return $ B.spanWith ((makeId contents), [], []) mempty
527− <> (B.strong contents)
526+ <> B.strong contents
528
527
529makeId :: Inlines -> String
528makeId :: Inlines -> String
530−makeId i = concat (stringify <$> (toList i))
529+makeId i = concat (stringify <$> toList i)
531
530
532emph :: PandocMonad m => VwParser m Inlines
531emph :: PandocMonad m => VwParser m Inlines
533emph = try $ do
532emph = try $ do
534 s <- lookAhead $ between (char '_') (char '_') (many1 $ noneOf "_")
533 s <- lookAhead $ between (char '_') (char '_') (many1 $ noneOf "_")
535− guard $ (not $ (head s) `elem` spaceChars)
534+ guard $ not ((head s) `elem` spaceChars)
536− && (not $ (last s) `elem` spaceChars)
535+ &&not ((last s) `elem` spaceChars)
537 char '_'
536 char '_'
538− contents <- mconcat <$> (manyTill inline' $ char '_'
537+ contents <- mconcat <$>manyTill inline' (char '_'
539 >> notFollowedBy alphaNum)
538 >> notFollowedBy alphaNum)
540 return $ B.emph contents
539 return $ B.emph contents
541
540
542strikeout :: PandocMonad m => VwParser m Inlines
541strikeout :: PandocMonad m => VwParser m Inlines
543strikeout = try $ do
542strikeout = try $ do
544 string "~~"
543 string "~~"
545− contents <- mconcat <$> (many1Till inline' $ string $ "~~")
544+ contents <- mconcat <$>many1Till inline' (string $ "~~")
546 return $ B.strikeout contents
545 return $ B.strikeout contents
547
546
548code :: PandocMonad m => VwParser m Inlines
547code :: PandocMonad m => VwParser m Inlines
@@ -553,11 +552,11 @@ code = try $ do
553
552
554superscript :: PandocMonad m => VwParser m Inlines
553superscript :: PandocMonad m => VwParser m Inlines
555superscript = try $
554superscript = try $
556− B.superscript <$> mconcat <$> (char '^' >> many1Till inline' (char '^'))
555+ B.superscript . mconcat <$> (char '^' >> many1Till inline' (char '^'))
557
556
558subscript :: PandocMonad m => VwParser m Inlines
557subscript :: PandocMonad m => VwParser m Inlines
559subscript = try $
558subscript = try $
560− B.subscript <$> mconcat <$> (string ",,"
559+ B.subscript . mconcat <$> (string ",,"
561 >> many1Till inline' (try $ string ",,"))
560 >> many1Till inline' (try $ string ",,"))
562
561
563link :: PandocMonad m => VwParser m Inlines
562link :: PandocMonad m => VwParser m Inlines
@@ -587,29 +586,29 @@ images k
587 return $ B.image (procImgurl imgurl) "" (B.str "")
586 return $ B.image (procImgurl imgurl) "" (B.str "")
588 | k == 1 = do
587 | k == 1 = do
589 imgurl <- manyTill anyChar (char '|')
588 imgurl <- manyTill anyChar (char '|')
590− alt <- mconcat <$> (manyTill inline $ (try $ string "}}"))
589+ alt <- mconcat <$> (manyTill inline (try $ string "}}"))
591 return $ B.image (procImgurl imgurl) "" alt
590 return $ B.image (procImgurl imgurl) "" alt
592 | k == 2 = do
591 | k == 2 = do
593 imgurl <- manyTill anyChar (char '|')
592 imgurl <- manyTill anyChar (char '|')
594− alt <- mconcat <$> (manyTill inline $ char '|')
593+ alt <- mconcat <$>manyTill inline (char '|')
595 attrText <- manyTill anyChar (try $ string "}}")
594 attrText <- manyTill anyChar (try $ string "}}")
596 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
595 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
597 | otherwise = do
596 | otherwise = do
598 imgurl <- manyTill anyChar (char '|')
597 imgurl <- manyTill anyChar (char '|')
599− alt <- mconcat <$> (manyTill inline $ char '|')
598+ alt <- mconcat <$>manyTill inline (char '|')
600 attrText <- manyTill anyChar (char '|')
599 attrText <- manyTill anyChar (char '|')
601 manyTill anyChar (try $ string "}}")
600 manyTill anyChar (try $ string "}}")
602 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
601 return $ B.imageWith (makeAttr attrText) (procImgurl imgurl) "" alt
603
602
604procLink' :: String -> String
603procLink' :: String -> String
605procLink' s
604procLink' s
606− | ((take 6 s) == "local:") = "file" ++ (drop 5 s)
605+ | (take 6 s) == "local:" = "file" ++ drop 5 s
607− | ((take 6 s) == "diary:") = "diary/" ++ (drop 6 s) ++ ".html"
606+ | (take 6 s) == "diary:" = "diary/" ++ drop 6 s ++ ".html"
608 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
607 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
609 "news:", "telnet:" ])
608 "news:", "telnet:" ])
610 = s
609 = s
611 | s == "" = ""
610 | s == "" = ""
612− | (last s) == '/' = s
611+ | last s == '/' = s
613 | otherwise = s ++ ".html"
612 | otherwise = s ++ ".html"
614
613
615procLink :: String -> String
614procLink :: String -> String
@@ -617,7 +616,7 @@ procLink s = procLink' x ++ y
617 where (x, y) = break (=='#') s
616 where (x, y) = break (=='#') s
618
617
619procImgurl :: String -> String
618procImgurl :: String -> String
620−procImgurl s = if ((take 6 s) == "local:") then "file" ++ (drop 5 s) else s
619+procImgurl s = if (take 6 s) == "local:" then "file" ++ drop 5 s else s
621
620
622inlineMath :: PandocMonad m => VwParser m Inlines
621inlineMath :: PandocMonad m => VwParser m Inlines
623inlineMath = try $ do
622inlineMath = try $ do
@@ -628,10 +627,10 @@ inlineMath = try $ do
628tag :: PandocMonad m => VwParser m Inlines
627tag :: PandocMonad m => VwParser m Inlines
629tag = try $ do
628tag = try $ do
630 char ':'
629 char ':'
631− s <- manyTill (noneOf spaceChars) (try (char ':' >> (lookAhead space)))
630+ s <- manyTill (noneOf spaceChars) (try (char ':' >> lookAhead space))
632 guard $ not $ "::" `isInfixOf` (":" ++ s ++ ":")
631 guard $ not $ "::" `isInfixOf` (":" ++ s ++ ":")
633 let ss = splitBy (==':') s
632 let ss = splitBy (==':') s
634− return $ mconcat $ (makeTagSpan' $ head ss):(makeTagSpan <$> (tail ss))
633+ return $ mconcat $ makeTagSpan' (head ss):(makeTagSpan <$> tail ss)
635
634
636todoMark :: PandocMonad m => VwParser m Inlines
635todoMark :: PandocMonad m => VwParser m Inlines
637todoMark = try $ do
636todoMark = try $ do
@@ -661,18 +660,18 @@ nFBTTBSB =
661 notFollowedBy hasDefMarker
660 notFollowedBy hasDefMarker
662
661
663hasDefMarker :: PandocMonad m => VwParser m ()
662hasDefMarker :: PandocMonad m => VwParser m ()
664−hasDefMarker = () <$ (manyTill (noneOf "\n") (string "::" >> oneOf spaceChars))
663+hasDefMarker = () <$ manyTill (noneOf "\n") (string "::" >> oneOf spaceChars)
665
664
666makeTagSpan' :: String -> Inlines
665makeTagSpan' :: String -> Inlines
667makeTagSpan' s = B.spanWith ('-' : s, [], []) (B.str "") <>
666makeTagSpan' s = B.spanWith ('-' : s, [], []) (B.str "") <>
668 B.spanWith (s, ["tag"], []) (B.str s)
667 B.spanWith (s, ["tag"], []) (B.str s)
669
668
670makeTagSpan :: String -> Inlines
669makeTagSpan :: String -> Inlines
671−makeTagSpan s = (B.space) <> (makeTagSpan' s)
670+makeTagSpan s = B.space <> makeTagSpan' s
672
671
673mathTagParser :: PandocMonad m => VwParser m String
672mathTagParser :: PandocMonad m => VwParser m String
674mathTagParser = do
673mathTagParser = do
675− s <- try $ lookAhead (char '%' >> (manyTill (noneOf spaceChars)
674+ s <- try $ lookAhead (char '%' >> manyTill (noneOf spaceChars)
676− (try $ char '%' >> many (noneOf $ '%':spaceChars) >> space)))
675+ (try $ char '%' >> many (noneOf $ '%':spaceChars) >> space))
677 char '%' >> string s >> char '%'
676 char '%' >> string s >> char '%'
678 return $ mathTagLaTeX s
677 return $ mathTagLaTeX s
src/Text/Pandoc/SelfContained.hs+5−8
@@ -178,10 +178,10 @@ pCSSComment = P.try $ do
178 return B.empty
178 return B.empty
179
179
180pCSSOther :: PandocMonad m => ParsecT ByteString () m ByteString
180pCSSOther :: PandocMonad m => ParsecT ByteString () m ByteString
181−pCSSOther = do
181+pCSSOther =
182 (B.pack <$> P.many1 (P.noneOf "u/ \n\r\t")) <|>
182 (B.pack <$> P.many1 (P.noneOf "u/ \n\r\t")) <|>
183− (B.singleton <$> P.char 'u') <|>
183+ (B.singleton <$> P.char 'u') <|>
184− (B.singleton <$> P.char '/')
184+ (B.singleton <$> P.char '/')
185
185
186pCSSUrl :: PandocMonad m
186pCSSUrl :: PandocMonad m
187 => FilePath -> ParsecT ByteString () m ByteString
187 => FilePath -> ParsecT ByteString () m ByteString
@@ -218,9 +218,7 @@ handleCSSUrl :: PandocMonad m
218 => FilePath -> (String, ByteString)
218 => FilePath -> (String, ByteString)
219 -> ParsecT ByteString () m
219 -> ParsecT ByteString () m
220 (Either ByteString (MimeType, ByteString))
220 (Either ByteString (MimeType, ByteString))
221−handleCSSUrl d (url, fallback) = do
221+handleCSSUrl d (url, fallback) =
222− -- pipes are used in URLs provided by Google Code fonts
223− -- but parseURI doesn't like them, so we escape them:
224 case escapeURIString (/='|') (trim url) of
222 case escapeURIString (/='|') (trim url) of
225 '#':_ -> return $ Left fallback
223 '#':_ -> return $ Left fallback
226 'd':'a':'t':'a':':':_ -> return $ Left fallback
224 'd':'a':'t':'a':':':_ -> return $ Left fallback
@@ -251,8 +249,7 @@ getData mimetype src = do
251 let ext = map toLower $ takeExtension src
249 let ext = map toLower $ takeExtension src
252 (raw, respMime) <- fetchItem src
250 (raw, respMime) <- fetchItem src
253 let raw' = if ext == ".gz"
251 let raw' = if ext == ".gz"
254− then B.concat $ L.toChunks $ Gzip.decompress $ L.fromChunks
252+ then B.concat $ L.toChunks $ Gzip.decompress $ L.fromChunks [raw]
255− $ [raw]
256 else raw
253 else raw
257 mime <- case (mimetype, respMime) of
254 mime <- case (mimetype, respMime) of
258 ("",Nothing) -> throwError $ PandocSomeError
255 ("",Nothing) -> throwError $ PandocSomeError
src/Text/Pandoc/Shared.hs+21−22
@@ -2,7 +2,7 @@
2{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
5−{-# LANGUAGE PatternGuards #-}
5+
6{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE ViewPatterns #-}
7{-# LANGUAGE ViewPatterns #-}
8{-
8{-
@@ -144,11 +144,11 @@ splitBy _ [] = []
144splitBy isSep lst =
144splitBy isSep lst =
145 let (first, rest) = break isSep lst
145 let (first, rest) = break isSep lst
146 rest' = dropWhile isSep rest
146 rest' = dropWhile isSep rest
147− in first:(splitBy isSep rest')
147+ in first:splitBy isSep rest'
148
148
149splitByIndices :: [Int] -> [a] -> [[a]]
149splitByIndices :: [Int] -> [a] -> [[a]]
150splitByIndices [] lst = [lst]
150splitByIndices [] lst = [lst]
151−splitByIndices (x:xs) lst = first:(splitByIndices (map (\y -> y - x) xs) rest)
151+splitByIndices (x:xs) lst = first:splitByIndices (map (\y -> y - x) xs) rest
152 where (first, rest) = splitAt x lst
152 where (first, rest) = splitAt x lst
153
153
154-- | Split string into chunks divided at specified indices.
154-- | Split string into chunks divided at specified indices.
@@ -156,7 +156,7 @@ splitStringByIndices :: [Int] -> [Char] -> [[Char]]
156splitStringByIndices [] lst = [lst]
156splitStringByIndices [] lst = [lst]
157splitStringByIndices (x:xs) lst =
157splitStringByIndices (x:xs) lst =
158 let (first, rest) = splitAt' x lst in
158 let (first, rest) = splitAt' x lst in
159− first : (splitStringByIndices (map (\y -> y - x) xs) rest)
159+ first : splitStringByIndices (map (\y -> y - x) xs) rest
160
160
161splitAt' :: Int -> [Char] -> ([Char],[Char])
161splitAt' :: Int -> [Char] -> ([Char],[Char])
162splitAt' _ [] = ([],[])
162splitAt' _ [] = ([],[])
@@ -195,7 +195,7 @@ backslashEscapes = map (\ch -> (ch, ['\\',ch]))
195escapeStringUsing :: [(Char, String)] -> String -> String
195escapeStringUsing :: [(Char, String)] -> String -> String
196escapeStringUsing _ [] = ""
196escapeStringUsing _ [] = ""
197escapeStringUsing escapeTable (x:xs) =
197escapeStringUsing escapeTable (x:xs) =
198− case (lookup x escapeTable) of
198+ case lookup x escapeTable of
199 Just str -> str ++ rest
199 Just str -> str ++ rest
200 Nothing -> x:rest
200 Nothing -> x:rest
201 where rest = escapeStringUsing escapeTable xs
201 where rest = escapeStringUsing escapeTable xs
@@ -219,14 +219,14 @@ trimr = reverse . triml . reverse
219-- | Strip leading and trailing characters from string
219-- | Strip leading and trailing characters from string
220stripFirstAndLast :: String -> String
220stripFirstAndLast :: String -> String
221stripFirstAndLast str =
221stripFirstAndLast str =
222− drop 1 $ take ((length str) - 1) str
222+ drop 1 $ take (length str - 1) str
223
223
224-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
224-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
225camelCaseToHyphenated :: String -> String
225camelCaseToHyphenated :: String -> String
226camelCaseToHyphenated [] = ""
226camelCaseToHyphenated [] = ""
227camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
227camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
228− a:'-':(toLower b):(camelCaseToHyphenated rest)
228+ a:'-':toLower b:camelCaseToHyphenated rest
229−camelCaseToHyphenated (a:rest) = (toLower a):(camelCaseToHyphenated rest)
229+camelCaseToHyphenated (a:rest) = toLower a:camelCaseToHyphenated rest
230
230
231-- | Convert number < 4000 to uppercase roman numeral.
231-- | Convert number < 4000 to uppercase roman numeral.
232toRomanNumeral :: Int -> String
232toRomanNumeral :: Int -> String
@@ -477,7 +477,7 @@ hierarchicalize blocks = S.evalState (hierarchicalizeWithIds blocks) []
477
477
478hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
478hierarchicalizeWithIds :: [Block] -> S.State [Int] [Element]
479hierarchicalizeWithIds [] = return []
479hierarchicalizeWithIds [] = return []
480−hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do
480+hierarchicalizeWithIds (Header level attr@(_,classes,_) title':xs) = do
481 lastnum <- S.get
481 lastnum <- S.get
482 let lastnum' = take level lastnum
482 let lastnum' = take level lastnum
483 let newnum = case length lastnum' of
483 let newnum = case length lastnum' of
@@ -490,13 +490,13 @@ hierarchicalizeWithIds ((Header level attr@(_,classes,_) title'):xs) = do
490 sectionContents' <- hierarchicalizeWithIds sectionContents
490 sectionContents' <- hierarchicalizeWithIds sectionContents
491 rest' <- hierarchicalizeWithIds rest
491 rest' <- hierarchicalizeWithIds rest
492 return $ Sec level newnum attr title' sectionContents' : rest'
492 return $ Sec level newnum attr title' sectionContents' : rest'
493−hierarchicalizeWithIds ((Div ("",["references"],[])
493+hierarchicalizeWithIds (Div ("",["references"],[])
494− (Header level (ident,classes,kvs) title' : xs)):ys) =
494+ (Header level (ident,classes,kvs) title' : xs):ys) =
495− hierarchicalizeWithIds ((Header level (ident,("references":classes),kvs)
495+ hierarchicalizeWithIds (Header level (ident,("references":classes),kvs)
496− title') : (xs ++ ys))
496+ title' : (xs ++ ys))
497hierarchicalizeWithIds (x:rest) = do
497hierarchicalizeWithIds (x:rest) = do
498 rest' <- hierarchicalizeWithIds rest
498 rest' <- hierarchicalizeWithIds rest
499− return $ (Blk x) : rest'
499+ return $ Blk x : rest'
500
500
501headerLtEq :: Int -> Block -> Bool
501headerLtEq :: Int -> Block -> Bool
502headerLtEq level (Header l _ _) = l <= level
502headerLtEq level (Header l _ _) = l <= level
@@ -519,7 +519,7 @@ uniqueIdent title' usedIdents
519
519
520-- | True if block is a Header block.
520-- | True if block is a Header block.
521isHeaderBlock :: Block -> Bool
521isHeaderBlock :: Block -> Bool
522−isHeaderBlock (Header _ _ _) = True
522+isHeaderBlock (Header{}) = True
523isHeaderBlock _ = False
523isHeaderBlock _ = False
524
524
525-- | Shift header levels up or down.
525-- | Shift header levels up or down.
@@ -555,15 +555,14 @@ makeMeta :: [Inline] -> [[Inline]] -> [Inline] -> Meta
555makeMeta title authors date =
555makeMeta title authors date =
556 addMetaField "title" (B.fromList title)
556 addMetaField "title" (B.fromList title)
557 $ addMetaField "author" (map B.fromList authors)
557 $ addMetaField "author" (map B.fromList authors)
558− $ addMetaField "date" (B.fromList date)
558+ $ addMetaField "date" (B.fromList date) nullMeta
559− $ nullMeta
560
559
561-- | Remove soft breaks between East Asian characters.
560-- | Remove soft breaks between East Asian characters.
562eastAsianLineBreakFilter :: Pandoc -> Pandoc
561eastAsianLineBreakFilter :: Pandoc -> Pandoc
563eastAsianLineBreakFilter = bottomUp go
562eastAsianLineBreakFilter = bottomUp go
564 where go (x:SoftBreak:y:zs) =
563 where go (x:SoftBreak:y:zs) =
565 case (stringify x, stringify y) of
564 case (stringify x, stringify y) of
566− (xs@(_:_), (c:_))
565+ (xs@(_:_), c:_)
567 | charWidth (last xs) == 2 && charWidth c == 2 -> x:y:zs
566 | charWidth (last xs) == 2 && charWidth c == 2 -> x:y:zs
568 _ -> x:SoftBreak:y:zs
567 _ -> x:SoftBreak:y:zs
569 go xs = xs
568 go xs = xs
@@ -620,8 +619,8 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
620 where
619 where
621 go rs "." = rs
620 go rs "." = rs
622 go r@(p:rs) ".." = case p of
621 go r@(p:rs) ".." = case p of
623− ".." -> ("..":r)
622+ ".." -> "..":r
624− (checkPathSeperator -> Just True) -> ("..":r)
623+ (checkPathSeperator -> Just True) -> "..":r
625 _ -> rs
624 _ -> rs
626 go _ (checkPathSeperator -> Just True) = [[Posix.pathSeparator]]
625 go _ (checkPathSeperator -> Just True) = [[Posix.pathSeparator]]
627 go rs x = x:rs
626 go rs x = x:rs
@@ -725,9 +724,9 @@ blockToInlines (DefinitionList pairslst) =
725 where
724 where
726 f (ils, blkslst) = ils ++
725 f (ils, blkslst) = ils ++
727 [Str ":", Space] ++
726 [Str ":", Space] ++
728− (concatMap blocksToInlines blkslst)
727+ concatMap blocksToInlines blkslst
729blockToInlines (Header _ _ ils) = ils
728blockToInlines (Header _ _ ils) = ils
730−blockToInlines (HorizontalRule) = []
729+blockToInlines HorizontalRule = []
731blockToInlines (Table _ _ _ headers rows) =
730blockToInlines (Table _ _ _ headers rows) =
732 intercalate [LineBreak] $ map (concatMap blocksToInlines) tbl
731 intercalate [LineBreak] $ map (concatMap blocksToInlines) tbl
733 where
732 where
src/Text/Pandoc/Slides.hs+2−2
@@ -40,8 +40,8 @@ getSlideLevel = go 6
40 | otherwise = go least (x:xs)
40 | otherwise = go least (x:xs)
41 go least (_ : xs) = go least xs
41 go least (_ : xs) = go least xs
42 go least [] = least
42 go least [] = least
43− nonHOrHR (Header{}) = False
43+ nonHOrHR Header{} = False
44− nonHOrHR (HorizontalRule) = False
44+ nonHOrHR HorizontalRule = False
45 nonHOrHR _ = True
45 nonHOrHR _ = True
46
46
47-- | Prepare a block list to be passed to hierarchicalize.
47-- | Prepare a block list to be passed to hierarchicalize.
src/Text/Pandoc/Templates.hs+2−2
@@ -1,5 +1,5 @@
1{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE TypeSynonymInstances #-}
4{-# LANGUAGE TypeSynonymInstances #-}
5{-
5{-
@@ -77,7 +77,7 @@ getDefaultTemplate writer = do
77-- raises an error if compilation fails.
77-- raises an error if compilation fails.
78renderTemplate' :: (PandocMonad m, ToJSON a, TemplateTarget b)
78renderTemplate' :: (PandocMonad m, ToJSON a, TemplateTarget b)
79 => String -> a -> m b
79 => String -> a -> m b
80−renderTemplate' template context = do
80+renderTemplate' template context =
81 case applyTemplate (T.pack template) context of
81 case applyTemplate (T.pack template) context of
82 Left e -> throwError (PandocTemplateError e)
82 Left e -> throwError (PandocTemplateError e)
83 Right r -> return r
83 Right r -> return r
src/Text/Pandoc/UUID.hs−1
@@ -75,4 +75,3 @@ getUUID gen =
75
75
76getRandomUUID :: IO UUID
76getRandomUUID :: IO UUID
77getRandomUUID = getUUID <$> getStdGen
77getRandomUUID = getUUID <$> getStdGen
78−