@@ -43,7 +43,7 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
43import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
43import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
44 isTextTag, isCommentTag )
44 isTextTag, isCommentTag )
45import Text.Pandoc.XML ( fromEntities )
45import Text.Pandoc.XML ( fromEntities )
46−import Text.ParserCombinators.Parsec
46+import Text.Parsec
47import Control.Monad (when, liftM, guard, mzero)
47import Control.Monad (when, liftM, guard, mzero)
48import Text.HTML.TagSoup
48import Text.HTML.TagSoup
49import Text.HTML.TagSoup.Match (tagOpen)
49import Text.HTML.TagSoup.Match (tagOpen)
@@ -83,14 +83,14 @@ isBlank _ = False
83-- auxiliary functions
83-- auxiliary functions
86−indentSpaces :: GenParser Char ParserState [Char]
86+indentSpaces :: Parsec [Char] ParserState [Char]
87indentSpaces = try $ do
87indentSpaces = try $ do
88 state <- getState
88 state <- getState
89 let tabStop = stateTabStop state
89 let tabStop = stateTabStop state
90 count tabStop (char ' ') <|>
90 count tabStop (char ' ') <|>
91 string "\t" <?> "indentation"
91 string "\t" <?> "indentation"
93−nonindentSpaces :: GenParser Char ParserState [Char]
93+nonindentSpaces :: Parsec [Char] ParserState [Char]
94nonindentSpaces = do
94nonindentSpaces = do
95 state <- getState
95 state <- getState
96 let tabStop = stateTabStop state
96 let tabStop = stateTabStop state
@@ -99,30 +99,30 @@ nonindentSpaces = do
99 then return sps
99 then return sps
100 else unexpected "indented line"
100 else unexpected "indented line"
102−skipNonindentSpaces :: GenParser Char ParserState ()
102+skipNonindentSpaces :: Parsec [Char] ParserState ()
103skipNonindentSpaces = do
103skipNonindentSpaces = do
104 state <- getState
104 state <- getState
105 atMostSpaces (stateTabStop state - 1)
105 atMostSpaces (stateTabStop state - 1)
107−atMostSpaces :: Int -> GenParser Char ParserState ()
107+atMostSpaces :: Int -> Parsec [Char] ParserState ()
108atMostSpaces 0 = notFollowedBy (char ' ')
108atMostSpaces 0 = notFollowedBy (char ' ')
109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
111−litChar :: GenParser Char ParserState Char
111+litChar :: Parsec [Char] ParserState Char
112litChar = escapedChar'
112litChar = escapedChar'
113 <|> noneOf "\n"
113 <|> noneOf "\n"
114 <|> (newline >> notFollowedBy blankline >> return ' ')
114 <|> (newline >> notFollowedBy blankline >> return ' ')
116-- | Fail unless we're at beginning of a line.
116-- | Fail unless we're at beginning of a line.
117−failUnlessBeginningOfLine :: GenParser tok st ()
117+failUnlessBeginningOfLine :: Parsec [tok] st ()
118failUnlessBeginningOfLine = do
118failUnlessBeginningOfLine = do
119 pos <- getPosition
119 pos <- getPosition
120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
122-- | Parse a sequence of inline elements between square brackets,
122-- | Parse a sequence of inline elements between square brackets,
123-- including inlines between balanced pairs of square brackets.
123-- including inlines between balanced pairs of square brackets.
124−inlinesInBalancedBrackets :: GenParser Char ParserState Inline
124+inlinesInBalancedBrackets :: Parsec [Char] ParserState Inline
125− -> GenParser Char ParserState [Inline]
125+ -> Parsec [Char] ParserState [Inline]
126inlinesInBalancedBrackets parser = try $ do
126inlinesInBalancedBrackets parser = try $ do
128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
@@ -137,7 +137,7 @@ inlinesInBalancedBrackets parser = try $ do
137-- document structure
137-- document structure
140−titleLine :: GenParser Char ParserState [Inline]
140+titleLine :: Parsec [Char] ParserState [Inline]
141titleLine = try $ do
141titleLine = try $ do
143 skipSpaces
143 skipSpaces
@@ -146,7 +146,7 @@ titleLine = try $ do
147 return $ normalizeSpaces res
147 return $ normalizeSpaces res
149−authorsLine :: GenParser Char ParserState [[Inline]]
149+authorsLine :: Parsec [Char] ParserState [[Inline]]
150authorsLine = try $ do
150authorsLine = try $ do
152 skipSpaces
152 skipSpaces
@@ -157,14 +157,14 @@ authorsLine = try $ do
158 return $ filter (not . null) $ map normalizeSpaces authors
158 return $ filter (not . null) $ map normalizeSpaces authors
160−dateLine :: GenParser Char ParserState [Inline]
160+dateLine :: Parsec [Char] ParserState [Inline]
161dateLine = try $ do
161dateLine = try $ do
163 skipSpaces
163 skipSpaces
164 date <- manyTill inline newline
164 date <- manyTill inline newline
165 return $ normalizeSpaces date
165 return $ normalizeSpaces date
167−titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline])
167+titleBlock :: Parsec [Char] ParserState ([Inline], [[Inline]], [Inline])
168titleBlock = try $ do
168titleBlock = try $ do
169 failIfStrict
169 failIfStrict
170 title <- option [] titleLine
170 title <- option [] titleLine
@@ -173,7 +173,7 @@ titleBlock = try $ do
173 optional blanklines
173 optional blanklines
174 return (title, author, date)
174 return (title, author, date)
176−parseMarkdown :: GenParser Char ParserState Pandoc
176+parseMarkdown :: Parsec [Char] ParserState Pandoc
177parseMarkdown = do
177parseMarkdown = do
178 -- markdown allows raw HTML
178 -- markdown allows raw HTML
179 updateState (\state -> state { stateParseRaw = True })
179 updateState (\state -> state { stateParseRaw = True })
@@ -182,7 +182,7 @@ parseMarkdown = do
182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
183 st <- getState
183 st <- getState
184 let firstPassParser = referenceKey
184 let firstPassParser = referenceKey
185− <|> (if stateStrict st then pzero else noteBlock)
185+ <|> (if stateStrict st then mzero else noteBlock)
186 <|> liftM snd (withRaw codeBlockDelimited)
186 <|> liftM snd (withRaw codeBlockDelimited)
187 <|> lineClump
187 <|> lineClump
188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
@@ -211,7 +211,7 @@ parseMarkdown = do
211-- initial pass for references and notes
211-- initial pass for references and notes
214−referenceKey :: GenParser Char ParserState [Char]
214+referenceKey :: Parsec [Char] ParserState [Char]
215referenceKey = try $ do
215referenceKey = try $ do
216 startPos <- getPosition
216 startPos <- getPosition
217 skipNonindentSpaces
217 skipNonindentSpaces
@@ -238,7 +238,7 @@ referenceKey = try $ do
238 -- return blanks so line count isn't affected
238 -- return blanks so line count isn't affected
239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
241−referenceTitle :: GenParser Char ParserState String
241+referenceTitle :: Parsec [Char] ParserState String
242referenceTitle = try $ do
242referenceTitle = try $ do
243 skipSpaces >> optional newline >> skipSpaces
243 skipSpaces >> optional newline >> skipSpaces
244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
@@ -247,23 +247,23 @@ referenceTitle = try $ do
247 notFollowedBy (noneOf ")\n")))
247 notFollowedBy (noneOf ")\n")))
248 return $ fromEntities tit
248 return $ fromEntities tit
250−noteMarker :: GenParser Char ParserState [Char]
250+noteMarker :: Parsec [Char] ParserState [Char]
251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
253−rawLine :: GenParser Char ParserState [Char]
253+rawLine :: Parsec [Char] ParserState [Char]
254rawLine = try $ do
254rawLine = try $ do
255 notFollowedBy blankline
255 notFollowedBy blankline
256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
257 optional indentSpaces
257 optional indentSpaces
260−rawLines :: GenParser Char ParserState [Char]
260+rawLines :: Parsec [Char] ParserState [Char]
261rawLines = do
261rawLines = do
262 first <- anyLine
262 first <- anyLine
263 rest <- many rawLine
263 rest <- many rawLine
264 return $ unlines (first:rest)
264 return $ unlines (first:rest)
266−noteBlock :: GenParser Char ParserState [Char]
266+noteBlock :: Parsec [Char] ParserState [Char]
267noteBlock = try $ do
267noteBlock = try $ do
268 startPos <- getPosition
268 startPos <- getPosition
269 skipNonindentSpaces
269 skipNonindentSpaces
@@ -287,10 +287,10 @@ noteBlock = try $ do
287-- parsing blocks
287-- parsing blocks
290−parseBlocks :: GenParser Char ParserState [Block]
290+parseBlocks :: Parsec [Char] ParserState [Block]
291parseBlocks = manyTill block eof
291parseBlocks = manyTill block eof
293−block :: GenParser Char ParserState Block
293+block :: Parsec [Char] ParserState Block
294block = do
294block = do
295 st <- getState
295 st <- getState
296 choice (if stateStrict st
296 choice (if stateStrict st
@@ -325,10 +325,10 @@ block = do
325-- header blocks
325-- header blocks
328−header :: GenParser Char ParserState Block
328+header :: Parsec [Char] ParserState Block
329header = setextHeader <|> atxHeader <?> "header"
329header = setextHeader <|> atxHeader <?> "header"
331−atxHeader :: GenParser Char ParserState Block
331+atxHeader :: Parsec [Char] ParserState Block
332atxHeader = try $ do
332atxHeader = try $ do
333 level <- many1 (char '#') >>= return . length
333 level <- many1 (char '#') >>= return . length
334 notFollowedBy (char '.' <|> char ')') -- this would be a list
334 notFollowedBy (char '.' <|> char ')') -- this would be a list
@@ -336,10 +336,10 @@ atxHeader = try $ do
336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
337 return $ Header level text
337 return $ Header level text
339−atxClosing :: GenParser Char st [Char]
339+atxClosing :: Parsec [Char] st [Char]
340atxClosing = try $ skipMany (char '#') >> blanklines
340atxClosing = try $ skipMany (char '#') >> blanklines
342−setextHeader :: GenParser Char ParserState Block
342+setextHeader :: Parsec [Char] ParserState Block
343setextHeader = try $ do
343setextHeader = try $ do
344 -- This lookahead prevents us from wasting time parsing Inlines
344 -- This lookahead prevents us from wasting time parsing Inlines
345 -- unless necessary -- it gives a significant performance boost.
345 -- unless necessary -- it gives a significant performance boost.
@@ -355,7 +355,7 @@ setextHeader = try $ do
355-- hrule block
355-- hrule block
358−hrule :: GenParser Char st Block
358+hrule :: Parsec [Char] st Block
359hrule = try $ do
359hrule = try $ do
360 skipSpaces
360 skipSpaces
361 start <- satisfy isHruleChar
361 start <- satisfy isHruleChar
@@ -369,12 +369,12 @@ hrule = try $ do
369-- code blocks
369-- code blocks
372−indentedLine :: GenParser Char ParserState [Char]
372+indentedLine :: Parsec [Char] ParserState [Char]
373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
375blockDelimiter :: (Char -> Bool)
375blockDelimiter :: (Char -> Bool)
376 -> Maybe Int
376 -> Maybe Int
377− -> GenParser Char st (Int, (String, [String], [(String, String)]), Char)
377+ -> Parsec [Char] st (Int, (String, [String], [(String, String)]), Char)
378blockDelimiter f len = try $ do
378blockDelimiter f len = try $ do
379 c <- lookAhead (satisfy f)
379 c <- lookAhead (satisfy f)
380 size <- case len of
380 size <- case len of
@@ -388,7 +388,7 @@ blockDelimiter f len = try $ do
388 blankline
388 blankline
389 return (size, attr, c)
389 return (size, attr, c)
391−attributes :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
391+attributes :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
392attributes = try $ do
392attributes = try $ do
@@ -400,28 +400,28 @@ attributes = try $ do
400 | otherwise = firstNonNull xs
400 | otherwise = firstNonNull xs
401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
403−attribute :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
403+attribute :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
404attribute = identifierAttr <|> classAttr <|> keyValAttr
404attribute = identifierAttr <|> classAttr <|> keyValAttr
406−identifier :: GenParser Char st [Char]
406+identifier :: Parsec [Char] st [Char]
407identifier = do
407identifier = do
408 first <- letter
408 first <- letter
409 rest <- many $ alphaNum <|> oneOf "-_:."
409 rest <- many $ alphaNum <|> oneOf "-_:."
410 return (first:rest)
410 return (first:rest)
412−identifierAttr :: GenParser Char st ([Char], [a], [a1])
412+identifierAttr :: Parsec [Char] st ([Char], [a], [a1])
413identifierAttr = try $ do
413identifierAttr = try $ do
415 result <- identifier
415 result <- identifier
416 return (result,[],[])
416 return (result,[],[])
418−classAttr :: GenParser Char st ([Char], [[Char]], [a])
418+classAttr :: Parsec [Char] st ([Char], [[Char]], [a])
419classAttr = try $ do
419classAttr = try $ do
421 result <- identifier
421 result <- identifier
422 return ("",[result],[])
422 return ("",[result],[])
424−keyValAttr :: GenParser Char st ([Char], [a], [([Char], [Char])])
424+keyValAttr :: Parsec [Char] st ([Char], [a], [([Char], [Char])])
425keyValAttr = try $ do
425keyValAttr = try $ do
426 key <- identifier
426 key <- identifier
@@ -430,14 +430,14 @@ keyValAttr = try $ do
430 <|> many nonspaceChar
430 <|> many nonspaceChar
431 return ("",[],[(key,val)])
431 return ("",[],[(key,val)])
433−codeBlockDelimited :: GenParser Char st Block
433+codeBlockDelimited :: Parsec [Char] st Block
434codeBlockDelimited = try $ do
434codeBlockDelimited = try $ do
435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
437 blanklines
437 blanklines
438 return $ CodeBlock attr $ intercalate "\n" contents
438 return $ CodeBlock attr $ intercalate "\n" contents
440−codeBlockIndented :: GenParser Char ParserState Block
440+codeBlockIndented :: Parsec [Char] ParserState Block
441codeBlockIndented = do
441codeBlockIndented = do
442 contents <- many1 (indentedLine <|>
442 contents <- many1 (indentedLine <|>
443 try (do b <- blanklines
443 try (do b <- blanklines
@@ -448,7 +448,7 @@ codeBlockIndented = do
448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
449 stripTrailingNewlines $ concat contents
449 stripTrailingNewlines $ concat contents
451−lhsCodeBlock :: GenParser Char ParserState Block
451+lhsCodeBlock :: Parsec [Char] ParserState Block
452lhsCodeBlock = do
452lhsCodeBlock = do
453 failUnlessLHS
453 failUnlessLHS
454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
@@ -456,7 +456,7 @@ lhsCodeBlock = do
456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
457 lhsCodeBlockInverseBird
457 lhsCodeBlockInverseBird
459−lhsCodeBlockLaTeX :: GenParser Char ParserState String
459+lhsCodeBlockLaTeX :: Parsec [Char] ParserState String
460lhsCodeBlockLaTeX = try $ do
460lhsCodeBlockLaTeX = try $ do
461 string "\\begin{code}"
461 string "\\begin{code}"
462 manyTill spaceChar newline
462 manyTill spaceChar newline
@@ -464,13 +464,13 @@ lhsCodeBlockLaTeX = try $ do
464 blanklines
464 blanklines
465 return $ stripTrailingNewlines contents
465 return $ stripTrailingNewlines contents
467−lhsCodeBlockBird :: GenParser Char ParserState String
467+lhsCodeBlockBird :: Parsec [Char] ParserState String
468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
470−lhsCodeBlockInverseBird :: GenParser Char ParserState String
470+lhsCodeBlockInverseBird :: Parsec [Char] ParserState String
471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
473−lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
473+lhsCodeBlockBirdWith :: Char -> Parsec [Char] ParserState String
474lhsCodeBlockBirdWith c = try $ do
474lhsCodeBlockBirdWith c = try $ do
475 pos <- getPosition
475 pos <- getPosition
476 when (sourceColumn pos /= 1) $ fail "Not in first column"
476 when (sourceColumn pos /= 1) $ fail "Not in first column"
@@ -482,7 +482,7 @@ lhsCodeBlockBirdWith c = try $ do
482 blanklines
482 blanklines
483 return $ intercalate "\n" lns'
483 return $ intercalate "\n" lns'
485−birdTrackLine :: Char -> GenParser Char st [Char]
485+birdTrackLine :: Char -> Parsec [Char] st [Char]
486birdTrackLine c = try $ do
486birdTrackLine c = try $ do
488 -- allow html tags on left margin:
488 -- allow html tags on left margin:
@@ -494,10 +494,10 @@ birdTrackLine c = try $ do
494-- block quotes
494-- block quotes
497−emailBlockQuoteStart :: GenParser Char ParserState Char
497+emailBlockQuoteStart :: Parsec [Char] ParserState Char
498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
500−emailBlockQuote :: GenParser Char ParserState [[Char]]
500+emailBlockQuote :: Parsec [Char] ParserState [[Char]]
501emailBlockQuote = try $ do
501emailBlockQuote = try $ do
502 emailBlockQuoteStart
502 emailBlockQuoteStart
503 raw <- sepBy (many (nonEndline <|>
503 raw <- sepBy (many (nonEndline <|>
@@ -508,7 +508,7 @@ emailBlockQuote = try $ do
508 optional blanklines
508 optional blanklines
509 return raw
509 return raw
511−blockQuote :: GenParser Char ParserState Block
511+blockQuote :: Parsec [Char] ParserState Block
512blockQuote = do
512blockQuote = do
513 raw <- emailBlockQuote
513 raw <- emailBlockQuote
514 -- parse the extracted block, which may contain various block elements:
514 -- parse the extracted block, which may contain various block elements:
@@ -519,7 +519,7 @@ blockQuote = do
519-- list blocks
519-- list blocks
522−bulletListStart :: GenParser Char ParserState ()
522+bulletListStart :: Parsec [Char] ParserState ()
523bulletListStart = try $ do
523bulletListStart = try $ do
524 optional newline -- if preceded by a Plain block in a list context
524 optional newline -- if preceded by a Plain block in a list context
525 skipNonindentSpaces
525 skipNonindentSpaces
@@ -528,7 +528,7 @@ bulletListStart = try $ do
528 spaceChar
528 spaceChar
529 skipSpaces
529 skipSpaces
531−anyOrderedListStart :: GenParser Char ParserState (Int, ListNumberStyle, ListNumberDelim)
531+anyOrderedListStart :: Parsec [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
532anyOrderedListStart = try $ do
532anyOrderedListStart = try $ do
533 optional newline -- if preceded by a Plain block in a list context
533 optional newline -- if preceded by a Plain block in a list context
534 skipNonindentSpaces
534 skipNonindentSpaces
@@ -548,11 +548,11 @@ anyOrderedListStart = try $ do
548 skipSpaces
548 skipSpaces
549 return (num, style, delim)
549 return (num, style, delim)
551−listStart :: GenParser Char ParserState ()
551+listStart :: Parsec [Char] ParserState ()
552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
554-- parse a line of a list item (start = parser for beginning of list item)
554-- 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]
556listLine = try $ do
556listLine = try $ do
557 notFollowedBy blankline
557 notFollowedBy blankline
558 notFollowedBy' (do indentSpaces
558 notFollowedBy' (do indentSpaces
@@ -562,8 +562,8 @@ listLine = try $ do
562 return $ concat chunks ++ "\n"
562 return $ concat chunks ++ "\n"
564-- parse raw text for one list item, excluding start marker and continuations
564-- parse raw text for one list item, excluding start marker and continuations
565−rawListItem :: GenParser Char ParserState a
565+rawListItem :: Parsec [Char] ParserState a
566− -> GenParser Char ParserState [Char]
566+ -> Parsec [Char] ParserState [Char]
567rawListItem start = try $ do
567rawListItem start = try $ do
569 first <- listLine
569 first <- listLine
@@ -574,14 +574,14 @@ rawListItem start = try $ do
574-- continuation of a list item - indented and separated by blankline
574-- continuation of a list item - indented and separated by blankline
575-- or (in compact lists) endline.
575-- or (in compact lists) endline.
576-- note: nested lists are parsed as continuations
576-- note: nested lists are parsed as continuations
577−listContinuation :: GenParser Char ParserState [Char]
577+listContinuation :: Parsec [Char] ParserState [Char]
578listContinuation = try $ do
578listContinuation = try $ do
579 lookAhead indentSpaces
579 lookAhead indentSpaces
580 result <- many1 listContinuationLine
580 result <- many1 listContinuationLine
581 blanks <- many blankline
581 blanks <- many blankline
582 return $ concat result ++ blanks
582 return $ concat result ++ blanks
584−listContinuationLine :: GenParser Char ParserState [Char]
584+listContinuationLine :: Parsec [Char] ParserState [Char]
585listContinuationLine = try $ do
585listContinuationLine = try $ do
586 notFollowedBy blankline
586 notFollowedBy blankline
587 notFollowedBy' listStart
587 notFollowedBy' listStart
@@ -589,8 +589,8 @@ listContinuationLine = try $ do
589 result <- manyTill anyChar newline
589 result <- manyTill anyChar newline
590 return $ result ++ "\n"
590 return $ result ++ "\n"
592−listItem :: GenParser Char ParserState a
592+listItem :: Parsec [Char] ParserState a
593− -> GenParser Char ParserState [Block]
593+ -> Parsec [Char] ParserState [Block]
594listItem start = try $ do
594listItem start = try $ do
595 first <- rawListItem start
595 first <- rawListItem start
596 continuations <- many listContinuation
596 continuations <- many listContinuation
@@ -606,7 +606,7 @@ listItem start = try $ do
606 updateState (\st -> st {stateParserContext = oldContext})
606 updateState (\st -> st {stateParserContext = oldContext})
607 return contents
607 return contents
609−orderedList :: GenParser Char ParserState Block
609+orderedList :: Parsec [Char] ParserState Block
610orderedList = try $ do
610orderedList = try $ do
611 (start, style, delim) <- lookAhead anyOrderedListStart
611 (start, style, delim) <- lookAhead anyOrderedListStart
612 items <- many1 $ listItem $ try $
612 items <- many1 $ listItem $ try $
@@ -615,13 +615,13 @@ orderedList = try $ do
615 orderedListMarker style delim
615 orderedListMarker style delim
616 return $ OrderedList (start, style, delim) $ compactify items
616 return $ OrderedList (start, style, delim) $ compactify items
618−bulletList :: GenParser Char ParserState Block
618+bulletList :: Parsec [Char] ParserState Block
619bulletList =
619bulletList =
620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
622-- definition lists
622-- definition lists
624−defListMarker :: GenParser Char ParserState ()
624+defListMarker :: Parsec [Char] ParserState ()
625defListMarker = do
625defListMarker = do
626 sps <- nonindentSpaces
626 sps <- nonindentSpaces
627 char ':' <|> char '~'
627 char ':' <|> char '~'
@@ -630,10 +630,10 @@ defListMarker = do
630 let remaining = tabStop - (length sps + 1)
630 let remaining = tabStop - (length sps + 1)
631 if remaining > 0
631 if remaining > 0
632 then count remaining (char ' ') <|> string "\t"
632 then count remaining (char ' ') <|> string "\t"
633− else pzero
633+ else mzero
634 return ()
634 return ()
636−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
636+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
637definitionListItem = try $ do
637definitionListItem = try $ do
638 -- first, see if this has any chance of being a definition list:
638 -- first, see if this has any chance of being a definition list:
639 lookAhead (anyLine >> optional blankline >> defListMarker)
639 lookAhead (anyLine >> optional blankline >> defListMarker)
@@ -647,7 +647,7 @@ definitionListItem = try $ do
647 updateState (\st -> st {stateParserContext = oldContext})
647 updateState (\st -> st {stateParserContext = oldContext})
648 return ((normalizeSpaces term), contents)
648 return ((normalizeSpaces term), contents)
650−defRawBlock :: GenParser Char ParserState [Char]
650+defRawBlock :: Parsec [Char] ParserState [Char]
651defRawBlock = try $ do
651defRawBlock = try $ do
652 defListMarker
652 defListMarker
653 firstline <- anyLine
653 firstline <- anyLine
@@ -659,7 +659,7 @@ defRawBlock = try $ do
659 return $ unlines lns ++ trl
659 return $ unlines lns ++ trl
660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
662−definitionList :: GenParser Char ParserState Block
662+definitionList :: Parsec [Char] ParserState Block
663definitionList = do
663definitionList = do
664 items <- many1 definitionListItem
664 items <- many1 definitionListItem
665 -- "compactify" the definition list:
665 -- "compactify" the definition list:
@@ -688,7 +688,7 @@ isHtmlOrBlank (Space) = True
688isHtmlOrBlank (LineBreak) = True
688isHtmlOrBlank (LineBreak) = True
689isHtmlOrBlank _ = False
689isHtmlOrBlank _ = False
691−para :: GenParser Char ParserState Block
691+para :: Parsec [Char] ParserState Block
692para = try $ do
692para = try $ do
693 result <- liftM normalizeSpaces $ many1 inline
693 result <- liftM normalizeSpaces $ many1 inline
694 guard $ not . all isHtmlOrBlank $ result
694 guard $ not . all isHtmlOrBlank $ result
@@ -699,17 +699,17 @@ para = try $ do
699 lookAhead (blockQuote <|> header) >> return "")
699 lookAhead (blockQuote <|> header) >> return "")
700 return $ Para result
700 return $ Para result
702−plain :: GenParser Char ParserState Block
702+plain :: Parsec [Char] ParserState Block
703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
706-- raw html
706-- raw html
709−htmlElement :: GenParser Char ParserState [Char]
709+htmlElement :: Parsec [Char] ParserState [Char]
710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
712−htmlBlock :: GenParser Char ParserState Block
712+htmlBlock :: Parsec [Char] ParserState Block
713htmlBlock = try $ do
713htmlBlock = try $ do
714 failUnlessBeginningOfLine
714 failUnlessBeginningOfLine
715 first <- htmlElement
715 first <- htmlElement
@@ -717,12 +717,12 @@ htmlBlock = try $ do
717 finalNewlines <- many newline
717 finalNewlines <- many newline
718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
720−strictHtmlBlock :: GenParser Char ParserState [Char]
720+strictHtmlBlock :: Parsec [Char] ParserState [Char]
721strictHtmlBlock = do
721strictHtmlBlock = do
722 failUnlessBeginningOfLine
722 failUnlessBeginningOfLine
723 htmlInBalanced (not . isInlineTag)
723 htmlInBalanced (not . isInlineTag)
725−rawVerbatimBlock :: GenParser Char ParserState String
725+rawVerbatimBlock :: Parsec [Char] ParserState String
726rawVerbatimBlock = try $ do
726rawVerbatimBlock = try $ do
727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
728 t == "pre" || t == "style" || t == "script")
728 t == "pre" || t == "style" || t == "script")
@@ -730,7 +730,7 @@ rawVerbatimBlock = try $ do
730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
731 return $ open ++ contents ++ renderTags [TagClose tag]
731 return $ open ++ contents ++ renderTags [TagClose tag]
733−rawTeXBlock :: GenParser Char ParserState Block
733+rawTeXBlock :: Parsec [Char] ParserState Block
734rawTeXBlock = do
734rawTeXBlock = do
735 failIfStrict
735 failIfStrict
736 result <- liftM (RawBlock "latex") rawLaTeXBlock
736 result <- liftM (RawBlock "latex") rawLaTeXBlock
@@ -738,7 +738,7 @@ rawTeXBlock = do
739 return result
739 return result
741−rawHtmlBlocks :: GenParser Char ParserState Block
741+rawHtmlBlocks :: Parsec [Char] ParserState Block
742rawHtmlBlocks = do
742rawHtmlBlocks = do
743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
744 liftM snd (htmlTag isBlockTag)
744 liftM snd (htmlTag isBlockTag)
@@ -762,7 +762,7 @@ rawHtmlBlocks = do
762-- Parse a dashed line with optional trailing spaces; return its length
762-- Parse a dashed line with optional trailing spaces; return its length
763-- and the length including trailing space.
763-- and the length including trailing space.
764dashedLine :: Char
764dashedLine :: Char
765− -> GenParser Char st (Int, Int)
765+ -> Parsec [Char] st (Int, Int)
766dashedLine ch = do
766dashedLine ch = do
767 dashes <- many1 (char ch)
767 dashes <- many1 (char ch)
768 sp <- many spaceChar
768 sp <- many spaceChar
@@ -771,7 +771,7 @@ dashedLine ch = do
771-- Parse a table header with dashed lines of '-' preceded by
771-- Parse a table header with dashed lines of '-' preceded by
772-- one (or zero) line of text.
772-- one (or zero) line of text.
773simpleTableHeader :: Bool -- ^ Headerless table
773simpleTableHeader :: Bool -- ^ Headerless table
774− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
774+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
775simpleTableHeader headless = try $ do
775simpleTableHeader headless = try $ do
776 rawContent <- if headless
776 rawContent <- if headless
777 then return ""
777 then return ""
@@ -795,16 +795,16 @@ simpleTableHeader headless = try $ do
795 return (heads, aligns, indices)
795 return (heads, aligns, indices)
797-- Parse a table footer - dashed lines followed by blank line.
797-- Parse a table footer - dashed lines followed by blank line.
798−tableFooter :: GenParser Char ParserState [Char]
798+tableFooter :: Parsec [Char] ParserState [Char]
799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
801-- Parse a table separator - dashed line.
801-- Parse a table separator - dashed line.
802−tableSep :: GenParser Char ParserState Char
802+tableSep :: Parsec [Char] ParserState Char
803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
805-- Parse a raw line and split it into chunks by indices.
805-- Parse a raw line and split it into chunks by indices.
806rawTableLine :: [Int]
806rawTableLine :: [Int]
807− -> GenParser Char ParserState [String]
807+ -> Parsec [Char] ParserState [String]
808rawTableLine indices = do
808rawTableLine indices = do
809 notFollowedBy' (blanklines <|> tableFooter)
809 notFollowedBy' (blanklines <|> tableFooter)
810 line <- many1Till anyChar newline
810 line <- many1Till anyChar newline
@@ -813,12 +813,12 @@ rawTableLine indices = do
814-- Parse a table line and return a list of lists of blocks (columns).
814-- Parse a table line and return a list of lists of blocks (columns).
815tableLine :: [Int]
815tableLine :: [Int]
816− -> GenParser Char ParserState [[Block]]
816+ -> Parsec [Char] ParserState [[Block]]
817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
819-- Parse a multiline table row and return a list of blocks (columns).
819-- Parse a multiline table row and return a list of blocks (columns).
820multilineRow :: [Int]
820multilineRow :: [Int]
821− -> GenParser Char ParserState [[Block]]
821+ -> Parsec [Char] ParserState [[Block]]
822multilineRow indices = do
822multilineRow indices = do
823 colLines <- many1 (rawTableLine indices)
823 colLines <- many1 (rawTableLine indices)
824 let cols = map unlines $ transpose colLines
824 let cols = map unlines $ transpose colLines
@@ -826,7 +826,7 @@ multilineRow indices = do
827-- Parses a table caption: inlines beginning with 'Table:'
827-- Parses a table caption: inlines beginning with 'Table:'
828-- and followed by blank lines.
828-- and followed by blank lines.
829−tableCaption :: GenParser Char ParserState [Inline]
829+tableCaption :: Parsec [Char] ParserState [Inline]
830tableCaption = try $ do
830tableCaption = try $ do
831 skipNonindentSpaces
831 skipNonindentSpaces
832 string ":" <|> string "Table:"
832 string ":" <|> string "Table:"
@@ -836,7 +836,7 @@ tableCaption = try $ do
837-- Parse a simple table with '---' header and one line per row.
837-- Parse a simple table with '---' header and one line per row.
838simpleTable :: Bool -- ^ Headerless table
838simpleTable :: Bool -- ^ Headerless table
839− -> GenParser Char ParserState Block
839+ -> Parsec [Char] ParserState Block
840simpleTable headless = do
840simpleTable headless = do
841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
842 (return ())
842 (return ())
@@ -850,12 +850,12 @@ simpleTable headless = do
850-- which may be multiline, separated by blank lines, and
850-- which may be multiline, separated by blank lines, and
851-- ending with a footer (dashed line followed by blank line).
851-- ending with a footer (dashed line followed by blank line).
852multilineTable :: Bool -- ^ Headerless table
852multilineTable :: Bool -- ^ Headerless table
853− -> GenParser Char ParserState Block
853+ -> Parsec [Char] ParserState Block
854multilineTable headless =
854multilineTable headless =
855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
857multilineTableHeader :: Bool -- ^ Headerless table
857multilineTableHeader :: Bool -- ^ Headerless table
858− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
858+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
859multilineTableHeader headless = try $ do
859multilineTableHeader headless = try $ do
860 if headless
860 if headless
861 then return '\n'
861 then return '\n'
@@ -903,10 +903,10 @@ alignType strLst len =
903 (False, False) -> AlignDefault
903 (False, False) -> AlignDefault
905gridTable :: Bool -- ^ Headerless table
905gridTable :: Bool -- ^ Headerless table
906− -> GenParser Char ParserState Block
906+ -> Parsec [Char] ParserState Block
907gridTable = gridTableWith block tableCaption
907gridTable = gridTableWith block tableCaption
909−table :: GenParser Char ParserState Block
909+table :: Parsec [Char] ParserState Block
910table = multilineTable False <|> simpleTable True <|>
910table = multilineTable False <|> simpleTable True <|>
911 simpleTable False <|> multilineTable True <|>
911 simpleTable False <|> multilineTable True <|>
912 gridTable False <|> gridTable True <?> "table"
912 gridTable False <|> gridTable True <?> "table"
@@ -915,10 +915,10 @@ table = multilineTable False <|> simpleTable True <|>
918−inline :: GenParser Char ParserState Inline
918+inline :: Parsec [Char] ParserState Inline
919inline = choice inlineParsers <?> "inline"
919inline = choice inlineParsers <?> "inline"
921−inlineParsers :: [GenParser Char ParserState Inline]
921+inlineParsers :: [Parsec [Char] ParserState Inline]
922inlineParsers = [ whitespace
922inlineParsers = [ whitespace
924 , endline
924 , endline
@@ -945,7 +945,7 @@ inlineParsers = [ whitespace
946 , ltSign ]
946 , ltSign ]
948−escapedChar' :: GenParser Char ParserState Char
948+escapedChar' :: Parsec [Char] ParserState Char
949escapedChar' = try $ do
949escapedChar' = try $ do
950 char '\\'
950 char '\\'
951 state <- getState
951 state <- getState
@@ -953,7 +953,7 @@ escapedChar' = try $ do
953 then oneOf "\\`*_{}[]()>#+-.!~"
953 then oneOf "\\`*_{}[]()>#+-.!~"
954 else satisfy (not . isAlphaNum)
954 else satisfy (not . isAlphaNum)
956−escapedChar :: GenParser Char ParserState Inline
956+escapedChar :: Parsec [Char] ParserState Inline
957escapedChar = do
957escapedChar = do
958 result <- escapedChar'
958 result <- escapedChar'
959 return $ case result of
959 return $ case result of
@@ -961,7 +961,7 @@ escapedChar = do
961 '\n' -> LineBreak -- "\[newline]" is a linebreak
961 '\n' -> LineBreak -- "\[newline]" is a linebreak
962 _ -> Str [result]
962 _ -> Str [result]
964−ltSign :: GenParser Char ParserState Inline
964+ltSign :: Parsec [Char] ParserState Inline
965ltSign = do
965ltSign = do
966 st <- getState
966 st <- getState
967 if stateStrict st
967 if stateStrict st
@@ -969,7 +969,7 @@ ltSign = do
969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
970 return $ Str ['<']
970 return $ Str ['<']
972−exampleRef :: GenParser Char ParserState Inline
972+exampleRef :: Parsec [Char] ParserState Inline
973exampleRef = try $ do
973exampleRef = try $ do
975 lab <- many1 (alphaNum <|> oneOf "-_")
975 lab <- many1 (alphaNum <|> oneOf "-_")
@@ -977,7 +977,7 @@ exampleRef = try $ do
977 -- later. See the end of parseMarkdown.
977 -- later. See the end of parseMarkdown.
978 return $ Str $ '@' : lab
978 return $ Str $ '@' : lab
980−symbol :: GenParser Char ParserState Inline
980+symbol :: Parsec [Char] ParserState Inline
981symbol = do
981symbol = do
982 result <- noneOf "<\\\n\t "
982 result <- noneOf "<\\\n\t "
983 <|> try (do lookAhead $ char '\\'
983 <|> try (do lookAhead $ char '\\'
@@ -986,7 +986,7 @@ symbol = do
986 return $ Str [result]
986 return $ Str [result]
988-- parses inline code, between n `s and n `s
988-- parses inline code, between n `s and n `s
989−code :: GenParser Char ParserState Inline
989+code :: Parsec [Char] ParserState Inline
990code = try $ do
990code = try $ do
991 starts <- many1 (char '`')
991 starts <- many1 (char '`')
992 skipSpaces
992 skipSpaces
@@ -997,26 +997,26 @@ code = try $ do
997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
1000−mathWord :: GenParser Char st [Char]
1000+mathWord :: Parsec [Char] st [Char]
1001mathWord = liftM concat $ many1 mathChunk
1001mathWord = liftM concat $ many1 mathChunk
1003−mathChunk :: GenParser Char st [Char]
1003+mathChunk :: Parsec [Char] st [Char]
1004mathChunk = do char '\\'
1004mathChunk = do char '\\'
1005 c <- anyChar
1005 c <- anyChar
1006 return ['\\',c]
1006 return ['\\',c]
1007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1009−math :: GenParser Char ParserState Inline
1009+math :: Parsec [Char] ParserState Inline
1010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1013−mathDisplay :: GenParser Char ParserState String
1013+mathDisplay :: Parsec [Char] ParserState String
1014mathDisplay = try $ do
1014mathDisplay = try $ do
1015 failIfStrict
1015 failIfStrict
1016 string "$$"
1016 string "$$"
1017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1019−mathInline :: GenParser Char ParserState String
1019+mathInline :: Parsec [Char] ParserState String
1020mathInline = try $ do
1020mathInline = try $ do
1021 failIfStrict
1021 failIfStrict
1022 char '$'
1022 char '$'
@@ -1028,7 +1028,7 @@ mathInline = try $ do
1029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1030-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1030-- 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
1032fours = try $ do
1032fours = try $ do
1033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1034 count 2 $ satisfy (==x)
1034 count 2 $ satisfy (==x)
@@ -1037,9 +1037,9 @@ fours = try $ do
1038-- | Parses a list of inlines between start and end delimiters.
1038-- | Parses a list of inlines between start and end delimiters.
1039inlinesBetween :: (Show b)
1039inlinesBetween :: (Show b)
1040− => GenParser Char ParserState a
1040+ => Parsec [Char] ParserState a
1041− -> GenParser Char ParserState b
1041+ -> Parsec [Char] ParserState b
1042− -> GenParser Char ParserState [Inline]
1042+ -> Parsec [Char] ParserState [Inline]
1043inlinesBetween start end =
1043inlinesBetween start end =
1044 normalizeSpaces `liftM` try (start >> many1Till inner end)
1044 normalizeSpaces `liftM` try (start >> many1Till inner end)
1045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
1045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
@@ -1047,8 +1047,8 @@ inlinesBetween start end =
1048-- This is used to prevent exponential blowups for things like:
1048-- This is used to prevent exponential blowups for things like:
1049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1050−nested :: GenParser Char ParserState a
1050+nested :: Parsec [Char] ParserState a
1051− -> GenParser Char ParserState a
1051+ -> Parsec [Char] ParserState a
1052nested p = do
1052nested p = do
1053 nestlevel <- stateMaxNestingLevel `fmap` getState
1053 nestlevel <- stateMaxNestingLevel `fmap` getState
1054 guard $ nestlevel > 0
1054 guard $ nestlevel > 0
@@ -1057,7 +1057,7 @@ nested p = do
1057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1058 return res
1058 return res
1060−emph :: GenParser Char ParserState Inline
1060+emph :: Parsec [Char] ParserState Inline
1061emph = Emph `fmap` nested
1061emph = Emph `fmap` nested
1062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1063 where starStart = char '*' >> lookAhead nonspaceChar
1063 where starStart = char '*' >> lookAhead nonspaceChar
@@ -1065,7 +1065,7 @@ emph = Emph `fmap` nested
1065 ulStart = char '_' >> lookAhead nonspaceChar
1065 ulStart = char '_' >> lookAhead nonspaceChar
1066 ulEnd = notFollowedBy' strong >> char '_'
1066 ulEnd = notFollowedBy' strong >> char '_'
1068−strong :: GenParser Char ParserState Inline
1068+strong :: Parsec [Char] ParserState Inline
1069strong = Strong `liftM` nested
1069strong = Strong `liftM` nested
1070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1071 where starStart = string "**" >> lookAhead nonspaceChar
1071 where starStart = string "**" >> lookAhead nonspaceChar
@@ -1073,32 +1073,32 @@ strong = Strong `liftM` nested
1073 ulStart = string "__" >> lookAhead nonspaceChar
1073 ulStart = string "__" >> lookAhead nonspaceChar
1074 ulEnd = try $ string "__"
1074 ulEnd = try $ string "__"
1076−strikeout :: GenParser Char ParserState Inline
1076+strikeout :: Parsec [Char] ParserState Inline
1077strikeout = Strikeout `liftM`
1077strikeout = Strikeout `liftM`
1078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1079 where strikeStart = string "~~" >> lookAhead nonspaceChar
1079 where strikeStart = string "~~" >> lookAhead nonspaceChar
1080 >> notFollowedBy (char '~')
1080 >> notFollowedBy (char '~')
1081 strikeEnd = try $ string "~~"
1081 strikeEnd = try $ string "~~"
1083−superscript :: GenParser Char ParserState Inline
1083+superscript :: Parsec [Char] ParserState Inline
1084superscript = failIfStrict >> enclosed (char '^') (char '^')
1084superscript = failIfStrict >> enclosed (char '^') (char '^')
1085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1086 return . Superscript
1086 return . Superscript
1088−subscript :: GenParser Char ParserState Inline
1088+subscript :: Parsec [Char] ParserState Inline
1089subscript = failIfStrict >> enclosed (char '~') (char '~')
1089subscript = failIfStrict >> enclosed (char '~') (char '~')
1090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1091 return . Subscript
1091 return . Subscript
1093−whitespace :: GenParser Char ParserState Inline
1093+whitespace :: Parsec [Char] ParserState Inline
1094whitespace = spaceChar >>
1094whitespace = spaceChar >>
1095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1098−nonEndline :: GenParser Char st Char
1098+nonEndline :: Parsec [Char] st Char
1099nonEndline = satisfy (/='\n')
1099nonEndline = satisfy (/='\n')
1101−str :: GenParser Char ParserState Inline
1101+str :: Parsec [Char] ParserState Inline
1103 smart <- stateSmart `fmap` getState
1103 smart <- stateSmart `fmap` getState
1104 a <- alphaNum
1104 a <- alphaNum
@@ -1136,7 +1136,7 @@ likelyAbbrev x =
1136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1138-- an endline character that can be treated as a space, not a structural break
1138-- 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
1140endline = try $ do
1140endline = try $ do
1142 notFollowedBy blankline
1142 notFollowedBy blankline
@@ -1155,20 +1155,20 @@ endline = try $ do
1157-- a reference label for a link
1157-- a reference label for a link
1158−reference :: GenParser Char ParserState [Inline]
1158+reference :: Parsec [Char] ParserState [Inline]
1159reference = do notFollowedBy' (string "[^") -- footnote reference
1159reference = do notFollowedBy' (string "[^") -- footnote reference
1160 result <- inlinesInBalancedBrackets inline
1160 result <- inlinesInBalancedBrackets inline
1161 return $ normalizeSpaces result
1161 return $ normalizeSpaces result
1163-- source for a link, with optional title
1163-- source for a link, with optional title
1164−source :: GenParser Char ParserState (String, [Char])
1164+source :: Parsec [Char] ParserState (String, [Char])
1166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1167 -- the following is needed for cases like: [ref](/url(a).
1167 -- the following is needed for cases like: [ref](/url(a).
1168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1170-- auxiliary function for source
1170-- auxiliary function for source
1171−source' :: GenParser Char ParserState (String, [Char])
1171+source' :: Parsec [Char] ParserState (String, [Char])
1172source' = do
1172source' = do
1173 skipSpaces
1173 skipSpaces
1174 let nl = char '\n' >>~ notFollowedBy blankline
1174 let nl = char '\n' >>~ notFollowedBy blankline
@@ -1186,7 +1186,7 @@ source' = do
1187 return (escapeURI $ removeTrailingSpace src, tit)
1187 return (escapeURI $ removeTrailingSpace src, tit)
1189−linkTitle :: GenParser Char ParserState String
1189+linkTitle :: Parsec [Char] ParserState String
1190linkTitle = try $ do
1190linkTitle = try $ do
1191 (many1 spaceChar >> option '\n' newline) <|> newline
1191 (many1 spaceChar >> option '\n' newline) <|> newline
1192 skipSpaces
1192 skipSpaces
@@ -1194,7 +1194,7 @@ linkTitle = try $ do
1194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1195 return $ fromEntities tit
1195 return $ fromEntities tit
1197−link :: GenParser Char ParserState Inline
1197+link :: Parsec [Char] ParserState Inline
1198link = try $ do
1198link = try $ do
1199 lab <- reference
1199 lab <- reference
1200 (src, tit) <- source <|> referenceLink lab
1200 (src, tit) <- source <|> referenceLink lab
@@ -1207,7 +1207,7 @@ delinkify = bottomUp $ concatMap go
1208-- a link like [this][ref] or [this][] or [this]
1208-- a link like [this][ref] or [this][] or [this]
1209referenceLink :: [Inline]
1209referenceLink :: [Inline]
1210− -> GenParser Char ParserState (String, [Char])
1210+ -> Parsec [Char] ParserState (String, [Char])
1211referenceLink lab = do
1211referenceLink lab = do
1212 ref <- option [] (try (optional (char ' ') >>
1212 ref <- option [] (try (optional (char ' ') >>
1213 optional (newline >> skipSpaces) >> reference))
1213 optional (newline >> skipSpaces) >> reference))
@@ -1217,7 +1217,7 @@ referenceLink lab = do
1217 Nothing -> fail "no corresponding key"
1217 Nothing -> fail "no corresponding key"
1218 Just target -> return target
1218 Just target -> return target
1220−autoLink :: GenParser Char ParserState Inline
1220+autoLink :: Parsec [Char] ParserState Inline
1221autoLink = try $ do
1221autoLink = try $ do
1222 char '<'
1222 char '<'
1223 (orig, src) <- uri <|> emailAddress
1223 (orig, src) <- uri <|> emailAddress
@@ -1227,14 +1227,14 @@ autoLink = try $ do
1227 then Link [Str orig] (src, "")
1227 then Link [Str orig] (src, "")
1228 else Link [Code ("",["url"],[]) orig] (src, "")
1228 else Link [Code ("",["url"],[]) orig] (src, "")
1230−image :: GenParser Char ParserState Inline
1230+image :: Parsec [Char] ParserState Inline
1231image = try $ do
1231image = try $ do
1232 char '!'
1232 char '!'
1233 lab <- reference
1233 lab <- reference
1234 (src, tit) <- source <|> referenceLink lab
1234 (src, tit) <- source <|> referenceLink lab
1235 return $ Image lab (src,tit)
1235 return $ Image lab (src,tit)
1237−note :: GenParser Char ParserState Inline
1237+note :: Parsec [Char] ParserState Inline
1238note = try $ do
1238note = try $ do
1239 failIfStrict
1239 failIfStrict
1240 ref <- noteMarker
1240 ref <- noteMarker
@@ -1251,21 +1251,21 @@ note = try $ do
1251 updateState $ \st -> st{ stateNotes = notes }
1251 updateState $ \st -> st{ stateNotes = notes }
1252 return $ Note contents
1252 return $ Note contents
1254−inlineNote :: GenParser Char ParserState Inline
1254+inlineNote :: Parsec [Char] ParserState Inline
1255inlineNote = try $ do
1255inlineNote = try $ do
1256 failIfStrict
1256 failIfStrict
1257 char '^'
1257 char '^'
1258 contents <- inlinesInBalancedBrackets inline
1258 contents <- inlinesInBalancedBrackets inline
1259 return $ Note [Para contents]
1259 return $ Note [Para contents]
1261−rawLaTeXInline' :: GenParser Char ParserState Inline
1261+rawLaTeXInline' :: Parsec [Char] ParserState Inline
1262rawLaTeXInline' = try $ do
1262rawLaTeXInline' = try $ do
1263 failIfStrict
1263 failIfStrict
1264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1265 RawInline _ s <- rawLaTeXInline
1265 RawInline _ s <- rawLaTeXInline
1266 return $ RawInline "tex" s -- "tex" because it might be context or latex
1266 return $ RawInline "tex" s -- "tex" because it might be context or latex
1268−rawConTeXtEnvironment :: GenParser Char st String
1268+rawConTeXtEnvironment :: Parsec [Char] st String
1269rawConTeXtEnvironment = try $ do
1269rawConTeXtEnvironment = try $ do
1270 string "\\start"
1270 string "\\start"
1271 completion <- inBrackets (letter <|> digit <|> spaceChar)
1271 completion <- inBrackets (letter <|> digit <|> spaceChar)
@@ -1274,14 +1274,14 @@ rawConTeXtEnvironment = try $ do
1274 (try $ string "\\stop" >> string completion)
1274 (try $ string "\\stop" >> string completion)
1275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1277−inBrackets :: (GenParser Char st Char) -> GenParser Char st String
1277+inBrackets :: (Parsec [Char] st Char) -> Parsec [Char] st String
1278inBrackets parser = do
1278inBrackets parser = do
1279 char '['
1279 char '['
1280 contents <- many parser
1280 contents <- many parser
1281 char ']'
1281 char ']'
1282 return $ "[" ++ contents ++ "]"
1282 return $ "[" ++ contents ++ "]"
1284−rawHtmlInline :: GenParser Char ParserState Inline
1284+rawHtmlInline :: Parsec [Char] ParserState Inline
1285rawHtmlInline = do
1285rawHtmlInline = do
1286 st <- getState
1286 st <- getState
1287 (_,result) <- if stateStrict st
1287 (_,result) <- if stateStrict st
@@ -1291,20 +1291,20 @@ rawHtmlInline = do
1292-- Citations
1292-- Citations
1294−cite :: GenParser Char ParserState Inline
1294+cite :: Parsec [Char] ParserState Inline
1295cite = do
1295cite = do
1296 failIfStrict
1296 failIfStrict
1297 citations <- textualCite <|> normalCite
1297 citations <- textualCite <|> normalCite
1298 return $ Cite citations []
1298 return $ Cite citations []
1300−spnl :: GenParser Char st ()
1300+spnl :: Parsec [Char] st ()
1301spnl = try $ do
1301spnl = try $ do
1302 skipSpaces
1302 skipSpaces
1303 optional newline
1303 optional newline
1304 skipSpaces
1304 skipSpaces
1305 notFollowedBy (char '\n')
1305 notFollowedBy (char '\n')
1307−textualCite :: GenParser Char ParserState [Citation]
1307+textualCite :: Parsec [Char] ParserState [Citation]
1308textualCite = try $ do
1308textualCite = try $ do
1309 (_, key) <- citeKey
1309 (_, key) <- citeKey
1310 let first = Citation{ citationId = key
1310 let first = Citation{ citationId = key
@@ -1319,7 +1319,7 @@ textualCite = try $ do
1319 then option [first] $ bareloc first
1319 then option [first] $ bareloc first
1320 else return $ first : rest
1320 else return $ first : rest
1322−bareloc :: Citation -> GenParser Char ParserState [Citation]
1322+bareloc :: Citation -> Parsec [Char] ParserState [Citation]
1323bareloc c = try $ do
1323bareloc c = try $ do
1325 char '['
1325 char '['
@@ -1329,7 +1329,7 @@ bareloc c = try $ do
1329 char ']'
1329 char ']'
1330 return $ c{ citationSuffix = suff } : rest
1330 return $ c{ citationSuffix = suff } : rest
1332−normalCite :: GenParser Char ParserState [Citation]
1332+normalCite :: Parsec [Char] ParserState [Citation]
1333normalCite = try $ do
1333normalCite = try $ do
1334 char '['
1334 char '['
@@ -1338,7 +1338,7 @@ normalCite = try $ do
1338 char ']'
1338 char ']'
1339 return citations
1339 return citations
1341−citeKey :: GenParser Char ParserState (Bool, String)
1341+citeKey :: Parsec [Char] ParserState (Bool, String)
1342citeKey = try $ do
1342citeKey = try $ do
1343 suppress_author <- option False (char '-' >> return True)
1343 suppress_author <- option False (char '-' >> return True)
1344 char '@'
1344 char '@'
@@ -1350,7 +1350,7 @@ citeKey = try $ do
1350 guard $ key `elem` stateCitations st
1350 guard $ key `elem` stateCitations st
1351 return (suppress_author, key)
1351 return (suppress_author, key)
1353−suffix :: GenParser Char ParserState [Inline]
1353+suffix :: Parsec [Char] ParserState [Inline]
1354suffix = try $ do
1354suffix = try $ do
1355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
1355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
@@ -1359,14 +1359,14 @@ suffix = try $ do
1359 then Space : rest
1359 then Space : rest
1360 else rest
1360 else rest
1362−prefix :: GenParser Char ParserState [Inline]
1362+prefix :: Parsec [Char] ParserState [Inline]
1363prefix = liftM normalizeSpaces $
1363prefix = liftM normalizeSpaces $
1364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1366−citeList :: GenParser Char ParserState [Citation]
1366+citeList :: Parsec [Char] ParserState [Citation]
1367citeList = sepBy1 citation (try $ char ';' >> spnl)
1367citeList = sepBy1 citation (try $ char ';' >> spnl)
1369−citation :: GenParser Char ParserState Citation
1369+citation :: Parsec [Char] ParserState Citation
1370citation = try $ do
1370citation = try $ do
1371 pref <- prefix
1371 pref <- prefix
1372 (suppress_author, key) <- citeKey
1372 (suppress_author, key) <- citeKey