@@ -31,7 +31,7 @@ Conversion of markdown-formatted plain text to 'Pandoc' document.
31module Text.Pandoc.Readers.Markdown ( readMarkdown,
31module Text.Pandoc.Readers.Markdown ( readMarkdown,
32 readMarkdownWithWarnings ) where
32 readMarkdownWithWarnings ) where
34−import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
34+import Data.List ( transpose, sortBy, intersperse, intercalate, elemIndex)
35import qualified Data.Map as M
35import qualified Data.Map as M
36import Data.Scientific (coefficient, base10Exponent)
36import Data.Scientific (coefficient, base10Exponent)
37import Data.Ord ( comparing )
37import Data.Ord ( comparing )
@@ -72,7 +72,7 @@ readMarkdown :: ReaderOptions -- ^ Reader options
72 -> String -- ^ String to parse (assuming @'\n'@ line endings)
72 -> String -- ^ String to parse (assuming @'\n'@ line endings)
74readMarkdown opts s =
74readMarkdown opts s =
75− (runMarkdown opts s parseMarkdown)
75+ runMarkdown opts s parseMarkdown
77-- | Read markdown from an input string and return a pair of a Pandoc document
77-- | Read markdown from an input string and return a pair of a Pandoc document
78-- and a list of warnings.
78-- and a list of warnings.
@@ -132,7 +132,7 @@ inList = do
132 guard (ctx == ListItemState)
132 guard (ctx == ListItemState)
134isNull :: Inlines -> Bool
134isNull :: Inlines -> Bool
135−isNull ils = B.isNull ils
135+isNull = B.isNull
137spnl :: Monad m => ParserT [Char] st m ()
137spnl :: Monad m => ParserT [Char] st m ()
138spnl = try $ do
138spnl = try $ do
@@ -236,7 +236,7 @@ pandocTitleBlock = try $ do
236 $ nullMeta
236 $ nullMeta
237 updateState $ \st -> st{ stateMeta = stateMeta st <> meta' }
237 updateState $ \st -> st{ stateMeta = stateMeta st <> meta' }
239−yamlMetaBlock :: MarkdownParser (Blocks)
239+yamlMetaBlock :: MarkdownParser Blocks
240yamlMetaBlock = try $ do
240yamlMetaBlock = try $ do
241 guardEnabled Ext_yaml_metadata_block
241 guardEnabled Ext_yaml_metadata_block
242 pos <- getPosition
242 pos <- getPosition
@@ -284,7 +284,7 @@ yamlMetaBlock = try $ do
285-- ignore fields ending with _
285-- ignore fields ending with _
286ignorable :: Text -> Bool
286ignorable :: Text -> Bool
287−ignorable t = (T.pack "_") `T.isSuffixOf` t
287+ignorable t = T.pack "_" `T.isSuffixOf` t
289toMetaValue :: ReaderOptions -> Text -> MetaValue
289toMetaValue :: ReaderOptions -> Text -> MetaValue
290toMetaValue opts x =
290toMetaValue opts x =
@@ -294,7 +294,7 @@ toMetaValue opts x =
294 | endsWithNewline x -> MetaBlocks [Para xs]
294 | endsWithNewline x -> MetaBlocks [Para xs]
295 | otherwise -> MetaInlines xs
295 | otherwise -> MetaInlines xs
296 Pandoc _ bs -> MetaBlocks bs
296 Pandoc _ bs -> MetaBlocks bs
297− where endsWithNewline t = (T.pack "\n") `T.isSuffixOf` t
297+ where endsWithNewline t = T.pack "\n" `T.isSuffixOf` t
299yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
299yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
300yamlToMeta opts (Yaml.String t) = toMetaValue opts t
300yamlToMeta opts (Yaml.String t) = toMetaValue opts t
@@ -347,7 +347,7 @@ parseMarkdown = do
347 let Pandoc _ bs = B.doc blocks
347 let Pandoc _ bs = B.doc blocks
348 return $ Pandoc meta bs
348 return $ Pandoc meta bs
350−referenceKey :: MarkdownParser (Blocks)
350+referenceKey :: MarkdownParser Blocks
351referenceKey = try $ do
351referenceKey = try $ do
352 pos <- getPosition
352 pos <- getPosition
353 skipNonindentSpaces
353 skipNonindentSpaces
@@ -394,7 +394,7 @@ quotedTitle c = try $ do
394-- | PHP Markdown Extra style abbreviation key. Currently
394-- | PHP Markdown Extra style abbreviation key. Currently
395-- we just skip them, since Pandoc doesn't have an element for
395-- we just skip them, since Pandoc doesn't have an element for
396-- an abbreviation.
396-- an abbreviation.
397−abbrevKey :: MarkdownParser (Blocks)
397+abbrevKey :: MarkdownParser Blocks
398abbrevKey = do
398abbrevKey = do
399 guardEnabled Ext_abbreviations
399 guardEnabled Ext_abbreviations
@@ -421,7 +421,7 @@ rawLines = do
421 rest <- many rawLine
421 rest <- many rawLine
422 return $ unlines (first:rest)
422 return $ unlines (first:rest)
424−noteBlock :: MarkdownParser (Blocks)
424+noteBlock :: MarkdownParser Blocks
425noteBlock = try $ do
425noteBlock = try $ do
426 pos <- getPosition
426 pos <- getPosition
427 skipNonindentSpaces
427 skipNonindentSpaces
@@ -454,10 +454,10 @@ inFootnote p = do
454-- parsing blocks
454-- parsing blocks
457−parseBlocks :: MarkdownParser (Blocks)
457+parseBlocks :: MarkdownParser Blocks
458parseBlocks = mconcat <$> manyTill block eof
458parseBlocks = mconcat <$> manyTill block eof
460−block :: MarkdownParser (Blocks)
460+block :: MarkdownParser Blocks
461block = do
461block = do
462 tr <- getOption readerTrace
462 tr <- getOption readerTrace
463 pos <- getPosition
463 pos <- getPosition
@@ -486,21 +486,21 @@ block = do
488 ] <?> "block"
488 ] <?> "block"
489− when tr $ do
489+ when tr $
490 trace (printf "line %d: %s" (sourceLine pos)
490 trace (printf "line %d: %s" (sourceLine pos)
491− (take 60 $ show $ B.toList $ res)) (return ())
491+ (take 60 . show . B.toList $ res)) (return ())
492 return res
492 return res
495-- header blocks
495-- header blocks
498−header :: MarkdownParser (Blocks)
498+header :: MarkdownParser Blocks
499header = setextHeader <|> atxHeader <?> "header"
499header = setextHeader <|> atxHeader <?> "header"
501atxHeader :: MarkdownParser Blocks
501atxHeader :: MarkdownParser Blocks
502atxHeader = try $ do
502atxHeader = try $ do
503− level <- many1 (char '#') >>= return . length
503+ level <- length <$> many1 (char '#')
504 notFollowedBy $ guardEnabled Ext_fancy_lists >>
504 notFollowedBy $ guardEnabled Ext_fancy_lists >>
505 (char '.' <|> char ')') -- this would be a list
505 (char '.' <|> char ')') -- this would be a list
506 skipSpaces
506 skipSpaces
@@ -544,7 +544,7 @@ setextHeader = try $ do
544 underlineChar <- oneOf setextHChars
544 underlineChar <- oneOf setextHChars
545 many (char underlineChar)
545 many (char underlineChar)
546 blanklines
546 blanklines
547− let level = (fromMaybe 0 $ findIndex (== underlineChar) setextHChars) + 1
547+ let level = (fromMaybe 0 $ elemIndex underlineChar setextHChars) + 1
548 attr' <- registerHeader attr text
548 attr' <- registerHeader attr text
549 return $ B.headerWith attr' level text
549 return $ B.headerWith attr' level text
@@ -567,7 +567,7 @@ hrule = try $ do
569indentedLine :: MarkdownParser String
569indentedLine :: MarkdownParser String
570−indentedLine = indentSpaces >> anyLine >>= return . (++ "\n")
570+indentedLine = indentSpaces >> ((++ "\n") <$> anyLine)
572blockDelimiter :: Monad m
572blockDelimiter :: Monad m
573 => (Char -> Bool)
573 => (Char -> Bool)
@@ -577,8 +577,7 @@ blockDelimiter f len = try $ do
577 c <- lookAhead (satisfy f)
577 c <- lookAhead (satisfy f)
578 case len of
578 case len of
579 Just l -> count l (char c) >> many (char c) >> return l
579 Just l -> count l (char c) >> many (char c) >> return l
580− Nothing -> count 3 (char c) >> many (char c) >>=
580+ Nothing -> count 3 (char c) >> ((+ 3) . length <$> many (char c))
581− return . (+ 3) . length
583attributes :: MarkdownParser Attr
582attributes :: MarkdownParser Attr
584attributes = try $ do
583attributes = try $ do
@@ -644,7 +643,7 @@ toLanguageId = map toLower . go
644 go "objective-c" = "objectivec"
643 go "objective-c" = "objectivec"
647−codeBlockIndented :: MarkdownParser (Blocks)
646+codeBlockIndented :: MarkdownParser Blocks
648codeBlockIndented = do
647codeBlockIndented = do
649 contents <- many1 (indentedLine <|>
648 contents <- many1 (indentedLine <|>
650 try (do b <- blanklines
649 try (do b <- blanklines
@@ -655,7 +654,7 @@ codeBlockIndented = do
655 return $ B.codeBlockWith ("", classes, []) $
654 return $ B.codeBlockWith ("", classes, []) $
656 stripTrailingNewlines $ concat contents
655 stripTrailingNewlines $ concat contents
658−lhsCodeBlock :: MarkdownParser (Blocks)
657+lhsCodeBlock :: MarkdownParser Blocks
659lhsCodeBlock = do
658lhsCodeBlock = do
660 guardEnabled Ext_literate_haskell
659 guardEnabled Ext_literate_haskell
661 (B.codeBlockWith ("",["sourceCode","literate","haskell"],[]) <$>
660 (B.codeBlockWith ("",["sourceCode","literate","haskell"],[]) <$>
@@ -717,11 +716,11 @@ emailBlockQuote = try $ do
717 optional blanklines
716 optional blanklines
718 return raw
717 return raw
720−blockQuote :: MarkdownParser (Blocks)
719+blockQuote :: MarkdownParser Blocks
721blockQuote = do
720blockQuote = do
722 raw <- emailBlockQuote
721 raw <- emailBlockQuote
723 -- parse the extracted block, which may contain various block elements:
722 -- parse the extracted block, which may contain various block elements:
724− contents <- parseFromString parseBlocks $ (intercalate "\n" raw) ++ "\n\n"
723+ contents <- parseFromString parseBlocks $ intercalate "\n" raw ++ "\n\n"
725 return $ B.blockQuote contents
724 return $ B.blockQuote contents
@@ -765,7 +764,7 @@ anyOrderedListStart = try $ do
765 return res
764 return res
767listStart :: MarkdownParser ()
766listStart :: MarkdownParser ()
768−listStart = bulletListStart <|> (anyOrderedListStart >> return ())
767+listStart = bulletListStart <|> void anyOrderedListStart
770listLine :: MarkdownParser String
769listLine :: MarkdownParser String
771listLine = try $ do
770listLine = try $ do
@@ -820,7 +819,7 @@ listContinuationLine = try $ do
820 return $ result ++ "\n"
819 return $ result ++ "\n"
822listItem :: MarkdownParser a
821listItem :: MarkdownParser a
823− -> MarkdownParser (Blocks)
822+ -> MarkdownParser Blocks
824listItem start = try $ do
823listItem start = try $ do
825 first <- rawListItem start
824 first <- rawListItem start
826 continuations <- many listContinuation
825 continuations <- many listContinuation
@@ -857,7 +856,7 @@ orderedList = try $ do
857 start' <- option 1 $ guardEnabled Ext_startnum >> return start
856 start' <- option 1 $ guardEnabled Ext_startnum >> return start
858 return $ B.orderedListWith (start', style, delim) (compactify' items)
857 return $ B.orderedListWith (start', style, delim) (compactify' items)
860−bulletList :: MarkdownParser (Blocks)
859+bulletList :: MarkdownParser Blocks
861bulletList = do
860bulletList = do
862 items <- many1 $ listItem bulletListStart
861 items <- many1 $ listItem bulletListStart
863 return $ B.bulletList (compactify' items)
862 return $ B.bulletList (compactify' items)
@@ -882,7 +881,7 @@ definitionListItem compact = try $ do
882 term <- parseFromString (trimInlines . mconcat <$> many inline) rawLine'
881 term <- parseFromString (trimInlines . mconcat <$> many inline) rawLine'
883 contents <- mapM (parseFromString parseBlocks) raw
882 contents <- mapM (parseFromString parseBlocks) raw
884 optional blanklines
883 optional blanklines
885− return $ (term, contents)
884+ return (term, contents)
887defRawBlock :: Bool -> MarkdownParser String
886defRawBlock :: Bool -> MarkdownParser String
888defRawBlock compact = try $ do
887defRawBlock compact = try $ do
@@ -905,18 +904,18 @@ defRawBlock compact = try $ do
905 return $ trimr (firstline ++ "\n" ++ unlines rawlines ++ cont) ++
904 return $ trimr (firstline ++ "\n" ++ unlines rawlines ++ cont) ++
906 if hasBlank || not (null cont) then "\n\n" else ""
905 if hasBlank || not (null cont) then "\n\n" else ""
908−definitionList :: MarkdownParser (Blocks)
907+definitionList :: MarkdownParser Blocks
909definitionList = try $ do
908definitionList = try $ do
910 lookAhead (anyLine >> optional blankline >> defListMarker)
909 lookAhead (anyLine >> optional blankline >> defListMarker)
911 compactDefinitionList <|> normalDefinitionList
910 compactDefinitionList <|> normalDefinitionList
913−compactDefinitionList :: MarkdownParser (Blocks)
912+compactDefinitionList :: MarkdownParser Blocks
914compactDefinitionList = do
913compactDefinitionList = do
915 guardEnabled Ext_compact_definition_lists
914 guardEnabled Ext_compact_definition_lists
916 items <- many1 $ definitionListItem True
915 items <- many1 $ definitionListItem True
917 return $ B.definitionList (compactify'DL items)
916 return $ B.definitionList (compactify'DL items)
919−normalDefinitionList :: MarkdownParser (Blocks)
918+normalDefinitionList :: MarkdownParser Blocks
920normalDefinitionList = do
919normalDefinitionList = do
921 guardEnabled Ext_definition_lists
920 guardEnabled Ext_definition_lists
922 items <- many1 $ definitionListItem False
921 items <- many1 $ definitionListItem False
@@ -947,7 +946,7 @@ para = try $ do
947 Just "div" -> () <$
946 Just "div" -> () <$
948 lookAhead (htmlTag (~== TagClose "div"))
947 lookAhead (htmlTag (~== TagClose "div"))
949 _ -> mzero
948 _ -> mzero
950− return $ do
949+ return $
951 case B.toList result of
950 case B.toList result of
952 [Image alt (src,tit)]
951 [Image alt (src,tit)]
953 | Ext_implicit_figures `Set.member` exts ->
952 | Ext_implicit_figures `Set.member` exts ->
@@ -956,7 +955,7 @@ para = try $ do
956 $ Image alt (src,'f':'i':'g':':':tit)
955 $ Image alt (src,'f':'i':'g':':':tit)
957 _ -> B.para result
956 _ -> B.para result
959−plain :: MarkdownParser (Blocks)
958+plain :: MarkdownParser Blocks
960plain = B.plain . trimInlines . mconcat <$> many1 inline
959plain = B.plain . trimInlines . mconcat <$> many1 inline
@@ -968,13 +967,13 @@ htmlElement = rawVerbatimBlock
968 <|> strictHtmlBlock
967 <|> strictHtmlBlock
969 <|> liftM snd (htmlTag isBlockTag)
968 <|> liftM snd (htmlTag isBlockTag)
971−htmlBlock :: MarkdownParser (Blocks)
970+htmlBlock :: MarkdownParser Blocks
972htmlBlock = do
971htmlBlock = do
973 guardEnabled Ext_raw_html
972 guardEnabled Ext_raw_html
975 (TagOpen t attrs) <- lookAhead $ fst <$> htmlTag isBlockTag
974 (TagOpen t attrs) <- lookAhead $ fst <$> htmlTag isBlockTag
976 (guard (t `elem` ["pre","style","script"]) >>
975 (guard (t `elem` ["pre","style","script"]) >>
977− (B.rawBlock "html") <$> rawVerbatimBlock)
976+ B.rawBlock "html" <$> rawVerbatimBlock)
978 <|> (do guardEnabled Ext_markdown_attribute
977 <|> (do guardEnabled Ext_markdown_attribute
979 oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
978 oldMarkdownAttribute <- stateMarkdownAttribute <$> getState
980 markdownAttribute <-
979 markdownAttribute <-
@@ -993,7 +992,7 @@ htmlBlock = do
993 <|> (guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks))
992 <|> (guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks))
994 <|> htmlBlock'
993 <|> htmlBlock'
996−htmlBlock' :: MarkdownParser (Blocks)
995+htmlBlock' :: MarkdownParser Blocks
997htmlBlock' = try $ do
996htmlBlock' = try $ do
998 first <- htmlElement
997 first <- htmlElement
999 skipMany spaceChar
998 skipMany spaceChar
@@ -1005,23 +1004,23 @@ strictHtmlBlock = htmlInBalanced (not . isInlineTag)
1006rawVerbatimBlock :: MarkdownParser String
1005rawVerbatimBlock :: MarkdownParser String
1007rawVerbatimBlock = try $ do
1006rawVerbatimBlock = try $ do
1008− (TagOpen tag _, open) <- htmlTag (tagOpen (flip elem
1007+ (TagOpen tag _, open) <-
1009− ["pre", "style", "script"])
1008+ htmlTag (tagOpen (`elem` ["pre", "style", "script"])
1010− (const True))
1009+ (const True))
1011 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
1010 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
1012 return $ open ++ contents ++ renderTags' [TagClose tag]
1011 return $ open ++ contents ++ renderTags' [TagClose tag]
1014−rawTeXBlock :: MarkdownParser (Blocks)
1013+rawTeXBlock :: MarkdownParser Blocks
1015rawTeXBlock = do
1014rawTeXBlock = do
1016 guardEnabled Ext_raw_tex
1015 guardEnabled Ext_raw_tex
1017 result <- (B.rawBlock "latex" . concat <$>
1016 result <- (B.rawBlock "latex" . concat <$>
1018− (generalize rawLaTeXBlock) `sepEndBy1` blankline)
1017+ generalize rawLaTeXBlock `sepEndBy1` blankline)
1019 <|> (B.rawBlock "context" . concat <$>
1018 <|> (B.rawBlock "context" . concat <$>
1020 rawConTeXtEnvironment `sepEndBy1` blankline)
1019 rawConTeXtEnvironment `sepEndBy1` blankline)
1022 return result
1021 return result
1024−rawHtmlBlocks :: MarkdownParser (Blocks)
1023+rawHtmlBlocks :: MarkdownParser Blocks
1025rawHtmlBlocks = do
1024rawHtmlBlocks = do
1026 (TagOpen tagtype _, raw) <- htmlTag isBlockTag
1025 (TagOpen tagtype _, raw) <- htmlTag isBlockTag
1027 -- try to find closing tag
1026 -- try to find closing tag
@@ -1036,7 +1035,7 @@ rawHtmlBlocks = do
1036 (B.rawBlock "html" $ stripMarkdownAttribute raw) <>
1035 (B.rawBlock "html" $ stripMarkdownAttribute raw) <>
1037 contents <>
1036 contents <>
1038 (B.rawBlock "html" rawcloser)))
1037 (B.rawBlock "html" rawcloser)))
1039− <|> return ((B.rawBlock "html" raw) <> contents)
1038+ <|> return (B.rawBlock "html" raw <> contents)
1040 updateState $ \st -> st{ stateInHtmlBlock = oldInHtmlBlock }
1039 updateState $ \st -> st{ stateInHtmlBlock = oldInHtmlBlock }
1041 return result
1040 return result
@@ -1051,7 +1050,7 @@ stripMarkdownAttribute s = renderTags' $ map filterAttrib $ parseTags s
1051-- line block
1050-- line block
1054−lineBlock :: MarkdownParser (Blocks)
1053+lineBlock :: MarkdownParser Blocks
1055lineBlock = try $ do
1054lineBlock = try $ do
1056 guardEnabled Ext_line_blocks
1055 guardEnabled Ext_line_blocks
1057 lines' <- lineBlockLines >>=
1056 lines' <- lineBlockLines >>=
@@ -1069,7 +1068,7 @@ dashedLine :: Monad m => Char
1069dashedLine ch = do
1068dashedLine ch = do
1070 dashes <- many1 (char ch)
1069 dashes <- many1 (char ch)
1071 sp <- many spaceChar
1070 sp <- many spaceChar
1072− return $ (length dashes, length $ dashes ++ sp)
1071+ return (length dashes, length $ dashes ++ sp)
1074-- Parse a table header with dashed lines of '-' preceded by
1073-- Parse a table header with dashed lines of '-' preceded by
1075-- one (or zero) line of text.
1074-- one (or zero) line of text.
@@ -1094,8 +1093,7 @@ simpleTableHeader headless = try $ do
1094 then replicate (length dashes) ""
1093 then replicate (length dashes) ""
1095 else rawHeads
1094 else rawHeads
1096 heads <-
1095 heads <-
1097− mapM (parseFromString (mconcat <$> many plain))
1096+ mapM (parseFromString (mconcat <$> many plain) . trim) rawHeads'
1098− $ map trim rawHeads'
1099 return (heads, aligns, indices)
1097 return (heads, aligns, indices)
1101-- Returns an alignment type for a table, based on a list of strings
1099-- Returns an alignment type for a table, based on a list of strings
@@ -1247,9 +1245,7 @@ gridTableHeader headless = try $ do
1247 else many1
1245 else many1
1248 (notFollowedBy (gridTableSep '=') >> char '|' >>
1246 (notFollowedBy (gridTableSep '=') >> char '|' >>
1249 many1Till anyChar newline)
1247 many1Till anyChar newline)
1252− else gridTableSep '=' >> return ()
1248+ unless headless (void $ gridTableSep '=')
1253 let lines' = map snd dashes
1249 let lines' = map snd dashes
1254 let indices = scanl (+) 0 lines'
1250 let indices = scanl (+) 0 lines'
1255 let aligns = replicate (length lines') AlignDefault
1251 let aligns = replicate (length lines') AlignDefault
@@ -1274,7 +1270,7 @@ gridTableRow indices = do
1274 colLines <- many1 (gridTableRawLine indices)
1270 colLines <- many1 (gridTableRawLine indices)
1275 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
1271 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
1276 transpose colLines
1272 transpose colLines
1277− compactify' <$> (mapM (parseFromString parseBlocks) cols)
1273+ compactify' <$> mapM (parseFromString parseBlocks) cols
1279removeOneLeadingSpace :: [String] -> [String]
1275removeOneLeadingSpace :: [String] -> [String]
1280removeOneLeadingSpace xs =
1276removeOneLeadingSpace xs =
@@ -1305,7 +1301,7 @@ pipeTable = try $ do
1305 (heads,aligns) <- (,) <$> pipeTableRow <*> pipeBreak
1301 (heads,aligns) <- (,) <$> pipeTableRow <*> pipeBreak
1306 lines' <- sequence <$> many1 pipeTableRow
1302 lines' <- sequence <$> many1 pipeTableRow
1307 let widths = replicate (length aligns) 0.0
1303 let widths = replicate (length aligns) 0.0
1308− return $ (aligns, widths, heads, lines')
1304+ return (aligns, widths, heads, lines')
1310sepPipe :: MarkdownParser ()
1306sepPipe :: MarkdownParser ()
1311sepPipe = try $ do
1307sepPipe = try $ do
@@ -1330,7 +1326,7 @@ pipeTableRow = do
1330 map (\ils ->
1326 map (\ils ->
1331 case trimInlines ils of
1327 case trimInlines ils of
1332 ils' | B.isNull ils' -> mempty
1328 ils' | B.isNull ils' -> mempty
1333− | otherwise -> B.plain $ ils') cells
1329+ | otherwise -> B.plain ils') cells
1335pipeTableHeaderPart :: Monad m => ParserT [Char] st m Alignment
1331pipeTableHeaderPart :: Monad m => ParserT [Char] st m Alignment
1336pipeTableHeaderPart = try $ do
1332pipeTableHeaderPart = try $ do
@@ -1367,10 +1363,10 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
1367 lines' <- rowParser indices `sepEndBy1` lineParser
1363 lines' <- rowParser indices `sepEndBy1` lineParser
1368 footerParser
1364 footerParser
1369 numColumns <- getOption readerColumns
1365 numColumns <- getOption readerColumns
1370− let widths = if (indices == [])
1366+ let widths = case indices of
1371− then replicate (length aligns) 0.0
1367+ [] -> replicate (length aligns) 0.0
1372− else widthsFromIndices numColumns indices
1368+ _ -> widthsFromIndices numColumns indices
1373− return $ (aligns, widths, heads, lines')
1369+ return (aligns, widths, heads, lines')
1375table :: MarkdownParser Blocks
1371table :: MarkdownParser Blocks
1376table = try $ do
1372table = try $ do
@@ -1491,8 +1487,8 @@ enclosure c = do
1491 <|> guard (c == '*')
1487 <|> guard (c == '*')
1492 <|> (guard =<< notAfterString)
1488 <|> (guard =<< notAfterString)
1493 cs <- many1 (char c)
1489 cs <- many1 (char c)
1494− ((B.str cs) <>) <$> whitespace
1490+ (B.str cs <>) <$> whitespace
1496 case length cs of
1492 case length cs of
1497 3 -> three c
1493 3 -> three c
1498 2 -> two c mempty
1494 2 -> two c mempty
@@ -1516,7 +1512,7 @@ three c = do
1516 (ender c 3 >> return ((B.strong . B.emph) contents))
1512 (ender c 3 >> return ((B.strong . B.emph) contents))
1517 <|> (ender c 2 >> one c (B.strong contents))
1513 <|> (ender c 2 >> one c (B.strong contents))
1518 <|> (ender c 1 >> two c (B.emph contents))
1514 <|> (ender c 1 >> two c (B.emph contents))
1519− <|> return ((B.str [c,c,c]) <> contents)
1515+ <|> return (B.str [c,c,c] <> contents)
1521-- Parse inlines til you hit two c's, and emit strong.
1517-- Parse inlines til you hit two c's, and emit strong.
1522-- If you never do hit two cs, emit ** plus inlines parsed.
1518-- If you never do hit two cs, emit ** plus inlines parsed.
@@ -1524,7 +1520,7 @@ two :: Char -> Inlines -> MarkdownParser Inlines
1524two c prefix' = do
1520two c prefix' = do
1525 contents <- mconcat <$> many (try $ notFollowedBy (ender c 2) >> inline)
1521 contents <- mconcat <$> many (try $ notFollowedBy (ender c 2) >> inline)
1526 (ender c 2 >> return (B.strong (prefix' <> contents)))
1522 (ender c 2 >> return (B.strong (prefix' <> contents)))
1527− <|> return ((B.str [c,c]) <> (prefix' <> contents))
1523+ <|> return (B.str [c,c] <> (prefix' <> contents))
1529-- Parse inlines til you hit a c, and emit emph.
1525-- Parse inlines til you hit a c, and emit emph.
1530-- If you never hit a c, emit * plus inlines parsed.
1526-- If you never hit a c, emit * plus inlines parsed.
@@ -1535,7 +1531,7 @@ one c prefix' = do
1535 notFollowedBy (ender c 1) >>
1531 notFollowedBy (ender c 1) >>
1536 two c mempty) )
1532 two c mempty) )
1537 (ender c 1 >> return (B.emph (prefix' <> contents)))
1533 (ender c 1 >> return (B.emph (prefix' <> contents)))
1538− <|> return ((B.str [c]) <> (prefix' <> contents))
1534+ <|> return (B.str [c] <> (prefix' <> contents))
1540strongOrEmph :: MarkdownParser Inlines
1536strongOrEmph :: MarkdownParser Inlines
1541strongOrEmph = enclosure '*' <|> enclosure '_'
1537strongOrEmph = enclosure '*' <|> enclosure '_'
@@ -1589,8 +1585,8 @@ str = do
1589 xs -> choice (map (\x ->
1585 xs -> choice (map (\x ->
1590 try (string x >> oneOf " \n" >>
1586 try (string x >> oneOf " \n" >>
1591 lookAhead alphaNum >>
1587 lookAhead alphaNum >>
1592− return (B.str
1588+ return (B.str $
1593− $ result ++ spacesToNbr x ++ "\160"))) xs)
1589+ result ++ spacesToNbr x ++ "\160"))) xs)
1594 <|> (return $ B.str result)
1590 <|> (return $ B.str result)
1595 else return $ B.str result
1591 else return $ B.str result
@@ -1622,7 +1618,7 @@ endline = try $ do
1622 (eof >> return mempty)
1618 (eof >> return mempty)
1623 <|> (guardEnabled Ext_hard_line_breaks >> return B.linebreak)
1619 <|> (guardEnabled Ext_hard_line_breaks >> return B.linebreak)
1624 <|> (guardEnabled Ext_ignore_line_breaks >> return mempty)
1620 <|> (guardEnabled Ext_ignore_line_breaks >> return mempty)
1625− <|> (return B.space)
1621+ <|> return B.space
@@ -1819,7 +1815,7 @@ divHtml = try $ do
1819 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1815 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1820 return $ B.divWith (ident, classes, keyvals) contents
1816 return $ B.divWith (ident, classes, keyvals) contents
1821 else -- avoid backtracing
1817 else -- avoid backtracing
1822− return $ (B.rawBlock "html" (rawtag <> bls)) <> contents
1818+ return $ B.rawBlock "html" (rawtag <> bls) <> contents
1824rawHtmlInline :: MarkdownParser Inlines
1820rawHtmlInline :: MarkdownParser Inlines
1825rawHtmlInline = do
1821rawHtmlInline = do
@@ -1843,10 +1839,8 @@ rawHtmlInline = do
1843cite :: MarkdownParser Inlines
1839cite :: MarkdownParser Inlines
1844cite = do
1840cite = do
1845 guardEnabled Ext_citations
1841 guardEnabled Ext_citations
1846− citations <- textualCite
1847− <|> do (cs, raw) <- withRaw normalCite
1842+ textualCite <|> do (cs, raw) <- withRaw normalCite
1848− return $ (flip B.cite (B.text raw)) cs
1843+ return $ B.cite cs (B.text raw)
1851textualCite :: MarkdownParser Inlines
1845textualCite :: MarkdownParser Inlines
1852textualCite = try $ do
1846textualCite = try $ do
@@ -1865,7 +1859,7 @@ textualCite = try $ do
1866 Nothing ->
1860 Nothing ->
1867 (do (cs, raw) <- withRaw $ bareloc first
1861 (do (cs, raw) <- withRaw $ bareloc first
1868− return $ (flip B.cite (B.text $ '@':key ++ " " ++ raw)) cs)
1862+ return $ B.cite cs (B.text $ '@':key ++ " " ++ raw))
1869 <|> do st <- ask
1863 <|> do st <- ask
1870 return $ case M.lookup key (stateExamples st) of
1864 return $ case M.lookup key (stateExamples st) of
1871 Just n -> B.str (show n)
1865 Just n -> B.str (show n)
@@ -1906,20 +1900,20 @@ prefix = trimInlines . mconcat <$>
1906citeList :: MarkdownParser [Citation]
1900citeList :: MarkdownParser [Citation]
1907citeList = sepBy1 citation (try $ char ';' >> spnl)
1901citeList = sepBy1 citation (try $ char ';' >> spnl)
1909−citation :: MarkdownParser (Citation)
1903+citation :: MarkdownParser Citation
1910citation = try $ do
1904citation = try $ do
1911 pref <- prefix
1905 pref <- prefix
1912 (suppress_author, key) <- citeKey
1906 (suppress_author, key) <- citeKey
1913 suff <- suffix
1907 suff <- suffix
1914− return $ Citation{ citationId = key
1908+ return Citation{ citationId = key
1915− , citationPrefix = B.toList pref
1909+ , citationPrefix = B.toList pref
1916− , citationSuffix = B.toList suff
1910+ , citationSuffix = B.toList suff
1917− , citationMode = if suppress_author
1911+ , citationMode = if suppress_author
1918− then SuppressAuthor
1912+ then SuppressAuthor
1919− else NormalCitation
1913+ else NormalCitation
1920− , citationNoteNum = 0
1914+ , citationNoteNum = 0
1921− , citationHash = 0
1915+ , citationHash = 0
1924smart :: MarkdownParser Inlines
1918smart :: MarkdownParser Inlines
1925smart = do
1919smart = do
@@ -1941,6 +1935,6 @@ doubleQuoted :: MarkdownParser Inlines
1941doubleQuoted = try $ do
1935doubleQuoted = try $ do
1942 doubleQuoteStart
1936 doubleQuoteStart
1943 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
1937 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
1944− (withQuoteContext InDoubleQuote $ doubleQuoteEnd >> return
1938+ (withQuoteContext InDoubleQuote doubleQuoteEnd >> return
1945 (B.doubleQuoted . trimInlines $ contents))
1939 (B.doubleQuoted . trimInlines $ contents))
1946− <|> return ((B.str "\8220") <> contents)
1940+ <|> return (B.str "\8220" <> contents)