@@ -82,14 +82,14 @@ isBlank _ = False
82-- auxiliary functions
82-- auxiliary functions
85−indentSpaces :: Parsec [Char] ParserState [Char]
85+indentSpaces :: Parser [Char] ParserState [Char]
86indentSpaces = try $ do
86indentSpaces = try $ do
87 state <- getState
87 state <- getState
88 let tabStop = stateTabStop state
88 let tabStop = stateTabStop state
89 count tabStop (char ' ') <|>
89 count tabStop (char ' ') <|>
90 string "\t" <?> "indentation"
90 string "\t" <?> "indentation"
92−nonindentSpaces :: Parsec [Char] ParserState [Char]
92+nonindentSpaces :: Parser [Char] ParserState [Char]
93nonindentSpaces = do
93nonindentSpaces = do
94 state <- getState
94 state <- getState
95 let tabStop = stateTabStop state
95 let tabStop = stateTabStop state
@@ -98,30 +98,30 @@ nonindentSpaces = do
98 then return sps
98 then return sps
99 else unexpected "indented line"
99 else unexpected "indented line"
101−skipNonindentSpaces :: Parsec [Char] ParserState ()
101+skipNonindentSpaces :: Parser [Char] ParserState ()
102skipNonindentSpaces = do
102skipNonindentSpaces = do
103 state <- getState
103 state <- getState
104 atMostSpaces (stateTabStop state - 1)
104 atMostSpaces (stateTabStop state - 1)
106−atMostSpaces :: Int -> Parsec [Char] ParserState ()
106+atMostSpaces :: Int -> Parser [Char] ParserState ()
107atMostSpaces 0 = notFollowedBy (char ' ')
107atMostSpaces 0 = notFollowedBy (char ' ')
108atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
108atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
110−litChar :: Parsec [Char] ParserState Char
110+litChar :: Parser [Char] ParserState Char
111litChar = escapedChar'
111litChar = escapedChar'
112 <|> noneOf "\n"
112 <|> noneOf "\n"
113 <|> (newline >> notFollowedBy blankline >> return ' ')
113 <|> (newline >> notFollowedBy blankline >> return ' ')
115-- | Fail unless we're at beginning of a line.
115-- | Fail unless we're at beginning of a line.
116−failUnlessBeginningOfLine :: Parsec [tok] st ()
116+failUnlessBeginningOfLine :: Parser [tok] st ()
117failUnlessBeginningOfLine = do
117failUnlessBeginningOfLine = do
118 pos <- getPosition
118 pos <- getPosition
119 if sourceColumn pos == 1 then return () else fail "not beginning of line"
119 if sourceColumn pos == 1 then return () else fail "not beginning of line"
121-- | Parse a sequence of inline elements between square brackets,
121-- | Parse a sequence of inline elements between square brackets,
122-- including inlines between balanced pairs of square brackets.
122-- including inlines between balanced pairs of square brackets.
123−inlinesInBalancedBrackets :: Parsec [Char] ParserState Inline
123+inlinesInBalancedBrackets :: Parser [Char] ParserState Inline
124− -> Parsec [Char] ParserState [Inline]
124+ -> Parser [Char] ParserState [Inline]
125inlinesInBalancedBrackets parser = try $ do
125inlinesInBalancedBrackets parser = try $ do
127 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
127 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
@@ -136,7 +136,7 @@ inlinesInBalancedBrackets parser = try $ do
136-- document structure
136-- document structure
139−titleLine :: Parsec [Char] ParserState [Inline]
139+titleLine :: Parser [Char] ParserState [Inline]
140titleLine = try $ do
140titleLine = try $ do
142 skipSpaces
142 skipSpaces
@@ -145,7 +145,7 @@ titleLine = try $ do
146 return $ normalizeSpaces res
146 return $ normalizeSpaces res
148−authorsLine :: Parsec [Char] ParserState [[Inline]]
148+authorsLine :: Parser [Char] ParserState [[Inline]]
149authorsLine = try $ do
149authorsLine = try $ do
151 skipSpaces
151 skipSpaces
@@ -156,14 +156,14 @@ authorsLine = try $ do
157 return $ filter (not . null) $ map normalizeSpaces authors
157 return $ filter (not . null) $ map normalizeSpaces authors
159−dateLine :: Parsec [Char] ParserState [Inline]
159+dateLine :: Parser [Char] ParserState [Inline]
160dateLine = try $ do
160dateLine = try $ do
162 skipSpaces
162 skipSpaces
163 date <- manyTill inline newline
163 date <- manyTill inline newline
164 return $ normalizeSpaces date
164 return $ normalizeSpaces date
166−titleBlock :: Parsec [Char] ParserState ([Inline], [[Inline]], [Inline])
166+titleBlock :: Parser [Char] ParserState ([Inline], [[Inline]], [Inline])
167titleBlock = try $ do
167titleBlock = try $ do
168 failIfStrict
168 failIfStrict
169 title <- option [] titleLine
169 title <- option [] titleLine
@@ -172,7 +172,7 @@ titleBlock = try $ do
172 optional blanklines
172 optional blanklines
173 return (title, author, date)
173 return (title, author, date)
175−parseMarkdown :: Parsec [Char] ParserState Pandoc
175+parseMarkdown :: Parser [Char] ParserState Pandoc
176parseMarkdown = do
176parseMarkdown = do
177 -- markdown allows raw HTML
177 -- markdown allows raw HTML
178 updateState (\state -> state { stateParseRaw = True })
178 updateState (\state -> state { stateParseRaw = True })
@@ -210,7 +210,7 @@ parseMarkdown = do
210-- initial pass for references and notes
210-- initial pass for references and notes
213−referenceKey :: Parsec [Char] ParserState [Char]
213+referenceKey :: Parser [Char] ParserState [Char]
214referenceKey = try $ do
214referenceKey = try $ do
215 startPos <- getPosition
215 startPos <- getPosition
216 skipNonindentSpaces
216 skipNonindentSpaces
@@ -237,7 +237,7 @@ referenceKey = try $ do
237 -- return blanks so line count isn't affected
237 -- return blanks so line count isn't affected
238 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
238 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
240−referenceTitle :: Parsec [Char] ParserState String
240+referenceTitle :: Parser [Char] ParserState String
241referenceTitle = try $ do
241referenceTitle = try $ do
242 skipSpaces >> optional newline >> skipSpaces
242 skipSpaces >> optional newline >> skipSpaces
243 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
243 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
@@ -246,23 +246,23 @@ referenceTitle = try $ do
246 notFollowedBy (noneOf ")\n")))
246 notFollowedBy (noneOf ")\n")))
247 return $ fromEntities tit
247 return $ fromEntities tit
249−noteMarker :: Parsec [Char] ParserState [Char]
249+noteMarker :: Parser [Char] ParserState [Char]
250noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
250noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
252−rawLine :: Parsec [Char] ParserState [Char]
252+rawLine :: Parser [Char] ParserState [Char]
253rawLine = try $ do
253rawLine = try $ do
254 notFollowedBy blankline
254 notFollowedBy blankline
255 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
255 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
256 optional indentSpaces
256 optional indentSpaces
259−rawLines :: Parsec [Char] ParserState [Char]
259+rawLines :: Parser [Char] ParserState [Char]
260rawLines = do
260rawLines = do
261 first <- anyLine
261 first <- anyLine
262 rest <- many rawLine
262 rest <- many rawLine
263 return $ unlines (first:rest)
263 return $ unlines (first:rest)
265−noteBlock :: Parsec [Char] ParserState [Char]
265+noteBlock :: Parser [Char] ParserState [Char]
266noteBlock = try $ do
266noteBlock = try $ do
267 startPos <- getPosition
267 startPos <- getPosition
268 skipNonindentSpaces
268 skipNonindentSpaces
@@ -286,10 +286,10 @@ noteBlock = try $ do
286-- parsing blocks
286-- parsing blocks
289−parseBlocks :: Parsec [Char] ParserState [Block]
289+parseBlocks :: Parser [Char] ParserState [Block]
290parseBlocks = manyTill block eof
290parseBlocks = manyTill block eof
292−block :: Parsec [Char] ParserState Block
292+block :: Parser [Char] ParserState Block
293block = do
293block = do
294 st <- getState
294 st <- getState
295 choice (if stateStrict st
295 choice (if stateStrict st
@@ -324,10 +324,10 @@ block = do
324-- header blocks
324-- header blocks
327−header :: Parsec [Char] ParserState Block
327+header :: Parser [Char] ParserState Block
328header = setextHeader <|> atxHeader <?> "header"
328header = setextHeader <|> atxHeader <?> "header"
330−atxHeader :: Parsec [Char] ParserState Block
330+atxHeader :: Parser [Char] ParserState Block
331atxHeader = try $ do
331atxHeader = try $ do
332 level <- many1 (char '#') >>= return . length
332 level <- many1 (char '#') >>= return . length
333 notFollowedBy (char '.' <|> char ')') -- this would be a list
333 notFollowedBy (char '.' <|> char ')') -- this would be a list
@@ -335,10 +335,10 @@ atxHeader = try $ do
335 text <- manyTill inline atxClosing >>= return . normalizeSpaces
335 text <- manyTill inline atxClosing >>= return . normalizeSpaces
336 return $ Header level text
336 return $ Header level text
338−atxClosing :: Parsec [Char] st [Char]
338+atxClosing :: Parser [Char] st [Char]
339atxClosing = try $ skipMany (char '#') >> blanklines
339atxClosing = try $ skipMany (char '#') >> blanklines
341−setextHeader :: Parsec [Char] ParserState Block
341+setextHeader :: Parser [Char] ParserState Block
342setextHeader = try $ do
342setextHeader = try $ do
343 -- This lookahead prevents us from wasting time parsing Inlines
343 -- This lookahead prevents us from wasting time parsing Inlines
344 -- unless necessary -- it gives a significant performance boost.
344 -- unless necessary -- it gives a significant performance boost.
@@ -354,7 +354,7 @@ setextHeader = try $ do
354-- hrule block
354-- hrule block
357−hrule :: Parsec [Char] st Block
357+hrule :: Parser [Char] st Block
358hrule = try $ do
358hrule = try $ do
359 skipSpaces
359 skipSpaces
360 start <- satisfy isHruleChar
360 start <- satisfy isHruleChar
@@ -368,12 +368,12 @@ hrule = try $ do
368-- code blocks
368-- code blocks
371−indentedLine :: Parsec [Char] ParserState [Char]
371+indentedLine :: Parser [Char] ParserState [Char]
372indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
372indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
374blockDelimiter :: (Char -> Bool)
374blockDelimiter :: (Char -> Bool)
375 -> Maybe Int
375 -> Maybe Int
376− -> Parsec [Char] st (Int, (String, [String], [(String, String)]), Char)
376+ -> Parser [Char] st (Int, (String, [String], [(String, String)]), Char)
377blockDelimiter f len = try $ do
377blockDelimiter f len = try $ do
378 c <- lookAhead (satisfy f)
378 c <- lookAhead (satisfy f)
379 size <- case len of
379 size <- case len of
@@ -387,7 +387,7 @@ blockDelimiter f len = try $ do
387 blankline
387 blankline
388 return (size, attr, c)
388 return (size, attr, c)
390−attributes :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
390+attributes :: Parser [Char] st ([Char], [[Char]], [([Char], [Char])])
391attributes = try $ do
391attributes = try $ do
@@ -399,28 +399,28 @@ attributes = try $ do
399 | otherwise = firstNonNull xs
399 | otherwise = firstNonNull xs
400 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
400 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
402−attribute :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
402+attribute :: Parser [Char] st ([Char], [[Char]], [([Char], [Char])])
403attribute = identifierAttr <|> classAttr <|> keyValAttr
403attribute = identifierAttr <|> classAttr <|> keyValAttr
405−identifier :: Parsec [Char] st [Char]
405+identifier :: Parser [Char] st [Char]
406identifier = do
406identifier = do
407 first <- letter
407 first <- letter
408 rest <- many $ alphaNum <|> oneOf "-_:."
408 rest <- many $ alphaNum <|> oneOf "-_:."
409 return (first:rest)
409 return (first:rest)
411−identifierAttr :: Parsec [Char] st ([Char], [a], [a1])
411+identifierAttr :: Parser [Char] st ([Char], [a], [a1])
412identifierAttr = try $ do
412identifierAttr = try $ do
414 result <- identifier
414 result <- identifier
415 return (result,[],[])
415 return (result,[],[])
417−classAttr :: Parsec [Char] st ([Char], [[Char]], [a])
417+classAttr :: Parser [Char] st ([Char], [[Char]], [a])
418classAttr = try $ do
418classAttr = try $ do
420 result <- identifier
420 result <- identifier
421 return ("",[result],[])
421 return ("",[result],[])
423−keyValAttr :: Parsec [Char] st ([Char], [a], [([Char], [Char])])
423+keyValAttr :: Parser [Char] st ([Char], [a], [([Char], [Char])])
424keyValAttr = try $ do
424keyValAttr = try $ do
425 key <- identifier
425 key <- identifier
@@ -429,14 +429,14 @@ keyValAttr = try $ do
429 <|> many nonspaceChar
429 <|> many nonspaceChar
430 return ("",[],[(key,val)])
430 return ("",[],[(key,val)])
432−codeBlockDelimited :: Parsec [Char] st Block
432+codeBlockDelimited :: Parser [Char] st Block
433codeBlockDelimited = try $ do
433codeBlockDelimited = try $ do
434 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
434 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
435 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
435 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
436 blanklines
436 blanklines
437 return $ CodeBlock attr $ intercalate "\n" contents
437 return $ CodeBlock attr $ intercalate "\n" contents
439−codeBlockIndented :: Parsec [Char] ParserState Block
439+codeBlockIndented :: Parser [Char] ParserState Block
440codeBlockIndented = do
440codeBlockIndented = do
441 contents <- many1 (indentedLine <|>
441 contents <- many1 (indentedLine <|>
442 try (do b <- blanklines
442 try (do b <- blanklines
@@ -447,7 +447,7 @@ codeBlockIndented = do
447 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
447 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
448 stripTrailingNewlines $ concat contents
448 stripTrailingNewlines $ concat contents
450−lhsCodeBlock :: Parsec [Char] ParserState Block
450+lhsCodeBlock :: Parser [Char] ParserState Block
451lhsCodeBlock = do
451lhsCodeBlock = do
452 failUnlessLHS
452 failUnlessLHS
453 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
453 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
@@ -455,7 +455,7 @@ lhsCodeBlock = do
455 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
455 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
456 lhsCodeBlockInverseBird
456 lhsCodeBlockInverseBird
458−lhsCodeBlockLaTeX :: Parsec [Char] ParserState String
458+lhsCodeBlockLaTeX :: Parser [Char] ParserState String
459lhsCodeBlockLaTeX = try $ do
459lhsCodeBlockLaTeX = try $ do
460 string "\\begin{code}"
460 string "\\begin{code}"
461 manyTill spaceChar newline
461 manyTill spaceChar newline
@@ -463,13 +463,13 @@ lhsCodeBlockLaTeX = try $ do
463 blanklines
463 blanklines
464 return $ stripTrailingNewlines contents
464 return $ stripTrailingNewlines contents
466−lhsCodeBlockBird :: Parsec [Char] ParserState String
466+lhsCodeBlockBird :: Parser [Char] ParserState String
467lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
467lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
469−lhsCodeBlockInverseBird :: Parsec [Char] ParserState String
469+lhsCodeBlockInverseBird :: Parser [Char] ParserState String
470lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
470lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
472−lhsCodeBlockBirdWith :: Char -> Parsec [Char] ParserState String
472+lhsCodeBlockBirdWith :: Char -> Parser [Char] ParserState String
473lhsCodeBlockBirdWith c = try $ do
473lhsCodeBlockBirdWith c = try $ do
474 pos <- getPosition
474 pos <- getPosition
475 when (sourceColumn pos /= 1) $ fail "Not in first column"
475 when (sourceColumn pos /= 1) $ fail "Not in first column"
@@ -481,7 +481,7 @@ lhsCodeBlockBirdWith c = try $ do
481 blanklines
481 blanklines
482 return $ intercalate "\n" lns'
482 return $ intercalate "\n" lns'
484−birdTrackLine :: Char -> Parsec [Char] st [Char]
484+birdTrackLine :: Char -> Parser [Char] st [Char]
485birdTrackLine c = try $ do
485birdTrackLine c = try $ do
487 -- allow html tags on left margin:
487 -- allow html tags on left margin:
@@ -493,10 +493,10 @@ birdTrackLine c = try $ do
493-- block quotes
493-- block quotes
496−emailBlockQuoteStart :: Parsec [Char] ParserState Char
496+emailBlockQuoteStart :: Parser [Char] ParserState Char
497emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
497emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
499−emailBlockQuote :: Parsec [Char] ParserState [[Char]]
499+emailBlockQuote :: Parser [Char] ParserState [[Char]]
500emailBlockQuote = try $ do
500emailBlockQuote = try $ do
501 emailBlockQuoteStart
501 emailBlockQuoteStart
502 raw <- sepBy (many (nonEndline <|>
502 raw <- sepBy (many (nonEndline <|>
@@ -507,7 +507,7 @@ emailBlockQuote = try $ do
507 optional blanklines
507 optional blanklines
508 return raw
508 return raw
510−blockQuote :: Parsec [Char] ParserState Block
510+blockQuote :: Parser [Char] ParserState Block
511blockQuote = do
511blockQuote = do
512 raw <- emailBlockQuote
512 raw <- emailBlockQuote
513 -- parse the extracted block, which may contain various block elements:
513 -- parse the extracted block, which may contain various block elements:
@@ -518,7 +518,7 @@ blockQuote = do
518-- list blocks
518-- list blocks
521−bulletListStart :: Parsec [Char] ParserState ()
521+bulletListStart :: Parser [Char] ParserState ()
522bulletListStart = try $ do
522bulletListStart = try $ do
523 optional newline -- if preceded by a Plain block in a list context
523 optional newline -- if preceded by a Plain block in a list context
524 skipNonindentSpaces
524 skipNonindentSpaces
@@ -527,7 +527,7 @@ bulletListStart = try $ do
527 spaceChar
527 spaceChar
528 skipSpaces
528 skipSpaces
530−anyOrderedListStart :: Parsec [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
530+anyOrderedListStart :: Parser [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
531anyOrderedListStart = try $ do
531anyOrderedListStart = try $ do
532 optional newline -- if preceded by a Plain block in a list context
532 optional newline -- if preceded by a Plain block in a list context
533 skipNonindentSpaces
533 skipNonindentSpaces
@@ -547,11 +547,11 @@ anyOrderedListStart = try $ do
547 skipSpaces
547 skipSpaces
548 return (num, style, delim)
548 return (num, style, delim)
550−listStart :: Parsec [Char] ParserState ()
550+listStart :: Parser [Char] ParserState ()
551listStart = bulletListStart <|> (anyOrderedListStart >> return ())
551listStart = bulletListStart <|> (anyOrderedListStart >> return ())
553-- parse a line of a list item (start = parser for beginning of list item)
553-- parse a line of a list item (start = parser for beginning of list item)
554−listLine :: Parsec [Char] ParserState [Char]
554+listLine :: Parser [Char] ParserState [Char]
555listLine = try $ do
555listLine = try $ do
556 notFollowedBy blankline
556 notFollowedBy blankline
557 notFollowedBy' (do indentSpaces
557 notFollowedBy' (do indentSpaces
@@ -561,8 +561,8 @@ listLine = try $ do
561 return $ concat chunks ++ "\n"
561 return $ concat chunks ++ "\n"
563-- parse raw text for one list item, excluding start marker and continuations
563-- parse raw text for one list item, excluding start marker and continuations
564−rawListItem :: Parsec [Char] ParserState a
564+rawListItem :: Parser [Char] ParserState a
565− -> Parsec [Char] ParserState [Char]
565+ -> Parser [Char] ParserState [Char]
566rawListItem start = try $ do
566rawListItem start = try $ do
568 first <- listLine
568 first <- listLine
@@ -573,14 +573,14 @@ rawListItem start = try $ do
573-- continuation of a list item - indented and separated by blankline
573-- continuation of a list item - indented and separated by blankline
574-- or (in compact lists) endline.
574-- or (in compact lists) endline.
575-- note: nested lists are parsed as continuations
575-- note: nested lists are parsed as continuations
576−listContinuation :: Parsec [Char] ParserState [Char]
576+listContinuation :: Parser [Char] ParserState [Char]
577listContinuation = try $ do
577listContinuation = try $ do
578 lookAhead indentSpaces
578 lookAhead indentSpaces
579 result <- many1 listContinuationLine
579 result <- many1 listContinuationLine
580 blanks <- many blankline
580 blanks <- many blankline
581 return $ concat result ++ blanks
581 return $ concat result ++ blanks
583−listContinuationLine :: Parsec [Char] ParserState [Char]
583+listContinuationLine :: Parser [Char] ParserState [Char]
584listContinuationLine = try $ do
584listContinuationLine = try $ do
585 notFollowedBy blankline
585 notFollowedBy blankline
586 notFollowedBy' listStart
586 notFollowedBy' listStart
@@ -588,8 +588,8 @@ listContinuationLine = try $ do
588 result <- manyTill anyChar newline
588 result <- manyTill anyChar newline
589 return $ result ++ "\n"
589 return $ result ++ "\n"
591−listItem :: Parsec [Char] ParserState a
591+listItem :: Parser [Char] ParserState a
592− -> Parsec [Char] ParserState [Block]
592+ -> Parser [Char] ParserState [Block]
593listItem start = try $ do
593listItem start = try $ do
594 first <- rawListItem start
594 first <- rawListItem start
595 continuations <- many listContinuation
595 continuations <- many listContinuation
@@ -605,7 +605,7 @@ listItem start = try $ do
605 updateState (\st -> st {stateParserContext = oldContext})
605 updateState (\st -> st {stateParserContext = oldContext})
606 return contents
606 return contents
608−orderedList :: Parsec [Char] ParserState Block
608+orderedList :: Parser [Char] ParserState Block
609orderedList = try $ do
609orderedList = try $ do
610 (start, style, delim) <- lookAhead anyOrderedListStart
610 (start, style, delim) <- lookAhead anyOrderedListStart
611 items <- many1 $ listItem $ try $
611 items <- many1 $ listItem $ try $
@@ -614,13 +614,13 @@ orderedList = try $ do
614 orderedListMarker style delim
614 orderedListMarker style delim
615 return $ OrderedList (start, style, delim) $ compactify items
615 return $ OrderedList (start, style, delim) $ compactify items
617−bulletList :: Parsec [Char] ParserState Block
617+bulletList :: Parser [Char] ParserState Block
618bulletList =
618bulletList =
619 many1 (listItem bulletListStart) >>= return . BulletList . compactify
619 many1 (listItem bulletListStart) >>= return . BulletList . compactify
621-- definition lists
621-- definition lists
623−defListMarker :: Parsec [Char] ParserState ()
623+defListMarker :: Parser [Char] ParserState ()
624defListMarker = do
624defListMarker = do
625 sps <- nonindentSpaces
625 sps <- nonindentSpaces
626 char ':' <|> char '~'
626 char ':' <|> char '~'
@@ -632,7 +632,7 @@ defListMarker = do
632 else mzero
632 else mzero
633 return ()
633 return ()
635−definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
635+definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
636definitionListItem = try $ do
636definitionListItem = try $ do
637 -- first, see if this has any chance of being a definition list:
637 -- first, see if this has any chance of being a definition list:
638 lookAhead (anyLine >> optional blankline >> defListMarker)
638 lookAhead (anyLine >> optional blankline >> defListMarker)
@@ -646,7 +646,7 @@ definitionListItem = try $ do
646 updateState (\st -> st {stateParserContext = oldContext})
646 updateState (\st -> st {stateParserContext = oldContext})
647 return ((normalizeSpaces term), contents)
647 return ((normalizeSpaces term), contents)
649−defRawBlock :: Parsec [Char] ParserState [Char]
649+defRawBlock :: Parser [Char] ParserState [Char]
650defRawBlock = try $ do
650defRawBlock = try $ do
651 defListMarker
651 defListMarker
652 firstline <- anyLine
652 firstline <- anyLine
@@ -658,7 +658,7 @@ defRawBlock = try $ do
658 return $ unlines lns ++ trl
658 return $ unlines lns ++ trl
659 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
659 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
661−definitionList :: Parsec [Char] ParserState Block
661+definitionList :: Parser [Char] ParserState Block
662definitionList = do
662definitionList = do
663 items <- many1 definitionListItem
663 items <- many1 definitionListItem
664 -- "compactify" the definition list:
664 -- "compactify" the definition list:
@@ -687,7 +687,7 @@ isHtmlOrBlank (Space) = True
687isHtmlOrBlank (LineBreak) = True
687isHtmlOrBlank (LineBreak) = True
688isHtmlOrBlank _ = False
688isHtmlOrBlank _ = False
690−para :: Parsec [Char] ParserState Block
690+para :: Parser [Char] ParserState Block
691para = try $ do
691para = try $ do
692 result <- liftM normalizeSpaces $ many1 inline
692 result <- liftM normalizeSpaces $ many1 inline
693 guard $ not . all isHtmlOrBlank $ result
693 guard $ not . all isHtmlOrBlank $ result
@@ -698,17 +698,17 @@ para = try $ do
698 lookAhead (blockQuote <|> header) >> return "")
698 lookAhead (blockQuote <|> header) >> return "")
699 return $ Para result
699 return $ Para result
701−plain :: Parsec [Char] ParserState Block
701+plain :: Parser [Char] ParserState Block
702plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
702plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
705-- raw html
705-- raw html
708−htmlElement :: Parsec [Char] ParserState [Char]
708+htmlElement :: Parser [Char] ParserState [Char]
709htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
709htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
711−htmlBlock :: Parsec [Char] ParserState Block
711+htmlBlock :: Parser [Char] ParserState Block
712htmlBlock = try $ do
712htmlBlock = try $ do
713 failUnlessBeginningOfLine
713 failUnlessBeginningOfLine
714 first <- htmlElement
714 first <- htmlElement
@@ -716,12 +716,12 @@ htmlBlock = try $ do
716 finalNewlines <- many newline
716 finalNewlines <- many newline
717 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
717 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
719−strictHtmlBlock :: Parsec [Char] ParserState [Char]
719+strictHtmlBlock :: Parser [Char] ParserState [Char]
720strictHtmlBlock = do
720strictHtmlBlock = do
721 failUnlessBeginningOfLine
721 failUnlessBeginningOfLine
722 htmlInBalanced (not . isInlineTag)
722 htmlInBalanced (not . isInlineTag)
724−rawVerbatimBlock :: Parsec [Char] ParserState String
724+rawVerbatimBlock :: Parser [Char] ParserState String
725rawVerbatimBlock = try $ do
725rawVerbatimBlock = try $ do
726 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
726 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
727 t == "pre" || t == "style" || t == "script")
727 t == "pre" || t == "style" || t == "script")
@@ -729,7 +729,7 @@ rawVerbatimBlock = try $ do
729 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
729 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
730 return $ open ++ contents ++ renderTags [TagClose tag]
730 return $ open ++ contents ++ renderTags [TagClose tag]
732−rawTeXBlock :: Parsec [Char] ParserState Block
732+rawTeXBlock :: Parser [Char] ParserState Block
733rawTeXBlock = do
733rawTeXBlock = do
734 failIfStrict
734 failIfStrict
735 result <- liftM (RawBlock "latex") rawLaTeXBlock
735 result <- liftM (RawBlock "latex") rawLaTeXBlock
@@ -737,7 +737,7 @@ rawTeXBlock = do
738 return result
738 return result
740−rawHtmlBlocks :: Parsec [Char] ParserState Block
740+rawHtmlBlocks :: Parser [Char] ParserState Block
741rawHtmlBlocks = do
741rawHtmlBlocks = do
742 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
742 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
743 liftM snd (htmlTag isBlockTag)
743 liftM snd (htmlTag isBlockTag)
@@ -761,7 +761,7 @@ rawHtmlBlocks = do
761-- Parse a dashed line with optional trailing spaces; return its length
761-- Parse a dashed line with optional trailing spaces; return its length
762-- and the length including trailing space.
762-- and the length including trailing space.
763dashedLine :: Char
763dashedLine :: Char
764− -> Parsec [Char] st (Int, Int)
764+ -> Parser [Char] st (Int, Int)
765dashedLine ch = do
765dashedLine ch = do
766 dashes <- many1 (char ch)
766 dashes <- many1 (char ch)
767 sp <- many spaceChar
767 sp <- many spaceChar
@@ -770,7 +770,7 @@ dashedLine ch = do
770-- Parse a table header with dashed lines of '-' preceded by
770-- Parse a table header with dashed lines of '-' preceded by
771-- one (or zero) line of text.
771-- one (or zero) line of text.
772simpleTableHeader :: Bool -- ^ Headerless table
772simpleTableHeader :: Bool -- ^ Headerless table
773− -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
773+ -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
774simpleTableHeader headless = try $ do
774simpleTableHeader headless = try $ do
775 rawContent <- if headless
775 rawContent <- if headless
776 then return ""
776 then return ""
@@ -794,16 +794,16 @@ simpleTableHeader headless = try $ do
794 return (heads, aligns, indices)
794 return (heads, aligns, indices)
796-- Parse a table footer - dashed lines followed by blank line.
796-- Parse a table footer - dashed lines followed by blank line.
797−tableFooter :: Parsec [Char] ParserState [Char]
797+tableFooter :: Parser [Char] ParserState [Char]
798tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
798tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
800-- Parse a table separator - dashed line.
800-- Parse a table separator - dashed line.
801−tableSep :: Parsec [Char] ParserState Char
801+tableSep :: Parser [Char] ParserState Char
802tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
802tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
804-- Parse a raw line and split it into chunks by indices.
804-- Parse a raw line and split it into chunks by indices.
805rawTableLine :: [Int]
805rawTableLine :: [Int]
806− -> Parsec [Char] ParserState [String]
806+ -> Parser [Char] ParserState [String]
807rawTableLine indices = do
807rawTableLine indices = do
808 notFollowedBy' (blanklines <|> tableFooter)
808 notFollowedBy' (blanklines <|> tableFooter)
809 line <- many1Till anyChar newline
809 line <- many1Till anyChar newline
@@ -812,12 +812,12 @@ rawTableLine indices = do
813-- Parse a table line and return a list of lists of blocks (columns).
813-- Parse a table line and return a list of lists of blocks (columns).
814tableLine :: [Int]
814tableLine :: [Int]
815− -> Parsec [Char] ParserState [[Block]]
815+ -> Parser [Char] ParserState [[Block]]
816tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
816tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
818-- Parse a multiline table row and return a list of blocks (columns).
818-- Parse a multiline table row and return a list of blocks (columns).
819multilineRow :: [Int]
819multilineRow :: [Int]
820− -> Parsec [Char] ParserState [[Block]]
820+ -> Parser [Char] ParserState [[Block]]
821multilineRow indices = do
821multilineRow indices = do
822 colLines <- many1 (rawTableLine indices)
822 colLines <- many1 (rawTableLine indices)
823 let cols = map unlines $ transpose colLines
823 let cols = map unlines $ transpose colLines
@@ -825,7 +825,7 @@ multilineRow indices = do
826-- Parses a table caption: inlines beginning with 'Table:'
826-- Parses a table caption: inlines beginning with 'Table:'
827-- and followed by blank lines.
827-- and followed by blank lines.
828−tableCaption :: Parsec [Char] ParserState [Inline]
828+tableCaption :: Parser [Char] ParserState [Inline]
829tableCaption = try $ do
829tableCaption = try $ do
830 skipNonindentSpaces
830 skipNonindentSpaces
831 string ":" <|> string "Table:"
831 string ":" <|> string "Table:"
@@ -835,7 +835,7 @@ tableCaption = try $ do
836-- Parse a simple table with '---' header and one line per row.
836-- Parse a simple table with '---' header and one line per row.
837simpleTable :: Bool -- ^ Headerless table
837simpleTable :: Bool -- ^ Headerless table
838− -> Parsec [Char] ParserState Block
838+ -> Parser [Char] ParserState Block
839simpleTable headless = do
839simpleTable headless = do
840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841 (return ())
841 (return ())
@@ -849,12 +849,12 @@ simpleTable headless = do
849-- which may be multiline, separated by blank lines, and
849-- which may be multiline, separated by blank lines, and
850-- ending with a footer (dashed line followed by blank line).
850-- ending with a footer (dashed line followed by blank line).
851multilineTable :: Bool -- ^ Headerless table
851multilineTable :: Bool -- ^ Headerless table
852− -> Parsec [Char] ParserState Block
852+ -> Parser [Char] ParserState Block
853multilineTable headless =
853multilineTable headless =
854 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
854 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
856multilineTableHeader :: Bool -- ^ Headerless table
856multilineTableHeader :: Bool -- ^ Headerless table
857− -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
857+ -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
858multilineTableHeader headless = try $ do
858multilineTableHeader headless = try $ do
859 if headless
859 if headless
860 then return '\n'
860 then return '\n'
@@ -902,10 +902,10 @@ alignType strLst len =
902 (False, False) -> AlignDefault
902 (False, False) -> AlignDefault
904gridTable :: Bool -- ^ Headerless table
904gridTable :: Bool -- ^ Headerless table
905− -> Parsec [Char] ParserState Block
905+ -> Parser [Char] ParserState Block
906gridTable = gridTableWith block tableCaption
906gridTable = gridTableWith block tableCaption
908−table :: Parsec [Char] ParserState Block
908+table :: Parser [Char] ParserState Block
909table = multilineTable False <|> simpleTable True <|>
909table = multilineTable False <|> simpleTable True <|>
910 simpleTable False <|> multilineTable True <|>
910 simpleTable False <|> multilineTable True <|>
911 gridTable False <|> gridTable True <?> "table"
911 gridTable False <|> gridTable True <?> "table"
@@ -914,10 +914,10 @@ table = multilineTable False <|> simpleTable True <|>
917−inline :: Parsec [Char] ParserState Inline
917+inline :: Parser [Char] ParserState Inline
918inline = choice inlineParsers <?> "inline"
918inline = choice inlineParsers <?> "inline"
920−inlineParsers :: [Parsec [Char] ParserState Inline]
920+inlineParsers :: [Parser [Char] ParserState Inline]
921inlineParsers = [ whitespace
921inlineParsers = [ whitespace
923 , endline
923 , endline
@@ -944,7 +944,7 @@ inlineParsers = [ whitespace
945 , ltSign ]
945 , ltSign ]
947−escapedChar' :: Parsec [Char] ParserState Char
947+escapedChar' :: Parser [Char] ParserState Char
948escapedChar' = try $ do
948escapedChar' = try $ do
949 char '\\'
949 char '\\'
950 state <- getState
950 state <- getState
@@ -952,7 +952,7 @@ escapedChar' = try $ do
952 then oneOf "\\`*_{}[]()>#+-.!~"
952 then oneOf "\\`*_{}[]()>#+-.!~"
953 else satisfy (not . isAlphaNum)
953 else satisfy (not . isAlphaNum)
955−escapedChar :: Parsec [Char] ParserState Inline
955+escapedChar :: Parser [Char] ParserState Inline
956escapedChar = do
956escapedChar = do
957 result <- escapedChar'
957 result <- escapedChar'
958 return $ case result of
958 return $ case result of
@@ -960,7 +960,7 @@ escapedChar = do
960 '\n' -> LineBreak -- "\[newline]" is a linebreak
960 '\n' -> LineBreak -- "\[newline]" is a linebreak
961 _ -> Str [result]
961 _ -> Str [result]
963−ltSign :: Parsec [Char] ParserState Inline
963+ltSign :: Parser [Char] ParserState Inline
964ltSign = do
964ltSign = do
965 st <- getState
965 st <- getState
966 if stateStrict st
966 if stateStrict st
@@ -968,7 +968,7 @@ ltSign = do
968 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
968 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
969 return $ Str ['<']
969 return $ Str ['<']
971−exampleRef :: Parsec [Char] ParserState Inline
971+exampleRef :: Parser [Char] ParserState Inline
972exampleRef = try $ do
972exampleRef = try $ do
974 lab <- many1 (alphaNum <|> oneOf "-_")
974 lab <- many1 (alphaNum <|> oneOf "-_")
@@ -976,7 +976,7 @@ exampleRef = try $ do
976 -- later. See the end of parseMarkdown.
976 -- later. See the end of parseMarkdown.
977 return $ Str $ '@' : lab
977 return $ Str $ '@' : lab
979−symbol :: Parsec [Char] ParserState Inline
979+symbol :: Parser [Char] ParserState Inline
980symbol = do
980symbol = do
981 result <- noneOf "<\\\n\t "
981 result <- noneOf "<\\\n\t "
982 <|> try (do lookAhead $ char '\\'
982 <|> try (do lookAhead $ char '\\'
@@ -985,7 +985,7 @@ symbol = do
985 return $ Str [result]
985 return $ Str [result]
987-- parses inline code, between n `s and n `s
987-- parses inline code, between n `s and n `s
988−code :: Parsec [Char] ParserState Inline
988+code :: Parser [Char] ParserState Inline
989code = try $ do
989code = try $ do
990 starts <- many1 (char '`')
990 starts <- many1 (char '`')
991 skipSpaces
991 skipSpaces
@@ -996,26 +996,26 @@ code = try $ do
996 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
996 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
997 return $ Code attr $ removeLeadingTrailingSpace $ concat result
997 return $ Code attr $ removeLeadingTrailingSpace $ concat result
999−mathWord :: Parsec [Char] st [Char]
999+mathWord :: Parser [Char] st [Char]
1000mathWord = liftM concat $ many1 mathChunk
1000mathWord = liftM concat $ many1 mathChunk
1002−mathChunk :: Parsec [Char] st [Char]
1002+mathChunk :: Parser [Char] st [Char]
1003mathChunk = do char '\\'
1003mathChunk = do char '\\'
1004 c <- anyChar
1004 c <- anyChar
1005 return ['\\',c]
1005 return ['\\',c]
1006 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1006 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1008−math :: Parsec [Char] ParserState Inline
1008+math :: Parser [Char] ParserState Inline
1009math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1009math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1010 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1010 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1012−mathDisplay :: Parsec [Char] ParserState String
1012+mathDisplay :: Parser [Char] ParserState String
1013mathDisplay = try $ do
1013mathDisplay = try $ do
1014 failIfStrict
1014 failIfStrict
1015 string "$$"
1015 string "$$"
1016 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1016 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1018−mathInline :: Parsec [Char] ParserState String
1018+mathInline :: Parser [Char] ParserState String
1019mathInline = try $ do
1019mathInline = try $ do
1020 failIfStrict
1020 failIfStrict
1021 char '$'
1021 char '$'
@@ -1027,7 +1027,7 @@ mathInline = try $ do
1028-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1028-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1029-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1029-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1030−fours :: Parsec [Char] st Inline
1030+fours :: Parser [Char] st Inline
1031fours = try $ do
1031fours = try $ do
1032 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1032 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1033 count 2 $ satisfy (==x)
1033 count 2 $ satisfy (==x)
@@ -1036,9 +1036,9 @@ fours = try $ do
1037-- | Parses a list of inlines between start and end delimiters.
1037-- | Parses a list of inlines between start and end delimiters.
1038inlinesBetween :: (Show b)
1038inlinesBetween :: (Show b)
1039− => Parsec [Char] ParserState a
1039+ => Parser [Char] ParserState a
1040− -> Parsec [Char] ParserState b
1040+ -> Parser [Char] ParserState b
1041− -> Parsec [Char] ParserState [Inline]
1041+ -> Parser [Char] ParserState [Inline]
1042inlinesBetween start end =
1042inlinesBetween start end =
1043 normalizeSpaces `liftM` try (start >> many1Till inner end)
1043 normalizeSpaces `liftM` try (start >> many1Till inner end)
1044 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
1044 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
@@ -1046,8 +1046,8 @@ inlinesBetween start end =
1047-- This is used to prevent exponential blowups for things like:
1047-- This is used to prevent exponential blowups for things like:
1048-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1048-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1049−nested :: Parsec [Char] ParserState a
1049+nested :: Parser [Char] ParserState a
1050− -> Parsec [Char] ParserState a
1050+ -> Parser [Char] ParserState a
1051nested p = do
1051nested p = do
1052 nestlevel <- stateMaxNestingLevel `fmap` getState
1052 nestlevel <- stateMaxNestingLevel `fmap` getState
1053 guard $ nestlevel > 0
1053 guard $ nestlevel > 0
@@ -1056,7 +1056,7 @@ nested p = do
1056 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1056 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1057 return res
1057 return res
1059−emph :: Parsec [Char] ParserState Inline
1059+emph :: Parser [Char] ParserState Inline
1060emph = Emph `fmap` nested
1060emph = Emph `fmap` nested
1061 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1061 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1062 where starStart = char '*' >> lookAhead nonspaceChar
1062 where starStart = char '*' >> lookAhead nonspaceChar
@@ -1064,7 +1064,7 @@ emph = Emph `fmap` nested
1064 ulStart = char '_' >> lookAhead nonspaceChar
1064 ulStart = char '_' >> lookAhead nonspaceChar
1065 ulEnd = notFollowedBy' strong >> char '_'
1065 ulEnd = notFollowedBy' strong >> char '_'
1067−strong :: Parsec [Char] ParserState Inline
1067+strong :: Parser [Char] ParserState Inline
1068strong = Strong `liftM` nested
1068strong = Strong `liftM` nested
1069 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1069 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1070 where starStart = string "**" >> lookAhead nonspaceChar
1070 where starStart = string "**" >> lookAhead nonspaceChar
@@ -1072,32 +1072,32 @@ strong = Strong `liftM` nested
1072 ulStart = string "__" >> lookAhead nonspaceChar
1072 ulStart = string "__" >> lookAhead nonspaceChar
1073 ulEnd = try $ string "__"
1073 ulEnd = try $ string "__"
1075−strikeout :: Parsec [Char] ParserState Inline
1075+strikeout :: Parser [Char] ParserState Inline
1076strikeout = Strikeout `liftM`
1076strikeout = Strikeout `liftM`
1077 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1077 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1078 where strikeStart = string "~~" >> lookAhead nonspaceChar
1078 where strikeStart = string "~~" >> lookAhead nonspaceChar
1079 >> notFollowedBy (char '~')
1079 >> notFollowedBy (char '~')
1080 strikeEnd = try $ string "~~"
1080 strikeEnd = try $ string "~~"
1082−superscript :: Parsec [Char] ParserState Inline
1082+superscript :: Parser [Char] ParserState Inline
1083superscript = failIfStrict >> enclosed (char '^') (char '^')
1083superscript = failIfStrict >> enclosed (char '^') (char '^')
1084 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1084 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1085 return . Superscript
1085 return . Superscript
1087−subscript :: Parsec [Char] ParserState Inline
1087+subscript :: Parser [Char] ParserState Inline
1088subscript = failIfStrict >> enclosed (char '~') (char '~')
1088subscript = failIfStrict >> enclosed (char '~') (char '~')
1089 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1089 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1090 return . Subscript
1090 return . Subscript
1092−whitespace :: Parsec [Char] ParserState Inline
1092+whitespace :: Parser [Char] ParserState Inline
1093whitespace = spaceChar >>
1093whitespace = spaceChar >>
1094 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1094 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1095 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1095 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1097−nonEndline :: Parsec [Char] st Char
1097+nonEndline :: Parser [Char] st Char
1098nonEndline = satisfy (/='\n')
1098nonEndline = satisfy (/='\n')
1100−str :: Parsec [Char] ParserState Inline
1100+str :: Parser [Char] ParserState Inline
1102 smart <- stateSmart `fmap` getState
1102 smart <- stateSmart `fmap` getState
1103 a <- alphaNum
1103 a <- alphaNum
@@ -1135,7 +1135,7 @@ likelyAbbrev x =
1135 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1135 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1137-- an endline character that can be treated as a space, not a structural break
1137-- an endline character that can be treated as a space, not a structural break
1138−endline :: Parsec [Char] ParserState Inline
1138+endline :: Parser [Char] ParserState Inline
1139endline = try $ do
1139endline = try $ do
1141 notFollowedBy blankline
1141 notFollowedBy blankline
@@ -1154,20 +1154,20 @@ endline = try $ do
1156-- a reference label for a link
1156-- a reference label for a link
1157−reference :: Parsec [Char] ParserState [Inline]
1157+reference :: Parser [Char] ParserState [Inline]
1158reference = do notFollowedBy' (string "[^") -- footnote reference
1158reference = do notFollowedBy' (string "[^") -- footnote reference
1159 result <- inlinesInBalancedBrackets inline
1159 result <- inlinesInBalancedBrackets inline
1160 return $ normalizeSpaces result
1160 return $ normalizeSpaces result
1162-- source for a link, with optional title
1162-- source for a link, with optional title
1163−source :: Parsec [Char] ParserState (String, [Char])
1163+source :: Parser [Char] ParserState (String, [Char])
1165 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1165 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1166 -- the following is needed for cases like: [ref](/url(a).
1166 -- the following is needed for cases like: [ref](/url(a).
1167 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1167 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1169-- auxiliary function for source
1169-- auxiliary function for source
1170−source' :: Parsec [Char] ParserState (String, [Char])
1170+source' :: Parser [Char] ParserState (String, [Char])
1171source' = do
1171source' = do
1172 skipSpaces
1172 skipSpaces
1173 let nl = char '\n' >>~ notFollowedBy blankline
1173 let nl = char '\n' >>~ notFollowedBy blankline
@@ -1185,7 +1185,7 @@ source' = do
1186 return (escapeURI $ removeTrailingSpace src, tit)
1186 return (escapeURI $ removeTrailingSpace src, tit)
1188−linkTitle :: Parsec [Char] ParserState String
1188+linkTitle :: Parser [Char] ParserState String
1189linkTitle = try $ do
1189linkTitle = try $ do
1190 (many1 spaceChar >> option '\n' newline) <|> newline
1190 (many1 spaceChar >> option '\n' newline) <|> newline
1191 skipSpaces
1191 skipSpaces
@@ -1193,7 +1193,7 @@ linkTitle = try $ do
1193 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1193 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1194 return $ fromEntities tit
1194 return $ fromEntities tit
1196−link :: Parsec [Char] ParserState Inline
1196+link :: Parser [Char] ParserState Inline
1197link = try $ do
1197link = try $ do
1198 lab <- reference
1198 lab <- reference
1199 (src, tit) <- source <|> referenceLink lab
1199 (src, tit) <- source <|> referenceLink lab
@@ -1206,7 +1206,7 @@ delinkify = bottomUp $ concatMap go
1207-- a link like [this][ref] or [this][] or [this]
1207-- a link like [this][ref] or [this][] or [this]
1208referenceLink :: [Inline]
1208referenceLink :: [Inline]
1209− -> Parsec [Char] ParserState (String, [Char])
1209+ -> Parser [Char] ParserState (String, [Char])
1210referenceLink lab = do
1210referenceLink lab = do
1211 ref <- option [] (try (optional (char ' ') >>
1211 ref <- option [] (try (optional (char ' ') >>
1212 optional (newline >> skipSpaces) >> reference))
1212 optional (newline >> skipSpaces) >> reference))
@@ -1216,7 +1216,7 @@ referenceLink lab = do
1216 Nothing -> fail "no corresponding key"
1216 Nothing -> fail "no corresponding key"
1217 Just target -> return target
1217 Just target -> return target
1219−autoLink :: Parsec [Char] ParserState Inline
1219+autoLink :: Parser [Char] ParserState Inline
1220autoLink = try $ do
1220autoLink = try $ do
1221 char '<'
1221 char '<'
1222 (orig, src) <- uri <|> emailAddress
1222 (orig, src) <- uri <|> emailAddress
@@ -1226,14 +1226,14 @@ autoLink = try $ do
1226 then Link [Str orig] (src, "")
1226 then Link [Str orig] (src, "")
1227 else Link [Code ("",["url"],[]) orig] (src, "")
1227 else Link [Code ("",["url"],[]) orig] (src, "")
1229−image :: Parsec [Char] ParserState Inline
1229+image :: Parser [Char] ParserState Inline
1230image = try $ do
1230image = try $ do
1231 char '!'
1231 char '!'
1232 lab <- reference
1232 lab <- reference
1233 (src, tit) <- source <|> referenceLink lab
1233 (src, tit) <- source <|> referenceLink lab
1234 return $ Image lab (src,tit)
1234 return $ Image lab (src,tit)
1236−note :: Parsec [Char] ParserState Inline
1236+note :: Parser [Char] ParserState Inline
1237note = try $ do
1237note = try $ do
1238 failIfStrict
1238 failIfStrict
1239 ref <- noteMarker
1239 ref <- noteMarker
@@ -1250,21 +1250,21 @@ note = try $ do
1250 updateState $ \st -> st{ stateNotes = notes }
1250 updateState $ \st -> st{ stateNotes = notes }
1251 return $ Note contents
1251 return $ Note contents
1253−inlineNote :: Parsec [Char] ParserState Inline
1253+inlineNote :: Parser [Char] ParserState Inline
1254inlineNote = try $ do
1254inlineNote = try $ do
1255 failIfStrict
1255 failIfStrict
1256 char '^'
1256 char '^'
1257 contents <- inlinesInBalancedBrackets inline
1257 contents <- inlinesInBalancedBrackets inline
1258 return $ Note [Para contents]
1258 return $ Note [Para contents]
1260−rawLaTeXInline' :: Parsec [Char] ParserState Inline
1260+rawLaTeXInline' :: Parser [Char] ParserState Inline
1261rawLaTeXInline' = try $ do
1261rawLaTeXInline' = try $ do
1262 failIfStrict
1262 failIfStrict
1263 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1263 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1264 RawInline _ s <- rawLaTeXInline
1264 RawInline _ s <- rawLaTeXInline
1265 return $ RawInline "tex" s -- "tex" because it might be context or latex
1265 return $ RawInline "tex" s -- "tex" because it might be context or latex
1267−rawConTeXtEnvironment :: Parsec [Char] st String
1267+rawConTeXtEnvironment :: Parser [Char] st String
1268rawConTeXtEnvironment = try $ do
1268rawConTeXtEnvironment = try $ do
1269 string "\\start"
1269 string "\\start"
1270 completion <- inBrackets (letter <|> digit <|> spaceChar)
1270 completion <- inBrackets (letter <|> digit <|> spaceChar)
@@ -1273,14 +1273,14 @@ rawConTeXtEnvironment = try $ do
1273 (try $ string "\\stop" >> string completion)
1273 (try $ string "\\stop" >> string completion)
1274 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1274 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1276−inBrackets :: (Parsec [Char] st Char) -> Parsec [Char] st String
1276+inBrackets :: (Parser [Char] st Char) -> Parser [Char] st String
1277inBrackets parser = do
1277inBrackets parser = do
1278 char '['
1278 char '['
1279 contents <- many parser
1279 contents <- many parser
1280 char ']'
1280 char ']'
1281 return $ "[" ++ contents ++ "]"
1281 return $ "[" ++ contents ++ "]"
1283−rawHtmlInline :: Parsec [Char] ParserState Inline
1283+rawHtmlInline :: Parser [Char] ParserState Inline
1284rawHtmlInline = do
1284rawHtmlInline = do
1285 st <- getState
1285 st <- getState
1286 (_,result) <- if stateStrict st
1286 (_,result) <- if stateStrict st
@@ -1290,20 +1290,20 @@ rawHtmlInline = do
1291-- Citations
1291-- Citations
1293−cite :: Parsec [Char] ParserState Inline
1293+cite :: Parser [Char] ParserState Inline
1294cite = do
1294cite = do
1295 failIfStrict
1295 failIfStrict
1296 citations <- textualCite <|> normalCite
1296 citations <- textualCite <|> normalCite
1297 return $ Cite citations []
1297 return $ Cite citations []
1299−spnl :: Parsec [Char] st ()
1299+spnl :: Parser [Char] st ()
1300spnl = try $ do
1300spnl = try $ do
1301 skipSpaces
1301 skipSpaces
1302 optional newline
1302 optional newline
1303 skipSpaces
1303 skipSpaces
1304 notFollowedBy (char '\n')
1304 notFollowedBy (char '\n')
1306−textualCite :: Parsec [Char] ParserState [Citation]
1306+textualCite :: Parser [Char] ParserState [Citation]
1307textualCite = try $ do
1307textualCite = try $ do
1308 (_, key) <- citeKey
1308 (_, key) <- citeKey
1309 let first = Citation{ citationId = key
1309 let first = Citation{ citationId = key
@@ -1318,7 +1318,7 @@ textualCite = try $ do
1318 then option [first] $ bareloc first
1318 then option [first] $ bareloc first
1319 else return $ first : rest
1319 else return $ first : rest
1321−bareloc :: Citation -> Parsec [Char] ParserState [Citation]
1321+bareloc :: Citation -> Parser [Char] ParserState [Citation]
1322bareloc c = try $ do
1322bareloc c = try $ do
1324 char '['
1324 char '['
@@ -1328,7 +1328,7 @@ bareloc c = try $ do
1328 char ']'
1328 char ']'
1329 return $ c{ citationSuffix = suff } : rest
1329 return $ c{ citationSuffix = suff } : rest
1331−normalCite :: Parsec [Char] ParserState [Citation]
1331+normalCite :: Parser [Char] ParserState [Citation]
1332normalCite = try $ do
1332normalCite = try $ do
1333 char '['
1333 char '['
@@ -1337,7 +1337,7 @@ normalCite = try $ do
1337 char ']'
1337 char ']'
1338 return citations
1338 return citations
1340−citeKey :: Parsec [Char] ParserState (Bool, String)
1340+citeKey :: Parser [Char] ParserState (Bool, String)
1341citeKey = try $ do
1341citeKey = try $ do
1342 suppress_author <- option False (char '-' >> return True)
1342 suppress_author <- option False (char '-' >> return True)
1343 char '@'
1343 char '@'
@@ -1349,7 +1349,7 @@ citeKey = try $ do
1349 guard $ key `elem` stateCitations st
1349 guard $ key `elem` stateCitations st
1350 return (suppress_author, key)
1350 return (suppress_author, key)
1352−suffix :: Parsec [Char] ParserState [Inline]
1352+suffix :: Parser [Char] ParserState [Inline]
1353suffix = try $ do
1353suffix = try $ do
1354 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
1354 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
@@ -1358,14 +1358,14 @@ suffix = try $ do
1358 then Space : rest
1358 then Space : rest
1359 else rest
1359 else rest
1361−prefix :: Parsec [Char] ParserState [Inline]
1361+prefix :: Parser [Char] ParserState [Inline]
1362prefix = liftM normalizeSpaces $
1362prefix = liftM normalizeSpaces $
1363 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1363 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1365−citeList :: Parsec [Char] ParserState [Citation]
1365+citeList :: Parser [Char] ParserState [Citation]
1366citeList = sepBy1 citation (try $ char ';' >> spnl)
1366citeList = sepBy1 citation (try $ char ';' >> spnl)
1368−citation :: Parsec [Char] ParserState Citation
1368+citation :: Parser [Char] ParserState Citation
1369citation = try $ do
1369citation = try $ do
1370 pref <- prefix
1370 pref <- prefix
1371 (suppress_author, key) <- citeKey
1371 (suppress_author, key) <- citeKey