git.iko.soy/typeable/pandoc
on master help sign in
Use Text.Parsec instead of Text.ParserCombinators.Parsec.
commita4c28ead79d0490de992fe9a642afdefee6080f4 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 20 Jul 2012, 14:19 (14 years ago) parent5be6bf0
10 files changed+442−442
src/Text/Pandoc/Biblio.hs+6−6 src/Text/Pandoc/Parsing.hs+103−103 src/Text/Pandoc/Readers/HTML.hs+12−12 src/Text/Pandoc/Readers/LaTeX.hs+4−4 src/Text/Pandoc/Readers/Markdown.hs+137−137 src/Text/Pandoc/Readers/RST.hs+95−95 src/Text/Pandoc/Readers/Textile.hs+69−69 src/Text/Pandoc/Templates.hs+12−12 src/Text/Pandoc/Writers/AsciiDoc.hs+2−2 src/Text/Pandoc/Writers/Markdown.hs+2−2
src/Text/Pandoc/Biblio.hs+6−6
@@ -38,7 +38,7 @@ import qualified Text.CSL as CSL ( Cite(..) )
3838import Text.Pandoc.Definition
3939import Text.Pandoc.Generic
4040import Text.Pandoc.Shared (stringify)
41−import Text.ParserCombinators.Parsec
41+import Text.Parsec
4242import Control.Monad
4343
4444-- | Process a 'Pandoc' document by adding citations formatted
@@ -165,7 +165,7 @@ locatorWords inp =
165165 breakup (x : xs) = x : breakup xs
166166 splitup = groupBy (\x y -> x /= '\160' && y /= '\160')
167167
168−pLocatorWords :: GenParser Inline st (String, [Inline])
168+pLocatorWords :: Parsec [Inline] st (String, [Inline])
169169pLocatorWords = do
170170 l <- pLocator
171171 s <- getInput -- rest is suffix
@@ -173,16 +173,16 @@ pLocatorWords = do
173173 then return (init l, Str "," : s)
174174 else return (l, s)
175175
176−pMatch :: (Inline -> Bool) -> GenParser Inline st Inline
176+pMatch :: (Inline -> Bool) -> Parsec [Inline] st Inline
177177pMatch condition = try $ do
178178 t <- anyToken
179179 guard $ condition t
180180 return t
181181
182−pSpace :: GenParser Inline st Inline
182+pSpace :: Parsec [Inline] st Inline
183183pSpace = pMatch (\t -> t == Space || t == Str "\160")
184184
185−pLocator :: GenParser Inline st String
185+pLocator :: Parsec [Inline] st String
186186pLocator = try $ do
187187 optional $ pMatch (== Str ",")
188188 optional pSpace
@@ -190,7 +190,7 @@ pLocator = try $ do
190190 gs <- many1 pWordWithDigits
191191 return $ stringify f ++ (' ' : unwords gs)
192192
193−pWordWithDigits :: GenParser Inline st String
193+pWordWithDigits :: Parsec [Inline] st String
194194pWordWithDigits = try $ do
195195 pSpace
196196 r <- many1 (notFollowedBy pSpace >> anyToken)
src/Text/Pandoc/Parsing.hs+103−103
@@ -79,11 +79,11 @@ where
7979import Text.Pandoc.Definition
8080import Text.Pandoc.Generic
8181import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
82−import Text.ParserCombinators.Parsec
82+import Text.Parsec
8383import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
8484import Data.List ( intercalate, transpose )
8585import Network.URI ( parseURI, URI (..), isAllowedInURI )
86−import Control.Monad ( join, liftM, guard )
86+import Control.Monad ( join, liftM, guard, mzero )
8787import Text.Pandoc.Shared
8888import qualified Data.Map as M
8989import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
@@ -96,13 +96,13 @@ import Data.Default
9696a >>~ b = a >>= \x -> b >> return x
9797
9898-- | Parse any line of text
99−anyLine :: GenParser Char st [Char]
99+anyLine :: Parsec [Char] st [Char]
100100anyLine = manyTill anyChar newline
101101
102102-- | Like @manyTill@, but reads at least one item.
103−many1Till :: GenParser tok st a
104− -> GenParser tok st end
105− -> GenParser tok st [a]
103+many1Till :: Parsec [tok] st a
104+ -> Parsec [tok] st end
105+ -> Parsec [tok] st [a]
106106many1Till p end = do
107107 first <- p
108108 rest <- manyTill p end
@@ -111,7 +111,7 @@ many1Till p end = do
111111-- | A more general form of @notFollowedBy@. This one allows any
112112-- type of parser to be specified, and succeeds only if that parser fails.
113113-- It does not consume any input.
114−notFollowedBy' :: Show b => GenParser a st b -> GenParser a st ()
114+notFollowedBy' :: Show b => Parsec [a] st b -> Parsec [a] st ()
115115notFollowedBy' p = try $ join $ do a <- try p
116116 return (unexpected (show a))
117117 <|>
@@ -119,39 +119,39 @@ notFollowedBy' p = try $ join $ do a <- try p
119119-- (This version due to Andrew Pimlott on the Haskell mailing list.)
120120
121121-- | Parses one of a list of strings (tried in order).
122−oneOfStrings :: [String] -> GenParser Char st String
122+oneOfStrings :: [String] -> Parsec [Char] st String
123123oneOfStrings listOfStrings = choice $ map (try . string) listOfStrings
124124
125125-- | Parses a space or tab.
126−spaceChar :: CharParser st Char
126+spaceChar :: Parsec [Char] st Char
127127spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
128128
129129-- | Parses a nonspace, nonnewline character.
130−nonspaceChar :: CharParser st Char
130+nonspaceChar :: Parsec [Char] st Char
131131nonspaceChar = satisfy $ \x -> x /= '\t' && x /= '\n' && x /= ' ' && x /= '\r'
132132
133133-- | Skips zero or more spaces or tabs.
134−skipSpaces :: GenParser Char st ()
134+skipSpaces :: Parsec [Char] st ()
135135skipSpaces = skipMany spaceChar
136136
137137-- | Skips zero or more spaces or tabs, then reads a newline.
138−blankline :: GenParser Char st Char
138+blankline :: Parsec [Char] st Char
139139blankline = try $ skipSpaces >> newline
140140
141141-- | Parses one or more blank lines and returns a string of newlines.
142−blanklines :: GenParser Char st [Char]
142+blanklines :: Parsec [Char] st [Char]
143143blanklines = many1 blankline
144144
145145-- | Parses material enclosed between start and end parsers.
146−enclosed :: GenParser Char st t -- ^ start parser
147− -> GenParser Char st end -- ^ end parser
148− -> GenParser Char st a -- ^ content parser (to be used repeatedly)
149− -> GenParser Char st [a]
146+enclosed :: Parsec [Char] st t -- ^ start parser
147+ -> Parsec [Char] st end -- ^ end parser
148+ -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
149+ -> Parsec [Char] st [a]
150150enclosed start end parser = try $
151151 start >> notFollowedBy space >> many1Till parser end
152152
153153-- | Parse string, case insensitive.
154−stringAnyCase :: [Char] -> CharParser st String
154+stringAnyCase :: [Char] -> Parsec [Char] st String
155155stringAnyCase [] = string ""
156156stringAnyCase (x:xs) = do
157157 firstChar <- char (toUpper x) <|> char (toLower x)
@@ -159,7 +159,7 @@ stringAnyCase (x:xs) = do
159159 return (firstChar:rest)
160160
161161-- | Parse contents of 'str' using 'parser' and return result.
162−parseFromString :: GenParser tok st a -> [tok] -> GenParser tok st a
162+parseFromString :: Parsec [tok] st a -> [tok] -> Parsec [tok] st a
163163parseFromString parser str = do
164164 oldPos <- getPosition
165165 oldInput <- getInput
@@ -170,7 +170,7 @@ parseFromString parser str = do
170170 return result
171171
172172-- | Parse raw line block up to and including blank lines.
173−lineClump :: GenParser Char st String
173+lineClump :: Parsec [Char] st String
174174lineClump = blanklines
175175 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
176176
@@ -179,8 +179,8 @@ lineClump = blanklines
179179-- pairs of open and close, which must be different. For example,
180180-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
181181-- and return "hello (there)".
182−charsInBalanced :: Char -> Char -> GenParser Char st Char
183− -> GenParser Char st String
182+charsInBalanced :: Char -> Char -> Parsec [Char] st Char
183+ -> Parsec [Char] st String
184184charsInBalanced open close parser = try $ do
185185 char open
186186 let isDelim c = c == open || c == close
@@ -205,7 +205,7 @@ uppercaseRomanDigits = map toUpper lowercaseRomanDigits
205205
206206-- | Parses a roman numeral (uppercase or lowercase), returns number.
207207romanNumeral :: Bool -- ^ Uppercase if true
208− -> GenParser Char st Int
208+ -> Parsec [Char] st Int
209209romanNumeral upperCase = do
210210 let romanDigits = if upperCase
211211 then uppercaseRomanDigits
@@ -235,14 +235,14 @@ romanNumeral upperCase = do
235235
236236-- Parsers for email addresses and URIs
237237
238−emailChar :: GenParser Char st Char
238+emailChar :: Parsec [Char] st Char
239239emailChar = alphaNum <|>
240240 satisfy (\c -> c == '-' || c == '+' || c == '_' || c == '.')
241241
242−domainChar :: GenParser Char st Char
242+domainChar :: Parsec [Char] st Char
243243domainChar = alphaNum <|> char '-'
244244
245−domain :: GenParser Char st [Char]
245+domain :: Parsec [Char] st [Char]
246246domain = do
247247 first <- many1 domainChar
248248 dom <- many1 $ try (char '.' >> many1 domainChar )
@@ -250,7 +250,7 @@ domain = do
250250
251251-- | Parses an email address; returns original and corresponding
252252-- escaped mailto: URI.
253−emailAddress :: GenParser Char st (String, String)
253+emailAddress :: Parsec [Char] st (String, String)
254254emailAddress = try $ do
255255 firstLetter <- alphaNum
256256 restAddr <- many emailChar
@@ -261,7 +261,7 @@ emailAddress = try $ do
261261 return (full, escapeURI $ "mailto:" ++ full)
262262
263263-- | Parses a URI. Returns pair of original and URI-escaped version.
264−uri :: GenParser Char st (String, String)
264+uri :: Parsec [Char] st (String, String)
265265uri = try $ do
266266 let protocols = [ "http:", "https:", "ftp:", "file:", "mailto:",
267267 "news:", "telnet:" ]
@@ -295,8 +295,8 @@ uri = try $ do
295295-- displacement (the difference between the source column at the end
296296-- and the source column at the beginning). Vertical displacement
297297-- (source row) is ignored.
298−withHorizDisplacement :: GenParser Char st a -- ^ Parser to apply
299− -> GenParser Char st (a, Int) -- ^ (result, displacement)
298+withHorizDisplacement :: Parsec [Char] st a -- ^ Parser to apply
299+ -> Parsec [Char] st (a, Int) -- ^ (result, displacement)
300300withHorizDisplacement parser = do
301301 pos1 <- getPosition
302302 result <- parser
@@ -305,7 +305,7 @@ withHorizDisplacement parser = do
305305
306306-- | Applies a parser and returns the raw string that was parsed,
307307-- along with the value produced by the parser.
308−withRaw :: GenParser Char st a -> GenParser Char st (a, [Char])
308+withRaw :: Parsec [Char] st a -> Parsec [Char] st (a, [Char])
309309withRaw parser = do
310310 pos1 <- getPosition
311311 inp <- getInput
@@ -322,26 +322,26 @@ withRaw parser = do
322322
323323-- | Parses a character and returns 'Null' (so that the parser can move on
324324-- if it gets stuck).
325−nullBlock :: GenParser Char st Block
325+nullBlock :: Parsec [Char] st Block
326326nullBlock = anyChar >> return Null
327327
328328-- | Fail if reader is in strict markdown syntax mode.
329−failIfStrict :: GenParser a ParserState ()
329+failIfStrict :: Parsec [a] ParserState ()
330330failIfStrict = do
331331 state <- getState
332332 if stateStrict state then fail "strict mode" else return ()
333333
334334-- | Fail unless we're in literate haskell mode.
335−failUnlessLHS :: GenParser tok ParserState ()
335+failUnlessLHS :: Parsec [tok] ParserState ()
336336failUnlessLHS = getState >>= guard . stateLiterateHaskell
337337
338338-- | Parses backslash, then applies character parser.
339−escaped :: GenParser Char st Char -- ^ Parser for character to escape
340− -> GenParser Char st Char
339+escaped :: Parsec [Char] st Char -- ^ Parser for character to escape
340+ -> Parsec [Char] st Char
341341escaped parser = try $ char '\\' >> parser
342342
343343-- | Parse character entity.
344−characterReference :: GenParser Char st Char
344+characterReference :: Parsec [Char] st Char
345345characterReference = try $ do
346346 char '&'
347347 ent <- many1Till nonspaceChar (char ';')
@@ -350,19 +350,19 @@ characterReference = try $ do
350350 Nothing -> fail "entity not found"
351351
352352-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
353−upperRoman :: GenParser Char st (ListNumberStyle, Int)
353+upperRoman :: Parsec [Char] st (ListNumberStyle, Int)
354354upperRoman = do
355355 num <- romanNumeral True
356356 return (UpperRoman, num)
357357
358358-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
359−lowerRoman :: GenParser Char st (ListNumberStyle, Int)
359+lowerRoman :: Parsec [Char] st (ListNumberStyle, Int)
360360lowerRoman = do
361361 num <- romanNumeral False
362362 return (LowerRoman, num)
363363
364364-- | Parses a decimal numeral and returns (Decimal, number).
365−decimal :: GenParser Char st (ListNumberStyle, Int)
365+decimal :: Parsec [Char] st (ListNumberStyle, Int)
366366decimal = do
367367 num <- many1 digit
368368 return (Decimal, read num)
@@ -371,7 +371,7 @@ decimal = do
371371-- returns (DefaultStyle, [next example number]). The next
372372-- example number is incremented in parser state, and the label
373373-- (if present) is added to the label table.
374−exampleNum :: GenParser Char ParserState (ListNumberStyle, Int)
374+exampleNum :: Parsec [Char] ParserState (ListNumberStyle, Int)
375375exampleNum = do
376376 char '@'
377377 lab <- many (alphaNum <|> satisfy (\c -> c == '_' || c == '-'))
@@ -385,38 +385,38 @@ exampleNum = do
385385 return (Example, num)
386386
387387-- | Parses a '#' returns (DefaultStyle, 1).
388−defaultNum :: GenParser Char st (ListNumberStyle, Int)
388+defaultNum :: Parsec [Char] st (ListNumberStyle, Int)
389389defaultNum = do
390390 char '#'
391391 return (DefaultStyle, 1)
392392
393393-- | Parses a lowercase letter and returns (LowerAlpha, number).
394−lowerAlpha :: GenParser Char st (ListNumberStyle, Int)
394+lowerAlpha :: Parsec [Char] st (ListNumberStyle, Int)
395395lowerAlpha = do
396396 ch <- oneOf ['a'..'z']
397397 return (LowerAlpha, ord ch - ord 'a' + 1)
398398
399399-- | Parses an uppercase letter and returns (UpperAlpha, number).
400−upperAlpha :: GenParser Char st (ListNumberStyle, Int)
400+upperAlpha :: Parsec [Char] st (ListNumberStyle, Int)
401401upperAlpha = do
402402 ch <- oneOf ['A'..'Z']
403403 return (UpperAlpha, ord ch - ord 'A' + 1)
404404
405405-- | Parses a roman numeral i or I
406−romanOne :: GenParser Char st (ListNumberStyle, Int)
406+romanOne :: Parsec [Char] st (ListNumberStyle, Int)
407407romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
408408 (char 'I' >> return (UpperRoman, 1))
409409
410410-- | Parses an ordered list marker and returns list attributes.
411−anyOrderedListMarker :: GenParser Char ParserState ListAttributes
411+anyOrderedListMarker :: Parsec [Char] ParserState ListAttributes
412412anyOrderedListMarker = choice $
413413 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
414414 numParser <- [decimal, exampleNum, defaultNum, romanOne,
415415 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
416416
417417-- | Parses a list number (num) followed by a period, returns list attributes.
418−inPeriod :: GenParser Char st (ListNumberStyle, Int)
419− -> GenParser Char st ListAttributes
418+inPeriod :: Parsec [Char] st (ListNumberStyle, Int)
419+ -> Parsec [Char] st ListAttributes
420420inPeriod num = try $ do
421421 (style, start) <- num
422422 char '.'
@@ -426,16 +426,16 @@ inPeriod num = try $ do
426426 return (start, style, delim)
427427
428428-- | Parses a list number (num) followed by a paren, returns list attributes.
429−inOneParen :: GenParser Char st (ListNumberStyle, Int)
430− -> GenParser Char st ListAttributes
429+inOneParen :: Parsec [Char] st (ListNumberStyle, Int)
430+ -> Parsec [Char] st ListAttributes
431431inOneParen num = try $ do
432432 (style, start) <- num
433433 char ')'
434434 return (start, style, OneParen)
435435
436436-- | Parses a list number (num) enclosed in parens, returns list attributes.
437−inTwoParens :: GenParser Char st (ListNumberStyle, Int)
438− -> GenParser Char st ListAttributes
437+inTwoParens :: Parsec [Char] st (ListNumberStyle, Int)
438+ -> Parsec [Char] st ListAttributes
439439inTwoParens num = try $ do
440440 char '('
441441 (style, start) <- num
@@ -446,7 +446,7 @@ inTwoParens num = try $ do
446446-- returns number.
447447orderedListMarker :: ListNumberStyle
448448 -> ListNumberDelim
449− -> GenParser Char ParserState Int
449+ -> Parsec [Char] ParserState Int
450450orderedListMarker style delim = do
451451 let num = defaultNum <|> -- # can continue any kind of list
452452 case style of
@@ -466,19 +466,19 @@ orderedListMarker style delim = do
466466 return start
467467
468468-- | Parses a character reference and returns a Str element.
469−charRef :: GenParser Char st Inline
469+charRef :: Parsec [Char] st Inline
470470charRef = do
471471 c <- characterReference
472472 return $ Str [c]
473473
474474-- | Parse a table using 'headerParser', 'rowParser',
475475-- 'lineParser', and 'footerParser'.
476−tableWith :: GenParser Char ParserState ([[Block]], [Alignment], [Int])
477− -> ([Int] -> GenParser Char ParserState [[Block]])
478− -> GenParser Char ParserState sep
479− -> GenParser Char ParserState end
480− -> GenParser Char ParserState [Inline]
481− -> GenParser Char ParserState Block
476+tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
477+ -> ([Int] -> Parsec [Char] ParserState [[Block]])
478+ -> Parsec [Char] ParserState sep
479+ -> Parsec [Char] ParserState end
480+ -> Parsec [Char] ParserState [Inline]
481+ -> Parsec [Char] ParserState Block
482482tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
483483 caption' <- option [] captionParser
484484 (heads, aligns, indices) <- headerParser
@@ -521,10 +521,10 @@ widthsFromIndices numColumns' indices =
521521-- (which may be grid), then the rows,
522522-- which may be grid, separated by blank lines, and
523523-- ending with a footer (dashed line followed by blank line).
524−gridTableWith :: GenParser Char ParserState Block -- ^ Block parser
525− -> GenParser Char ParserState [Inline] -- ^ Caption parser
524+gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser
525+ -> Parsec [Char] ParserState [Inline] -- ^ Caption parser
526526 -> Bool -- ^ Headerless table
527− -> GenParser Char ParserState Block
527+ -> Parsec [Char] ParserState Block
528528gridTableWith block tableCaption headless =
529529 tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
530530
@@ -532,13 +532,13 @@ gridTableSplitLine :: [Int] -> String -> [String]
532532gridTableSplitLine indices line = map removeFinalBar $ tail $
533533 splitStringByIndices (init indices) $ removeTrailingSpace line
534534
535−gridPart :: Char -> GenParser Char st (Int, Int)
535+gridPart :: Char -> Parsec [Char] st (Int, Int)
536536gridPart ch = do
537537 dashes <- many1 (char ch)
538538 char '+'
539539 return (length dashes, length dashes + 1)
540540
541−gridDashedLines :: Char -> GenParser Char st [(Int,Int)]
541+gridDashedLines :: Char -> Parsec [Char] st [(Int,Int)]
542542gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
543543
544544removeFinalBar :: String -> String
@@ -546,13 +546,13 @@ removeFinalBar =
546546 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
547547
548548-- | Separator between rows of grid table.
549−gridTableSep :: Char -> GenParser Char ParserState Char
549+gridTableSep :: Char -> Parsec [Char] ParserState Char
550550gridTableSep ch = try $ gridDashedLines ch >> return '\n'
551551
552552-- | Parse header for a grid table.
553553gridTableHeader :: Bool -- ^ Headerless table
554− -> GenParser Char ParserState Block
555− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
554+ -> Parsec [Char] ParserState Block
555+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
556556gridTableHeader headless block = try $ do
557557 optional blanklines
558558 dashes <- gridDashedLines '-'
@@ -576,16 +576,16 @@ gridTableHeader headless block = try $ do
576576 map removeLeadingTrailingSpace rawHeads
577577 return (heads, aligns, indices)
578578
579−gridTableRawLine :: [Int] -> GenParser Char ParserState [String]
579+gridTableRawLine :: [Int] -> Parsec [Char] ParserState [String]
580580gridTableRawLine indices = do
581581 char '|'
582582 line <- many1Till anyChar newline
583583 return (gridTableSplitLine indices line)
584584
585585-- | Parse row of grid table.
586−gridTableRow :: GenParser Char ParserState Block
586+gridTableRow :: Parsec [Char] ParserState Block
587587 -> [Int]
588− -> GenParser Char ParserState [[Block]]
588+ -> Parsec [Char] ParserState [[Block]]
589589gridTableRow block indices = do
590590 colLines <- many1 (gridTableRawLine indices)
591591 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
@@ -604,13 +604,13 @@ compactifyCell :: [Block] -> [Block]
604604compactifyCell bs = head $ compactify [bs]
605605
606606-- | Parse footer for a grid table.
607−gridTableFooter :: GenParser Char ParserState [Char]
607+gridTableFooter :: Parsec [Char] ParserState [Char]
608608gridTableFooter = blanklines
609609
610610---
611611
612612-- | Parse a string with a given parser and state.
613−readWith :: GenParser t ParserState a -- ^ parser
613+readWith :: Parsec [t] ParserState a -- ^ parser
614614 -> ParserState -- ^ initial state
615615 -> [t] -- ^ input
616616 -> a
@@ -620,7 +620,7 @@ readWith parser state input =
620620 Right result -> result
621621
622622-- | Parse a string with @parser@ (for testing).
623−testStringWith :: (Show a) => GenParser Char ParserState a
623+testStringWith :: (Show a) => Parsec [Char] ParserState a
624624 -> String
625625 -> IO ()
626626testStringWith parser str = UTF8.putStrLn $ show $
@@ -735,25 +735,25 @@ lookupKeySrc table key = case M.lookup key table of
735735 Just src -> Just src
736736
737737-- | Fail unless we're in "smart typography" mode.
738−failUnlessSmart :: GenParser tok ParserState ()
738+failUnlessSmart :: Parsec [tok] ParserState ()
739739failUnlessSmart = getState >>= guard . stateSmart
740740
741−smartPunctuation :: GenParser Char ParserState Inline
742− -> GenParser Char ParserState Inline
741+smartPunctuation :: Parsec [Char] ParserState Inline
742+ -> Parsec [Char] ParserState Inline
743743smartPunctuation inlineParser = do
744744 failUnlessSmart
745745 choice [ quoted inlineParser, apostrophe, dash, ellipses ]
746746
747−apostrophe :: GenParser Char ParserState Inline
747+apostrophe :: Parsec [Char] ParserState Inline
748748apostrophe = (char '\'' <|> char '\8217') >> return (Str "\x2019")
749749
750−quoted :: GenParser Char ParserState Inline
751− -> GenParser Char ParserState Inline
750+quoted :: Parsec [Char] ParserState Inline
751+ -> Parsec [Char] ParserState Inline
752752quoted inlineParser = doubleQuoted inlineParser <|> singleQuoted inlineParser
753753
754754withQuoteContext :: QuoteContext
755− -> (GenParser Char ParserState Inline)
756− -> GenParser Char ParserState Inline
755+ -> (Parsec [Char] ParserState Inline)
756+ -> Parsec [Char] ParserState Inline
757757withQuoteContext context parser = do
758758 oldState <- getState
759759 let oldQuoteContext = stateQuoteContext oldState
@@ -763,39 +763,39 @@ withQuoteContext context parser = do
763763 setState newState { stateQuoteContext = oldQuoteContext }
764764 return result
765765
766−singleQuoted :: GenParser Char ParserState Inline
767− -> GenParser Char ParserState Inline
766+singleQuoted :: Parsec [Char] ParserState Inline
767+ -> Parsec [Char] ParserState Inline
768768singleQuoted inlineParser = try $ do
769769 singleQuoteStart
770770 withQuoteContext InSingleQuote $ many1Till inlineParser singleQuoteEnd >>=
771771 return . Quoted SingleQuote . normalizeSpaces
772772
773−doubleQuoted :: GenParser Char ParserState Inline
774− -> GenParser Char ParserState Inline
773+doubleQuoted :: Parsec [Char] ParserState Inline
774+ -> Parsec [Char] ParserState Inline
775775doubleQuoted inlineParser = try $ do
776776 doubleQuoteStart
777777 withQuoteContext InDoubleQuote $ do
778778 contents <- manyTill inlineParser doubleQuoteEnd
779779 return . Quoted DoubleQuote . normalizeSpaces $ contents
780780
781−failIfInQuoteContext :: QuoteContext -> GenParser tok ParserState ()
781+failIfInQuoteContext :: QuoteContext -> Parsec [tok] ParserState ()
782782failIfInQuoteContext context = do
783783 st <- getState
784784 if stateQuoteContext st == context
785785 then fail "already inside quotes"
786786 else return ()
787787
788−charOrRef :: [Char] -> GenParser Char st Char
788+charOrRef :: [Char] -> Parsec [Char] st Char
789789charOrRef cs =
790790 oneOf cs <|> try (do c <- characterReference
791791 guard (c `elem` cs)
792792 return c)
793793
794−updateLastStrPos :: GenParser Char ParserState ()
794+updateLastStrPos :: Parsec [Char] ParserState ()
795795updateLastStrPos = getPosition >>= \p ->
796796 updateState $ \s -> s{ stateLastStrPos = Just p }
797797
798−singleQuoteStart :: GenParser Char ParserState ()
798+singleQuoteStart :: Parsec [Char] ParserState ()
799799singleQuoteStart = do
800800 failIfInQuoteContext InSingleQuote
801801 pos <- getPosition
@@ -810,28 +810,28 @@ singleQuoteStart = do
810810 -- possess/contraction
811811 return ()
812812
813−singleQuoteEnd :: GenParser Char st ()
813+singleQuoteEnd :: Parsec [Char] st ()
814814singleQuoteEnd = try $ do
815815 charOrRef "'\8217\146"
816816 notFollowedBy alphaNum
817817
818−doubleQuoteStart :: GenParser Char ParserState ()
818+doubleQuoteStart :: Parsec [Char] ParserState ()
819819doubleQuoteStart = do
820820 failIfInQuoteContext InDoubleQuote
821821 try $ do charOrRef "\"\8220\147"
822822 notFollowedBy (satisfy (\c -> c == ' ' || c == '\t' || c == '\n'))
823823
824−doubleQuoteEnd :: GenParser Char st ()
824+doubleQuoteEnd :: Parsec [Char] st ()
825825doubleQuoteEnd = do
826826 charOrRef "\"\8221\148"
827827 return ()
828828
829−ellipses :: GenParser Char st Inline
829+ellipses :: Parsec [Char] st Inline
830830ellipses = do
831831 try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
832832 return (Str "\8230")
833833
834−dash :: GenParser Char ParserState Inline
834+dash :: Parsec [Char] ParserState Inline
835835dash = do
836836 oldDashes <- stateOldDashes `fmap` getState
837837 if oldDashes
@@ -839,28 +839,28 @@ dash = do
839839 else Str `fmap` (hyphenDash <|> emDash <|> enDash)
840840
841841-- Two hyphens = en-dash, three = em-dash
842−hyphenDash :: GenParser Char st String
842+hyphenDash :: Parsec [Char] st String
843843hyphenDash = do
844844 try $ string "--"
845845 option "\8211" (char '-' >> return "\8212")
846846
847−emDash :: GenParser Char st String
847+emDash :: Parsec [Char] st String
848848emDash = do
849849 try (charOrRef "\8212\151")
850850 return "\8212"
851851
852−enDash :: GenParser Char st String
852+enDash :: Parsec [Char] st String
853853enDash = do
854854 try (charOrRef "\8212\151")
855855 return "\8211"
856856
857−enDashOld :: GenParser Char st Inline
857+enDashOld :: Parsec [Char] st Inline
858858enDashOld = do
859859 try (charOrRef "\8211\150") <|>
860860 try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
861861 return (Str "\8211")
862862
863−emDashOld :: GenParser Char st Inline
863+emDashOld :: Parsec [Char] st Inline
864864emDashOld = do
865865 try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
866866 return (Str "\8212")
@@ -870,12 +870,12 @@ emDashOld = do
870870--
871871
872872-- | Parse a \newcommand or \renewcommand macro definition.
873−macro :: GenParser Char ParserState Block
873+macro :: Parsec [Char] ParserState Block
874874macro = do
875875 apply <- stateApplyMacros `fmap` getState
876876 inp <- getInput
877877 case parseMacroDefinitions inp of
878− ([], _) -> pzero
878+ ([], _) -> mzero
879879 (ms, rest) -> do def' <- count (length inp - length rest) anyChar
880880 if apply
881881 then do
@@ -885,7 +885,7 @@ macro = do
885885 else return $ RawBlock "latex" def'
886886
887887-- | Apply current macros to string.
888−applyMacros' :: String -> GenParser Char ParserState String
888+applyMacros' :: String -> Parsec [Char] ParserState String
889889applyMacros' target = do
890890 apply <- liftM stateApplyMacros getState
891891 if apply
src/Text/Pandoc/Readers/HTML.hs+12−12
@@ -36,8 +36,8 @@ module Text.Pandoc.Readers.HTML ( readHtml
3636 , isCommentTag
3737 ) where
3838
39−import Text.ParserCombinators.Parsec
40−import Text.ParserCombinators.Parsec.Pos
39+import Text.Parsec
40+import Text.Parsec.Pos
4141import Text.HTML.TagSoup
4242import Text.HTML.TagSoup.Match
4343import Text.Pandoc.Definition
@@ -47,7 +47,7 @@ import Text.Pandoc.Parsing
4747import Data.Maybe ( fromMaybe, isJust )
4848import Data.List ( intercalate )
4949import Data.Char ( isDigit, toLower )
50−import Control.Monad ( liftM, guard, when )
50+import Control.Monad ( liftM, guard, when, mzero )
5151
5252isSpace :: Char -> Bool
5353isSpace ' ' = True
@@ -68,7 +68,7 @@ readHtml st inp = Pandoc meta blocks
6868 then parseHeader tags
6969 else (Meta [] [] [], tags)
7070
71−type TagParser = GenParser (Tag String) ParserState
71+type TagParser = Parsec [Tag String] ParserState
7272
7373-- TODO - fix this - not every header has a title tag
7474parseHeader :: [Tag String] -> (Meta, [Tag String])
@@ -417,7 +417,7 @@ pCloses tagtype = try $ do
417417 (TagClose "ul") | tagtype == "li" -> return ()
418418 (TagClose "ol") | tagtype == "li" -> return ()
419419 (TagClose "dl") | tagtype == "li" -> return ()
420− _ -> pzero
420+ _ -> mzero
421421
422422pTagText :: TagParser [Inline]
423423pTagText = try $ do
@@ -432,11 +432,11 @@ pBlank = try $ do
432432 (TagText str) <- pSatisfy isTagText
433433 guard $ all isSpace str
434434
435−pTagContents :: GenParser Char ParserState Inline
435+pTagContents :: Parsec [Char] ParserState Inline
436436pTagContents =
437437 pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol <|> pBad
438438
439−pStr :: GenParser Char ParserState Inline
439+pStr :: Parsec [Char] ParserState Inline
440440pStr = do
441441 result <- many1 $ satisfy $ \c ->
442442 not (isSpace c) && not (isSpecial c) && not (isBad c)
@@ -455,13 +455,13 @@ isSpecial '\8220' = True
455455isSpecial '\8221' = True
456456isSpecial _ = False
457457
458−pSymbol :: GenParser Char ParserState Inline
458+pSymbol :: Parsec [Char] ParserState Inline
459459pSymbol = satisfy isSpecial >>= return . Str . (:[])
460460
461461isBad :: Char -> Bool
462462isBad c = c >= '\128' && c <= '\159' -- not allowed in HTML
463463
464−pBad :: GenParser Char ParserState Inline
464+pBad :: Parsec [Char] ParserState Inline
465465pBad = do
466466 c <- satisfy isBad
467467 let c' = case c of
@@ -495,7 +495,7 @@ pBad = do
495495 _ -> '?'
496496 return $ Str [c']
497497
498−pSpace :: GenParser Char ParserState Inline
498+pSpace :: Parsec [Char] ParserState Inline
499499pSpace = many1 (satisfy isSpace) >> return Space
500500
501501--
@@ -593,7 +593,7 @@ _ `closes` _ = False
593593--- parsers for use in markdown, textile readers
594594
595595-- | Matches a stretch of HTML in balanced tags.
596−htmlInBalanced :: (Tag String -> Bool) -> GenParser Char ParserState String
596+htmlInBalanced :: (Tag String -> Bool) -> Parsec [Char] ParserState String
597597htmlInBalanced f = try $ do
598598 (TagOpen t _, tag) <- htmlTag f
599599 guard $ '/' `notElem` tag -- not a self-closing tag
@@ -606,7 +606,7 @@ htmlInBalanced f = try $ do
606606 return $ tag ++ concat contents ++ endtag
607607
608608-- | Matches a tag meeting a certain condition.
609−htmlTag :: (Tag String -> Bool) -> GenParser Char ParserState (Tag String, String)
609+htmlTag :: (Tag String -> Bool) -> Parsec [Char] ParserState (Tag String, String)
610610htmlTag f = try $ do
611611 lookAhead (char '<')
612612 (next : _) <- getInput >>= return . canonicalizeTags . parseTags
src/Text/Pandoc/Readers/LaTeX.hs+4−4
@@ -33,7 +33,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
3333 handleIncludes
3434 ) where
3535
36−import Text.ParserCombinators.Parsec hiding ((<|>), space, many, optional)
36+import Text.Parsec hiding ((<|>), space, many, optional)
3737import Text.Pandoc.Definition
3838import Text.Pandoc.Shared
3939import Text.Pandoc.Parsing
@@ -64,7 +64,7 @@ parseLaTeX = do
6464 let date' = stateDate st
6565 return $ Pandoc (Meta title' authors' date') $ toList bs
6666
67−type LP = GenParser Char ParserState
67+type LP = Parsec [Char] ParserState
6868
6969anyControlSeq :: LP String
7070anyControlSeq = do
@@ -713,10 +713,10 @@ verbatimEnv = do
713713 rest <- getInput
714714 return (r,rest)
715715
716−rawLaTeXBlock :: GenParser Char ParserState String
716+rawLaTeXBlock :: Parsec [Char] ParserState String
717717rawLaTeXBlock = snd <$> withRaw (environment <|> blockCommand)
718718
719−rawLaTeXInline :: GenParser Char ParserState Inline
719+rawLaTeXInline :: Parsec [Char] ParserState Inline
720720rawLaTeXInline = do
721721 (res, raw) <- withRaw inlineCommand
722722 if res == mempty
src/Text/Pandoc/Readers/Markdown.hs+137−137
@@ -43,7 +43,7 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
4343import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
4444 isTextTag, isCommentTag )
4545import Text.Pandoc.XML ( fromEntities )
46−import Text.ParserCombinators.Parsec
46+import Text.Parsec
4747import Control.Monad (when, liftM, guard, mzero)
4848import Text.HTML.TagSoup
4949import Text.HTML.TagSoup.Match (tagOpen)
@@ -83,14 +83,14 @@ isBlank _ = False
8383-- auxiliary functions
8484--
8585
86−indentSpaces :: GenParser Char ParserState [Char]
86+indentSpaces :: Parsec [Char] ParserState [Char]
8787indentSpaces = try $ do
8888 state <- getState
8989 let tabStop = stateTabStop state
9090 count tabStop (char ' ') <|>
9191 string "\t" <?> "indentation"
9292
93−nonindentSpaces :: GenParser Char ParserState [Char]
93+nonindentSpaces :: Parsec [Char] ParserState [Char]
9494nonindentSpaces = do
9595 state <- getState
9696 let tabStop = stateTabStop state
@@ -99,30 +99,30 @@ nonindentSpaces = do
9999 then return sps
100100 else unexpected "indented line"
101101
102−skipNonindentSpaces :: GenParser Char ParserState ()
102+skipNonindentSpaces :: Parsec [Char] ParserState ()
103103skipNonindentSpaces = do
104104 state <- getState
105105 atMostSpaces (stateTabStop state - 1)
106106
107−atMostSpaces :: Int -> GenParser Char ParserState ()
107+atMostSpaces :: Int -> Parsec [Char] ParserState ()
108108atMostSpaces 0 = notFollowedBy (char ' ')
109109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
110110
111−litChar :: GenParser Char ParserState Char
111+litChar :: Parsec [Char] ParserState Char
112112litChar = escapedChar'
113113 <|> noneOf "\n"
114114 <|> (newline >> notFollowedBy blankline >> return ' ')
115115
116116-- | Fail unless we're at beginning of a line.
117−failUnlessBeginningOfLine :: GenParser tok st ()
117+failUnlessBeginningOfLine :: Parsec [tok] st ()
118118failUnlessBeginningOfLine = do
119119 pos <- getPosition
120120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
121121
122122-- | Parse a sequence of inline elements between square brackets,
123123-- including inlines between balanced pairs of square brackets.
124−inlinesInBalancedBrackets :: GenParser Char ParserState Inline
125− -> GenParser Char ParserState [Inline]
124+inlinesInBalancedBrackets :: Parsec [Char] ParserState Inline
125+ -> Parsec [Char] ParserState [Inline]
126126inlinesInBalancedBrackets parser = try $ do
127127 char '['
128128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
@@ -137,7 +137,7 @@ inlinesInBalancedBrackets parser = try $ do
137137-- document structure
138138--
139139
140−titleLine :: GenParser Char ParserState [Inline]
140+titleLine :: Parsec [Char] ParserState [Inline]
141141titleLine = try $ do
142142 char '%'
143143 skipSpaces
@@ -146,7 +146,7 @@ titleLine = try $ do
146146 newline
147147 return $ normalizeSpaces res
148148
149−authorsLine :: GenParser Char ParserState [[Inline]]
149+authorsLine :: Parsec [Char] ParserState [[Inline]]
150150authorsLine = try $ do
151151 char '%'
152152 skipSpaces
@@ -157,14 +157,14 @@ authorsLine = try $ do
157157 newline
158158 return $ filter (not . null) $ map normalizeSpaces authors
159159
160−dateLine :: GenParser Char ParserState [Inline]
160+dateLine :: Parsec [Char] ParserState [Inline]
161161dateLine = try $ do
162162 char '%'
163163 skipSpaces
164164 date <- manyTill inline newline
165165 return $ normalizeSpaces date
166166
167−titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline])
167+titleBlock :: Parsec [Char] ParserState ([Inline], [[Inline]], [Inline])
168168titleBlock = try $ do
169169 failIfStrict
170170 title <- option [] titleLine
@@ -173,7 +173,7 @@ titleBlock = try $ do
173173 optional blanklines
174174 return (title, author, date)
175175
176−parseMarkdown :: GenParser Char ParserState Pandoc
176+parseMarkdown :: Parsec [Char] ParserState Pandoc
177177parseMarkdown = do
178178 -- markdown allows raw HTML
179179 updateState (\state -> state { stateParseRaw = True })
@@ -182,7 +182,7 @@ parseMarkdown = do
182182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
183183 st <- getState
184184 let firstPassParser = referenceKey
185− <|> (if stateStrict st then pzero else noteBlock)
185+ <|> (if stateStrict st then mzero else noteBlock)
186186 <|> liftM snd (withRaw codeBlockDelimited)
187187 <|> lineClump
188188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
@@ -211,7 +211,7 @@ parseMarkdown = do
211211-- initial pass for references and notes
212212--
213213
214−referenceKey :: GenParser Char ParserState [Char]
214+referenceKey :: Parsec [Char] ParserState [Char]
215215referenceKey = try $ do
216216 startPos <- getPosition
217217 skipNonindentSpaces
@@ -238,7 +238,7 @@ referenceKey = try $ do
238238 -- return blanks so line count isn't affected
239239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
240240
241−referenceTitle :: GenParser Char ParserState String
241+referenceTitle :: Parsec [Char] ParserState String
242242referenceTitle = try $ do
243243 skipSpaces >> optional newline >> skipSpaces
244244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
@@ -247,23 +247,23 @@ referenceTitle = try $ do
247247 notFollowedBy (noneOf ")\n")))
248248 return $ fromEntities tit
249249
250−noteMarker :: GenParser Char ParserState [Char]
250+noteMarker :: Parsec [Char] ParserState [Char]
251251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
252252
253−rawLine :: GenParser Char ParserState [Char]
253+rawLine :: Parsec [Char] ParserState [Char]
254254rawLine = try $ do
255255 notFollowedBy blankline
256256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
257257 optional indentSpaces
258258 anyLine
259259
260−rawLines :: GenParser Char ParserState [Char]
260+rawLines :: Parsec [Char] ParserState [Char]
261261rawLines = do
262262 first <- anyLine
263263 rest <- many rawLine
264264 return $ unlines (first:rest)
265265
266−noteBlock :: GenParser Char ParserState [Char]
266+noteBlock :: Parsec [Char] ParserState [Char]
267267noteBlock = try $ do
268268 startPos <- getPosition
269269 skipNonindentSpaces
@@ -287,10 +287,10 @@ noteBlock = try $ do
287287-- parsing blocks
288288--
289289
290−parseBlocks :: GenParser Char ParserState [Block]
290+parseBlocks :: Parsec [Char] ParserState [Block]
291291parseBlocks = manyTill block eof
292292
293−block :: GenParser Char ParserState Block
293+block :: Parsec [Char] ParserState Block
294294block = do
295295 st <- getState
296296 choice (if stateStrict st
@@ -325,10 +325,10 @@ block = do
325325-- header blocks
326326--
327327
328−header :: GenParser Char ParserState Block
328+header :: Parsec [Char] ParserState Block
329329header = setextHeader <|> atxHeader <?> "header"
330330
331−atxHeader :: GenParser Char ParserState Block
331+atxHeader :: Parsec [Char] ParserState Block
332332atxHeader = try $ do
333333 level <- many1 (char '#') >>= return . length
334334 notFollowedBy (char '.' <|> char ')') -- this would be a list
@@ -336,10 +336,10 @@ atxHeader = try $ do
336336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
337337 return $ Header level text
338338
339−atxClosing :: GenParser Char st [Char]
339+atxClosing :: Parsec [Char] st [Char]
340340atxClosing = try $ skipMany (char '#') >> blanklines
341341
342−setextHeader :: GenParser Char ParserState Block
342+setextHeader :: Parsec [Char] ParserState Block
343343setextHeader = try $ do
344344 -- This lookahead prevents us from wasting time parsing Inlines
345345 -- unless necessary -- it gives a significant performance boost.
@@ -355,7 +355,7 @@ setextHeader = try $ do
355355-- hrule block
356356--
357357
358−hrule :: GenParser Char st Block
358+hrule :: Parsec [Char] st Block
359359hrule = try $ do
360360 skipSpaces
361361 start <- satisfy isHruleChar
@@ -369,12 +369,12 @@ hrule = try $ do
369369-- code blocks
370370--
371371
372−indentedLine :: GenParser Char ParserState [Char]
372+indentedLine :: Parsec [Char] ParserState [Char]
373373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
374374
375375blockDelimiter :: (Char -> Bool)
376376 -> Maybe Int
377− -> GenParser Char st (Int, (String, [String], [(String, String)]), Char)
377+ -> Parsec [Char] st (Int, (String, [String], [(String, String)]), Char)
378378blockDelimiter f len = try $ do
379379 c <- lookAhead (satisfy f)
380380 size <- case len of
@@ -388,7 +388,7 @@ blockDelimiter f len = try $ do
388388 blankline
389389 return (size, attr, c)
390390
391−attributes :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
391+attributes :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
392392attributes = try $ do
393393 char '{'
394394 spnl
@@ -400,28 +400,28 @@ attributes = try $ do
400400 | otherwise = firstNonNull xs
401401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
402402
403−attribute :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
403+attribute :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
404404attribute = identifierAttr <|> classAttr <|> keyValAttr
405405
406−identifier :: GenParser Char st [Char]
406+identifier :: Parsec [Char] st [Char]
407407identifier = do
408408 first <- letter
409409 rest <- many $ alphaNum <|> oneOf "-_:."
410410 return (first:rest)
411411
412−identifierAttr :: GenParser Char st ([Char], [a], [a1])
412+identifierAttr :: Parsec [Char] st ([Char], [a], [a1])
413413identifierAttr = try $ do
414414 char '#'
415415 result <- identifier
416416 return (result,[],[])
417417
418−classAttr :: GenParser Char st ([Char], [[Char]], [a])
418+classAttr :: Parsec [Char] st ([Char], [[Char]], [a])
419419classAttr = try $ do
420420 char '.'
421421 result <- identifier
422422 return ("",[result],[])
423423
424−keyValAttr :: GenParser Char st ([Char], [a], [([Char], [Char])])
424+keyValAttr :: Parsec [Char] st ([Char], [a], [([Char], [Char])])
425425keyValAttr = try $ do
426426 key <- identifier
427427 char '='
@@ -430,14 +430,14 @@ keyValAttr = try $ do
430430 <|> many nonspaceChar
431431 return ("",[],[(key,val)])
432432
433−codeBlockDelimited :: GenParser Char st Block
433+codeBlockDelimited :: Parsec [Char] st Block
434434codeBlockDelimited = try $ do
435435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
436436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
437437 blanklines
438438 return $ CodeBlock attr $ intercalate "\n" contents
439439
440−codeBlockIndented :: GenParser Char ParserState Block
440+codeBlockIndented :: Parsec [Char] ParserState Block
441441codeBlockIndented = do
442442 contents <- many1 (indentedLine <|>
443443 try (do b <- blanklines
@@ -448,7 +448,7 @@ codeBlockIndented = do
448448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
449449 stripTrailingNewlines $ concat contents
450450
451−lhsCodeBlock :: GenParser Char ParserState Block
451+lhsCodeBlock :: Parsec [Char] ParserState Block
452452lhsCodeBlock = do
453453 failUnlessLHS
454454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
@@ -456,7 +456,7 @@ lhsCodeBlock = do
456456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
457457 lhsCodeBlockInverseBird
458458
459−lhsCodeBlockLaTeX :: GenParser Char ParserState String
459+lhsCodeBlockLaTeX :: Parsec [Char] ParserState String
460460lhsCodeBlockLaTeX = try $ do
461461 string "\\begin{code}"
462462 manyTill spaceChar newline
@@ -464,13 +464,13 @@ lhsCodeBlockLaTeX = try $ do
464464 blanklines
465465 return $ stripTrailingNewlines contents
466466
467−lhsCodeBlockBird :: GenParser Char ParserState String
467+lhsCodeBlockBird :: Parsec [Char] ParserState String
468468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
469469
470−lhsCodeBlockInverseBird :: GenParser Char ParserState String
470+lhsCodeBlockInverseBird :: Parsec [Char] ParserState String
471471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
472472
473−lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
473+lhsCodeBlockBirdWith :: Char -> Parsec [Char] ParserState String
474474lhsCodeBlockBirdWith c = try $ do
475475 pos <- getPosition
476476 when (sourceColumn pos /= 1) $ fail "Not in first column"
@@ -482,7 +482,7 @@ lhsCodeBlockBirdWith c = try $ do
482482 blanklines
483483 return $ intercalate "\n" lns'
484484
485−birdTrackLine :: Char -> GenParser Char st [Char]
485+birdTrackLine :: Char -> Parsec [Char] st [Char]
486486birdTrackLine c = try $ do
487487 char c
488488 -- allow html tags on left margin:
@@ -494,10 +494,10 @@ birdTrackLine c = try $ do
494494-- block quotes
495495--
496496
497−emailBlockQuoteStart :: GenParser Char ParserState Char
497+emailBlockQuoteStart :: Parsec [Char] ParserState Char
498498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
499499
500−emailBlockQuote :: GenParser Char ParserState [[Char]]
500+emailBlockQuote :: Parsec [Char] ParserState [[Char]]
501501emailBlockQuote = try $ do
502502 emailBlockQuoteStart
503503 raw <- sepBy (many (nonEndline <|>
@@ -508,7 +508,7 @@ emailBlockQuote = try $ do
508508 optional blanklines
509509 return raw
510510
511−blockQuote :: GenParser Char ParserState Block
511+blockQuote :: Parsec [Char] ParserState Block
512512blockQuote = do
513513 raw <- emailBlockQuote
514514 -- parse the extracted block, which may contain various block elements:
@@ -519,7 +519,7 @@ blockQuote = do
519519-- list blocks
520520--
521521
522−bulletListStart :: GenParser Char ParserState ()
522+bulletListStart :: Parsec [Char] ParserState ()
523523bulletListStart = try $ do
524524 optional newline -- if preceded by a Plain block in a list context
525525 skipNonindentSpaces
@@ -528,7 +528,7 @@ bulletListStart = try $ do
528528 spaceChar
529529 skipSpaces
530530
531−anyOrderedListStart :: GenParser Char ParserState (Int, ListNumberStyle, ListNumberDelim)
531+anyOrderedListStart :: Parsec [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
532532anyOrderedListStart = try $ do
533533 optional newline -- if preceded by a Plain block in a list context
534534 skipNonindentSpaces
@@ -548,11 +548,11 @@ anyOrderedListStart = try $ do
548548 skipSpaces
549549 return (num, style, delim)
550550
551−listStart :: GenParser Char ParserState ()
551+listStart :: Parsec [Char] ParserState ()
552552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
553553
554554-- parse a line of a list item (start = parser for beginning of list item)
555−listLine :: GenParser Char ParserState [Char]
555+listLine :: Parsec [Char] ParserState [Char]
556556listLine = try $ do
557557 notFollowedBy blankline
558558 notFollowedBy' (do indentSpaces
@@ -562,8 +562,8 @@ listLine = try $ do
562562 return $ concat chunks ++ "\n"
563563
564564-- parse raw text for one list item, excluding start marker and continuations
565−rawListItem :: GenParser Char ParserState a
566− -> GenParser Char ParserState [Char]
565+rawListItem :: Parsec [Char] ParserState a
566+ -> Parsec [Char] ParserState [Char]
567567rawListItem start = try $ do
568568 start
569569 first <- listLine
@@ -574,14 +574,14 @@ rawListItem start = try $ do
574574-- continuation of a list item - indented and separated by blankline
575575-- or (in compact lists) endline.
576576-- note: nested lists are parsed as continuations
577−listContinuation :: GenParser Char ParserState [Char]
577+listContinuation :: Parsec [Char] ParserState [Char]
578578listContinuation = try $ do
579579 lookAhead indentSpaces
580580 result <- many1 listContinuationLine
581581 blanks <- many blankline
582582 return $ concat result ++ blanks
583583
584−listContinuationLine :: GenParser Char ParserState [Char]
584+listContinuationLine :: Parsec [Char] ParserState [Char]
585585listContinuationLine = try $ do
586586 notFollowedBy blankline
587587 notFollowedBy' listStart
@@ -589,8 +589,8 @@ listContinuationLine = try $ do
589589 result <- manyTill anyChar newline
590590 return $ result ++ "\n"
591591
592−listItem :: GenParser Char ParserState a
593− -> GenParser Char ParserState [Block]
592+listItem :: Parsec [Char] ParserState a
593+ -> Parsec [Char] ParserState [Block]
594594listItem start = try $ do
595595 first <- rawListItem start
596596 continuations <- many listContinuation
@@ -606,7 +606,7 @@ listItem start = try $ do
606606 updateState (\st -> st {stateParserContext = oldContext})
607607 return contents
608608
609−orderedList :: GenParser Char ParserState Block
609+orderedList :: Parsec [Char] ParserState Block
610610orderedList = try $ do
611611 (start, style, delim) <- lookAhead anyOrderedListStart
612612 items <- many1 $ listItem $ try $
@@ -615,13 +615,13 @@ orderedList = try $ do
615615 orderedListMarker style delim
616616 return $ OrderedList (start, style, delim) $ compactify items
617617
618−bulletList :: GenParser Char ParserState Block
618+bulletList :: Parsec [Char] ParserState Block
619619bulletList =
620620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
621621
622622-- definition lists
623623
624−defListMarker :: GenParser Char ParserState ()
624+defListMarker :: Parsec [Char] ParserState ()
625625defListMarker = do
626626 sps <- nonindentSpaces
627627 char ':' <|> char '~'
@@ -630,10 +630,10 @@ defListMarker = do
630630 let remaining = tabStop - (length sps + 1)
631631 if remaining > 0
632632 then count remaining (char ' ') <|> string "\t"
633− else pzero
633+ else mzero
634634 return ()
635635
636−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
636+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
637637definitionListItem = try $ do
638638 -- first, see if this has any chance of being a definition list:
639639 lookAhead (anyLine >> optional blankline >> defListMarker)
@@ -647,7 +647,7 @@ definitionListItem = try $ do
647647 updateState (\st -> st {stateParserContext = oldContext})
648648 return ((normalizeSpaces term), contents)
649649
650−defRawBlock :: GenParser Char ParserState [Char]
650+defRawBlock :: Parsec [Char] ParserState [Char]
651651defRawBlock = try $ do
652652 defListMarker
653653 firstline <- anyLine
@@ -659,7 +659,7 @@ defRawBlock = try $ do
659659 return $ unlines lns ++ trl
660660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
661661
662−definitionList :: GenParser Char ParserState Block
662+definitionList :: Parsec [Char] ParserState Block
663663definitionList = do
664664 items <- many1 definitionListItem
665665 -- "compactify" the definition list:
@@ -688,7 +688,7 @@ isHtmlOrBlank (Space) = True
688688isHtmlOrBlank (LineBreak) = True
689689isHtmlOrBlank _ = False
690690
691−para :: GenParser Char ParserState Block
691+para :: Parsec [Char] ParserState Block
692692para = try $ do
693693 result <- liftM normalizeSpaces $ many1 inline
694694 guard $ not . all isHtmlOrBlank $ result
@@ -699,17 +699,17 @@ para = try $ do
699699 lookAhead (blockQuote <|> header) >> return "")
700700 return $ Para result
701701
702−plain :: GenParser Char ParserState Block
702+plain :: Parsec [Char] ParserState Block
703703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
704704
705705--
706706-- raw html
707707--
708708
709−htmlElement :: GenParser Char ParserState [Char]
709+htmlElement :: Parsec [Char] ParserState [Char]
710710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
711711
712−htmlBlock :: GenParser Char ParserState Block
712+htmlBlock :: Parsec [Char] ParserState Block
713713htmlBlock = try $ do
714714 failUnlessBeginningOfLine
715715 first <- htmlElement
@@ -717,12 +717,12 @@ htmlBlock = try $ do
717717 finalNewlines <- many newline
718718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
719719
720−strictHtmlBlock :: GenParser Char ParserState [Char]
720+strictHtmlBlock :: Parsec [Char] ParserState [Char]
721721strictHtmlBlock = do
722722 failUnlessBeginningOfLine
723723 htmlInBalanced (not . isInlineTag)
724724
725−rawVerbatimBlock :: GenParser Char ParserState String
725+rawVerbatimBlock :: Parsec [Char] ParserState String
726726rawVerbatimBlock = try $ do
727727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
728728 t == "pre" || t == "style" || t == "script")
@@ -730,7 +730,7 @@ rawVerbatimBlock = try $ do
730730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
731731 return $ open ++ contents ++ renderTags [TagClose tag]
732732
733−rawTeXBlock :: GenParser Char ParserState Block
733+rawTeXBlock :: Parsec [Char] ParserState Block
734734rawTeXBlock = do
735735 failIfStrict
736736 result <- liftM (RawBlock "latex") rawLaTeXBlock
@@ -738,7 +738,7 @@ rawTeXBlock = do
738738 spaces
739739 return result
740740
741−rawHtmlBlocks :: GenParser Char ParserState Block
741+rawHtmlBlocks :: Parsec [Char] ParserState Block
742742rawHtmlBlocks = do
743743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
744744 liftM snd (htmlTag isBlockTag)
@@ -762,7 +762,7 @@ rawHtmlBlocks = do
762762-- Parse a dashed line with optional trailing spaces; return its length
763763-- and the length including trailing space.
764764dashedLine :: Char
765− -> GenParser Char st (Int, Int)
765+ -> Parsec [Char] st (Int, Int)
766766dashedLine ch = do
767767 dashes <- many1 (char ch)
768768 sp <- many spaceChar
@@ -771,7 +771,7 @@ dashedLine ch = do
771771-- Parse a table header with dashed lines of '-' preceded by
772772-- one (or zero) line of text.
773773simpleTableHeader :: Bool -- ^ Headerless table
774− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
774+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
775775simpleTableHeader headless = try $ do
776776 rawContent <- if headless
777777 then return ""
@@ -795,16 +795,16 @@ simpleTableHeader headless = try $ do
795795 return (heads, aligns, indices)
796796
797797-- Parse a table footer - dashed lines followed by blank line.
798−tableFooter :: GenParser Char ParserState [Char]
798+tableFooter :: Parsec [Char] ParserState [Char]
799799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
800800
801801-- Parse a table separator - dashed line.
802−tableSep :: GenParser Char ParserState Char
802+tableSep :: Parsec [Char] ParserState Char
803803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
804804
805805-- Parse a raw line and split it into chunks by indices.
806806rawTableLine :: [Int]
807− -> GenParser Char ParserState [String]
807+ -> Parsec [Char] ParserState [String]
808808rawTableLine indices = do
809809 notFollowedBy' (blanklines <|> tableFooter)
810810 line <- many1Till anyChar newline
@@ -813,12 +813,12 @@ rawTableLine indices = do
813813
814814-- Parse a table line and return a list of lists of blocks (columns).
815815tableLine :: [Int]
816− -> GenParser Char ParserState [[Block]]
816+ -> Parsec [Char] ParserState [[Block]]
817817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
818818
819819-- Parse a multiline table row and return a list of blocks (columns).
820820multilineRow :: [Int]
821− -> GenParser Char ParserState [[Block]]
821+ -> Parsec [Char] ParserState [[Block]]
822822multilineRow indices = do
823823 colLines <- many1 (rawTableLine indices)
824824 let cols = map unlines $ transpose colLines
@@ -826,7 +826,7 @@ multilineRow indices = do
826826
827827-- Parses a table caption: inlines beginning with 'Table:'
828828-- and followed by blank lines.
829−tableCaption :: GenParser Char ParserState [Inline]
829+tableCaption :: Parsec [Char] ParserState [Inline]
830830tableCaption = try $ do
831831 skipNonindentSpaces
832832 string ":" <|> string "Table:"
@@ -836,7 +836,7 @@ tableCaption = try $ do
836836
837837-- Parse a simple table with '---' header and one line per row.
838838simpleTable :: Bool -- ^ Headerless table
839− -> GenParser Char ParserState Block
839+ -> Parsec [Char] ParserState Block
840840simpleTable headless = do
841841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
842842 (return ())
@@ -850,12 +850,12 @@ simpleTable headless = do
850850-- which may be multiline, separated by blank lines, and
851851-- ending with a footer (dashed line followed by blank line).
852852multilineTable :: Bool -- ^ Headerless table
853− -> GenParser Char ParserState Block
853+ -> Parsec [Char] ParserState Block
854854multilineTable headless =
855855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
856856
857857multilineTableHeader :: Bool -- ^ Headerless table
858− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
858+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
859859multilineTableHeader headless = try $ do
860860 if headless
861861 then return '\n'
@@ -903,10 +903,10 @@ alignType strLst len =
903903 (False, False) -> AlignDefault
904904
905905gridTable :: Bool -- ^ Headerless table
906− -> GenParser Char ParserState Block
906+ -> Parsec [Char] ParserState Block
907907gridTable = gridTableWith block tableCaption
908908
909−table :: GenParser Char ParserState Block
909+table :: Parsec [Char] ParserState Block
910910table = multilineTable False <|> simpleTable True <|>
911911 simpleTable False <|> multilineTable True <|>
912912 gridTable False <|> gridTable True <?> "table"
@@ -915,10 +915,10 @@ table = multilineTable False <|> simpleTable True <|>
915915-- inline
916916--
917917
918−inline :: GenParser Char ParserState Inline
918+inline :: Parsec [Char] ParserState Inline
919919inline = choice inlineParsers <?> "inline"
920920
921−inlineParsers :: [GenParser Char ParserState Inline]
921+inlineParsers :: [Parsec [Char] ParserState Inline]
922922inlineParsers = [ whitespace
923923 , str
924924 , endline
@@ -945,7 +945,7 @@ inlineParsers = [ whitespace
945945 , symbol
946946 , ltSign ]
947947
948−escapedChar' :: GenParser Char ParserState Char
948+escapedChar' :: Parsec [Char] ParserState Char
949949escapedChar' = try $ do
950950 char '\\'
951951 state <- getState
@@ -953,7 +953,7 @@ escapedChar' = try $ do
953953 then oneOf "\\`*_{}[]()>#+-.!~"
954954 else satisfy (not . isAlphaNum)
955955
956−escapedChar :: GenParser Char ParserState Inline
956+escapedChar :: Parsec [Char] ParserState Inline
957957escapedChar = do
958958 result <- escapedChar'
959959 return $ case result of
@@ -961,7 +961,7 @@ escapedChar = do
961961 '\n' -> LineBreak -- "\[newline]" is a linebreak
962962 _ -> Str [result]
963963
964−ltSign :: GenParser Char ParserState Inline
964+ltSign :: Parsec [Char] ParserState Inline
965965ltSign = do
966966 st <- getState
967967 if stateStrict st
@@ -969,7 +969,7 @@ ltSign = do
969969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
970970 return $ Str ['<']
971971
972−exampleRef :: GenParser Char ParserState Inline
972+exampleRef :: Parsec [Char] ParserState Inline
973973exampleRef = try $ do
974974 char '@'
975975 lab <- many1 (alphaNum <|> oneOf "-_")
@@ -977,7 +977,7 @@ exampleRef = try $ do
977977 -- later. See the end of parseMarkdown.
978978 return $ Str $ '@' : lab
979979
980−symbol :: GenParser Char ParserState Inline
980+symbol :: Parsec [Char] ParserState Inline
981981symbol = do
982982 result <- noneOf "<\\\n\t "
983983 <|> try (do lookAhead $ char '\\'
@@ -986,7 +986,7 @@ symbol = do
986986 return $ Str [result]
987987
988988-- parses inline code, between n `s and n `s
989−code :: GenParser Char ParserState Inline
989+code :: Parsec [Char] ParserState Inline
990990code = try $ do
991991 starts <- many1 (char '`')
992992 skipSpaces
@@ -997,26 +997,26 @@ code = try $ do
997997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
998998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
999999
1000−mathWord :: GenParser Char st [Char]
1000+mathWord :: Parsec [Char] st [Char]
10011001mathWord = liftM concat $ many1 mathChunk
10021002
1003−mathChunk :: GenParser Char st [Char]
1003+mathChunk :: Parsec [Char] st [Char]
10041004mathChunk = do char '\\'
10051005 c <- anyChar
10061006 return ['\\',c]
10071007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
10081008
1009−math :: GenParser Char ParserState Inline
1009+math :: Parsec [Char] ParserState Inline
10101010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
10111011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
10121012
1013−mathDisplay :: GenParser Char ParserState String
1013+mathDisplay :: Parsec [Char] ParserState String
10141014mathDisplay = try $ do
10151015 failIfStrict
10161016 string "$$"
10171017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
10181018
1019−mathInline :: GenParser Char ParserState String
1019+mathInline :: Parsec [Char] ParserState String
10201020mathInline = try $ do
10211021 failIfStrict
10221022 char '$'
@@ -1028,7 +1028,7 @@ mathInline = try $ do
10281028
10291029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
10301030-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1031−fours :: GenParser Char st Inline
1031+fours :: Parsec [Char] st Inline
10321032fours = try $ do
10331033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
10341034 count 2 $ satisfy (==x)
@@ -1037,9 +1037,9 @@ fours = try $ do
10371037
10381038-- | Parses a list of inlines between start and end delimiters.
10391039inlinesBetween :: (Show b)
1040− => GenParser Char ParserState a
1041− -> GenParser Char ParserState b
1042− -> GenParser Char ParserState [Inline]
1040+ => Parsec [Char] ParserState a
1041+ -> Parsec [Char] ParserState b
1042+ -> Parsec [Char] ParserState [Inline]
10431043inlinesBetween start end =
10441044 normalizeSpaces `liftM` try (start >> many1Till inner end)
10451045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
@@ -1047,8 +1047,8 @@ inlinesBetween start end =
10471047
10481048-- This is used to prevent exponential blowups for things like:
10491049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1050−nested :: GenParser Char ParserState a
1051− -> GenParser Char ParserState a
1050+nested :: Parsec [Char] ParserState a
1051+ -> Parsec [Char] ParserState a
10521052nested p = do
10531053 nestlevel <- stateMaxNestingLevel `fmap` getState
10541054 guard $ nestlevel > 0
@@ -1057,7 +1057,7 @@ nested p = do
10571057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
10581058 return res
10591059
1060−emph :: GenParser Char ParserState Inline
1060+emph :: Parsec [Char] ParserState Inline
10611061emph = Emph `fmap` nested
10621062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
10631063 where starStart = char '*' >> lookAhead nonspaceChar
@@ -1065,7 +1065,7 @@ emph = Emph `fmap` nested
10651065 ulStart = char '_' >> lookAhead nonspaceChar
10661066 ulEnd = notFollowedBy' strong >> char '_'
10671067
1068−strong :: GenParser Char ParserState Inline
1068+strong :: Parsec [Char] ParserState Inline
10691069strong = Strong `liftM` nested
10701070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
10711071 where starStart = string "**" >> lookAhead nonspaceChar
@@ -1073,32 +1073,32 @@ strong = Strong `liftM` nested
10731073 ulStart = string "__" >> lookAhead nonspaceChar
10741074 ulEnd = try $ string "__"
10751075
1076−strikeout :: GenParser Char ParserState Inline
1076+strikeout :: Parsec [Char] ParserState Inline
10771077strikeout = Strikeout `liftM`
10781078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
10791079 where strikeStart = string "~~" >> lookAhead nonspaceChar
10801080 >> notFollowedBy (char '~')
10811081 strikeEnd = try $ string "~~"
10821082
1083−superscript :: GenParser Char ParserState Inline
1083+superscript :: Parsec [Char] ParserState Inline
10841084superscript = failIfStrict >> enclosed (char '^') (char '^')
10851085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
10861086 return . Superscript
10871087
1088−subscript :: GenParser Char ParserState Inline
1088+subscript :: Parsec [Char] ParserState Inline
10891089subscript = failIfStrict >> enclosed (char '~') (char '~')
10901090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
10911091 return . Subscript
10921092
1093−whitespace :: GenParser Char ParserState Inline
1093+whitespace :: Parsec [Char] ParserState Inline
10941094whitespace = spaceChar >>
10951095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
10961096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
10971097
1098−nonEndline :: GenParser Char st Char
1098+nonEndline :: Parsec [Char] st Char
10991099nonEndline = satisfy (/='\n')
11001100
1101−str :: GenParser Char ParserState Inline
1101+str :: Parsec [Char] ParserState Inline
11021102str = do
11031103 smart <- stateSmart `fmap` getState
11041104 a <- alphaNum
@@ -1136,7 +1136,7 @@ likelyAbbrev x =
11361136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
11371137
11381138-- an endline character that can be treated as a space, not a structural break
1139−endline :: GenParser Char ParserState Inline
1139+endline :: Parsec [Char] ParserState Inline
11401140endline = try $ do
11411141 newline
11421142 notFollowedBy blankline
@@ -1155,20 +1155,20 @@ endline = try $ do
11551155--
11561156
11571157-- a reference label for a link
1158−reference :: GenParser Char ParserState [Inline]
1158+reference :: Parsec [Char] ParserState [Inline]
11591159reference = do notFollowedBy' (string "[^") -- footnote reference
11601160 result <- inlinesInBalancedBrackets inline
11611161 return $ normalizeSpaces result
11621162
11631163-- source for a link, with optional title
1164−source :: GenParser Char ParserState (String, [Char])
1164+source :: Parsec [Char] ParserState (String, [Char])
11651165source =
11661166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
11671167 -- the following is needed for cases like: [ref](/url(a).
11681168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
11691169
11701170-- auxiliary function for source
1171−source' :: GenParser Char ParserState (String, [Char])
1171+source' :: Parsec [Char] ParserState (String, [Char])
11721172source' = do
11731173 skipSpaces
11741174 let nl = char '\n' >>~ notFollowedBy blankline
@@ -1186,7 +1186,7 @@ source' = do
11861186 eof
11871187 return (escapeURI $ removeTrailingSpace src, tit)
11881188
1189−linkTitle :: GenParser Char ParserState String
1189+linkTitle :: Parsec [Char] ParserState String
11901190linkTitle = try $ do
11911191 (many1 spaceChar >> option '\n' newline) <|> newline
11921192 skipSpaces
@@ -1194,7 +1194,7 @@ linkTitle = try $ do
11941194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
11951195 return $ fromEntities tit
11961196
1197−link :: GenParser Char ParserState Inline
1197+link :: Parsec [Char] ParserState Inline
11981198link = try $ do
11991199 lab <- reference
12001200 (src, tit) <- source <|> referenceLink lab
@@ -1207,7 +1207,7 @@ delinkify = bottomUp $ concatMap go
12071207
12081208-- a link like [this][ref] or [this][] or [this]
12091209referenceLink :: [Inline]
1210− -> GenParser Char ParserState (String, [Char])
1210+ -> Parsec [Char] ParserState (String, [Char])
12111211referenceLink lab = do
12121212 ref <- option [] (try (optional (char ' ') >>
12131213 optional (newline >> skipSpaces) >> reference))
@@ -1217,7 +1217,7 @@ referenceLink lab = do
12171217 Nothing -> fail "no corresponding key"
12181218 Just target -> return target
12191219
1220−autoLink :: GenParser Char ParserState Inline
1220+autoLink :: Parsec [Char] ParserState Inline
12211221autoLink = try $ do
12221222 char '<'
12231223 (orig, src) <- uri <|> emailAddress
@@ -1227,14 +1227,14 @@ autoLink = try $ do
12271227 then Link [Str orig] (src, "")
12281228 else Link [Code ("",["url"],[]) orig] (src, "")
12291229
1230−image :: GenParser Char ParserState Inline
1230+image :: Parsec [Char] ParserState Inline
12311231image = try $ do
12321232 char '!'
12331233 lab <- reference
12341234 (src, tit) <- source <|> referenceLink lab
12351235 return $ Image lab (src,tit)
12361236
1237−note :: GenParser Char ParserState Inline
1237+note :: Parsec [Char] ParserState Inline
12381238note = try $ do
12391239 failIfStrict
12401240 ref <- noteMarker
@@ -1251,21 +1251,21 @@ note = try $ do
12511251 updateState $ \st -> st{ stateNotes = notes }
12521252 return $ Note contents
12531253
1254−inlineNote :: GenParser Char ParserState Inline
1254+inlineNote :: Parsec [Char] ParserState Inline
12551255inlineNote = try $ do
12561256 failIfStrict
12571257 char '^'
12581258 contents <- inlinesInBalancedBrackets inline
12591259 return $ Note [Para contents]
12601260
1261−rawLaTeXInline' :: GenParser Char ParserState Inline
1261+rawLaTeXInline' :: Parsec [Char] ParserState Inline
12621262rawLaTeXInline' = try $ do
12631263 failIfStrict
12641264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
12651265 RawInline _ s <- rawLaTeXInline
12661266 return $ RawInline "tex" s -- "tex" because it might be context or latex
12671267
1268−rawConTeXtEnvironment :: GenParser Char st String
1268+rawConTeXtEnvironment :: Parsec [Char] st String
12691269rawConTeXtEnvironment = try $ do
12701270 string "\\start"
12711271 completion <- inBrackets (letter <|> digit <|> spaceChar)
@@ -1274,14 +1274,14 @@ rawConTeXtEnvironment = try $ do
12741274 (try $ string "\\stop" >> string completion)
12751275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
12761276
1277−inBrackets :: (GenParser Char st Char) -> GenParser Char st String
1277+inBrackets :: (Parsec [Char] st Char) -> Parsec [Char] st String
12781278inBrackets parser = do
12791279 char '['
12801280 contents <- many parser
12811281 char ']'
12821282 return $ "[" ++ contents ++ "]"
12831283
1284−rawHtmlInline :: GenParser Char ParserState Inline
1284+rawHtmlInline :: Parsec [Char] ParserState Inline
12851285rawHtmlInline = do
12861286 st <- getState
12871287 (_,result) <- if stateStrict st
@@ -1291,20 +1291,20 @@ rawHtmlInline = do
12911291
12921292-- Citations
12931293
1294−cite :: GenParser Char ParserState Inline
1294+cite :: Parsec [Char] ParserState Inline
12951295cite = do
12961296 failIfStrict
12971297 citations <- textualCite <|> normalCite
12981298 return $ Cite citations []
12991299
1300−spnl :: GenParser Char st ()
1300+spnl :: Parsec [Char] st ()
13011301spnl = try $ do
13021302 skipSpaces
13031303 optional newline
13041304 skipSpaces
13051305 notFollowedBy (char '\n')
13061306
1307−textualCite :: GenParser Char ParserState [Citation]
1307+textualCite :: Parsec [Char] ParserState [Citation]
13081308textualCite = try $ do
13091309 (_, key) <- citeKey
13101310 let first = Citation{ citationId = key
@@ -1319,7 +1319,7 @@ textualCite = try $ do
13191319 then option [first] $ bareloc first
13201320 else return $ first : rest
13211321
1322−bareloc :: Citation -> GenParser Char ParserState [Citation]
1322+bareloc :: Citation -> Parsec [Char] ParserState [Citation]
13231323bareloc c = try $ do
13241324 spnl
13251325 char '['
@@ -1329,7 +1329,7 @@ bareloc c = try $ do
13291329 char ']'
13301330 return $ c{ citationSuffix = suff } : rest
13311331
1332−normalCite :: GenParser Char ParserState [Citation]
1332+normalCite :: Parsec [Char] ParserState [Citation]
13331333normalCite = try $ do
13341334 char '['
13351335 spnl
@@ -1338,7 +1338,7 @@ normalCite = try $ do
13381338 char ']'
13391339 return citations
13401340
1341−citeKey :: GenParser Char ParserState (Bool, String)
1341+citeKey :: Parsec [Char] ParserState (Bool, String)
13421342citeKey = try $ do
13431343 suppress_author <- option False (char '-' >> return True)
13441344 char '@'
@@ -1350,7 +1350,7 @@ citeKey = try $ do
13501350 guard $ key `elem` stateCitations st
13511351 return (suppress_author, key)
13521352
1353−suffix :: GenParser Char ParserState [Inline]
1353+suffix :: Parsec [Char] ParserState [Inline]
13541354suffix = try $ do
13551355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
13561356 spnl
@@ -1359,14 +1359,14 @@ suffix = try $ do
13591359 then Space : rest
13601360 else rest
13611361
1362−prefix :: GenParser Char ParserState [Inline]
1362+prefix :: Parsec [Char] ParserState [Inline]
13631363prefix = liftM normalizeSpaces $
13641364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
13651365
1366−citeList :: GenParser Char ParserState [Citation]
1366+citeList :: Parsec [Char] ParserState [Citation]
13671367citeList = sepBy1 citation (try $ char ';' >> spnl)
13681368
1369−citation :: GenParser Char ParserState Citation
1369+citation :: Parsec [Char] ParserState Citation
13701370citation = try $ do
13711371 pref <- prefix
13721372 (suppress_author, key) <- citeKey
src/Text/Pandoc/Readers/RST.hs+95−95
@@ -33,8 +33,8 @@ module Text.Pandoc.Readers.RST (
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.Pandoc.Parsing
36−import Text.ParserCombinators.Parsec
37−import Control.Monad ( when, liftM, guard )
36+import Text.Parsec
37+import Control.Monad ( when, liftM, guard, mzero )
3838import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
3939import qualified Data.Map as M
4040import Text.Printf ( printf )
@@ -89,7 +89,7 @@ titleTransform ((Header 1 head1):rest) |
8989 (promoteHeaders 1 rest, head1)
9090titleTransform blocks = (blocks, [])
9191
92−parseRST :: GenParser Char ParserState Pandoc
92+parseRST :: Parsec [Char] ParserState Pandoc
9393parseRST = do
9494 optional blanklines -- skip blank lines at beginning of file
9595 startPos <- getPosition
@@ -118,10 +118,10 @@ parseRST = do
118118-- parsing blocks
119119--
120120
121−parseBlocks :: GenParser Char ParserState [Block]
121+parseBlocks :: Parsec [Char] ParserState [Block]
122122parseBlocks = manyTill block eof
123123
124−block :: GenParser Char ParserState Block
124+block :: Parsec [Char] ParserState Block
125125block = choice [ codeBlock
126126 , rawBlock
127127 , blockQuote
@@ -146,7 +146,7 @@ block = choice [ codeBlock
146146-- field list
147147--
148148
149−rawFieldListItem :: String -> GenParser Char ParserState (String, String)
149+rawFieldListItem :: String -> Parsec [Char] ParserState (String, String)
150150rawFieldListItem indent = try $ do
151151 string indent
152152 char ':'
@@ -160,7 +160,7 @@ rawFieldListItem indent = try $ do
160160 return (name, raw)
161161
162162fieldListItem :: String
163− -> GenParser Char ParserState (Maybe ([Inline], [[Block]]))
163+ -> Parsec [Char] ParserState (Maybe ([Inline], [[Block]]))
164164fieldListItem indent = try $ do
165165 (name, raw) <- rawFieldListItem indent
166166 let term = [Str name]
@@ -187,7 +187,7 @@ extractContents [Plain auth] = auth
187187extractContents [Para auth] = auth
188188extractContents _ = []
189189
190−fieldList :: GenParser Char ParserState Block
190+fieldList :: Parsec [Char] ParserState Block
191191fieldList = try $ do
192192 indent <- lookAhead $ many spaceChar
193193 items <- many1 $ fieldListItem indent
@@ -199,7 +199,7 @@ fieldList = try $ do
199199-- line block
200200--
201201
202−lineBlockLine :: GenParser Char ParserState [Inline]
202+lineBlockLine :: Parsec [Char] ParserState [Inline]
203203lineBlockLine = try $ do
204204 char '|'
205205 char ' ' <|> lookAhead (char '\n')
@@ -210,7 +210,7 @@ lineBlockLine = try $ do
210210 then normalizeSpaces line
211211 else Str white : normalizeSpaces line
212212
213−lineBlock :: GenParser Char ParserState Block
213+lineBlock :: Parsec [Char] ParserState Block
214214lineBlock = try $ do
215215 lines' <- many1 lineBlockLine
216216 blanklines
@@ -220,14 +220,14 @@ lineBlock = try $ do
220220-- paragraph block
221221--
222222
223−para :: GenParser Char ParserState Block
223+para :: Parsec [Char] ParserState Block
224224para = paraBeforeCodeBlock <|> paraNormal <?> "paragraph"
225225
226−codeBlockStart :: GenParser Char st Char
226+codeBlockStart :: Parsec [Char] st Char
227227codeBlockStart = string "::" >> blankline >> blankline
228228
229229-- paragraph that ends in a :: starting a code block
230−paraBeforeCodeBlock :: GenParser Char ParserState Block
230+paraBeforeCodeBlock :: Parsec [Char] ParserState Block
231231paraBeforeCodeBlock = try $ do
232232 result <- many1 (notFollowedBy' codeBlockStart >> inline)
233233 lookAhead (string "::")
@@ -236,21 +236,21 @@ paraBeforeCodeBlock = try $ do
236236 else (normalizeSpaces result) ++ [Str ":"]
237237
238238-- regular paragraph
239−paraNormal :: GenParser Char ParserState Block
239+paraNormal :: Parsec [Char] ParserState Block
240240paraNormal = try $ do
241241 result <- many1 inline
242242 newline
243243 blanklines
244244 return $ Para $ normalizeSpaces result
245245
246−plain :: GenParser Char ParserState Block
246+plain :: Parsec [Char] ParserState Block
247247plain = many1 inline >>= return . Plain . normalizeSpaces
248248
249249--
250250-- image block
251251--
252252
253−imageBlock :: GenParser Char ParserState Block
253+imageBlock :: Parsec [Char] ParserState Block
254254imageBlock = try $ do
255255 string ".. image:: "
256256 src <- manyTill anyChar newline
@@ -265,11 +265,11 @@ imageBlock = try $ do
265265-- header blocks
266266--
267267
268−header :: GenParser Char ParserState Block
268+header :: Parsec [Char] ParserState Block
269269header = doubleHeader <|> singleHeader <?> "header"
270270
271271-- a header with lines on top and bottom
272−doubleHeader :: GenParser Char ParserState Block
272+doubleHeader :: Parsec [Char] ParserState Block
273273doubleHeader = try $ do
274274 c <- oneOf underlineChars
275275 rest <- many (char c) -- the top line
@@ -294,7 +294,7 @@ doubleHeader = try $ do
294294 return $ Header level (normalizeSpaces txt)
295295
296296-- a header with line on the bottom only
297−singleHeader :: GenParser Char ParserState Block
297+singleHeader :: Parsec [Char] ParserState Block
298298singleHeader = try $ do
299299 notFollowedBy' whitespace
300300 txt <- many1 (do {notFollowedBy blankline; inline})
@@ -317,7 +317,7 @@ singleHeader = try $ do
317317-- hrule block
318318--
319319
320−hrule :: GenParser Char st Block
320+hrule :: Parsec [Char] st Block
321321hrule = try $ do
322322 chr <- oneOf underlineChars
323323 count 3 (char chr)
@@ -331,14 +331,14 @@ hrule = try $ do
331331--
332332
333333-- read a line indented by a given string
334−indentedLine :: String -> GenParser Char st [Char]
334+indentedLine :: String -> Parsec [Char] st [Char]
335335indentedLine indents = try $ do
336336 string indents
337337 manyTill anyChar newline
338338
339339-- one or more indented lines, possibly separated by blank lines.
340340-- any amount of indentation will work.
341−indentedBlock :: GenParser Char st [Char]
341+indentedBlock :: Parsec [Char] st [Char]
342342indentedBlock = try $ do
343343 indents <- lookAhead $ many1 spaceChar
344344 lns <- many1 $ try $ do b <- option "" blanklines
@@ -347,7 +347,7 @@ indentedBlock = try $ do
347347 optional blanklines
348348 return $ unlines lns
349349
350−codeBlock :: GenParser Char st Block
350+codeBlock :: Parsec [Char] st Block
351351codeBlock = try $ do
352352 codeBlockStart
353353 result <- indentedBlock
@@ -355,7 +355,7 @@ codeBlock = try $ do
355355
356356-- | The 'code-block' directive (from Sphinx) that allows a language to be
357357-- specified.
358−customCodeBlock :: GenParser Char st Block
358+customCodeBlock :: Parsec [Char] st Block
359359customCodeBlock = try $ do
360360 string ".. code-block:: "
361361 language <- manyTill anyChar newline
@@ -364,7 +364,7 @@ customCodeBlock = try $ do
364364 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
365365
366366
367−figureBlock :: GenParser Char ParserState Block
367+figureBlock :: Parsec [Char] ParserState Block
368368figureBlock = try $ do
369369 string ".. figure::"
370370 src <- removeLeadingTrailingSpace `fmap` manyTill anyChar newline
@@ -372,24 +372,24 @@ figureBlock = try $ do
372372 caption <- parseFromString extractCaption body
373373 return $ Para [Image caption (src,"")]
374374
375−extractCaption :: GenParser Char ParserState [Inline]
375+extractCaption :: Parsec [Char] ParserState [Inline]
376376extractCaption = try $ do
377377 manyTill anyLine blanklines
378378 many inline
379379
380380-- | The 'math' directive (from Sphinx) for display math.
381−mathBlock :: GenParser Char st Block
381+mathBlock :: Parsec [Char] st Block
382382mathBlock = try $ do
383383 string ".. math::"
384384 mathBlockMultiline <|> mathBlockOneLine
385385
386−mathBlockOneLine :: GenParser Char st Block
386+mathBlockOneLine :: Parsec [Char] st Block
387387mathBlockOneLine = try $ do
388388 result <- manyTill anyChar newline
389389 blanklines
390390 return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
391391
392−mathBlockMultiline :: GenParser Char st Block
392+mathBlockMultiline :: Parsec [Char] st Block
393393mathBlockMultiline = try $ do
394394 blanklines
395395 result <- indentedBlock
@@ -404,7 +404,7 @@ mathBlockMultiline = try $ do
404404 $ filter (not . null) $ splitBy null lns'
405405 return $ Para $ map (Math DisplayMath) eqs
406406
407−lhsCodeBlock :: GenParser Char ParserState Block
407+lhsCodeBlock :: Parsec [Char] ParserState Block
408408lhsCodeBlock = try $ do
409409 failUnlessLHS
410410 optional codeBlockStart
@@ -418,7 +418,7 @@ lhsCodeBlock = try $ do
418418 blanklines
419419 return $ CodeBlock ("", ["sourceCode", "literate", "haskell"], []) $ intercalate "\n" lns'
420420
421−birdTrackLine :: GenParser Char st [Char]
421+birdTrackLine :: Parsec [Char] st [Char]
422422birdTrackLine = do
423423 char '>'
424424 manyTill anyChar newline
@@ -427,7 +427,7 @@ birdTrackLine = do
427427-- raw html/latex/etc
428428--
429429
430−rawBlock :: GenParser Char st Block
430+rawBlock :: Parsec [Char] st Block
431431rawBlock = try $ do
432432 string ".. raw:: "
433433 lang <- many1 (letter <|> digit)
@@ -439,7 +439,7 @@ rawBlock = try $ do
439439-- block quotes
440440--
441441
442−blockQuote :: GenParser Char ParserState Block
442+blockQuote :: Parsec [Char] ParserState Block
443443blockQuote = do
444444 raw <- indentedBlock
445445 -- parse the extracted block, which may contain various block elements:
@@ -450,10 +450,10 @@ blockQuote = do
450450-- list blocks
451451--
452452
453−list :: GenParser Char ParserState Block
453+list :: Parsec [Char] ParserState Block
454454list = choice [ bulletList, orderedList, definitionList ] <?> "list"
455455
456−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
456+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
457457definitionListItem = try $ do
458458 -- avoid capturing a directive or comment
459459 notFollowedBy (try $ char '.' >> char '.')
@@ -463,11 +463,11 @@ definitionListItem = try $ do
463463 contents <- parseFromString parseBlocks $ raw ++ "\n"
464464 return (normalizeSpaces term, [contents])
465465
466−definitionList :: GenParser Char ParserState Block
466+definitionList :: Parsec [Char] ParserState Block
467467definitionList = many1 definitionListItem >>= return . DefinitionList
468468
469469-- parses bullet list start and returns its length (inc. following whitespace)
470−bulletListStart :: GenParser Char st Int
470+bulletListStart :: Parsec [Char] st Int
471471bulletListStart = try $ do
472472 notFollowedBy' hrule -- because hrules start out just like lists
473473 marker <- oneOf bulletListMarkers
@@ -477,14 +477,14 @@ bulletListStart = try $ do
477477-- parses ordered list start and returns its length (inc following whitespace)
478478orderedListStart :: ListNumberStyle
479479 -> ListNumberDelim
480− -> GenParser Char ParserState Int
480+ -> Parsec [Char] ParserState Int
481481orderedListStart style delim = try $ do
482482 (_, markerLen) <- withHorizDisplacement (orderedListMarker style delim)
483483 white <- many1 spaceChar
484484 return $ markerLen + length white
485485
486486-- parse a line of a list item
487−listLine :: Int -> GenParser Char ParserState [Char]
487+listLine :: Int -> Parsec [Char] ParserState [Char]
488488listLine markerLength = try $ do
489489 notFollowedBy blankline
490490 indentWith markerLength
@@ -492,7 +492,7 @@ listLine markerLength = try $ do
492492 return $ line ++ "\n"
493493
494494-- indent by specified number of spaces (or equiv. tabs)
495−indentWith :: Int -> GenParser Char ParserState [Char]
495+indentWith :: Int -> Parsec [Char] ParserState [Char]
496496indentWith num = do
497497 state <- getState
498498 let tabStop = stateTabStop state
@@ -502,8 +502,8 @@ indentWith num = do
502502 (try (char '\t' >> count (num - tabStop) (char ' '))) ]
503503
504504-- parse raw text for one list item, excluding start marker and continuations
505−rawListItem :: GenParser Char ParserState Int
506− -> GenParser Char ParserState (Int, [Char])
505+rawListItem :: Parsec [Char] ParserState Int
506+ -> Parsec [Char] ParserState (Int, [Char])
507507rawListItem start = try $ do
508508 markerLength <- start
509509 firstLine <- manyTill anyChar newline
@@ -513,14 +513,14 @@ rawListItem start = try $ do
513513-- continuation of a list item - indented and separated by blankline or
514514-- (in compact lists) endline.
515515-- Note: nested lists are parsed as continuations.
516−listContinuation :: Int -> GenParser Char ParserState [Char]
516+listContinuation :: Int -> Parsec [Char] ParserState [Char]
517517listContinuation markerLength = try $ do
518518 blanks <- many1 blankline
519519 result <- many1 (listLine markerLength)
520520 return $ blanks ++ concat result
521521
522−listItem :: GenParser Char ParserState Int
523− -> GenParser Char ParserState [Block]
522+listItem :: Parsec [Char] ParserState Int
523+ -> Parsec [Char] ParserState [Block]
524524listItem start = try $ do
525525 (markerLength, first) <- rawListItem start
526526 rest <- many (listContinuation markerLength)
@@ -537,14 +537,14 @@ listItem start = try $ do
537537 updateState (\st -> st {stateParserContext = oldContext})
538538 return parsed
539539
540−orderedList :: GenParser Char ParserState Block
540+orderedList :: Parsec [Char] ParserState Block
541541orderedList = try $ do
542542 (start, style, delim) <- lookAhead (anyOrderedListMarker >>~ spaceChar)
543543 items <- many1 (listItem (orderedListStart style delim))
544544 let items' = compactify items
545545 return $ OrderedList (start, style, delim) items'
546546
547−bulletList :: GenParser Char ParserState Block
547+bulletList :: Parsec [Char] ParserState Block
548548bulletList = many1 (listItem bulletListStart) >>=
549549 return . BulletList . compactify
550550
@@ -552,7 +552,7 @@ bulletList = many1 (listItem bulletListStart) >>=
552552-- default-role block
553553--
554554
555−defaultRoleBlock :: GenParser Char ParserState Block
555+defaultRoleBlock :: Parsec [Char] ParserState Block
556556defaultRoleBlock = try $ do
557557 string ".. default-role::"
558558 -- doesn't enforce any restrictions on the role name; embedded spaces shouldn't be allowed, for one
@@ -570,7 +570,7 @@ defaultRoleBlock = try $ do
570570-- unknown directive (e.g. comment)
571571--
572572
573−unknownDirective :: GenParser Char st Block
573+unknownDirective :: Parsec [Char] st Block
574574unknownDirective = try $ do
575575 string ".."
576576 notFollowedBy (noneOf " \t\n")
@@ -582,7 +582,7 @@ unknownDirective = try $ do
582582--- note block
583583---
584584
585−noteBlock :: GenParser Char ParserState [Char]
585+noteBlock :: Parsec [Char] ParserState [Char]
586586noteBlock = try $ do
587587 startPos <- getPosition
588588 string ".."
@@ -601,7 +601,7 @@ noteBlock = try $ do
601601 -- return blanks so line count isn't affected
602602 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
603603
604−noteMarker :: GenParser Char ParserState [Char]
604+noteMarker :: Parsec [Char] ParserState [Char]
605605noteMarker = do
606606 char '['
607607 res <- many1 digit
@@ -614,13 +614,13 @@ noteMarker = do
614614-- reference key
615615--
616616
617−quotedReferenceName :: GenParser Char ParserState [Inline]
617+quotedReferenceName :: Parsec [Char] ParserState [Inline]
618618quotedReferenceName = try $ do
619619 char '`' >> notFollowedBy (char '`') -- `` means inline code!
620620 label' <- many1Till inline (char '`')
621621 return label'
622622
623−unquotedReferenceName :: GenParser Char ParserState [Inline]
623+unquotedReferenceName :: Parsec [Char] ParserState [Inline]
624624unquotedReferenceName = try $ do
625625 label' <- many1Till inline (lookAhead $ char ':')
626626 return label'
@@ -629,24 +629,24 @@ unquotedReferenceName = try $ do
629629-- plus isolated (no two adjacent) internal hyphens, underscores,
630630-- periods, colons and plus signs; no whitespace or other characters
631631-- are allowed.
632−simpleReferenceName' :: GenParser Char st String
632+simpleReferenceName' :: Parsec [Char] st String
633633simpleReferenceName' = do
634634 x <- alphaNum
635635 xs <- many $ alphaNum
636636 <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
637637 return (x:xs)
638638
639−simpleReferenceName :: GenParser Char st [Inline]
639+simpleReferenceName :: Parsec [Char] st [Inline]
640640simpleReferenceName = do
641641 raw <- simpleReferenceName'
642642 return [Str raw]
643643
644−referenceName :: GenParser Char ParserState [Inline]
644+referenceName :: Parsec [Char] ParserState [Inline]
645645referenceName = quotedReferenceName <|>
646646 (try $ simpleReferenceName >>~ lookAhead (char ':')) <|>
647647 unquotedReferenceName
648648
649−referenceKey :: GenParser Char ParserState [Char]
649+referenceKey :: Parsec [Char] ParserState [Char]
650650referenceKey = do
651651 startPos <- getPosition
652652 (key, target) <- choice [imageKey, anonymousKey, regularKey]
@@ -658,7 +658,7 @@ referenceKey = do
658658 -- return enough blanks to replace key
659659 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
660660
661−targetURI :: GenParser Char st [Char]
661+targetURI :: Parsec [Char] st [Char]
662662targetURI = do
663663 skipSpaces
664664 optional newline
@@ -667,7 +667,7 @@ targetURI = do
667667 blanklines
668668 return $ escapeURI $ removeLeadingTrailingSpace $ contents
669669
670−imageKey :: GenParser Char ParserState (Key, Target)
670+imageKey :: Parsec [Char] ParserState (Key, Target)
671671imageKey = try $ do
672672 string ".. |"
673673 ref <- manyTill inline (char '|')
@@ -676,14 +676,14 @@ imageKey = try $ do
676676 src <- targetURI
677677 return (toKey (normalizeSpaces ref), (src, ""))
678678
679−anonymousKey :: GenParser Char st (Key, Target)
679+anonymousKey :: Parsec [Char] st (Key, Target)
680680anonymousKey = try $ do
681681 oneOfStrings [".. __:", "__"]
682682 src <- targetURI
683683 pos <- getPosition
684684 return (toKey [Str $ "_" ++ printf "%09d" (sourceLine pos)], (src, ""))
685685
686−regularKey :: GenParser Char ParserState (Key, Target)
686+regularKey :: Parsec [Char] ParserState (Key, Target)
687687regularKey = try $ do
688688 string ".. _"
689689 ref <- referenceName
@@ -708,31 +708,31 @@ regularKey = try $ do
708708-- Grid tables TODO:
709709-- - column spans
710710
711−dashedLine :: Char -> GenParser Char st (Int, Int)
711+dashedLine :: Char -> Parsec [Char] st (Int, Int)
712712dashedLine ch = do
713713 dashes <- many1 (char ch)
714714 sp <- many (char ' ')
715715 return (length dashes, length $ dashes ++ sp)
716716
717−simpleDashedLines :: Char -> GenParser Char st [(Int,Int)]
717+simpleDashedLines :: Char -> Parsec [Char] st [(Int,Int)]
718718simpleDashedLines ch = try $ many1 (dashedLine ch)
719719
720720-- Parse a table row separator
721−simpleTableSep :: Char -> GenParser Char ParserState Char
721+simpleTableSep :: Char -> Parsec [Char] ParserState Char
722722simpleTableSep ch = try $ simpleDashedLines ch >> newline
723723
724724-- Parse a table footer
725−simpleTableFooter :: GenParser Char ParserState [Char]
725+simpleTableFooter :: Parsec [Char] ParserState [Char]
726726simpleTableFooter = try $ simpleTableSep '=' >> blanklines
727727
728728-- Parse a raw line and split it into chunks by indices.
729−simpleTableRawLine :: [Int] -> GenParser Char ParserState [String]
729+simpleTableRawLine :: [Int] -> Parsec [Char] ParserState [String]
730730simpleTableRawLine indices = do
731731 line <- many1Till anyChar newline
732732 return (simpleTableSplitLine indices line)
733733
734734-- Parse a table row and return a list of blocks (columns).
735−simpleTableRow :: [Int] -> GenParser Char ParserState [[Block]]
735+simpleTableRow :: [Int] -> Parsec [Char] ParserState [[Block]]
736736simpleTableRow indices = do
737737 notFollowedBy' simpleTableFooter
738738 firstLine <- simpleTableRawLine indices
@@ -746,7 +746,7 @@ simpleTableSplitLine indices line =
746746 $ tail $ splitByIndices (init indices) line
747747
748748simpleTableHeader :: Bool -- ^ Headerless table
749− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
749+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
750750simpleTableHeader headless = try $ do
751751 optional blanklines
752752 rawContent <- if headless
@@ -766,7 +766,7 @@ simpleTableHeader headless = try $ do
766766
767767-- Parse a simple table.
768768simpleTable :: Bool -- ^ Headerless table
769− -> GenParser Char ParserState Block
769+ -> Parsec [Char] ParserState Block
770770simpleTable headless = do
771771 Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter (return [])
772772 -- Simple tables get 0s for relative column widths (i.e., use default)
@@ -775,10 +775,10 @@ simpleTable headless = do
775775 sep = return () -- optional (simpleTableSep '-')
776776
777777gridTable :: Bool -- ^ Headerless table
778− -> GenParser Char ParserState Block
778+ -> Parsec [Char] ParserState Block
779779gridTable = gridTableWith block (return [])
780780
781−table :: GenParser Char ParserState Block
781+table :: Parsec [Char] ParserState Block
782782table = gridTable False <|> simpleTable False <|>
783783 gridTable True <|> simpleTable True <?> "table"
784784
@@ -787,7 +787,7 @@ table = gridTable False <|> simpleTable False <|>
787787 -- inline
788788 --
789789
790−inline :: GenParser Char ParserState Inline
790+inline :: Parsec [Char] ParserState Inline
791791inline = choice [ whitespace
792792 , link
793793 , str
@@ -805,26 +805,26 @@ inline = choice [ whitespace
805805 , escapedChar
806806 , symbol ] <?> "inline"
807807
808−hyphens :: GenParser Char ParserState Inline
808+hyphens :: Parsec [Char] ParserState Inline
809809hyphens = do
810810 result <- many1 (char '-')
811811 option Space endline
812812 -- don't want to treat endline after hyphen or dash as a space
813813 return $ Str result
814814
815−escapedChar :: GenParser Char st Inline
815+escapedChar :: Parsec [Char] st Inline
816816escapedChar = do c <- escaped anyChar
817817 return $ if c == ' ' -- '\ ' is null in RST
818818 then Str ""
819819 else Str [c]
820820
821−symbol :: GenParser Char ParserState Inline
821+symbol :: Parsec [Char] ParserState Inline
822822symbol = do
823823 result <- oneOf specialChars
824824 return $ Str [result]
825825
826826-- parses inline code, between codeStart and codeEnd
827−code :: GenParser Char ParserState Inline
827+code :: Parsec [Char] ParserState Inline
828828code = try $ do
829829 string "``"
830830 result <- manyTill anyChar (try (string "``"))
@@ -832,7 +832,7 @@ code = try $ do
832832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
833833
834834-- succeeds only if we're not right after a str (ie. in middle of word)
835−atStart :: GenParser Char ParserState a -> GenParser Char ParserState a
835+atStart :: Parsec [Char] ParserState a -> Parsec [Char] ParserState a
836836atStart p = do
837837 pos <- getPosition
838838 st <- getState
@@ -840,18 +840,18 @@ atStart p = do
840840 guard $ stateLastStrPos st /= Just pos
841841 p
842842
843−emph :: GenParser Char ParserState Inline
843+emph :: Parsec [Char] ParserState Inline
844844emph = enclosed (atStart $ char '*') (char '*') inline >>=
845845 return . Emph . normalizeSpaces
846846
847−strong :: GenParser Char ParserState Inline
847+strong :: Parsec [Char] ParserState Inline
848848strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
849849 return . Strong . normalizeSpaces
850850
851851-- Parses inline interpreted text which is required to have the given role.
852852-- This decision is based on the role marker (if present),
853853-- and the current default interpreted text role.
854−interpreted :: [Char] -> GenParser Char ParserState [Char]
854+interpreted :: [Char] -> Parsec [Char] ParserState [Char]
855855interpreted role = try $ do
856856 state <- getState
857857 if role == stateRstDefaultRole state
@@ -868,19 +868,19 @@ interpreted role = try $ do
868868 result <- enclosed (atStart $ char '`') (char '`') anyChar
869869 return result
870870
871−superscript :: GenParser Char ParserState Inline
871+superscript :: Parsec [Char] ParserState Inline
872872superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])
873873
874−subscript :: GenParser Char ParserState Inline
874+subscript :: Parsec [Char] ParserState Inline
875875subscript = interpreted "sub" >>= \x -> return (Subscript [Str x])
876876
877−math :: GenParser Char ParserState Inline
877+math :: Parsec [Char] ParserState Inline
878878math = interpreted "math" >>= \x -> return (Math InlineMath x)
879879
880−whitespace :: GenParser Char ParserState Inline
880+whitespace :: Parsec [Char] ParserState Inline
881881whitespace = many1 spaceChar >> return Space <?> "whitespace"
882882
883−str :: GenParser Char ParserState Inline
883+str :: Parsec [Char] ParserState Inline
884884str = do
885885 let strChar = noneOf ("\t\n " ++ specialChars)
886886 result <- many1 strChar
@@ -888,7 +888,7 @@ str = do
888888 return $ Str result
889889
890890-- an endline character that can be treated as a space, not a structural break
891−endline :: GenParser Char ParserState Inline
891+endline :: Parsec [Char] ParserState Inline
892892endline = try $ do
893893 newline
894894 notFollowedBy blankline
@@ -904,10 +904,10 @@ endline = try $ do
904904-- links
905905--
906906
907−link :: GenParser Char ParserState Inline
907+link :: Parsec [Char] ParserState Inline
908908link = choice [explicitLink, referenceLink, autoLink] <?> "link"
909909
910−explicitLink :: GenParser Char ParserState Inline
910+explicitLink :: Parsec [Char] ParserState Inline
911911explicitLink = try $ do
912912 char '`'
913913 notFollowedBy (char '`') -- `` marks start of inline code
@@ -919,7 +919,7 @@ explicitLink = try $ do
919919 return $ Link (normalizeSpaces label')
920920 (escapeURI $ removeLeadingTrailingSpace src, "")
921921
922−referenceLink :: GenParser Char ParserState Inline
922+referenceLink :: Parsec [Char] ParserState Inline
923923referenceLink = try $ do
924924 label' <- (quotedReferenceName <|> simpleReferenceName) >>~ char '_'
925925 state <- getState
@@ -931,7 +931,7 @@ referenceLink = try $ do
931931 do char '_'
932932 let anonKeys = sort $ filter isAnonKey $ M.keys keyTable
933933 if null anonKeys
934− then pzero
934+ then mzero
935935 else return (head anonKeys)
936936 (src,tit) <- case lookupKeySrc keyTable key of
937937 Nothing -> fail "no corresponding key"
@@ -940,21 +940,21 @@ referenceLink = try $ do
940940 when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
941941 return $ Link (normalizeSpaces label') (src, tit)
942942
943−autoURI :: GenParser Char ParserState Inline
943+autoURI :: Parsec [Char] ParserState Inline
944944autoURI = do
945945 (orig, src) <- uri
946946 return $ Link [Str orig] (src, "")
947947
948−autoEmail :: GenParser Char ParserState Inline
948+autoEmail :: Parsec [Char] ParserState Inline
949949autoEmail = do
950950 (orig, src) <- emailAddress
951951 return $ Link [Str orig] (src, "")
952952
953−autoLink :: GenParser Char ParserState Inline
953+autoLink :: Parsec [Char] ParserState Inline
954954autoLink = autoURI <|> autoEmail
955955
956956-- For now, we assume that all substitution references are for images.
957−image :: GenParser Char ParserState Inline
957+image :: Parsec [Char] ParserState Inline
958958image = try $ do
959959 char '|'
960960 ref <- manyTill inline (char '|')
@@ -965,7 +965,7 @@ image = try $ do
965965 Just target -> return target
966966 return $ Image (normalizeSpaces ref) (src, tit)
967967
968−note :: GenParser Char ParserState Inline
968+note :: Parsec [Char] ParserState Inline
969969note = try $ do
970970 ref <- noteMarker
971971 char '_'
src/Text/Pandoc/Readers/Textile.hs+69−69
@@ -60,7 +60,7 @@ import Text.Pandoc.Shared
6060import Text.Pandoc.Parsing
6161import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
6262import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
63−import Text.ParserCombinators.Parsec
63+import Text.Parsec
6464import Text.HTML.TagSoup.Match
6565import Data.Char ( digitToInt, isUpper )
6666import Control.Monad ( guard, liftM )
@@ -75,7 +75,7 @@ readTextile state s =
7575
7676
7777-- | Generate a Pandoc ADT from a textile document
78−parseTextile :: GenParser Char ParserState Pandoc
78+parseTextile :: Parsec [Char] ParserState Pandoc
7979parseTextile = do
8080 -- textile allows raw HTML and does smart punctuation by default
8181 updateState (\state -> state { stateParseRaw = True, stateSmart = True })
@@ -93,10 +93,10 @@ parseTextile = do
9393 blocks <- parseBlocks
9494 return $ Pandoc (Meta [] [] []) blocks -- FIXME
9595
96−noteMarker :: GenParser Char ParserState [Char]
96+noteMarker :: Parsec [Char] ParserState [Char]
9797noteMarker = skipMany spaceChar >> string "fn" >> manyTill digit (char '.')
9898
99−noteBlock :: GenParser Char ParserState [Char]
99+noteBlock :: Parsec [Char] ParserState [Char]
100100noteBlock = try $ do
101101 startPos <- getPosition
102102 ref <- noteMarker
@@ -111,11 +111,11 @@ noteBlock = try $ do
111111 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
112112
113113-- | Parse document blocks
114−parseBlocks :: GenParser Char ParserState [Block]
114+parseBlocks :: Parsec [Char] ParserState [Block]
115115parseBlocks = manyTill block eof
116116
117117-- | Block parsers list tried in definition order
118−blockParsers :: [GenParser Char ParserState Block]
118+blockParsers :: [Parsec [Char] ParserState Block]
119119blockParsers = [ codeBlock
120120 , header
121121 , blockQuote
@@ -128,20 +128,20 @@ blockParsers = [ codeBlock
128128 , nullBlock ]
129129
130130-- | Any block in the order of definition of blockParsers
131−block :: GenParser Char ParserState Block
131+block :: Parsec [Char] ParserState Block
132132block = choice blockParsers <?> "block"
133133
134−codeBlock :: GenParser Char ParserState Block
134+codeBlock :: Parsec [Char] ParserState Block
135135codeBlock = codeBlockBc <|> codeBlockPre
136136
137−codeBlockBc :: GenParser Char ParserState Block
137+codeBlockBc :: Parsec [Char] ParserState Block
138138codeBlockBc = try $ do
139139 string "bc. "
140140 contents <- manyTill anyLine blanklines
141141 return $ CodeBlock ("",[],[]) $ unlines contents
142142
143143-- | Code Blocks in Textile are between <pre> and </pre>
144−codeBlockPre :: GenParser Char ParserState Block
144+codeBlockPre :: Parsec [Char] ParserState Block
145145codeBlockPre = try $ do
146146 htmlTag (tagOpen (=="pre") null)
147147 result' <- manyTill anyChar (try $ htmlTag (tagClose (=="pre")) >> blockBreak)
@@ -156,7 +156,7 @@ codeBlockPre = try $ do
156156 return $ CodeBlock ("",[],[]) result'''
157157
158158-- | Header of the form "hN. content" with N in 1..6
159−header :: GenParser Char ParserState Block
159+header :: Parsec [Char] ParserState Block
160160header = try $ do
161161 char 'h'
162162 level <- digitToInt <$> oneOf "123456"
@@ -165,14 +165,14 @@ header = try $ do
165165 return $ Header level name
166166
167167-- | Blockquote of the form "bq. content"
168−blockQuote :: GenParser Char ParserState Block
168+blockQuote :: Parsec [Char] ParserState Block
169169blockQuote = try $ do
170170 string "bq" >> optional attributes >> char '.' >> whitespace
171171 BlockQuote . singleton <$> para
172172
173173-- Horizontal rule
174174
175−hrule :: GenParser Char st Block
175+hrule :: Parsec [Char] st Block
176176hrule = try $ do
177177 skipSpaces
178178 start <- oneOf "-*"
@@ -187,39 +187,39 @@ hrule = try $ do
187187-- | Can be a bullet list or an ordered list. This implementation is
188188-- strict in the nesting, sublist must start at exactly "parent depth
189189-- plus one"
190−anyList :: GenParser Char ParserState Block
190+anyList :: Parsec [Char] ParserState Block
191191anyList = try $ ( (anyListAtDepth 1) <* blanklines )
192192
193193-- | This allow one type of list to be nested into an other type,
194194-- provided correct nesting
195−anyListAtDepth :: Int -> GenParser Char ParserState Block
195+anyListAtDepth :: Int -> Parsec [Char] ParserState Block
196196anyListAtDepth depth = choice [ bulletListAtDepth depth,
197197 orderedListAtDepth depth,
198198 definitionList ]
199199
200200-- | Bullet List of given depth, depth being the number of leading '*'
201−bulletListAtDepth :: Int -> GenParser Char ParserState Block
201+bulletListAtDepth :: Int -> Parsec [Char] ParserState Block
202202bulletListAtDepth depth = try $ BulletList <$> many1 (bulletListItemAtDepth depth)
203203
204204-- | Bullet List Item of given depth, depth being the number of
205205-- leading '*'
206−bulletListItemAtDepth :: Int -> GenParser Char ParserState [Block]
206+bulletListItemAtDepth :: Int -> Parsec [Char] ParserState [Block]
207207bulletListItemAtDepth = genericListItemAtDepth '*'
208208
209209-- | Ordered List of given depth, depth being the number of
210210-- leading '#'
211−orderedListAtDepth :: Int -> GenParser Char ParserState Block
211+orderedListAtDepth :: Int -> Parsec [Char] ParserState Block
212212orderedListAtDepth depth = try $ do
213213 items <- many1 (orderedListItemAtDepth depth)
214214 return (OrderedList (1, DefaultStyle, DefaultDelim) items)
215215
216216-- | Ordered List Item of given depth, depth being the number of
217217-- leading '#'
218−orderedListItemAtDepth :: Int -> GenParser Char ParserState [Block]
218+orderedListItemAtDepth :: Int -> Parsec [Char] ParserState [Block]
219219orderedListItemAtDepth = genericListItemAtDepth '#'
220220
221221-- | Common implementation of list items
222−genericListItemAtDepth :: Char -> Int -> GenParser Char ParserState [Block]
222+genericListItemAtDepth :: Char -> Int -> Parsec [Char] ParserState [Block]
223223genericListItemAtDepth c depth = try $ do
224224 count depth (char c) >> optional attributes >> whitespace
225225 p <- inlines
@@ -227,22 +227,22 @@ genericListItemAtDepth c depth = try $ do
227227 return ((Plain p):sublist)
228228
229229-- | A definition list is a set of consecutive definition items
230−definitionList :: GenParser Char ParserState Block
230+definitionList :: Parsec [Char] ParserState Block
231231definitionList = try $ DefinitionList <$> many1 definitionListItem
232232
233233-- | A definition list item in textile begins with '- ', followed by
234234-- the term defined, then spaces and ":=". The definition follows, on
235235-- the same single line, or spaned on multiple line, after a line
236236-- break.
237−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
237+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
238238definitionListItem = try $ do
239239 string "- "
240240 term <- many1Till inline (try (whitespace >> string ":="))
241241 def <- inlineDef <|> multilineDef
242242 return (term, def)
243− where inlineDef :: GenParser Char ParserState [[Block]]
243+ where inlineDef :: Parsec [Char] ParserState [[Block]]
244244 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
245− multilineDef :: GenParser Char ParserState [[Block]]
245+ multilineDef :: Parsec [Char] ParserState [[Block]]
246246 multilineDef = try $ do
247247 optional whitespace >> newline
248248 s <- many1Till anyChar (try (string "=:" >> newline))
@@ -252,57 +252,57 @@ definitionListItem = try $ do
252252
253253-- | This terminates a block such as a paragraph. Because of raw html
254254-- blocks support, we have to lookAhead for a rawHtmlBlock.
255−blockBreak :: GenParser Char ParserState ()
255+blockBreak :: Parsec [Char] ParserState ()
256256blockBreak = try (newline >> blanklines >> return ()) <|>
257257 (lookAhead rawHtmlBlock >> return ())
258258
259259-- raw content
260260
261261-- | A raw Html Block, optionally followed by blanklines
262−rawHtmlBlock :: GenParser Char ParserState Block
262+rawHtmlBlock :: Parsec [Char] ParserState Block
263263rawHtmlBlock = try $ do
264264 (_,b) <- htmlTag isBlockTag
265265 optional blanklines
266266 return $ RawBlock "html" b
267267
268268-- | Raw block of LaTeX content
269−rawLaTeXBlock' :: GenParser Char ParserState Block
269+rawLaTeXBlock' :: Parsec [Char] ParserState Block
270270rawLaTeXBlock' = do
271271 failIfStrict
272272 RawBlock "latex" <$> (rawLaTeXBlock <* spaces)
273273
274274
275275-- | In textile, paragraphs are separated by blank lines.
276−para :: GenParser Char ParserState Block
276+para :: Parsec [Char] ParserState Block
277277para = try $ Para . normalizeSpaces <$> manyTill inline blockBreak
278278
279279
280280-- Tables
281281
282282-- | A table cell spans until a pipe |
283−tableCell :: GenParser Char ParserState TableCell
283+tableCell :: Parsec [Char] ParserState TableCell
284284tableCell = do
285285 c <- many1 (noneOf "|\n")
286286 content <- parseFromString (many1 inline) c
287287 return $ [ Plain $ normalizeSpaces content ]
288288
289289-- | A table row is made of many table cells
290−tableRow :: GenParser Char ParserState [TableCell]
290+tableRow :: Parsec [Char] ParserState [TableCell]
291291tableRow = try $ ( char '|' *> (endBy1 tableCell (char '|')) <* newline)
292292
293293-- | Many table rows
294−tableRows :: GenParser Char ParserState [[TableCell]]
294+tableRows :: Parsec [Char] ParserState [[TableCell]]
295295tableRows = many1 tableRow
296296
297297-- | Table headers are made of cells separated by a tag "|_."
298−tableHeaders :: GenParser Char ParserState [TableCell]
298+tableHeaders :: Parsec [Char] ParserState [TableCell]
299299tableHeaders = let separator = (try $ string "|_.") in
300300 try $ ( separator *> (sepBy1 tableCell separator) <* char '|' <* newline )
301301
302302-- | A table with an optional header. Current implementation can
303303-- handle tables with and without header, but will parse cells
304304-- alignment attributes as content.
305−table :: GenParser Char ParserState Block
305+table :: Parsec [Char] ParserState Block
306306table = try $ do
307307 headers <- option [] tableHeaders
308308 rows <- tableRows
@@ -318,8 +318,8 @@ table = try $ do
318318-- | Blocks like 'p' and 'table' do not need explicit block tag.
319319-- However, they can be used to set HTML/CSS attributes when needed.
320320maybeExplicitBlock :: String -- ^ block tag name
321− -> GenParser Char ParserState Block -- ^ implicit block
322− -> GenParser Char ParserState Block
321+ -> Parsec [Char] ParserState Block -- ^ implicit block
322+ -> Parsec [Char] ParserState Block
323323maybeExplicitBlock name blk = try $ do
324324 optional $ try $ string name >> optional attributes >> char '.' >>
325325 ((try whitespace) <|> endline)
@@ -333,15 +333,15 @@ maybeExplicitBlock name blk = try $ do
333333
334334
335335-- | Any inline element
336−inline :: GenParser Char ParserState Inline
336+inline :: Parsec [Char] ParserState Inline
337337inline = choice inlineParsers <?> "inline"
338338
339339-- | List of consecutive inlines before a newline
340−inlines :: GenParser Char ParserState [Inline]
340+inlines :: Parsec [Char] ParserState [Inline]
341341inlines = manyTill inline newline
342342
343343-- | Inline parsers tried in order
344−inlineParsers :: [GenParser Char ParserState Inline]
344+inlineParsers :: [Parsec [Char] ParserState Inline]
345345inlineParsers = [ autoLink
346346 , str
347347 , whitespace
@@ -362,7 +362,7 @@ inlineParsers = [ autoLink
362362 ]
363363
364364-- | Inline markups
365−inlineMarkup :: GenParser Char ParserState Inline
365+inlineMarkup :: Parsec [Char] ParserState Inline
366366inlineMarkup = choice [ simpleInline (string "??") (Cite [])
367367 , simpleInline (string "**") Strong
368368 , simpleInline (string "__") Emph
@@ -375,29 +375,29 @@ inlineMarkup = choice [ simpleInline (string "??") (Cite [])
375375 ]
376376
377377-- | Trademark, registered, copyright
378−mark :: GenParser Char st Inline
378+mark :: Parsec [Char] st Inline
379379mark = try $ char '(' >> (try tm <|> try reg <|> copy)
380380
381−reg :: GenParser Char st Inline
381+reg :: Parsec [Char] st Inline
382382reg = do
383383 oneOf "Rr"
384384 char ')'
385385 return $ Str "\174"
386386
387−tm :: GenParser Char st Inline
387+tm :: Parsec [Char] st Inline
388388tm = do
389389 oneOf "Tt"
390390 oneOf "Mm"
391391 char ')'
392392 return $ Str "\8482"
393393
394−copy :: GenParser Char st Inline
394+copy :: Parsec [Char] st Inline
395395copy = do
396396 oneOf "Cc"
397397 char ')'
398398 return $ Str "\169"
399399
400−note :: GenParser Char ParserState Inline
400+note :: Parsec [Char] ParserState Inline
401401note = try $ do
402402 ref <- (char '[' *> many1 digit <* char ']')
403403 notes <- stateNotes <$> getState
@@ -421,7 +421,7 @@ wordBoundaries :: [Char]
421421wordBoundaries = markupChars ++ stringBreakers
422422
423423-- | Parse a hyphened sequence of words
424−hyphenedWords :: GenParser Char ParserState String
424+hyphenedWords :: Parsec [Char] ParserState String
425425hyphenedWords = try $ do
426426 hd <- noneOf wordBoundaries
427427 tl <- many ( (noneOf wordBoundaries) <|>
@@ -431,7 +431,7 @@ hyphenedWords = try $ do
431431 (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
432432
433433-- | Any string
434−str :: GenParser Char ParserState Inline
434+str :: Parsec [Char] ParserState Inline
435435str = do
436436 baseStr <- hyphenedWords
437437 -- RedCloth compliance : if parsed word is uppercase and immediatly
@@ -444,34 +444,34 @@ str = do
444444 return $ Str fullStr
445445
446446-- | Textile allows HTML span infos, we discard them
447−htmlSpan :: GenParser Char ParserState Inline
447+htmlSpan :: Parsec [Char] ParserState Inline
448448htmlSpan = try $ Str <$> ( char '%' *> attributes *> manyTill anyChar (char '%') )
449449
450450-- | Some number of space chars
451−whitespace :: GenParser Char ParserState Inline
451+whitespace :: Parsec [Char] ParserState Inline
452452whitespace = many1 spaceChar >> return Space <?> "whitespace"
453453
454454-- | In Textile, an isolated endline character is a line break
455−endline :: GenParser Char ParserState Inline
455+endline :: Parsec [Char] ParserState Inline
456456endline = try $ do
457457 newline >> notFollowedBy blankline
458458 return LineBreak
459459
460−rawHtmlInline :: GenParser Char ParserState Inline
460+rawHtmlInline :: Parsec [Char] ParserState Inline
461461rawHtmlInline = RawInline "html" . snd <$> htmlTag isInlineTag
462462
463463-- | Raw LaTeX Inline
464−rawLaTeXInline' :: GenParser Char ParserState Inline
464+rawLaTeXInline' :: Parsec [Char] ParserState Inline
465465rawLaTeXInline' = try $ do
466466 failIfStrict
467467 rawLaTeXInline
468468
469469-- | Textile standard link syntax is "label":target. But we
470470-- can also have ["label":target].
471−link :: GenParser Char ParserState Inline
471+link :: Parsec [Char] ParserState Inline
472472link = linkB <|> linkNoB
473473
474−linkNoB :: GenParser Char ParserState Inline
474+linkNoB :: Parsec [Char] ParserState Inline
475475linkNoB = try $ do
476476 name <- surrounded (char '"') inline
477477 char ':'
@@ -479,7 +479,7 @@ linkNoB = try $ do
479479 url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
480480 return $ Link name (url, "")
481481
482−linkB :: GenParser Char ParserState Inline
482+linkB :: Parsec [Char] ParserState Inline
483483linkB = try $ do
484484 char '['
485485 name <- surrounded (char '"') inline
@@ -488,13 +488,13 @@ linkB = try $ do
488488 return $ Link name (url, "")
489489
490490-- | Detect plain links to http or email.
491−autoLink :: GenParser Char ParserState Inline
491+autoLink :: Parsec [Char] ParserState Inline
492492autoLink = do
493493 (orig, src) <- (try uri <|> try emailAddress)
494494 return $ Link [Str orig] (src, "")
495495
496496-- | image embedding
497−image :: GenParser Char ParserState Inline
497+image :: Parsec [Char] ParserState Inline
498498image = try $ do
499499 char '!' >> notFollowedBy space
500500 src <- manyTill anyChar (lookAhead $ oneOf "!(")
@@ -502,49 +502,49 @@ image = try $ do
502502 char '!'
503503 return $ Image [Str alt] (src, alt)
504504
505−escapedInline :: GenParser Char ParserState Inline
505+escapedInline :: Parsec [Char] ParserState Inline
506506escapedInline = escapedEqs <|> escapedTag
507507
508−escapedEqs :: GenParser Char ParserState Inline
508+escapedEqs :: Parsec [Char] ParserState Inline
509509escapedEqs = Str <$> (try $ string "==" *> manyTill anyChar (try $ string "=="))
510510
511511-- | literal text escaped btw <notextile> tags
512−escapedTag :: GenParser Char ParserState Inline
512+escapedTag :: Parsec [Char] ParserState Inline
513513escapedTag = Str <$>
514514 (try $ string "<notextile>" *> manyTill anyChar (try $ string "</notextile>"))
515515
516516-- | Any special symbol defined in wordBoundaries
517−symbol :: GenParser Char ParserState Inline
517+symbol :: Parsec [Char] ParserState Inline
518518symbol = Str . singleton <$> oneOf wordBoundaries
519519
520520-- | Inline code
521−code :: GenParser Char ParserState Inline
521+code :: Parsec [Char] ParserState Inline
522522code = code1 <|> code2
523523
524−code1 :: GenParser Char ParserState Inline
524+code1 :: Parsec [Char] ParserState Inline
525525code1 = Code nullAttr <$> surrounded (char '@') anyChar
526526
527−code2 :: GenParser Char ParserState Inline
527+code2 :: Parsec [Char] ParserState Inline
528528code2 = do
529529 htmlTag (tagOpen (=="tt") null)
530530 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
531531
532532-- | Html / CSS attributes
533−attributes :: GenParser Char ParserState String
533+attributes :: Parsec [Char] ParserState String
534534attributes = choice [ enclosed (char '(') (char ')') anyChar,
535535 enclosed (char '{') (char '}') anyChar,
536536 enclosed (char '[') (char ']') anyChar]
537537
538538-- | Parses material surrounded by a parser.
539−surrounded :: GenParser Char st t -- ^ surrounding parser
540− -> GenParser Char st a -- ^ content parser (to be used repeatedly)
541− -> GenParser Char st [a]
539+surrounded :: Parsec [Char] st t -- ^ surrounding parser
540+ -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
541+ -> Parsec [Char] st [a]
542542surrounded border = enclosed border (try border)
543543
544544-- | Inlines are most of the time of the same form
545−simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
545+simpleInline :: Parsec [Char] ParserState t -- ^ surrounding parser
546546 -> ([Inline] -> Inline) -- ^ Inline constructor
547− -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
547+ -> Parsec [Char] ParserState Inline -- ^ content parser (to be used repeatedly)
548548simpleInline border construct = surrounded border (inlineWithAttribute) >>=
549549 return . construct . normalizeSpaces
550550 where inlineWithAttribute = (try $ optional attributes) >> inline
src/Text/Pandoc/Templates.hs+12−12
@@ -68,8 +68,8 @@ module Text.Pandoc.Templates ( renderTemplate
6868 , TemplateTarget
6969 , getDefaultTemplate ) where
7070
71−import Text.ParserCombinators.Parsec
72−import Control.Monad (liftM, when, forM)
71+import Text.Parsec
72+import Control.Monad (liftM, when, forM, mzero)
7373import System.FilePath
7474import Data.List (intercalate, intersperse)
7575#if MIN_VERSION_blaze_html(0,5,0)
@@ -98,7 +98,7 @@ getDefaultTemplate user writer = do
9898
9999data TemplateState = TemplateState Int [(String,String)]
100100
101−adjustPosition :: String -> GenParser Char TemplateState String
101+adjustPosition :: String -> Parsec [Char] TemplateState String
102102adjustPosition str = do
103103 let lastline = takeWhile (/= '\n') $ reverse str
104104 updateState $ \(TemplateState pos x) ->
@@ -132,21 +132,21 @@ renderTemplate vals templ =
132132reservedWords :: [String]
133133reservedWords = ["else","endif","for","endfor","sep"]
134134
135−parseTemplate :: GenParser Char TemplateState [String]
135+parseTemplate :: Parsec [Char] TemplateState [String]
136136parseTemplate =
137137 many $ (plaintext <|> escapedDollar <|> conditional <|> for <|> variable)
138138 >>= adjustPosition
139139
140−plaintext :: GenParser Char TemplateState String
140+plaintext :: Parsec [Char] TemplateState String
141141plaintext = many1 $ noneOf "$"
142142
143−escapedDollar :: GenParser Char TemplateState String
143+escapedDollar :: Parsec [Char] TemplateState String
144144escapedDollar = try $ string "$$" >> return "$"
145145
146−skipEndline :: GenParser Char st ()
146+skipEndline :: Parsec [Char] st ()
147147skipEndline = try $ skipMany (oneOf " \t") >> newline >> return ()
148148
149−conditional :: GenParser Char TemplateState String
149+conditional :: Parsec [Char] TemplateState String
150150conditional = try $ do
151151 TemplateState pos vars <- getState
152152 string "$if("
@@ -170,7 +170,7 @@ conditional = try $ do
170170 then ifContents
171171 else elseContents
172172
173−for :: GenParser Char TemplateState String
173+for :: Parsec [Char] TemplateState String
174174for = try $ do
175175 TemplateState pos vars <- getState
176176 string "$for("
@@ -193,16 +193,16 @@ for = try $ do
193193 setState $ TemplateState pos vars
194194 return $ concat $ intersperse sep contents
195195
196−ident :: GenParser Char TemplateState String
196+ident :: Parsec [Char] TemplateState String
197197ident = do
198198 first <- letter
199199 rest <- many (alphaNum <|> oneOf "_-")
200200 let id' = first : rest
201201 if id' `elem` reservedWords
202− then pzero
202+ then mzero
203203 else return id'
204204
205−variable :: GenParser Char TemplateState String
205+variable :: Parsec [Char] TemplateState String
206206variable = try $ do
207207 char '$'
208208 id' <- ident
src/Text/Pandoc/Writers/AsciiDoc.hs+2−2
@@ -41,7 +41,7 @@ import Text.Pandoc.Definition
4141import Text.Pandoc.Templates (renderTemplate)
4242import Text.Pandoc.Shared
4343import Text.Pandoc.Parsing hiding (blankline)
44−import Text.ParserCombinators.Parsec ( runParser, GenParser )
44+import Text.Parsec ( Parsec, runParser )
4545import Data.List ( isPrefixOf, intersperse, intercalate )
4646import Text.Pandoc.Pretty
4747import Control.Monad.State
@@ -93,7 +93,7 @@ escapeString = escapeStringUsing escs
9393 where escs = backslashEscapes "{"
9494
9595-- | Ordered list start parser for use in Para below.
96−olMarker :: GenParser Char ParserState Char
96+olMarker :: Parsec [Char] ParserState Char
9797olMarker = do (start, style', delim) <- anyOrderedListMarker
9898 if delim == Period &&
9999 (style' == UpperAlpha || (style' == UpperRoman &&
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -36,7 +36,7 @@ import Text.Pandoc.Generic
3636import Text.Pandoc.Templates (renderTemplate)
3737import Text.Pandoc.Shared
3838import Text.Pandoc.Parsing hiding (blankline)
39−import Text.ParserCombinators.Parsec ( runParser, GenParser )
39+import Text.Parsec ( Parsec, runParser )
4040import Data.List ( group, isPrefixOf, find, intersperse, transpose )
4141import Text.Pandoc.Pretty
4242import Control.Monad.State
@@ -188,7 +188,7 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
188188 <> "=\"" <> text v <> "\"") ks
189189
190190-- | Ordered list start parser for use in Para below.
191−olMarker :: GenParser Char ParserState Char
191+olMarker :: Parsec [Char] ParserState Char
192192olMarker = do (start, style', delim) <- anyOrderedListMarker
193193 if delim == Period &&
194194 (style' == UpperAlpha || (style' == UpperRoman &&