@@ -43,7 +43,7 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
4343import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
4444 isTextTag, isCommentTag )
4545import Text.Pandoc.XML ( fromEntities )
46−import Text.ParserCombinators.Parsec
46+import Text.Parsec
4747import Control.Monad (when, liftM, guard, mzero)
4848import Text.HTML.TagSoup
4949import Text.HTML.TagSoup.Match (tagOpen)
@@ -83,14 +83,14 @@ isBlank _ = False
8383-- auxiliary functions
8484--
8585
86−indentSpaces :: GenParser Char ParserState [Char]
86+indentSpaces :: Parsec [Char] ParserState [Char]
8787indentSpaces = try $ do
8888 state <- getState
8989 let tabStop = stateTabStop state
9090 count tabStop (char ' ') <|>
9191 string "\t" <?> "indentation"
9292
93−nonindentSpaces :: GenParser Char ParserState [Char]
93+nonindentSpaces :: Parsec [Char] ParserState [Char]
9494nonindentSpaces = do
9595 state <- getState
9696 let tabStop = stateTabStop state
@@ -99,30 +99,30 @@ nonindentSpaces = do
9999 then return sps
100100 else unexpected "indented line"
101101
102−skipNonindentSpaces :: GenParser Char ParserState ()
102+skipNonindentSpaces :: Parsec [Char] ParserState ()
103103skipNonindentSpaces = do
104104 state <- getState
105105 atMostSpaces (stateTabStop state - 1)
106106
107−atMostSpaces :: Int -> GenParser Char ParserState ()
107+atMostSpaces :: Int -> Parsec [Char] ParserState ()
108108atMostSpaces 0 = notFollowedBy (char ' ')
109109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
110110
111−litChar :: GenParser Char ParserState Char
111+litChar :: Parsec [Char] ParserState Char
112112litChar = escapedChar'
113113 <|> noneOf "\n"
114114 <|> (newline >> notFollowedBy blankline >> return ' ')
115115
116116-- | Fail unless we're at beginning of a line.
117−failUnlessBeginningOfLine :: GenParser tok st ()
117+failUnlessBeginningOfLine :: Parsec [tok] st ()
118118failUnlessBeginningOfLine = do
119119 pos <- getPosition
120120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
121121
122122-- | Parse a sequence of inline elements between square brackets,
123123-- including inlines between balanced pairs of square brackets.
124−inlinesInBalancedBrackets :: GenParser Char ParserState Inline
125− -> GenParser Char ParserState [Inline]
124+inlinesInBalancedBrackets :: Parsec [Char] ParserState Inline
125+ -> Parsec [Char] ParserState [Inline]
126126inlinesInBalancedBrackets parser = try $ do
127127 char '['
128128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
@@ -137,7 +137,7 @@ inlinesInBalancedBrackets parser = try $ do
137137-- document structure
138138--
139139
140−titleLine :: GenParser Char ParserState [Inline]
140+titleLine :: Parsec [Char] ParserState [Inline]
141141titleLine = try $ do
142142 char '%'
143143 skipSpaces
@@ -146,7 +146,7 @@ titleLine = try $ do
146146 newline
147147 return $ normalizeSpaces res
148148
149−authorsLine :: GenParser Char ParserState [[Inline]]
149+authorsLine :: Parsec [Char] ParserState [[Inline]]
150150authorsLine = try $ do
151151 char '%'
152152 skipSpaces
@@ -157,14 +157,14 @@ authorsLine = try $ do
157157 newline
158158 return $ filter (not . null) $ map normalizeSpaces authors
159159
160−dateLine :: GenParser Char ParserState [Inline]
160+dateLine :: Parsec [Char] ParserState [Inline]
161161dateLine = try $ do
162162 char '%'
163163 skipSpaces
164164 date <- manyTill inline newline
165165 return $ normalizeSpaces date
166166
167−titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline])
167+titleBlock :: Parsec [Char] ParserState ([Inline], [[Inline]], [Inline])
168168titleBlock = try $ do
169169 failIfStrict
170170 title <- option [] titleLine
@@ -173,7 +173,7 @@ titleBlock = try $ do
173173 optional blanklines
174174 return (title, author, date)
175175
176−parseMarkdown :: GenParser Char ParserState Pandoc
176+parseMarkdown :: Parsec [Char] ParserState Pandoc
177177parseMarkdown = do
178178 -- markdown allows raw HTML
179179 updateState (\state -> state { stateParseRaw = True })
@@ -182,7 +182,7 @@ parseMarkdown = do
182182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
183183 st <- getState
184184 let firstPassParser = referenceKey
185− <|> (if stateStrict st then pzero else noteBlock)
185+ <|> (if stateStrict st then mzero else noteBlock)
186186 <|> liftM snd (withRaw codeBlockDelimited)
187187 <|> lineClump
188188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
@@ -211,7 +211,7 @@ parseMarkdown = do
211211-- initial pass for references and notes
212212--
213213
214−referenceKey :: GenParser Char ParserState [Char]
214+referenceKey :: Parsec [Char] ParserState [Char]
215215referenceKey = try $ do
216216 startPos <- getPosition
217217 skipNonindentSpaces
@@ -238,7 +238,7 @@ referenceKey = try $ do
238238 -- return blanks so line count isn't affected
239239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
240240
241−referenceTitle :: GenParser Char ParserState String
241+referenceTitle :: Parsec [Char] ParserState String
242242referenceTitle = try $ do
243243 skipSpaces >> optional newline >> skipSpaces
244244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
@@ -247,23 +247,23 @@ referenceTitle = try $ do
247247 notFollowedBy (noneOf ")\n")))
248248 return $ fromEntities tit
249249
250−noteMarker :: GenParser Char ParserState [Char]
250+noteMarker :: Parsec [Char] ParserState [Char]
251251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
252252
253−rawLine :: GenParser Char ParserState [Char]
253+rawLine :: Parsec [Char] ParserState [Char]
254254rawLine = try $ do
255255 notFollowedBy blankline
256256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
257257 optional indentSpaces
258258 anyLine
259259
260−rawLines :: GenParser Char ParserState [Char]
260+rawLines :: Parsec [Char] ParserState [Char]
261261rawLines = do
262262 first <- anyLine
263263 rest <- many rawLine
264264 return $ unlines (first:rest)
265265
266−noteBlock :: GenParser Char ParserState [Char]
266+noteBlock :: Parsec [Char] ParserState [Char]
267267noteBlock = try $ do
268268 startPos <- getPosition
269269 skipNonindentSpaces
@@ -287,10 +287,10 @@ noteBlock = try $ do
287287-- parsing blocks
288288--
289289
290−parseBlocks :: GenParser Char ParserState [Block]
290+parseBlocks :: Parsec [Char] ParserState [Block]
291291parseBlocks = manyTill block eof
292292
293−block :: GenParser Char ParserState Block
293+block :: Parsec [Char] ParserState Block
294294block = do
295295 st <- getState
296296 choice (if stateStrict st
@@ -325,10 +325,10 @@ block = do
325325-- header blocks
326326--
327327
328−header :: GenParser Char ParserState Block
328+header :: Parsec [Char] ParserState Block
329329header = setextHeader <|> atxHeader <?> "header"
330330
331−atxHeader :: GenParser Char ParserState Block
331+atxHeader :: Parsec [Char] ParserState Block
332332atxHeader = try $ do
333333 level <- many1 (char '#') >>= return . length
334334 notFollowedBy (char '.' <|> char ')') -- this would be a list
@@ -336,10 +336,10 @@ atxHeader = try $ do
336336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
337337 return $ Header level text
338338
339−atxClosing :: GenParser Char st [Char]
339+atxClosing :: Parsec [Char] st [Char]
340340atxClosing = try $ skipMany (char '#') >> blanklines
341341
342−setextHeader :: GenParser Char ParserState Block
342+setextHeader :: Parsec [Char] ParserState Block
343343setextHeader = try $ do
344344 -- This lookahead prevents us from wasting time parsing Inlines
345345 -- unless necessary -- it gives a significant performance boost.
@@ -355,7 +355,7 @@ setextHeader = try $ do
355355-- hrule block
356356--
357357
358−hrule :: GenParser Char st Block
358+hrule :: Parsec [Char] st Block
359359hrule = try $ do
360360 skipSpaces
361361 start <- satisfy isHruleChar
@@ -369,12 +369,12 @@ hrule = try $ do
369369-- code blocks
370370--
371371
372−indentedLine :: GenParser Char ParserState [Char]
372+indentedLine :: Parsec [Char] ParserState [Char]
373373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
374374
375375blockDelimiter :: (Char -> Bool)
376376 -> Maybe Int
377− -> GenParser Char st (Int, (String, [String], [(String, String)]), Char)
377+ -> Parsec [Char] st (Int, (String, [String], [(String, String)]), Char)
378378blockDelimiter f len = try $ do
379379 c <- lookAhead (satisfy f)
380380 size <- case len of
@@ -388,7 +388,7 @@ blockDelimiter f len = try $ do
388388 blankline
389389 return (size, attr, c)
390390
391−attributes :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
391+attributes :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
392392attributes = try $ do
393393 char '{'
394394 spnl
@@ -400,28 +400,28 @@ attributes = try $ do
400400 | otherwise = firstNonNull xs
401401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
402402
403−attribute :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
403+attribute :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
404404attribute = identifierAttr <|> classAttr <|> keyValAttr
405405
406−identifier :: GenParser Char st [Char]
406+identifier :: Parsec [Char] st [Char]
407407identifier = do
408408 first <- letter
409409 rest <- many $ alphaNum <|> oneOf "-_:."
410410 return (first:rest)
411411
412−identifierAttr :: GenParser Char st ([Char], [a], [a1])
412+identifierAttr :: Parsec [Char] st ([Char], [a], [a1])
413413identifierAttr = try $ do
414414 char '#'
415415 result <- identifier
416416 return (result,[],[])
417417
418−classAttr :: GenParser Char st ([Char], [[Char]], [a])
418+classAttr :: Parsec [Char] st ([Char], [[Char]], [a])
419419classAttr = try $ do
420420 char '.'
421421 result <- identifier
422422 return ("",[result],[])
423423
424−keyValAttr :: GenParser Char st ([Char], [a], [([Char], [Char])])
424+keyValAttr :: Parsec [Char] st ([Char], [a], [([Char], [Char])])
425425keyValAttr = try $ do
426426 key <- identifier
427427 char '='
@@ -430,14 +430,14 @@ keyValAttr = try $ do
430430 <|> many nonspaceChar
431431 return ("",[],[(key,val)])
432432
433−codeBlockDelimited :: GenParser Char st Block
433+codeBlockDelimited :: Parsec [Char] st Block
434434codeBlockDelimited = try $ do
435435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
436436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
437437 blanklines
438438 return $ CodeBlock attr $ intercalate "\n" contents
439439
440−codeBlockIndented :: GenParser Char ParserState Block
440+codeBlockIndented :: Parsec [Char] ParserState Block
441441codeBlockIndented = do
442442 contents <- many1 (indentedLine <|>
443443 try (do b <- blanklines
@@ -448,7 +448,7 @@ codeBlockIndented = do
448448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
449449 stripTrailingNewlines $ concat contents
450450
451−lhsCodeBlock :: GenParser Char ParserState Block
451+lhsCodeBlock :: Parsec [Char] ParserState Block
452452lhsCodeBlock = do
453453 failUnlessLHS
454454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
@@ -456,7 +456,7 @@ lhsCodeBlock = do
456456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
457457 lhsCodeBlockInverseBird
458458
459−lhsCodeBlockLaTeX :: GenParser Char ParserState String
459+lhsCodeBlockLaTeX :: Parsec [Char] ParserState String
460460lhsCodeBlockLaTeX = try $ do
461461 string "\\begin{code}"
462462 manyTill spaceChar newline
@@ -464,13 +464,13 @@ lhsCodeBlockLaTeX = try $ do
464464 blanklines
465465 return $ stripTrailingNewlines contents
466466
467−lhsCodeBlockBird :: GenParser Char ParserState String
467+lhsCodeBlockBird :: Parsec [Char] ParserState String
468468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
469469
470−lhsCodeBlockInverseBird :: GenParser Char ParserState String
470+lhsCodeBlockInverseBird :: Parsec [Char] ParserState String
471471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
472472
473−lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
473+lhsCodeBlockBirdWith :: Char -> Parsec [Char] ParserState String
474474lhsCodeBlockBirdWith c = try $ do
475475 pos <- getPosition
476476 when (sourceColumn pos /= 1) $ fail "Not in first column"
@@ -482,7 +482,7 @@ lhsCodeBlockBirdWith c = try $ do
482482 blanklines
483483 return $ intercalate "\n" lns'
484484
485−birdTrackLine :: Char -> GenParser Char st [Char]
485+birdTrackLine :: Char -> Parsec [Char] st [Char]
486486birdTrackLine c = try $ do
487487 char c
488488 -- allow html tags on left margin:
@@ -494,10 +494,10 @@ birdTrackLine c = try $ do
494494-- block quotes
495495--
496496
497−emailBlockQuoteStart :: GenParser Char ParserState Char
497+emailBlockQuoteStart :: Parsec [Char] ParserState Char
498498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
499499
500−emailBlockQuote :: GenParser Char ParserState [[Char]]
500+emailBlockQuote :: Parsec [Char] ParserState [[Char]]
501501emailBlockQuote = try $ do
502502 emailBlockQuoteStart
503503 raw <- sepBy (many (nonEndline <|>
@@ -508,7 +508,7 @@ emailBlockQuote = try $ do
508508 optional blanklines
509509 return raw
510510
511−blockQuote :: GenParser Char ParserState Block
511+blockQuote :: Parsec [Char] ParserState Block
512512blockQuote = do
513513 raw <- emailBlockQuote
514514 -- parse the extracted block, which may contain various block elements:
@@ -519,7 +519,7 @@ blockQuote = do
519519-- list blocks
520520--
521521
522−bulletListStart :: GenParser Char ParserState ()
522+bulletListStart :: Parsec [Char] ParserState ()
523523bulletListStart = try $ do
524524 optional newline -- if preceded by a Plain block in a list context
525525 skipNonindentSpaces
@@ -528,7 +528,7 @@ bulletListStart = try $ do
528528 spaceChar
529529 skipSpaces
530530
531−anyOrderedListStart :: GenParser Char ParserState (Int, ListNumberStyle, ListNumberDelim)
531+anyOrderedListStart :: Parsec [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
532532anyOrderedListStart = try $ do
533533 optional newline -- if preceded by a Plain block in a list context
534534 skipNonindentSpaces
@@ -548,11 +548,11 @@ anyOrderedListStart = try $ do
548548 skipSpaces
549549 return (num, style, delim)
550550
551−listStart :: GenParser Char ParserState ()
551+listStart :: Parsec [Char] ParserState ()
552552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
553553
554554-- parse a line of a list item (start = parser for beginning of list item)
555−listLine :: GenParser Char ParserState [Char]
555+listLine :: Parsec [Char] ParserState [Char]
556556listLine = try $ do
557557 notFollowedBy blankline
558558 notFollowedBy' (do indentSpaces
@@ -562,8 +562,8 @@ listLine = try $ do
562562 return $ concat chunks ++ "\n"
563563
564564-- parse raw text for one list item, excluding start marker and continuations
565−rawListItem :: GenParser Char ParserState a
566− -> GenParser Char ParserState [Char]
565+rawListItem :: Parsec [Char] ParserState a
566+ -> Parsec [Char] ParserState [Char]
567567rawListItem start = try $ do
568568 start
569569 first <- listLine
@@ -574,14 +574,14 @@ rawListItem start = try $ do
574574-- continuation of a list item - indented and separated by blankline
575575-- or (in compact lists) endline.
576576-- note: nested lists are parsed as continuations
577−listContinuation :: GenParser Char ParserState [Char]
577+listContinuation :: Parsec [Char] ParserState [Char]
578578listContinuation = try $ do
579579 lookAhead indentSpaces
580580 result <- many1 listContinuationLine
581581 blanks <- many blankline
582582 return $ concat result ++ blanks
583583
584−listContinuationLine :: GenParser Char ParserState [Char]
584+listContinuationLine :: Parsec [Char] ParserState [Char]
585585listContinuationLine = try $ do
586586 notFollowedBy blankline
587587 notFollowedBy' listStart
@@ -589,8 +589,8 @@ listContinuationLine = try $ do
589589 result <- manyTill anyChar newline
590590 return $ result ++ "\n"
591591
592−listItem :: GenParser Char ParserState a
593− -> GenParser Char ParserState [Block]
592+listItem :: Parsec [Char] ParserState a
593+ -> Parsec [Char] ParserState [Block]
594594listItem start = try $ do
595595 first <- rawListItem start
596596 continuations <- many listContinuation
@@ -606,7 +606,7 @@ listItem start = try $ do
606606 updateState (\st -> st {stateParserContext = oldContext})
607607 return contents
608608
609−orderedList :: GenParser Char ParserState Block
609+orderedList :: Parsec [Char] ParserState Block
610610orderedList = try $ do
611611 (start, style, delim) <- lookAhead anyOrderedListStart
612612 items <- many1 $ listItem $ try $
@@ -615,13 +615,13 @@ orderedList = try $ do
615615 orderedListMarker style delim
616616 return $ OrderedList (start, style, delim) $ compactify items
617617
618−bulletList :: GenParser Char ParserState Block
618+bulletList :: Parsec [Char] ParserState Block
619619bulletList =
620620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
621621
622622-- definition lists
623623
624−defListMarker :: GenParser Char ParserState ()
624+defListMarker :: Parsec [Char] ParserState ()
625625defListMarker = do
626626 sps <- nonindentSpaces
627627 char ':' <|> char '~'
@@ -630,10 +630,10 @@ defListMarker = do
630630 let remaining = tabStop - (length sps + 1)
631631 if remaining > 0
632632 then count remaining (char ' ') <|> string "\t"
633− else pzero
633+ else mzero
634634 return ()
635635
636−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
636+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
637637definitionListItem = try $ do
638638 -- first, see if this has any chance of being a definition list:
639639 lookAhead (anyLine >> optional blankline >> defListMarker)
@@ -647,7 +647,7 @@ definitionListItem = try $ do
647647 updateState (\st -> st {stateParserContext = oldContext})
648648 return ((normalizeSpaces term), contents)
649649
650−defRawBlock :: GenParser Char ParserState [Char]
650+defRawBlock :: Parsec [Char] ParserState [Char]
651651defRawBlock = try $ do
652652 defListMarker
653653 firstline <- anyLine
@@ -659,7 +659,7 @@ defRawBlock = try $ do
659659 return $ unlines lns ++ trl
660660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
661661
662−definitionList :: GenParser Char ParserState Block
662+definitionList :: Parsec [Char] ParserState Block
663663definitionList = do
664664 items <- many1 definitionListItem
665665 -- "compactify" the definition list:
@@ -688,7 +688,7 @@ isHtmlOrBlank (Space) = True
688688isHtmlOrBlank (LineBreak) = True
689689isHtmlOrBlank _ = False
690690
691−para :: GenParser Char ParserState Block
691+para :: Parsec [Char] ParserState Block
692692para = try $ do
693693 result <- liftM normalizeSpaces $ many1 inline
694694 guard $ not . all isHtmlOrBlank $ result
@@ -699,17 +699,17 @@ para = try $ do
699699 lookAhead (blockQuote <|> header) >> return "")
700700 return $ Para result
701701
702−plain :: GenParser Char ParserState Block
702+plain :: Parsec [Char] ParserState Block
703703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
704704
705705--
706706-- raw html
707707--
708708
709−htmlElement :: GenParser Char ParserState [Char]
709+htmlElement :: Parsec [Char] ParserState [Char]
710710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
711711
712−htmlBlock :: GenParser Char ParserState Block
712+htmlBlock :: Parsec [Char] ParserState Block
713713htmlBlock = try $ do
714714 failUnlessBeginningOfLine
715715 first <- htmlElement
@@ -717,12 +717,12 @@ htmlBlock = try $ do
717717 finalNewlines <- many newline
718718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
719719
720−strictHtmlBlock :: GenParser Char ParserState [Char]
720+strictHtmlBlock :: Parsec [Char] ParserState [Char]
721721strictHtmlBlock = do
722722 failUnlessBeginningOfLine
723723 htmlInBalanced (not . isInlineTag)
724724
725−rawVerbatimBlock :: GenParser Char ParserState String
725+rawVerbatimBlock :: Parsec [Char] ParserState String
726726rawVerbatimBlock = try $ do
727727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
728728 t == "pre" || t == "style" || t == "script")
@@ -730,7 +730,7 @@ rawVerbatimBlock = try $ do
730730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
731731 return $ open ++ contents ++ renderTags [TagClose tag]
732732
733−rawTeXBlock :: GenParser Char ParserState Block
733+rawTeXBlock :: Parsec [Char] ParserState Block
734734rawTeXBlock = do
735735 failIfStrict
736736 result <- liftM (RawBlock "latex") rawLaTeXBlock
@@ -738,7 +738,7 @@ rawTeXBlock = do
738738 spaces
739739 return result
740740
741−rawHtmlBlocks :: GenParser Char ParserState Block
741+rawHtmlBlocks :: Parsec [Char] ParserState Block
742742rawHtmlBlocks = do
743743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
744744 liftM snd (htmlTag isBlockTag)
@@ -762,7 +762,7 @@ rawHtmlBlocks = do
762762-- Parse a dashed line with optional trailing spaces; return its length
763763-- and the length including trailing space.
764764dashedLine :: Char
765− -> GenParser Char st (Int, Int)
765+ -> Parsec [Char] st (Int, Int)
766766dashedLine ch = do
767767 dashes <- many1 (char ch)
768768 sp <- many spaceChar
@@ -771,7 +771,7 @@ dashedLine ch = do
771771-- Parse a table header with dashed lines of '-' preceded by
772772-- one (or zero) line of text.
773773simpleTableHeader :: Bool -- ^ Headerless table
774− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
774+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
775775simpleTableHeader headless = try $ do
776776 rawContent <- if headless
777777 then return ""
@@ -795,16 +795,16 @@ simpleTableHeader headless = try $ do
795795 return (heads, aligns, indices)
796796
797797-- Parse a table footer - dashed lines followed by blank line.
798−tableFooter :: GenParser Char ParserState [Char]
798+tableFooter :: Parsec [Char] ParserState [Char]
799799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
800800
801801-- Parse a table separator - dashed line.
802−tableSep :: GenParser Char ParserState Char
802+tableSep :: Parsec [Char] ParserState Char
803803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
804804
805805-- Parse a raw line and split it into chunks by indices.
806806rawTableLine :: [Int]
807− -> GenParser Char ParserState [String]
807+ -> Parsec [Char] ParserState [String]
808808rawTableLine indices = do
809809 notFollowedBy' (blanklines <|> tableFooter)
810810 line <- many1Till anyChar newline
@@ -813,12 +813,12 @@ rawTableLine indices = do
813813
814814-- Parse a table line and return a list of lists of blocks (columns).
815815tableLine :: [Int]
816− -> GenParser Char ParserState [[Block]]
816+ -> Parsec [Char] ParserState [[Block]]
817817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
818818
819819-- Parse a multiline table row and return a list of blocks (columns).
820820multilineRow :: [Int]
821− -> GenParser Char ParserState [[Block]]
821+ -> Parsec [Char] ParserState [[Block]]
822822multilineRow indices = do
823823 colLines <- many1 (rawTableLine indices)
824824 let cols = map unlines $ transpose colLines
@@ -826,7 +826,7 @@ multilineRow indices = do
826826
827827-- Parses a table caption: inlines beginning with 'Table:'
828828-- and followed by blank lines.
829−tableCaption :: GenParser Char ParserState [Inline]
829+tableCaption :: Parsec [Char] ParserState [Inline]
830830tableCaption = try $ do
831831 skipNonindentSpaces
832832 string ":" <|> string "Table:"
@@ -836,7 +836,7 @@ tableCaption = try $ do
836836
837837-- Parse a simple table with '---' header and one line per row.
838838simpleTable :: Bool -- ^ Headerless table
839− -> GenParser Char ParserState Block
839+ -> Parsec [Char] ParserState Block
840840simpleTable headless = do
841841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
842842 (return ())
@@ -850,12 +850,12 @@ simpleTable headless = do
850850-- which may be multiline, separated by blank lines, and
851851-- ending with a footer (dashed line followed by blank line).
852852multilineTable :: Bool -- ^ Headerless table
853− -> GenParser Char ParserState Block
853+ -> Parsec [Char] ParserState Block
854854multilineTable headless =
855855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
856856
857857multilineTableHeader :: Bool -- ^ Headerless table
858− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
858+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
859859multilineTableHeader headless = try $ do
860860 if headless
861861 then return '\n'
@@ -903,10 +903,10 @@ alignType strLst len =
903903 (False, False) -> AlignDefault
904904
905905gridTable :: Bool -- ^ Headerless table
906− -> GenParser Char ParserState Block
906+ -> Parsec [Char] ParserState Block
907907gridTable = gridTableWith block tableCaption
908908
909−table :: GenParser Char ParserState Block
909+table :: Parsec [Char] ParserState Block
910910table = multilineTable False <|> simpleTable True <|>
911911 simpleTable False <|> multilineTable True <|>
912912 gridTable False <|> gridTable True <?> "table"
@@ -915,10 +915,10 @@ table = multilineTable False <|> simpleTable True <|>
915915-- inline
916916--
917917
918−inline :: GenParser Char ParserState Inline
918+inline :: Parsec [Char] ParserState Inline
919919inline = choice inlineParsers <?> "inline"
920920
921−inlineParsers :: [GenParser Char ParserState Inline]
921+inlineParsers :: [Parsec [Char] ParserState Inline]
922922inlineParsers = [ whitespace
923923 , str
924924 , endline
@@ -945,7 +945,7 @@ inlineParsers = [ whitespace
945945 , symbol
946946 , ltSign ]
947947
948−escapedChar' :: GenParser Char ParserState Char
948+escapedChar' :: Parsec [Char] ParserState Char
949949escapedChar' = try $ do
950950 char '\\'
951951 state <- getState
@@ -953,7 +953,7 @@ escapedChar' = try $ do
953953 then oneOf "\\`*_{}[]()>#+-.!~"
954954 else satisfy (not . isAlphaNum)
955955
956−escapedChar :: GenParser Char ParserState Inline
956+escapedChar :: Parsec [Char] ParserState Inline
957957escapedChar = do
958958 result <- escapedChar'
959959 return $ case result of
@@ -961,7 +961,7 @@ escapedChar = do
961961 '\n' -> LineBreak -- "\[newline]" is a linebreak
962962 _ -> Str [result]
963963
964−ltSign :: GenParser Char ParserState Inline
964+ltSign :: Parsec [Char] ParserState Inline
965965ltSign = do
966966 st <- getState
967967 if stateStrict st
@@ -969,7 +969,7 @@ ltSign = do
969969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
970970 return $ Str ['<']
971971
972−exampleRef :: GenParser Char ParserState Inline
972+exampleRef :: Parsec [Char] ParserState Inline
973973exampleRef = try $ do
974974 char '@'
975975 lab <- many1 (alphaNum <|> oneOf "-_")
@@ -977,7 +977,7 @@ exampleRef = try $ do
977977 -- later. See the end of parseMarkdown.
978978 return $ Str $ '@' : lab
979979
980−symbol :: GenParser Char ParserState Inline
980+symbol :: Parsec [Char] ParserState Inline
981981symbol = do
982982 result <- noneOf "<\\\n\t "
983983 <|> try (do lookAhead $ char '\\'
@@ -986,7 +986,7 @@ symbol = do
986986 return $ Str [result]
987987
988988-- parses inline code, between n `s and n `s
989−code :: GenParser Char ParserState Inline
989+code :: Parsec [Char] ParserState Inline
990990code = try $ do
991991 starts <- many1 (char '`')
992992 skipSpaces
@@ -997,26 +997,26 @@ code = try $ do
997997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
998998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
999999
1000−mathWord :: GenParser Char st [Char]
1000+mathWord :: Parsec [Char] st [Char]
10011001mathWord = liftM concat $ many1 mathChunk
10021002
1003−mathChunk :: GenParser Char st [Char]
1003+mathChunk :: Parsec [Char] st [Char]
10041004mathChunk = do char '\\'
10051005 c <- anyChar
10061006 return ['\\',c]
10071007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
10081008
1009−math :: GenParser Char ParserState Inline
1009+math :: Parsec [Char] ParserState Inline
10101010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
10111011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
10121012
1013−mathDisplay :: GenParser Char ParserState String
1013+mathDisplay :: Parsec [Char] ParserState String
10141014mathDisplay = try $ do
10151015 failIfStrict
10161016 string "$$"
10171017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
10181018
1019−mathInline :: GenParser Char ParserState String
1019+mathInline :: Parsec [Char] ParserState String
10201020mathInline = try $ do
10211021 failIfStrict
10221022 char '$'
@@ -1028,7 +1028,7 @@ mathInline = try $ do
10281028
10291029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
10301030-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1031−fours :: GenParser Char st Inline
1031+fours :: Parsec [Char] st Inline
10321032fours = try $ do
10331033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
10341034 count 2 $ satisfy (==x)
@@ -1037,9 +1037,9 @@ fours = try $ do
10371037
10381038-- | Parses a list of inlines between start and end delimiters.
10391039inlinesBetween :: (Show b)
1040− => GenParser Char ParserState a
1041− -> GenParser Char ParserState b
1042− -> GenParser Char ParserState [Inline]
1040+ => Parsec [Char] ParserState a
1041+ -> Parsec [Char] ParserState b
1042+ -> Parsec [Char] ParserState [Inline]
10431043inlinesBetween start end =
10441044 normalizeSpaces `liftM` try (start >> many1Till inner end)
10451045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
@@ -1047,8 +1047,8 @@ inlinesBetween start end =
10471047
10481048-- This is used to prevent exponential blowups for things like:
10491049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1050−nested :: GenParser Char ParserState a
1051− -> GenParser Char ParserState a
1050+nested :: Parsec [Char] ParserState a
1051+ -> Parsec [Char] ParserState a
10521052nested p = do
10531053 nestlevel <- stateMaxNestingLevel `fmap` getState
10541054 guard $ nestlevel > 0
@@ -1057,7 +1057,7 @@ nested p = do
10571057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
10581058 return res
10591059
1060−emph :: GenParser Char ParserState Inline
1060+emph :: Parsec [Char] ParserState Inline
10611061emph = Emph `fmap` nested
10621062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
10631063 where starStart = char '*' >> lookAhead nonspaceChar
@@ -1065,7 +1065,7 @@ emph = Emph `fmap` nested
10651065 ulStart = char '_' >> lookAhead nonspaceChar
10661066 ulEnd = notFollowedBy' strong >> char '_'
10671067
1068−strong :: GenParser Char ParserState Inline
1068+strong :: Parsec [Char] ParserState Inline
10691069strong = Strong `liftM` nested
10701070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
10711071 where starStart = string "**" >> lookAhead nonspaceChar
@@ -1073,32 +1073,32 @@ strong = Strong `liftM` nested
10731073 ulStart = string "__" >> lookAhead nonspaceChar
10741074 ulEnd = try $ string "__"
10751075
1076−strikeout :: GenParser Char ParserState Inline
1076+strikeout :: Parsec [Char] ParserState Inline
10771077strikeout = Strikeout `liftM`
10781078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
10791079 where strikeStart = string "~~" >> lookAhead nonspaceChar
10801080 >> notFollowedBy (char '~')
10811081 strikeEnd = try $ string "~~"
10821082
1083−superscript :: GenParser Char ParserState Inline
1083+superscript :: Parsec [Char] ParserState Inline
10841084superscript = failIfStrict >> enclosed (char '^') (char '^')
10851085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
10861086 return . Superscript
10871087
1088−subscript :: GenParser Char ParserState Inline
1088+subscript :: Parsec [Char] ParserState Inline
10891089subscript = failIfStrict >> enclosed (char '~') (char '~')
10901090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
10911091 return . Subscript
10921092
1093−whitespace :: GenParser Char ParserState Inline
1093+whitespace :: Parsec [Char] ParserState Inline
10941094whitespace = spaceChar >>
10951095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
10961096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
10971097
1098−nonEndline :: GenParser Char st Char
1098+nonEndline :: Parsec [Char] st Char
10991099nonEndline = satisfy (/='\n')
11001100
1101−str :: GenParser Char ParserState Inline
1101+str :: Parsec [Char] ParserState Inline
11021102str = do
11031103 smart <- stateSmart `fmap` getState
11041104 a <- alphaNum
@@ -1136,7 +1136,7 @@ likelyAbbrev x =
11361136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
11371137
11381138-- an endline character that can be treated as a space, not a structural break
1139−endline :: GenParser Char ParserState Inline
1139+endline :: Parsec [Char] ParserState Inline
11401140endline = try $ do
11411141 newline
11421142 notFollowedBy blankline
@@ -1155,20 +1155,20 @@ endline = try $ do
11551155--
11561156
11571157-- a reference label for a link
1158−reference :: GenParser Char ParserState [Inline]
1158+reference :: Parsec [Char] ParserState [Inline]
11591159reference = do notFollowedBy' (string "[^") -- footnote reference
11601160 result <- inlinesInBalancedBrackets inline
11611161 return $ normalizeSpaces result
11621162
11631163-- source for a link, with optional title
1164−source :: GenParser Char ParserState (String, [Char])
1164+source :: Parsec [Char] ParserState (String, [Char])
11651165source =
11661166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
11671167 -- the following is needed for cases like: [ref](/url(a).
11681168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
11691169
11701170-- auxiliary function for source
1171−source' :: GenParser Char ParserState (String, [Char])
1171+source' :: Parsec [Char] ParserState (String, [Char])
11721172source' = do
11731173 skipSpaces
11741174 let nl = char '\n' >>~ notFollowedBy blankline
@@ -1186,7 +1186,7 @@ source' = do
11861186 eof
11871187 return (escapeURI $ removeTrailingSpace src, tit)
11881188
1189−linkTitle :: GenParser Char ParserState String
1189+linkTitle :: Parsec [Char] ParserState String
11901190linkTitle = try $ do
11911191 (many1 spaceChar >> option '\n' newline) <|> newline
11921192 skipSpaces
@@ -1194,7 +1194,7 @@ linkTitle = try $ do
11941194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
11951195 return $ fromEntities tit
11961196
1197−link :: GenParser Char ParserState Inline
1197+link :: Parsec [Char] ParserState Inline
11981198link = try $ do
11991199 lab <- reference
12001200 (src, tit) <- source <|> referenceLink lab
@@ -1207,7 +1207,7 @@ delinkify = bottomUp $ concatMap go
12071207
12081208-- a link like [this][ref] or [this][] or [this]
12091209referenceLink :: [Inline]
1210− -> GenParser Char ParserState (String, [Char])
1210+ -> Parsec [Char] ParserState (String, [Char])
12111211referenceLink lab = do
12121212 ref <- option [] (try (optional (char ' ') >>
12131213 optional (newline >> skipSpaces) >> reference))
@@ -1217,7 +1217,7 @@ referenceLink lab = do
12171217 Nothing -> fail "no corresponding key"
12181218 Just target -> return target
12191219
1220−autoLink :: GenParser Char ParserState Inline
1220+autoLink :: Parsec [Char] ParserState Inline
12211221autoLink = try $ do
12221222 char '<'
12231223 (orig, src) <- uri <|> emailAddress
@@ -1227,14 +1227,14 @@ autoLink = try $ do
12271227 then Link [Str orig] (src, "")
12281228 else Link [Code ("",["url"],[]) orig] (src, "")
12291229
1230−image :: GenParser Char ParserState Inline
1230+image :: Parsec [Char] ParserState Inline
12311231image = try $ do
12321232 char '!'
12331233 lab <- reference
12341234 (src, tit) <- source <|> referenceLink lab
12351235 return $ Image lab (src,tit)
12361236
1237−note :: GenParser Char ParserState Inline
1237+note :: Parsec [Char] ParserState Inline
12381238note = try $ do
12391239 failIfStrict
12401240 ref <- noteMarker
@@ -1251,21 +1251,21 @@ note = try $ do
12511251 updateState $ \st -> st{ stateNotes = notes }
12521252 return $ Note contents
12531253
1254−inlineNote :: GenParser Char ParserState Inline
1254+inlineNote :: Parsec [Char] ParserState Inline
12551255inlineNote = try $ do
12561256 failIfStrict
12571257 char '^'
12581258 contents <- inlinesInBalancedBrackets inline
12591259 return $ Note [Para contents]
12601260
1261−rawLaTeXInline' :: GenParser Char ParserState Inline
1261+rawLaTeXInline' :: Parsec [Char] ParserState Inline
12621262rawLaTeXInline' = try $ do
12631263 failIfStrict
12641264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
12651265 RawInline _ s <- rawLaTeXInline
12661266 return $ RawInline "tex" s -- "tex" because it might be context or latex
12671267
1268−rawConTeXtEnvironment :: GenParser Char st String
1268+rawConTeXtEnvironment :: Parsec [Char] st String
12691269rawConTeXtEnvironment = try $ do
12701270 string "\\start"
12711271 completion <- inBrackets (letter <|> digit <|> spaceChar)
@@ -1274,14 +1274,14 @@ rawConTeXtEnvironment = try $ do
12741274 (try $ string "\\stop" >> string completion)
12751275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
12761276
1277−inBrackets :: (GenParser Char st Char) -> GenParser Char st String
1277+inBrackets :: (Parsec [Char] st Char) -> Parsec [Char] st String
12781278inBrackets parser = do
12791279 char '['
12801280 contents <- many parser
12811281 char ']'
12821282 return $ "[" ++ contents ++ "]"
12831283
1284−rawHtmlInline :: GenParser Char ParserState Inline
1284+rawHtmlInline :: Parsec [Char] ParserState Inline
12851285rawHtmlInline = do
12861286 st <- getState
12871287 (_,result) <- if stateStrict st
@@ -1291,20 +1291,20 @@ rawHtmlInline = do
12911291
12921292-- Citations
12931293
1294−cite :: GenParser Char ParserState Inline
1294+cite :: Parsec [Char] ParserState Inline
12951295cite = do
12961296 failIfStrict
12971297 citations <- textualCite <|> normalCite
12981298 return $ Cite citations []
12991299
1300−spnl :: GenParser Char st ()
1300+spnl :: Parsec [Char] st ()
13011301spnl = try $ do
13021302 skipSpaces
13031303 optional newline
13041304 skipSpaces
13051305 notFollowedBy (char '\n')
13061306
1307−textualCite :: GenParser Char ParserState [Citation]
1307+textualCite :: Parsec [Char] ParserState [Citation]
13081308textualCite = try $ do
13091309 (_, key) <- citeKey
13101310 let first = Citation{ citationId = key
@@ -1319,7 +1319,7 @@ textualCite = try $ do
13191319 then option [first] $ bareloc first
13201320 else return $ first : rest
13211321
1322−bareloc :: Citation -> GenParser Char ParserState [Citation]
1322+bareloc :: Citation -> Parsec [Char] ParserState [Citation]
13231323bareloc c = try $ do
13241324 spnl
13251325 char '['
@@ -1329,7 +1329,7 @@ bareloc c = try $ do
13291329 char ']'
13301330 return $ c{ citationSuffix = suff } : rest
13311331
1332−normalCite :: GenParser Char ParserState [Citation]
1332+normalCite :: Parsec [Char] ParserState [Citation]
13331333normalCite = try $ do
13341334 char '['
13351335 spnl
@@ -1338,7 +1338,7 @@ normalCite = try $ do
13381338 char ']'
13391339 return citations
13401340
1341−citeKey :: GenParser Char ParserState (Bool, String)
1341+citeKey :: Parsec [Char] ParserState (Bool, String)
13421342citeKey = try $ do
13431343 suppress_author <- option False (char '-' >> return True)
13441344 char '@'
@@ -1350,7 +1350,7 @@ citeKey = try $ do
13501350 guard $ key `elem` stateCitations st
13511351 return (suppress_author, key)
13521352
1353−suffix :: GenParser Char ParserState [Inline]
1353+suffix :: Parsec [Char] ParserState [Inline]
13541354suffix = try $ do
13551355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
13561356 spnl
@@ -1359,14 +1359,14 @@ suffix = try $ do
13591359 then Space : rest
13601360 else rest
13611361
1362−prefix :: GenParser Char ParserState [Inline]
1362+prefix :: Parsec [Char] ParserState [Inline]
13631363prefix = liftM normalizeSpaces $
13641364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
13651365
1366−citeList :: GenParser Char ParserState [Citation]
1366+citeList :: Parsec [Char] ParserState [Citation]
13671367citeList = sepBy1 citation (try $ char ';' >> spnl)
13681368
1369−citation :: GenParser Char ParserState Citation
1369+citation :: Parsec [Char] ParserState Citation
13701370citation = try $ do
13711371 pref <- prefix
13721372 (suppress_author, key) <- citeKey