git.iko.soy/typeable/pandoc
on master help sign in
Use Text.Parsec instead of Text.ParserCombinators.Parsec.
a4c28eaJohn MacFarlane
src/Text/Pandoc/Biblio.hs+6−6
@@ -38,7 +38,7 @@ import qualified Text.CSL as CSL ( Cite(..) )
38import Text.Pandoc.Definition
38import Text.Pandoc.Definition
39import Text.Pandoc.Generic
39import Text.Pandoc.Generic
40import Text.Pandoc.Shared (stringify)
40import Text.Pandoc.Shared (stringify)
41−import Text.ParserCombinators.Parsec
41+import Text.Parsec
42import Control.Monad
42import Control.Monad
43
43
44-- | Process a 'Pandoc' document by adding citations formatted
44-- | Process a 'Pandoc' document by adding citations formatted
@@ -165,7 +165,7 @@ locatorWords inp =
165 breakup (x : xs) = x : breakup xs
165 breakup (x : xs) = x : breakup xs
166 splitup = groupBy (\x y -> x /= '\160' && y /= '\160')
166 splitup = groupBy (\x y -> x /= '\160' && y /= '\160')
167
167
168−pLocatorWords :: GenParser Inline st (String, [Inline])
168+pLocatorWords :: Parsec [Inline] st (String, [Inline])
169pLocatorWords = do
169pLocatorWords = do
170 l <- pLocator
170 l <- pLocator
171 s <- getInput -- rest is suffix
171 s <- getInput -- rest is suffix
@@ -173,16 +173,16 @@ pLocatorWords = do
173 then return (init l, Str "," : s)
173 then return (init l, Str "," : s)
174 else return (l, s)
174 else return (l, s)
175
175
176−pMatch :: (Inline -> Bool) -> GenParser Inline st Inline
176+pMatch :: (Inline -> Bool) -> Parsec [Inline] st Inline
177pMatch condition = try $ do
177pMatch condition = try $ do
178 t <- anyToken
178 t <- anyToken
179 guard $ condition t
179 guard $ condition t
180 return t
180 return t
181
181
182−pSpace :: GenParser Inline st Inline
182+pSpace :: Parsec [Inline] st Inline
183pSpace = pMatch (\t -> t == Space || t == Str "\160")
183pSpace = pMatch (\t -> t == Space || t == Str "\160")
184
184
185−pLocator :: GenParser Inline st String
185+pLocator :: Parsec [Inline] st String
186pLocator = try $ do
186pLocator = try $ do
187 optional $ pMatch (== Str ",")
187 optional $ pMatch (== Str ",")
188 optional pSpace
188 optional pSpace
@@ -190,7 +190,7 @@ pLocator = try $ do
190 gs <- many1 pWordWithDigits
190 gs <- many1 pWordWithDigits
191 return $ stringify f ++ (' ' : unwords gs)
191 return $ stringify f ++ (' ' : unwords gs)
192
192
193−pWordWithDigits :: GenParser Inline st String
193+pWordWithDigits :: Parsec [Inline] st String
194pWordWithDigits = try $ do
194pWordWithDigits = try $ do
195 pSpace
195 pSpace
196 r <- many1 (notFollowedBy pSpace >> anyToken)
196 r <- many1 (notFollowedBy pSpace >> anyToken)
src/Text/Pandoc/Parsing.hs+103−103
@@ -79,11 +79,11 @@ where
79import Text.Pandoc.Definition
79import Text.Pandoc.Definition
80import Text.Pandoc.Generic
80import Text.Pandoc.Generic
81import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
81import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
82−import Text.ParserCombinators.Parsec
82+import Text.Parsec
83import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
83import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
84import Data.List ( intercalate, transpose )
84import Data.List ( intercalate, transpose )
85import Network.URI ( parseURI, URI (..), isAllowedInURI )
85import Network.URI ( parseURI, URI (..), isAllowedInURI )
86−import Control.Monad ( join, liftM, guard )
86+import Control.Monad ( join, liftM, guard, mzero )
87import Text.Pandoc.Shared
87import Text.Pandoc.Shared
88import qualified Data.Map as M
88import qualified Data.Map as M
89import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
89import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
@@ -96,13 +96,13 @@ import Data.Default
96a >>~ b = a >>= \x -> b >> return x
96a >>~ b = a >>= \x -> b >> return x
97
97
98-- | Parse any line of text
98-- | Parse any line of text
99−anyLine :: GenParser Char st [Char]
99+anyLine :: Parsec [Char] st [Char]
100anyLine = manyTill anyChar newline
100anyLine = manyTill anyChar newline
101
101
102-- | Like @manyTill@, but reads at least one item.
102-- | Like @manyTill@, but reads at least one item.
103−many1Till :: GenParser tok st a
103+many1Till :: Parsec [tok] st a
104− -> GenParser tok st end
104+ -> Parsec [tok] st end
105− -> GenParser tok st [a]
105+ -> Parsec [tok] st [a]
106many1Till p end = do
106many1Till p end = do
107 first <- p
107 first <- p
108 rest <- manyTill p end
108 rest <- manyTill p end
@@ -111,7 +111,7 @@ many1Till p end = do
111-- | A more general form of @notFollowedBy@. This one allows any
111-- | A more general form of @notFollowedBy@. This one allows any
112-- type of parser to be specified, and succeeds only if that parser fails.
112-- type of parser to be specified, and succeeds only if that parser fails.
113-- It does not consume any input.
113-- 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 ()
115notFollowedBy' p = try $ join $ do a <- try p
115notFollowedBy' p = try $ join $ do a <- try p
116 return (unexpected (show a))
116 return (unexpected (show a))
117 <|>
117 <|>
@@ -119,39 +119,39 @@ notFollowedBy' p = try $ join $ do a <- try p
119-- (This version due to Andrew Pimlott on the Haskell mailing list.)
119-- (This version due to Andrew Pimlott on the Haskell mailing list.)
120
120
121-- | Parses one of a list of strings (tried in order).
121-- | Parses one of a list of strings (tried in order).
122−oneOfStrings :: [String] -> GenParser Char st String
122+oneOfStrings :: [String] -> Parsec [Char] st String
123oneOfStrings listOfStrings = choice $ map (try . string) listOfStrings
123oneOfStrings listOfStrings = choice $ map (try . string) listOfStrings
124
124
125-- | Parses a space or tab.
125-- | Parses a space or tab.
126−spaceChar :: CharParser st Char
126+spaceChar :: Parsec [Char] st Char
127spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
127spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
128
128
129-- | Parses a nonspace, nonnewline character.
129-- | Parses a nonspace, nonnewline character.
130−nonspaceChar :: CharParser st Char
130+nonspaceChar :: Parsec [Char] st Char
131nonspaceChar = satisfy $ \x -> x /= '\t' && x /= '\n' && x /= ' ' && x /= '\r'
131nonspaceChar = satisfy $ \x -> x /= '\t' && x /= '\n' && x /= ' ' && x /= '\r'
132
132
133-- | Skips zero or more spaces or tabs.
133-- | Skips zero or more spaces or tabs.
134−skipSpaces :: GenParser Char st ()
134+skipSpaces :: Parsec [Char] st ()
135skipSpaces = skipMany spaceChar
135skipSpaces = skipMany spaceChar
136
136
137-- | Skips zero or more spaces or tabs, then reads a newline.
137-- | Skips zero or more spaces or tabs, then reads a newline.
138−blankline :: GenParser Char st Char
138+blankline :: Parsec [Char] st Char
139blankline = try $ skipSpaces >> newline
139blankline = try $ skipSpaces >> newline
140
140
141-- | Parses one or more blank lines and returns a string of newlines.
141-- | Parses one or more blank lines and returns a string of newlines.
142−blanklines :: GenParser Char st [Char]
142+blanklines :: Parsec [Char] st [Char]
143blanklines = many1 blankline
143blanklines = many1 blankline
144
144
145-- | Parses material enclosed between start and end parsers.
145-- | Parses material enclosed between start and end parsers.
146−enclosed :: GenParser Char st t -- ^ start parser
146+enclosed :: Parsec [Char] st t -- ^ start parser
147− -> GenParser Char st end -- ^ end parser
147+ -> Parsec [Char] st end -- ^ end parser
148− -> GenParser Char st a -- ^ content parser (to be used repeatedly)
148+ -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
149− -> GenParser Char st [a]
149+ -> Parsec [Char] st [a]
150enclosed start end parser = try $
150enclosed start end parser = try $
151 start >> notFollowedBy space >> many1Till parser end
151 start >> notFollowedBy space >> many1Till parser end
152
152
153-- | Parse string, case insensitive.
153-- | Parse string, case insensitive.
154−stringAnyCase :: [Char] -> CharParser st String
154+stringAnyCase :: [Char] -> Parsec [Char] st String
155stringAnyCase [] = string ""
155stringAnyCase [] = string ""
156stringAnyCase (x:xs) = do
156stringAnyCase (x:xs) = do
157 firstChar <- char (toUpper x) <|> char (toLower x)
157 firstChar <- char (toUpper x) <|> char (toLower x)
@@ -159,7 +159,7 @@ stringAnyCase (x:xs) = do
159 return (firstChar:rest)
159 return (firstChar:rest)
160
160
161-- | Parse contents of 'str' using 'parser' and return result.
161-- | 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
163parseFromString parser str = do
163parseFromString parser str = do
164 oldPos <- getPosition
164 oldPos <- getPosition
165 oldInput <- getInput
165 oldInput <- getInput
@@ -170,7 +170,7 @@ parseFromString parser str = do
170 return result
170 return result
171
171
172-- | Parse raw line block up to and including blank lines.
172-- | Parse raw line block up to and including blank lines.
173−lineClump :: GenParser Char st String
173+lineClump :: Parsec [Char] st String
174lineClump = blanklines
174lineClump = blanklines
175 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
175 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
176
176
@@ -179,8 +179,8 @@ lineClump = blanklines
179-- pairs of open and close, which must be different. For example,
179-- pairs of open and close, which must be different. For example,
180-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
180-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
181-- and return "hello (there)".
181-- and return "hello (there)".
182−charsInBalanced :: Char -> Char -> GenParser Char st Char
182+charsInBalanced :: Char -> Char -> Parsec [Char] st Char
183− -> GenParser Char st String
183+ -> Parsec [Char] st String
184charsInBalanced open close parser = try $ do
184charsInBalanced open close parser = try $ do
185 char open
185 char open
186 let isDelim c = c == open || c == close
186 let isDelim c = c == open || c == close
@@ -205,7 +205,7 @@ uppercaseRomanDigits = map toUpper lowercaseRomanDigits
205
205
206-- | Parses a roman numeral (uppercase or lowercase), returns number.
206-- | Parses a roman numeral (uppercase or lowercase), returns number.
207romanNumeral :: Bool -- ^ Uppercase if true
207romanNumeral :: Bool -- ^ Uppercase if true
208− -> GenParser Char st Int
208+ -> Parsec [Char] st Int
209romanNumeral upperCase = do
209romanNumeral upperCase = do
210 let romanDigits = if upperCase
210 let romanDigits = if upperCase
211 then uppercaseRomanDigits
211 then uppercaseRomanDigits
@@ -235,14 +235,14 @@ romanNumeral upperCase = do
235
235
236-- Parsers for email addresses and URIs
236-- Parsers for email addresses and URIs
237
237
238−emailChar :: GenParser Char st Char
238+emailChar :: Parsec [Char] st Char
239emailChar = alphaNum <|>
239emailChar = alphaNum <|>
240 satisfy (\c -> c == '-' || c == '+' || c == '_' || c == '.')
240 satisfy (\c -> c == '-' || c == '+' || c == '_' || c == '.')
241
241
242−domainChar :: GenParser Char st Char
242+domainChar :: Parsec [Char] st Char
243domainChar = alphaNum <|> char '-'
243domainChar = alphaNum <|> char '-'
244
244
245−domain :: GenParser Char st [Char]
245+domain :: Parsec [Char] st [Char]
246domain = do
246domain = do
247 first <- many1 domainChar
247 first <- many1 domainChar
248 dom <- many1 $ try (char '.' >> many1 domainChar )
248 dom <- many1 $ try (char '.' >> many1 domainChar )
@@ -250,7 +250,7 @@ domain = do
250
250
251-- | Parses an email address; returns original and corresponding
251-- | Parses an email address; returns original and corresponding
252-- escaped mailto: URI.
252-- escaped mailto: URI.
253−emailAddress :: GenParser Char st (String, String)
253+emailAddress :: Parsec [Char] st (String, String)
254emailAddress = try $ do
254emailAddress = try $ do
255 firstLetter <- alphaNum
255 firstLetter <- alphaNum
256 restAddr <- many emailChar
256 restAddr <- many emailChar
@@ -261,7 +261,7 @@ emailAddress = try $ do
261 return (full, escapeURI $ "mailto:" ++ full)
261 return (full, escapeURI $ "mailto:" ++ full)
262
262
263-- | Parses a URI. Returns pair of original and URI-escaped version.
263-- | 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)
265uri = try $ do
265uri = try $ do
266 let protocols = [ "http:", "https:", "ftp:", "file:", "mailto:",
266 let protocols = [ "http:", "https:", "ftp:", "file:", "mailto:",
267 "news:", "telnet:" ]
267 "news:", "telnet:" ]
@@ -295,8 +295,8 @@ uri = try $ do
295-- displacement (the difference between the source column at the end
295-- displacement (the difference between the source column at the end
296-- and the source column at the beginning). Vertical displacement
296-- and the source column at the beginning). Vertical displacement
297-- (source row) is ignored.
297-- (source row) is ignored.
298−withHorizDisplacement :: GenParser Char st a -- ^ Parser to apply
298+withHorizDisplacement :: Parsec [Char] st a -- ^ Parser to apply
299− -> GenParser Char st (a, Int) -- ^ (result, displacement)
299+ -> Parsec [Char] st (a, Int) -- ^ (result, displacement)
300withHorizDisplacement parser = do
300withHorizDisplacement parser = do
301 pos1 <- getPosition
301 pos1 <- getPosition
302 result <- parser
302 result <- parser
@@ -305,7 +305,7 @@ withHorizDisplacement parser = do
305
305
306-- | Applies a parser and returns the raw string that was parsed,
306-- | Applies a parser and returns the raw string that was parsed,
307-- along with the value produced by the parser.
307-- 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])
309withRaw parser = do
309withRaw parser = do
310 pos1 <- getPosition
310 pos1 <- getPosition
311 inp <- getInput
311 inp <- getInput
@@ -322,26 +322,26 @@ withRaw parser = do
322
322
323-- | Parses a character and returns 'Null' (so that the parser can move on
323-- | Parses a character and returns 'Null' (so that the parser can move on
324-- if it gets stuck).
324-- if it gets stuck).
325−nullBlock :: GenParser Char st Block
325+nullBlock :: Parsec [Char] st Block
326nullBlock = anyChar >> return Null
326nullBlock = anyChar >> return Null
327
327
328-- | Fail if reader is in strict markdown syntax mode.
328-- | Fail if reader is in strict markdown syntax mode.
329−failIfStrict :: GenParser a ParserState ()
329+failIfStrict :: Parsec [a] ParserState ()
330failIfStrict = do
330failIfStrict = do
331 state <- getState
331 state <- getState
332 if stateStrict state then fail "strict mode" else return ()
332 if stateStrict state then fail "strict mode" else return ()
333
333
334-- | Fail unless we're in literate haskell mode.
334-- | Fail unless we're in literate haskell mode.
335−failUnlessLHS :: GenParser tok ParserState ()
335+failUnlessLHS :: Parsec [tok] ParserState ()
336failUnlessLHS = getState >>= guard . stateLiterateHaskell
336failUnlessLHS = getState >>= guard . stateLiterateHaskell
337
337
338-- | Parses backslash, then applies character parser.
338-- | Parses backslash, then applies character parser.
339−escaped :: GenParser Char st Char -- ^ Parser for character to escape
339+escaped :: Parsec [Char] st Char -- ^ Parser for character to escape
340− -> GenParser Char st Char
340+ -> Parsec [Char] st Char
341escaped parser = try $ char '\\' >> parser
341escaped parser = try $ char '\\' >> parser
342
342
343-- | Parse character entity.
343-- | Parse character entity.
344−characterReference :: GenParser Char st Char
344+characterReference :: Parsec [Char] st Char
345characterReference = try $ do
345characterReference = try $ do
346 char '&'
346 char '&'
347 ent <- many1Till nonspaceChar (char ';')
347 ent <- many1Till nonspaceChar (char ';')
@@ -350,19 +350,19 @@ characterReference = try $ do
350 Nothing -> fail "entity not found"
350 Nothing -> fail "entity not found"
351
351
352-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
352-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
353−upperRoman :: GenParser Char st (ListNumberStyle, Int)
353+upperRoman :: Parsec [Char] st (ListNumberStyle, Int)
354upperRoman = do
354upperRoman = do
355 num <- romanNumeral True
355 num <- romanNumeral True
356 return (UpperRoman, num)
356 return (UpperRoman, num)
357
357
358-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
358-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
359−lowerRoman :: GenParser Char st (ListNumberStyle, Int)
359+lowerRoman :: Parsec [Char] st (ListNumberStyle, Int)
360lowerRoman = do
360lowerRoman = do
361 num <- romanNumeral False
361 num <- romanNumeral False
362 return (LowerRoman, num)
362 return (LowerRoman, num)
363
363
364-- | Parses a decimal numeral and returns (Decimal, number).
364-- | Parses a decimal numeral and returns (Decimal, number).
365−decimal :: GenParser Char st (ListNumberStyle, Int)
365+decimal :: Parsec [Char] st (ListNumberStyle, Int)
366decimal = do
366decimal = do
367 num <- many1 digit
367 num <- many1 digit
368 return (Decimal, read num)
368 return (Decimal, read num)
@@ -371,7 +371,7 @@ decimal = do
371-- returns (DefaultStyle, [next example number]). The next
371-- returns (DefaultStyle, [next example number]). The next
372-- example number is incremented in parser state, and the label
372-- example number is incremented in parser state, and the label
373-- (if present) is added to the label table.
373-- (if present) is added to the label table.
374−exampleNum :: GenParser Char ParserState (ListNumberStyle, Int)
374+exampleNum :: Parsec [Char] ParserState (ListNumberStyle, Int)
375exampleNum = do
375exampleNum = do
376 char '@'
376 char '@'
377 lab <- many (alphaNum <|> satisfy (\c -> c == '_' || c == '-'))
377 lab <- many (alphaNum <|> satisfy (\c -> c == '_' || c == '-'))
@@ -385,38 +385,38 @@ exampleNum = do
385 return (Example, num)
385 return (Example, num)
386
386
387-- | Parses a '#' returns (DefaultStyle, 1).
387-- | Parses a '#' returns (DefaultStyle, 1).
388−defaultNum :: GenParser Char st (ListNumberStyle, Int)
388+defaultNum :: Parsec [Char] st (ListNumberStyle, Int)
389defaultNum = do
389defaultNum = do
390 char '#'
390 char '#'
391 return (DefaultStyle, 1)
391 return (DefaultStyle, 1)
392
392
393-- | Parses a lowercase letter and returns (LowerAlpha, number).
393-- | Parses a lowercase letter and returns (LowerAlpha, number).
394−lowerAlpha :: GenParser Char st (ListNumberStyle, Int)
394+lowerAlpha :: Parsec [Char] st (ListNumberStyle, Int)
395lowerAlpha = do
395lowerAlpha = do
396 ch <- oneOf ['a'..'z']
396 ch <- oneOf ['a'..'z']
397 return (LowerAlpha, ord ch - ord 'a' + 1)
397 return (LowerAlpha, ord ch - ord 'a' + 1)
398
398
399-- | Parses an uppercase letter and returns (UpperAlpha, number).
399-- | Parses an uppercase letter and returns (UpperAlpha, number).
400−upperAlpha :: GenParser Char st (ListNumberStyle, Int)
400+upperAlpha :: Parsec [Char] st (ListNumberStyle, Int)
401upperAlpha = do
401upperAlpha = do
402 ch <- oneOf ['A'..'Z']
402 ch <- oneOf ['A'..'Z']
403 return (UpperAlpha, ord ch - ord 'A' + 1)
403 return (UpperAlpha, ord ch - ord 'A' + 1)
404
404
405-- | Parses a roman numeral i or I
405-- | Parses a roman numeral i or I
406−romanOne :: GenParser Char st (ListNumberStyle, Int)
406+romanOne :: Parsec [Char] st (ListNumberStyle, Int)
407romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
407romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
408 (char 'I' >> return (UpperRoman, 1))
408 (char 'I' >> return (UpperRoman, 1))
409
409
410-- | Parses an ordered list marker and returns list attributes.
410-- | Parses an ordered list marker and returns list attributes.
411−anyOrderedListMarker :: GenParser Char ParserState ListAttributes
411+anyOrderedListMarker :: Parsec [Char] ParserState ListAttributes
412anyOrderedListMarker = choice $
412anyOrderedListMarker = choice $
413 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
413 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
414 numParser <- [decimal, exampleNum, defaultNum, romanOne,
414 numParser <- [decimal, exampleNum, defaultNum, romanOne,
415 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
415 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
416
416
417-- | Parses a list number (num) followed by a period, returns list attributes.
417-- | Parses a list number (num) followed by a period, returns list attributes.
418−inPeriod :: GenParser Char st (ListNumberStyle, Int)
418+inPeriod :: Parsec [Char] st (ListNumberStyle, Int)
419− -> GenParser Char st ListAttributes
419+ -> Parsec [Char] st ListAttributes
420inPeriod num = try $ do
420inPeriod num = try $ do
421 (style, start) <- num
421 (style, start) <- num
422 char '.'
422 char '.'
@@ -426,16 +426,16 @@ inPeriod num = try $ do
426 return (start, style, delim)
426 return (start, style, delim)
427
427
428-- | Parses a list number (num) followed by a paren, returns list attributes.
428-- | Parses a list number (num) followed by a paren, returns list attributes.
429−inOneParen :: GenParser Char st (ListNumberStyle, Int)
429+inOneParen :: Parsec [Char] st (ListNumberStyle, Int)
430− -> GenParser Char st ListAttributes
430+ -> Parsec [Char] st ListAttributes
431inOneParen num = try $ do
431inOneParen num = try $ do
432 (style, start) <- num
432 (style, start) <- num
433 char ')'
433 char ')'
434 return (start, style, OneParen)
434 return (start, style, OneParen)
435
435
436-- | Parses a list number (num) enclosed in parens, returns list attributes.
436-- | Parses a list number (num) enclosed in parens, returns list attributes.
437−inTwoParens :: GenParser Char st (ListNumberStyle, Int)
437+inTwoParens :: Parsec [Char] st (ListNumberStyle, Int)
438− -> GenParser Char st ListAttributes
438+ -> Parsec [Char] st ListAttributes
439inTwoParens num = try $ do
439inTwoParens num = try $ do
440 char '('
440 char '('
441 (style, start) <- num
441 (style, start) <- num
@@ -446,7 +446,7 @@ inTwoParens num = try $ do
446-- returns number.
446-- returns number.
447orderedListMarker :: ListNumberStyle
447orderedListMarker :: ListNumberStyle
448 -> ListNumberDelim
448 -> ListNumberDelim
449− -> GenParser Char ParserState Int
449+ -> Parsec [Char] ParserState Int
450orderedListMarker style delim = do
450orderedListMarker style delim = do
451 let num = defaultNum <|> -- # can continue any kind of list
451 let num = defaultNum <|> -- # can continue any kind of list
452 case style of
452 case style of
@@ -466,19 +466,19 @@ orderedListMarker style delim = do
466 return start
466 return start
467
467
468-- | Parses a character reference and returns a Str element.
468-- | Parses a character reference and returns a Str element.
469−charRef :: GenParser Char st Inline
469+charRef :: Parsec [Char] st Inline
470charRef = do
470charRef = do
471 c <- characterReference
471 c <- characterReference
472 return $ Str [c]
472 return $ Str [c]
473
473
474-- | Parse a table using 'headerParser', 'rowParser',
474-- | Parse a table using 'headerParser', 'rowParser',
475-- 'lineParser', and 'footerParser'.
475-- 'lineParser', and 'footerParser'.
476−tableWith :: GenParser Char ParserState ([[Block]], [Alignment], [Int])
476+tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
477− -> ([Int] -> GenParser Char ParserState [[Block]])
477+ -> ([Int] -> Parsec [Char] ParserState [[Block]])
478− -> GenParser Char ParserState sep
478+ -> Parsec [Char] ParserState sep
479− -> GenParser Char ParserState end
479+ -> Parsec [Char] ParserState end
480− -> GenParser Char ParserState [Inline]
480+ -> Parsec [Char] ParserState [Inline]
481− -> GenParser Char ParserState Block
481+ -> Parsec [Char] ParserState Block
482tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
482tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
483 caption' <- option [] captionParser
483 caption' <- option [] captionParser
484 (heads, aligns, indices) <- headerParser
484 (heads, aligns, indices) <- headerParser
@@ -521,10 +521,10 @@ widthsFromIndices numColumns' indices =
521-- (which may be grid), then the rows,
521-- (which may be grid), then the rows,
522-- which may be grid, separated by blank lines, and
522-- which may be grid, separated by blank lines, and
523-- ending with a footer (dashed line followed by blank line).
523-- ending with a footer (dashed line followed by blank line).
524−gridTableWith :: GenParser Char ParserState Block -- ^ Block parser
524+gridTableWith :: Parsec [Char] ParserState Block -- ^ Block parser
525− -> GenParser Char ParserState [Inline] -- ^ Caption parser
525+ -> Parsec [Char] ParserState [Inline] -- ^ Caption parser
526 -> Bool -- ^ Headerless table
526 -> Bool -- ^ Headerless table
527− -> GenParser Char ParserState Block
527+ -> Parsec [Char] ParserState Block
528gridTableWith block tableCaption headless =
528gridTableWith block tableCaption headless =
529 tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
529 tableWith (gridTableHeader headless block) (gridTableRow block) (gridTableSep '-') gridTableFooter tableCaption
530
530
@@ -532,13 +532,13 @@ gridTableSplitLine :: [Int] -> String -> [String]
532gridTableSplitLine indices line = map removeFinalBar $ tail $
532gridTableSplitLine indices line = map removeFinalBar $ tail $
533 splitStringByIndices (init indices) $ removeTrailingSpace line
533 splitStringByIndices (init indices) $ removeTrailingSpace line
534
534
535−gridPart :: Char -> GenParser Char st (Int, Int)
535+gridPart :: Char -> Parsec [Char] st (Int, Int)
536gridPart ch = do
536gridPart ch = do
537 dashes <- many1 (char ch)
537 dashes <- many1 (char ch)
538 char '+'
538 char '+'
539 return (length dashes, length dashes + 1)
539 return (length dashes, length dashes + 1)
540
540
541−gridDashedLines :: Char -> GenParser Char st [(Int,Int)]
541+gridDashedLines :: Char -> Parsec [Char] st [(Int,Int)]
542gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
542gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
543
543
544removeFinalBar :: String -> String
544removeFinalBar :: String -> String
@@ -546,13 +546,13 @@ removeFinalBar =
546 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
546 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
547
547
548-- | Separator between rows of grid table.
548-- | Separator between rows of grid table.
549−gridTableSep :: Char -> GenParser Char ParserState Char
549+gridTableSep :: Char -> Parsec [Char] ParserState Char
550gridTableSep ch = try $ gridDashedLines ch >> return '\n'
550gridTableSep ch = try $ gridDashedLines ch >> return '\n'
551
551
552-- | Parse header for a grid table.
552-- | Parse header for a grid table.
553gridTableHeader :: Bool -- ^ Headerless table
553gridTableHeader :: Bool -- ^ Headerless table
554− -> GenParser Char ParserState Block
554+ -> Parsec [Char] ParserState Block
555− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
555+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
556gridTableHeader headless block = try $ do
556gridTableHeader headless block = try $ do
557 optional blanklines
557 optional blanklines
558 dashes <- gridDashedLines '-'
558 dashes <- gridDashedLines '-'
@@ -576,16 +576,16 @@ gridTableHeader headless block = try $ do
576 map removeLeadingTrailingSpace rawHeads
576 map removeLeadingTrailingSpace rawHeads
577 return (heads, aligns, indices)
577 return (heads, aligns, indices)
578
578
579−gridTableRawLine :: [Int] -> GenParser Char ParserState [String]
579+gridTableRawLine :: [Int] -> Parsec [Char] ParserState [String]
580gridTableRawLine indices = do
580gridTableRawLine indices = do
581 char '|'
581 char '|'
582 line <- many1Till anyChar newline
582 line <- many1Till anyChar newline
583 return (gridTableSplitLine indices line)
583 return (gridTableSplitLine indices line)
584
584
585-- | Parse row of grid table.
585-- | Parse row of grid table.
586−gridTableRow :: GenParser Char ParserState Block
586+gridTableRow :: Parsec [Char] ParserState Block
587 -> [Int]
587 -> [Int]
588− -> GenParser Char ParserState [[Block]]
588+ -> Parsec [Char] ParserState [[Block]]
589gridTableRow block indices = do
589gridTableRow block indices = do
590 colLines <- many1 (gridTableRawLine indices)
590 colLines <- many1 (gridTableRawLine indices)
591 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
591 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
@@ -604,13 +604,13 @@ compactifyCell :: [Block] -> [Block]
604compactifyCell bs = head $ compactify [bs]
604compactifyCell bs = head $ compactify [bs]
605
605
606-- | Parse footer for a grid table.
606-- | Parse footer for a grid table.
607−gridTableFooter :: GenParser Char ParserState [Char]
607+gridTableFooter :: Parsec [Char] ParserState [Char]
608gridTableFooter = blanklines
608gridTableFooter = blanklines
609
609
610---
610---
611
611
612-- | Parse a string with a given parser and state.
612-- | Parse a string with a given parser and state.
613−readWith :: GenParser t ParserState a -- ^ parser
613+readWith :: Parsec [t] ParserState a -- ^ parser
614 -> ParserState -- ^ initial state
614 -> ParserState -- ^ initial state
615 -> [t] -- ^ input
615 -> [t] -- ^ input
616 -> a
616 -> a
@@ -620,7 +620,7 @@ readWith parser state input =
620 Right result -> result
620 Right result -> result
621
621
622-- | Parse a string with @parser@ (for testing).
622-- | Parse a string with @parser@ (for testing).
623−testStringWith :: (Show a) => GenParser Char ParserState a
623+testStringWith :: (Show a) => Parsec [Char] ParserState a
624 -> String
624 -> String
625 -> IO ()
625 -> IO ()
626testStringWith parser str = UTF8.putStrLn $ show $
626testStringWith parser str = UTF8.putStrLn $ show $
@@ -735,25 +735,25 @@ lookupKeySrc table key = case M.lookup key table of
735 Just src -> Just src
735 Just src -> Just src
736
736
737-- | Fail unless we're in "smart typography" mode.
737-- | Fail unless we're in "smart typography" mode.
738−failUnlessSmart :: GenParser tok ParserState ()
738+failUnlessSmart :: Parsec [tok] ParserState ()
739failUnlessSmart = getState >>= guard . stateSmart
739failUnlessSmart = getState >>= guard . stateSmart
740
740
741−smartPunctuation :: GenParser Char ParserState Inline
741+smartPunctuation :: Parsec [Char] ParserState Inline
742− -> GenParser Char ParserState Inline
742+ -> Parsec [Char] ParserState Inline
743smartPunctuation inlineParser = do
743smartPunctuation inlineParser = do
744 failUnlessSmart
744 failUnlessSmart
745 choice [ quoted inlineParser, apostrophe, dash, ellipses ]
745 choice [ quoted inlineParser, apostrophe, dash, ellipses ]
746
746
747−apostrophe :: GenParser Char ParserState Inline
747+apostrophe :: Parsec [Char] ParserState Inline
748apostrophe = (char '\'' <|> char '\8217') >> return (Str "\x2019")
748apostrophe = (char '\'' <|> char '\8217') >> return (Str "\x2019")
749
749
750−quoted :: GenParser Char ParserState Inline
750+quoted :: Parsec [Char] ParserState Inline
751− -> GenParser Char ParserState Inline
751+ -> Parsec [Char] ParserState Inline
752quoted inlineParser = doubleQuoted inlineParser <|> singleQuoted inlineParser
752quoted inlineParser = doubleQuoted inlineParser <|> singleQuoted inlineParser
753
753
754withQuoteContext :: QuoteContext
754withQuoteContext :: QuoteContext
755− -> (GenParser Char ParserState Inline)
755+ -> (Parsec [Char] ParserState Inline)
756− -> GenParser Char ParserState Inline
756+ -> Parsec [Char] ParserState Inline
757withQuoteContext context parser = do
757withQuoteContext context parser = do
758 oldState <- getState
758 oldState <- getState
759 let oldQuoteContext = stateQuoteContext oldState
759 let oldQuoteContext = stateQuoteContext oldState
@@ -763,39 +763,39 @@ withQuoteContext context parser = do
763 setState newState { stateQuoteContext = oldQuoteContext }
763 setState newState { stateQuoteContext = oldQuoteContext }
764 return result
764 return result
765
765
766−singleQuoted :: GenParser Char ParserState Inline
766+singleQuoted :: Parsec [Char] ParserState Inline
767− -> GenParser Char ParserState Inline
767+ -> Parsec [Char] ParserState Inline
768singleQuoted inlineParser = try $ do
768singleQuoted inlineParser = try $ do
769 singleQuoteStart
769 singleQuoteStart
770 withQuoteContext InSingleQuote $ many1Till inlineParser singleQuoteEnd >>=
770 withQuoteContext InSingleQuote $ many1Till inlineParser singleQuoteEnd >>=
771 return . Quoted SingleQuote . normalizeSpaces
771 return . Quoted SingleQuote . normalizeSpaces
772
772
773−doubleQuoted :: GenParser Char ParserState Inline
773+doubleQuoted :: Parsec [Char] ParserState Inline
774− -> GenParser Char ParserState Inline
774+ -> Parsec [Char] ParserState Inline
775doubleQuoted inlineParser = try $ do
775doubleQuoted inlineParser = try $ do
776 doubleQuoteStart
776 doubleQuoteStart
777 withQuoteContext InDoubleQuote $ do
777 withQuoteContext InDoubleQuote $ do
778 contents <- manyTill inlineParser doubleQuoteEnd
778 contents <- manyTill inlineParser doubleQuoteEnd
779 return . Quoted DoubleQuote . normalizeSpaces $ contents
779 return . Quoted DoubleQuote . normalizeSpaces $ contents
780
780
781−failIfInQuoteContext :: QuoteContext -> GenParser tok ParserState ()
781+failIfInQuoteContext :: QuoteContext -> Parsec [tok] ParserState ()
782failIfInQuoteContext context = do
782failIfInQuoteContext context = do
783 st <- getState
783 st <- getState
784 if stateQuoteContext st == context
784 if stateQuoteContext st == context
785 then fail "already inside quotes"
785 then fail "already inside quotes"
786 else return ()
786 else return ()
787
787
788−charOrRef :: [Char] -> GenParser Char st Char
788+charOrRef :: [Char] -> Parsec [Char] st Char
789charOrRef cs =
789charOrRef cs =
790 oneOf cs <|> try (do c <- characterReference
790 oneOf cs <|> try (do c <- characterReference
791 guard (c `elem` cs)
791 guard (c `elem` cs)
792 return c)
792 return c)
793
793
794−updateLastStrPos :: GenParser Char ParserState ()
794+updateLastStrPos :: Parsec [Char] ParserState ()
795updateLastStrPos = getPosition >>= \p ->
795updateLastStrPos = getPosition >>= \p ->
796 updateState $ \s -> s{ stateLastStrPos = Just p }
796 updateState $ \s -> s{ stateLastStrPos = Just p }
797
797
798−singleQuoteStart :: GenParser Char ParserState ()
798+singleQuoteStart :: Parsec [Char] ParserState ()
799singleQuoteStart = do
799singleQuoteStart = do
800 failIfInQuoteContext InSingleQuote
800 failIfInQuoteContext InSingleQuote
801 pos <- getPosition
801 pos <- getPosition
@@ -810,28 +810,28 @@ singleQuoteStart = do
810 -- possess/contraction
810 -- possess/contraction
811 return ()
811 return ()
812
812
813−singleQuoteEnd :: GenParser Char st ()
813+singleQuoteEnd :: Parsec [Char] st ()
814singleQuoteEnd = try $ do
814singleQuoteEnd = try $ do
815 charOrRef "'\8217\146"
815 charOrRef "'\8217\146"
816 notFollowedBy alphaNum
816 notFollowedBy alphaNum
817
817
818−doubleQuoteStart :: GenParser Char ParserState ()
818+doubleQuoteStart :: Parsec [Char] ParserState ()
819doubleQuoteStart = do
819doubleQuoteStart = do
820 failIfInQuoteContext InDoubleQuote
820 failIfInQuoteContext InDoubleQuote
821 try $ do charOrRef "\"\8220\147"
821 try $ do charOrRef "\"\8220\147"
822 notFollowedBy (satisfy (\c -> c == ' ' || c == '\t' || c == '\n'))
822 notFollowedBy (satisfy (\c -> c == ' ' || c == '\t' || c == '\n'))
823
823
824−doubleQuoteEnd :: GenParser Char st ()
824+doubleQuoteEnd :: Parsec [Char] st ()
825doubleQuoteEnd = do
825doubleQuoteEnd = do
826 charOrRef "\"\8221\148"
826 charOrRef "\"\8221\148"
827 return ()
827 return ()
828
828
829−ellipses :: GenParser Char st Inline
829+ellipses :: Parsec [Char] st Inline
830ellipses = do
830ellipses = do
831 try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
831 try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
832 return (Str "\8230")
832 return (Str "\8230")
833
833
834−dash :: GenParser Char ParserState Inline
834+dash :: Parsec [Char] ParserState Inline
835dash = do
835dash = do
836 oldDashes <- stateOldDashes `fmap` getState
836 oldDashes <- stateOldDashes `fmap` getState
837 if oldDashes
837 if oldDashes
@@ -839,28 +839,28 @@ dash = do
839 else Str `fmap` (hyphenDash <|> emDash <|> enDash)
839 else Str `fmap` (hyphenDash <|> emDash <|> enDash)
840
840
841-- Two hyphens = en-dash, three = em-dash
841-- Two hyphens = en-dash, three = em-dash
842−hyphenDash :: GenParser Char st String
842+hyphenDash :: Parsec [Char] st String
843hyphenDash = do
843hyphenDash = do
844 try $ string "--"
844 try $ string "--"
845 option "\8211" (char '-' >> return "\8212")
845 option "\8211" (char '-' >> return "\8212")
846
846
847−emDash :: GenParser Char st String
847+emDash :: Parsec [Char] st String
848emDash = do
848emDash = do
849 try (charOrRef "\8212\151")
849 try (charOrRef "\8212\151")
850 return "\8212"
850 return "\8212"
851
851
852−enDash :: GenParser Char st String
852+enDash :: Parsec [Char] st String
853enDash = do
853enDash = do
854 try (charOrRef "\8212\151")
854 try (charOrRef "\8212\151")
855 return "\8211"
855 return "\8211"
856
856
857−enDashOld :: GenParser Char st Inline
857+enDashOld :: Parsec [Char] st Inline
858enDashOld = do
858enDashOld = do
859 try (charOrRef "\8211\150") <|>
859 try (charOrRef "\8211\150") <|>
860 try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
860 try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
861 return (Str "\8211")
861 return (Str "\8211")
862
862
863−emDashOld :: GenParser Char st Inline
863+emDashOld :: Parsec [Char] st Inline
864emDashOld = do
864emDashOld = do
865 try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
865 try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
866 return (Str "\8212")
866 return (Str "\8212")
@@ -870,12 +870,12 @@ emDashOld = do
870--
870--
871
871
872-- | Parse a \newcommand or \renewcommand macro definition.
872-- | Parse a \newcommand or \renewcommand macro definition.
873−macro :: GenParser Char ParserState Block
873+macro :: Parsec [Char] ParserState Block
874macro = do
874macro = do
875 apply <- stateApplyMacros `fmap` getState
875 apply <- stateApplyMacros `fmap` getState
876 inp <- getInput
876 inp <- getInput
877 case parseMacroDefinitions inp of
877 case parseMacroDefinitions inp of
878− ([], _) -> pzero
878+ ([], _) -> mzero
879 (ms, rest) -> do def' <- count (length inp - length rest) anyChar
879 (ms, rest) -> do def' <- count (length inp - length rest) anyChar
880 if apply
880 if apply
881 then do
881 then do
@@ -885,7 +885,7 @@ macro = do
885 else return $ RawBlock "latex" def'
885 else return $ RawBlock "latex" def'
886
886
887-- | Apply current macros to string.
887-- | Apply current macros to string.
888−applyMacros' :: String -> GenParser Char ParserState String
888+applyMacros' :: String -> Parsec [Char] ParserState String
889applyMacros' target = do
889applyMacros' target = do
890 apply <- liftM stateApplyMacros getState
890 apply <- liftM stateApplyMacros getState
891 if apply
891 if apply
src/Text/Pandoc/Readers/HTML.hs+12−12
@@ -36,8 +36,8 @@ module Text.Pandoc.Readers.HTML ( readHtml
36 , isCommentTag
36 , isCommentTag
37 ) where
37 ) where
38
38
39−import Text.ParserCombinators.Parsec
39+import Text.Parsec
40−import Text.ParserCombinators.Parsec.Pos
40+import Text.Parsec.Pos
41import Text.HTML.TagSoup
41import Text.HTML.TagSoup
42import Text.HTML.TagSoup.Match
42import Text.HTML.TagSoup.Match
43import Text.Pandoc.Definition
43import Text.Pandoc.Definition
@@ -47,7 +47,7 @@ import Text.Pandoc.Parsing
47import Data.Maybe ( fromMaybe, isJust )
47import Data.Maybe ( fromMaybe, isJust )
48import Data.List ( intercalate )
48import Data.List ( intercalate )
49import Data.Char ( isDigit, toLower )
49import Data.Char ( isDigit, toLower )
50−import Control.Monad ( liftM, guard, when )
50+import Control.Monad ( liftM, guard, when, mzero )
51
51
52isSpace :: Char -> Bool
52isSpace :: Char -> Bool
53isSpace ' ' = True
53isSpace ' ' = True
@@ -68,7 +68,7 @@ readHtml st inp = Pandoc meta blocks
68 then parseHeader tags
68 then parseHeader tags
69 else (Meta [] [] [], tags)
69 else (Meta [] [] [], tags)
70
70
71−type TagParser = GenParser (Tag String) ParserState
71+type TagParser = Parsec [Tag String] ParserState
72
72
73-- TODO - fix this - not every header has a title tag
73-- TODO - fix this - not every header has a title tag
74parseHeader :: [Tag String] -> (Meta, [Tag String])
74parseHeader :: [Tag String] -> (Meta, [Tag String])
@@ -417,7 +417,7 @@ pCloses tagtype = try $ do
417 (TagClose "ul") | tagtype == "li" -> return ()
417 (TagClose "ul") | tagtype == "li" -> return ()
418 (TagClose "ol") | tagtype == "li" -> return ()
418 (TagClose "ol") | tagtype == "li" -> return ()
419 (TagClose "dl") | tagtype == "li" -> return ()
419 (TagClose "dl") | tagtype == "li" -> return ()
420− _ -> pzero
420+ _ -> mzero
421
421
422pTagText :: TagParser [Inline]
422pTagText :: TagParser [Inline]
423pTagText = try $ do
423pTagText = try $ do
@@ -432,11 +432,11 @@ pBlank = try $ do
432 (TagText str) <- pSatisfy isTagText
432 (TagText str) <- pSatisfy isTagText
433 guard $ all isSpace str
433 guard $ all isSpace str
434
434
435−pTagContents :: GenParser Char ParserState Inline
435+pTagContents :: Parsec [Char] ParserState Inline
436pTagContents =
436pTagContents =
437 pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol <|> pBad
437 pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol <|> pBad
438
438
439−pStr :: GenParser Char ParserState Inline
439+pStr :: Parsec [Char] ParserState Inline
440pStr = do
440pStr = do
441 result <- many1 $ satisfy $ \c ->
441 result <- many1 $ satisfy $ \c ->
442 not (isSpace c) && not (isSpecial c) && not (isBad c)
442 not (isSpace c) && not (isSpecial c) && not (isBad c)
@@ -455,13 +455,13 @@ isSpecial '\8220' = True
455isSpecial '\8221' = True
455isSpecial '\8221' = True
456isSpecial _ = False
456isSpecial _ = False
457
457
458−pSymbol :: GenParser Char ParserState Inline
458+pSymbol :: Parsec [Char] ParserState Inline
459pSymbol = satisfy isSpecial >>= return . Str . (:[])
459pSymbol = satisfy isSpecial >>= return . Str . (:[])
460
460
461isBad :: Char -> Bool
461isBad :: Char -> Bool
462isBad c = c >= '\128' && c <= '\159' -- not allowed in HTML
462isBad c = c >= '\128' && c <= '\159' -- not allowed in HTML
463
463
464−pBad :: GenParser Char ParserState Inline
464+pBad :: Parsec [Char] ParserState Inline
465pBad = do
465pBad = do
466 c <- satisfy isBad
466 c <- satisfy isBad
467 let c' = case c of
467 let c' = case c of
@@ -495,7 +495,7 @@ pBad = do
495 _ -> '?'
495 _ -> '?'
496 return $ Str [c']
496 return $ Str [c']
497
497
498−pSpace :: GenParser Char ParserState Inline
498+pSpace :: Parsec [Char] ParserState Inline
499pSpace = many1 (satisfy isSpace) >> return Space
499pSpace = many1 (satisfy isSpace) >> return Space
500
500
501--
501--
@@ -593,7 +593,7 @@ _ `closes` _ = False
593--- parsers for use in markdown, textile readers
593--- parsers for use in markdown, textile readers
594
594
595-- | Matches a stretch of HTML in balanced tags.
595-- | 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
597htmlInBalanced f = try $ do
597htmlInBalanced f = try $ do
598 (TagOpen t _, tag) <- htmlTag f
598 (TagOpen t _, tag) <- htmlTag f
599 guard $ '/' `notElem` tag -- not a self-closing tag
599 guard $ '/' `notElem` tag -- not a self-closing tag
@@ -606,7 +606,7 @@ htmlInBalanced f = try $ do
606 return $ tag ++ concat contents ++ endtag
606 return $ tag ++ concat contents ++ endtag
607
607
608-- | Matches a tag meeting a certain condition.
608-- | 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)
610htmlTag f = try $ do
610htmlTag f = try $ do
611 lookAhead (char '<')
611 lookAhead (char '<')
612 (next : _) <- getInput >>= return . canonicalizeTags . parseTags
612 (next : _) <- getInput >>= return . canonicalizeTags . parseTags
src/Text/Pandoc/Readers/LaTeX.hs+4−4
@@ -33,7 +33,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
33 handleIncludes
33 handleIncludes
34 ) where
34 ) where
35
35
36−import Text.ParserCombinators.Parsec hiding ((<|>), space, many, optional)
36+import Text.Parsec hiding ((<|>), space, many, optional)
37import Text.Pandoc.Definition
37import Text.Pandoc.Definition
38import Text.Pandoc.Shared
38import Text.Pandoc.Shared
39import Text.Pandoc.Parsing
39import Text.Pandoc.Parsing
@@ -64,7 +64,7 @@ parseLaTeX = do
64 let date' = stateDate st
64 let date' = stateDate st
65 return $ Pandoc (Meta title' authors' date') $ toList bs
65 return $ Pandoc (Meta title' authors' date') $ toList bs
66
66
67−type LP = GenParser Char ParserState
67+type LP = Parsec [Char] ParserState
68
68
69anyControlSeq :: LP String
69anyControlSeq :: LP String
70anyControlSeq = do
70anyControlSeq = do
@@ -713,10 +713,10 @@ verbatimEnv = do
713 rest <- getInput
713 rest <- getInput
714 return (r,rest)
714 return (r,rest)
715
715
716−rawLaTeXBlock :: GenParser Char ParserState String
716+rawLaTeXBlock :: Parsec [Char] ParserState String
717rawLaTeXBlock = snd <$> withRaw (environment <|> blockCommand)
717rawLaTeXBlock = snd <$> withRaw (environment <|> blockCommand)
718
718
719−rawLaTeXInline :: GenParser Char ParserState Inline
719+rawLaTeXInline :: Parsec [Char] ParserState Inline
720rawLaTeXInline = do
720rawLaTeXInline = do
721 (res, raw) <- withRaw inlineCommand
721 (res, raw) <- withRaw inlineCommand
722 if res == mempty
722 if res == mempty
src/Text/Pandoc/Readers/Markdown.hs+137−137
@@ -43,7 +43,7 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
43import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
43import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
44 isTextTag, isCommentTag )
44 isTextTag, isCommentTag )
45import Text.Pandoc.XML ( fromEntities )
45import Text.Pandoc.XML ( fromEntities )
46−import Text.ParserCombinators.Parsec
46+import Text.Parsec
47import Control.Monad (when, liftM, guard, mzero)
47import Control.Monad (when, liftM, guard, mzero)
48import Text.HTML.TagSoup
48import Text.HTML.TagSoup
49import Text.HTML.TagSoup.Match (tagOpen)
49import Text.HTML.TagSoup.Match (tagOpen)
@@ -83,14 +83,14 @@ isBlank _ = False
83-- auxiliary functions
83-- auxiliary functions
84--
84--
85
85
86−indentSpaces :: GenParser Char ParserState [Char]
86+indentSpaces :: Parsec [Char] ParserState [Char]
87indentSpaces = try $ do
87indentSpaces = try $ do
88 state <- getState
88 state <- getState
89 let tabStop = stateTabStop state
89 let tabStop = stateTabStop state
90 count tabStop (char ' ') <|>
90 count tabStop (char ' ') <|>
91 string "\t" <?> "indentation"
91 string "\t" <?> "indentation"
92
92
93−nonindentSpaces :: GenParser Char ParserState [Char]
93+nonindentSpaces :: Parsec [Char] ParserState [Char]
94nonindentSpaces = do
94nonindentSpaces = do
95 state <- getState
95 state <- getState
96 let tabStop = stateTabStop state
96 let tabStop = stateTabStop state
@@ -99,30 +99,30 @@ nonindentSpaces = do
99 then return sps
99 then return sps
100 else unexpected "indented line"
100 else unexpected "indented line"
101
101
102−skipNonindentSpaces :: GenParser Char ParserState ()
102+skipNonindentSpaces :: Parsec [Char] ParserState ()
103skipNonindentSpaces = do
103skipNonindentSpaces = do
104 state <- getState
104 state <- getState
105 atMostSpaces (stateTabStop state - 1)
105 atMostSpaces (stateTabStop state - 1)
106
106
107−atMostSpaces :: Int -> GenParser Char ParserState ()
107+atMostSpaces :: Int -> Parsec [Char] ParserState ()
108atMostSpaces 0 = notFollowedBy (char ' ')
108atMostSpaces 0 = notFollowedBy (char ' ')
109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
109atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
110
110
111−litChar :: GenParser Char ParserState Char
111+litChar :: Parsec [Char] ParserState Char
112litChar = escapedChar'
112litChar = escapedChar'
113 <|> noneOf "\n"
113 <|> noneOf "\n"
114 <|> (newline >> notFollowedBy blankline >> return ' ')
114 <|> (newline >> notFollowedBy blankline >> return ' ')
115
115
116-- | Fail unless we're at beginning of a line.
116-- | Fail unless we're at beginning of a line.
117−failUnlessBeginningOfLine :: GenParser tok st ()
117+failUnlessBeginningOfLine :: Parsec [tok] st ()
118failUnlessBeginningOfLine = do
118failUnlessBeginningOfLine = do
119 pos <- getPosition
119 pos <- getPosition
120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
120 if sourceColumn pos == 1 then return () else fail "not beginning of line"
121
121
122-- | Parse a sequence of inline elements between square brackets,
122-- | Parse a sequence of inline elements between square brackets,
123-- including inlines between balanced pairs of square brackets.
123-- including inlines between balanced pairs of square brackets.
124−inlinesInBalancedBrackets :: GenParser Char ParserState Inline
124+inlinesInBalancedBrackets :: Parsec [Char] ParserState Inline
125− -> GenParser Char ParserState [Inline]
125+ -> Parsec [Char] ParserState [Inline]
126inlinesInBalancedBrackets parser = try $ do
126inlinesInBalancedBrackets parser = try $ do
127 char '['
127 char '['
128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
128 result <- manyTill ( (do lookAhead $ try $ do (Str res) <- parser
@@ -137,7 +137,7 @@ inlinesInBalancedBrackets parser = try $ do
137-- document structure
137-- document structure
138--
138--
139
139
140−titleLine :: GenParser Char ParserState [Inline]
140+titleLine :: Parsec [Char] ParserState [Inline]
141titleLine = try $ do
141titleLine = try $ do
142 char '%'
142 char '%'
143 skipSpaces
143 skipSpaces
@@ -146,7 +146,7 @@ titleLine = try $ do
146 newline
146 newline
147 return $ normalizeSpaces res
147 return $ normalizeSpaces res
148
148
149−authorsLine :: GenParser Char ParserState [[Inline]]
149+authorsLine :: Parsec [Char] ParserState [[Inline]]
150authorsLine = try $ do
150authorsLine = try $ do
151 char '%'
151 char '%'
152 skipSpaces
152 skipSpaces
@@ -157,14 +157,14 @@ authorsLine = try $ do
157 newline
157 newline
158 return $ filter (not . null) $ map normalizeSpaces authors
158 return $ filter (not . null) $ map normalizeSpaces authors
159
159
160−dateLine :: GenParser Char ParserState [Inline]
160+dateLine :: Parsec [Char] ParserState [Inline]
161dateLine = try $ do
161dateLine = try $ do
162 char '%'
162 char '%'
163 skipSpaces
163 skipSpaces
164 date <- manyTill inline newline
164 date <- manyTill inline newline
165 return $ normalizeSpaces date
165 return $ normalizeSpaces date
166
166
167−titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline])
167+titleBlock :: Parsec [Char] ParserState ([Inline], [[Inline]], [Inline])
168titleBlock = try $ do
168titleBlock = try $ do
169 failIfStrict
169 failIfStrict
170 title <- option [] titleLine
170 title <- option [] titleLine
@@ -173,7 +173,7 @@ titleBlock = try $ do
173 optional blanklines
173 optional blanklines
174 return (title, author, date)
174 return (title, author, date)
175
175
176−parseMarkdown :: GenParser Char ParserState Pandoc
176+parseMarkdown :: Parsec [Char] ParserState Pandoc
177parseMarkdown = do
177parseMarkdown = do
178 -- markdown allows raw HTML
178 -- markdown allows raw HTML
179 updateState (\state -> state { stateParseRaw = True })
179 updateState (\state -> state { stateParseRaw = True })
@@ -182,7 +182,7 @@ parseMarkdown = do
182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
182 -- docMinusKeys is the raw document with blanks where the keys/notes were...
183 st <- getState
183 st <- getState
184 let firstPassParser = referenceKey
184 let firstPassParser = referenceKey
185− <|> (if stateStrict st then pzero else noteBlock)
185+ <|> (if stateStrict st then mzero else noteBlock)
186 <|> liftM snd (withRaw codeBlockDelimited)
186 <|> liftM snd (withRaw codeBlockDelimited)
187 <|> lineClump
187 <|> lineClump
188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
188 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
@@ -211,7 +211,7 @@ parseMarkdown = do
211-- initial pass for references and notes
211-- initial pass for references and notes
212--
212--
213
213
214−referenceKey :: GenParser Char ParserState [Char]
214+referenceKey :: Parsec [Char] ParserState [Char]
215referenceKey = try $ do
215referenceKey = try $ do
216 startPos <- getPosition
216 startPos <- getPosition
217 skipNonindentSpaces
217 skipNonindentSpaces
@@ -238,7 +238,7 @@ referenceKey = try $ do
238 -- return blanks so line count isn't affected
238 -- return blanks so line count isn't affected
239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
239 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
240
240
241−referenceTitle :: GenParser Char ParserState String
241+referenceTitle :: Parsec [Char] ParserState String
242referenceTitle = try $ do
242referenceTitle = try $ do
243 skipSpaces >> optional newline >> skipSpaces
243 skipSpaces >> optional newline >> skipSpaces
244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
244 tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
@@ -247,23 +247,23 @@ referenceTitle = try $ do
247 notFollowedBy (noneOf ")\n")))
247 notFollowedBy (noneOf ")\n")))
248 return $ fromEntities tit
248 return $ fromEntities tit
249
249
250−noteMarker :: GenParser Char ParserState [Char]
250+noteMarker :: Parsec [Char] ParserState [Char]
251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
251noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
252
252
253−rawLine :: GenParser Char ParserState [Char]
253+rawLine :: Parsec [Char] ParserState [Char]
254rawLine = try $ do
254rawLine = try $ do
255 notFollowedBy blankline
255 notFollowedBy blankline
256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
256 notFollowedBy' $ try $ skipNonindentSpaces >> noteMarker
257 optional indentSpaces
257 optional indentSpaces
258 anyLine
258 anyLine
259
259
260−rawLines :: GenParser Char ParserState [Char]
260+rawLines :: Parsec [Char] ParserState [Char]
261rawLines = do
261rawLines = do
262 first <- anyLine
262 first <- anyLine
263 rest <- many rawLine
263 rest <- many rawLine
264 return $ unlines (first:rest)
264 return $ unlines (first:rest)
265
265
266−noteBlock :: GenParser Char ParserState [Char]
266+noteBlock :: Parsec [Char] ParserState [Char]
267noteBlock = try $ do
267noteBlock = try $ do
268 startPos <- getPosition
268 startPos <- getPosition
269 skipNonindentSpaces
269 skipNonindentSpaces
@@ -287,10 +287,10 @@ noteBlock = try $ do
287-- parsing blocks
287-- parsing blocks
288--
288--
289
289
290−parseBlocks :: GenParser Char ParserState [Block]
290+parseBlocks :: Parsec [Char] ParserState [Block]
291parseBlocks = manyTill block eof
291parseBlocks = manyTill block eof
292
292
293−block :: GenParser Char ParserState Block
293+block :: Parsec [Char] ParserState Block
294block = do
294block = do
295 st <- getState
295 st <- getState
296 choice (if stateStrict st
296 choice (if stateStrict st
@@ -325,10 +325,10 @@ block = do
325-- header blocks
325-- header blocks
326--
326--
327
327
328−header :: GenParser Char ParserState Block
328+header :: Parsec [Char] ParserState Block
329header = setextHeader <|> atxHeader <?> "header"
329header = setextHeader <|> atxHeader <?> "header"
330
330
331−atxHeader :: GenParser Char ParserState Block
331+atxHeader :: Parsec [Char] ParserState Block
332atxHeader = try $ do
332atxHeader = try $ do
333 level <- many1 (char '#') >>= return . length
333 level <- many1 (char '#') >>= return . length
334 notFollowedBy (char '.' <|> char ')') -- this would be a list
334 notFollowedBy (char '.' <|> char ')') -- this would be a list
@@ -336,10 +336,10 @@ atxHeader = try $ do
336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
336 text <- manyTill inline atxClosing >>= return . normalizeSpaces
337 return $ Header level text
337 return $ Header level text
338
338
339−atxClosing :: GenParser Char st [Char]
339+atxClosing :: Parsec [Char] st [Char]
340atxClosing = try $ skipMany (char '#') >> blanklines
340atxClosing = try $ skipMany (char '#') >> blanklines
341
341
342−setextHeader :: GenParser Char ParserState Block
342+setextHeader :: Parsec [Char] ParserState Block
343setextHeader = try $ do
343setextHeader = try $ do
344 -- This lookahead prevents us from wasting time parsing Inlines
344 -- This lookahead prevents us from wasting time parsing Inlines
345 -- unless necessary -- it gives a significant performance boost.
345 -- unless necessary -- it gives a significant performance boost.
@@ -355,7 +355,7 @@ setextHeader = try $ do
355-- hrule block
355-- hrule block
356--
356--
357
357
358−hrule :: GenParser Char st Block
358+hrule :: Parsec [Char] st Block
359hrule = try $ do
359hrule = try $ do
360 skipSpaces
360 skipSpaces
361 start <- satisfy isHruleChar
361 start <- satisfy isHruleChar
@@ -369,12 +369,12 @@ hrule = try $ do
369-- code blocks
369-- code blocks
370--
370--
371
371
372−indentedLine :: GenParser Char ParserState [Char]
372+indentedLine :: Parsec [Char] ParserState [Char]
373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
373indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n")
374
374
375blockDelimiter :: (Char -> Bool)
375blockDelimiter :: (Char -> Bool)
376 -> Maybe Int
376 -> Maybe Int
377− -> GenParser Char st (Int, (String, [String], [(String, String)]), Char)
377+ -> Parsec [Char] st (Int, (String, [String], [(String, String)]), Char)
378blockDelimiter f len = try $ do
378blockDelimiter f len = try $ do
379 c <- lookAhead (satisfy f)
379 c <- lookAhead (satisfy f)
380 size <- case len of
380 size <- case len of
@@ -388,7 +388,7 @@ blockDelimiter f len = try $ do
388 blankline
388 blankline
389 return (size, attr, c)
389 return (size, attr, c)
390
390
391−attributes :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
391+attributes :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
392attributes = try $ do
392attributes = try $ do
393 char '{'
393 char '{'
394 spnl
394 spnl
@@ -400,28 +400,28 @@ attributes = try $ do
400 | otherwise = firstNonNull xs
400 | otherwise = firstNonNull xs
401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
401 return (firstNonNull $ reverse ids, concat classes, concat keyvals)
402
402
403−attribute :: GenParser Char st ([Char], [[Char]], [([Char], [Char])])
403+attribute :: Parsec [Char] st ([Char], [[Char]], [([Char], [Char])])
404attribute = identifierAttr <|> classAttr <|> keyValAttr
404attribute = identifierAttr <|> classAttr <|> keyValAttr
405
405
406−identifier :: GenParser Char st [Char]
406+identifier :: Parsec [Char] st [Char]
407identifier = do
407identifier = do
408 first <- letter
408 first <- letter
409 rest <- many $ alphaNum <|> oneOf "-_:."
409 rest <- many $ alphaNum <|> oneOf "-_:."
410 return (first:rest)
410 return (first:rest)
411
411
412−identifierAttr :: GenParser Char st ([Char], [a], [a1])
412+identifierAttr :: Parsec [Char] st ([Char], [a], [a1])
413identifierAttr = try $ do
413identifierAttr = try $ do
414 char '#'
414 char '#'
415 result <- identifier
415 result <- identifier
416 return (result,[],[])
416 return (result,[],[])
417
417
418−classAttr :: GenParser Char st ([Char], [[Char]], [a])
418+classAttr :: Parsec [Char] st ([Char], [[Char]], [a])
419classAttr = try $ do
419classAttr = try $ do
420 char '.'
420 char '.'
421 result <- identifier
421 result <- identifier
422 return ("",[result],[])
422 return ("",[result],[])
423
423
424−keyValAttr :: GenParser Char st ([Char], [a], [([Char], [Char])])
424+keyValAttr :: Parsec [Char] st ([Char], [a], [([Char], [Char])])
425keyValAttr = try $ do
425keyValAttr = try $ do
426 key <- identifier
426 key <- identifier
427 char '='
427 char '='
@@ -430,14 +430,14 @@ keyValAttr = try $ do
430 <|> many nonspaceChar
430 <|> many nonspaceChar
431 return ("",[],[(key,val)])
431 return ("",[],[(key,val)])
432
432
433−codeBlockDelimited :: GenParser Char st Block
433+codeBlockDelimited :: Parsec [Char] st Block
434codeBlockDelimited = try $ do
434codeBlockDelimited = try $ do
435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
435 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
436 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
437 blanklines
437 blanklines
438 return $ CodeBlock attr $ intercalate "\n" contents
438 return $ CodeBlock attr $ intercalate "\n" contents
439
439
440−codeBlockIndented :: GenParser Char ParserState Block
440+codeBlockIndented :: Parsec [Char] ParserState Block
441codeBlockIndented = do
441codeBlockIndented = do
442 contents <- many1 (indentedLine <|>
442 contents <- many1 (indentedLine <|>
443 try (do b <- blanklines
443 try (do b <- blanklines
@@ -448,7 +448,7 @@ codeBlockIndented = do
448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
448 return $ CodeBlock ("", stateIndentedCodeClasses st, []) $
449 stripTrailingNewlines $ concat contents
449 stripTrailingNewlines $ concat contents
450
450
451−lhsCodeBlock :: GenParser Char ParserState Block
451+lhsCodeBlock :: Parsec [Char] ParserState Block
452lhsCodeBlock = do
452lhsCodeBlock = do
453 failUnlessLHS
453 failUnlessLHS
454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
454 liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
@@ -456,7 +456,7 @@ lhsCodeBlock = do
456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
456 <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
457 lhsCodeBlockInverseBird
457 lhsCodeBlockInverseBird
458
458
459−lhsCodeBlockLaTeX :: GenParser Char ParserState String
459+lhsCodeBlockLaTeX :: Parsec [Char] ParserState String
460lhsCodeBlockLaTeX = try $ do
460lhsCodeBlockLaTeX = try $ do
461 string "\\begin{code}"
461 string "\\begin{code}"
462 manyTill spaceChar newline
462 manyTill spaceChar newline
@@ -464,13 +464,13 @@ lhsCodeBlockLaTeX = try $ do
464 blanklines
464 blanklines
465 return $ stripTrailingNewlines contents
465 return $ stripTrailingNewlines contents
466
466
467−lhsCodeBlockBird :: GenParser Char ParserState String
467+lhsCodeBlockBird :: Parsec [Char] ParserState String
468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
468lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
469
469
470−lhsCodeBlockInverseBird :: GenParser Char ParserState String
470+lhsCodeBlockInverseBird :: Parsec [Char] ParserState String
471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
471lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
472
472
473−lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
473+lhsCodeBlockBirdWith :: Char -> Parsec [Char] ParserState String
474lhsCodeBlockBirdWith c = try $ do
474lhsCodeBlockBirdWith c = try $ do
475 pos <- getPosition
475 pos <- getPosition
476 when (sourceColumn pos /= 1) $ fail "Not in first column"
476 when (sourceColumn pos /= 1) $ fail "Not in first column"
@@ -482,7 +482,7 @@ lhsCodeBlockBirdWith c = try $ do
482 blanklines
482 blanklines
483 return $ intercalate "\n" lns'
483 return $ intercalate "\n" lns'
484
484
485−birdTrackLine :: Char -> GenParser Char st [Char]
485+birdTrackLine :: Char -> Parsec [Char] st [Char]
486birdTrackLine c = try $ do
486birdTrackLine c = try $ do
487 char c
487 char c
488 -- allow html tags on left margin:
488 -- allow html tags on left margin:
@@ -494,10 +494,10 @@ birdTrackLine c = try $ do
494-- block quotes
494-- block quotes
495--
495--
496
496
497−emailBlockQuoteStart :: GenParser Char ParserState Char
497+emailBlockQuoteStart :: Parsec [Char] ParserState Char
498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
498emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char ' ')
499
499
500−emailBlockQuote :: GenParser Char ParserState [[Char]]
500+emailBlockQuote :: Parsec [Char] ParserState [[Char]]
501emailBlockQuote = try $ do
501emailBlockQuote = try $ do
502 emailBlockQuoteStart
502 emailBlockQuoteStart
503 raw <- sepBy (many (nonEndline <|>
503 raw <- sepBy (many (nonEndline <|>
@@ -508,7 +508,7 @@ emailBlockQuote = try $ do
508 optional blanklines
508 optional blanklines
509 return raw
509 return raw
510
510
511−blockQuote :: GenParser Char ParserState Block
511+blockQuote :: Parsec [Char] ParserState Block
512blockQuote = do
512blockQuote = do
513 raw <- emailBlockQuote
513 raw <- emailBlockQuote
514 -- parse the extracted block, which may contain various block elements:
514 -- parse the extracted block, which may contain various block elements:
@@ -519,7 +519,7 @@ blockQuote = do
519-- list blocks
519-- list blocks
520--
520--
521
521
522−bulletListStart :: GenParser Char ParserState ()
522+bulletListStart :: Parsec [Char] ParserState ()
523bulletListStart = try $ do
523bulletListStart = try $ do
524 optional newline -- if preceded by a Plain block in a list context
524 optional newline -- if preceded by a Plain block in a list context
525 skipNonindentSpaces
525 skipNonindentSpaces
@@ -528,7 +528,7 @@ bulletListStart = try $ do
528 spaceChar
528 spaceChar
529 skipSpaces
529 skipSpaces
530
530
531−anyOrderedListStart :: GenParser Char ParserState (Int, ListNumberStyle, ListNumberDelim)
531+anyOrderedListStart :: Parsec [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
532anyOrderedListStart = try $ do
532anyOrderedListStart = try $ do
533 optional newline -- if preceded by a Plain block in a list context
533 optional newline -- if preceded by a Plain block in a list context
534 skipNonindentSpaces
534 skipNonindentSpaces
@@ -548,11 +548,11 @@ anyOrderedListStart = try $ do
548 skipSpaces
548 skipSpaces
549 return (num, style, delim)
549 return (num, style, delim)
550
550
551−listStart :: GenParser Char ParserState ()
551+listStart :: Parsec [Char] ParserState ()
552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
552listStart = bulletListStart <|> (anyOrderedListStart >> return ())
553
553
554-- parse a line of a list item (start = parser for beginning of list item)
554-- parse a line of a list item (start = parser for beginning of list item)
555−listLine :: GenParser Char ParserState [Char]
555+listLine :: Parsec [Char] ParserState [Char]
556listLine = try $ do
556listLine = try $ do
557 notFollowedBy blankline
557 notFollowedBy blankline
558 notFollowedBy' (do indentSpaces
558 notFollowedBy' (do indentSpaces
@@ -562,8 +562,8 @@ listLine = try $ do
562 return $ concat chunks ++ "\n"
562 return $ concat chunks ++ "\n"
563
563
564-- parse raw text for one list item, excluding start marker and continuations
564-- parse raw text for one list item, excluding start marker and continuations
565−rawListItem :: GenParser Char ParserState a
565+rawListItem :: Parsec [Char] ParserState a
566− -> GenParser Char ParserState [Char]
566+ -> Parsec [Char] ParserState [Char]
567rawListItem start = try $ do
567rawListItem start = try $ do
568 start
568 start
569 first <- listLine
569 first <- listLine
@@ -574,14 +574,14 @@ rawListItem start = try $ do
574-- continuation of a list item - indented and separated by blankline
574-- continuation of a list item - indented and separated by blankline
575-- or (in compact lists) endline.
575-- or (in compact lists) endline.
576-- note: nested lists are parsed as continuations
576-- note: nested lists are parsed as continuations
577−listContinuation :: GenParser Char ParserState [Char]
577+listContinuation :: Parsec [Char] ParserState [Char]
578listContinuation = try $ do
578listContinuation = try $ do
579 lookAhead indentSpaces
579 lookAhead indentSpaces
580 result <- many1 listContinuationLine
580 result <- many1 listContinuationLine
581 blanks <- many blankline
581 blanks <- many blankline
582 return $ concat result ++ blanks
582 return $ concat result ++ blanks
583
583
584−listContinuationLine :: GenParser Char ParserState [Char]
584+listContinuationLine :: Parsec [Char] ParserState [Char]
585listContinuationLine = try $ do
585listContinuationLine = try $ do
586 notFollowedBy blankline
586 notFollowedBy blankline
587 notFollowedBy' listStart
587 notFollowedBy' listStart
@@ -589,8 +589,8 @@ listContinuationLine = try $ do
589 result <- manyTill anyChar newline
589 result <- manyTill anyChar newline
590 return $ result ++ "\n"
590 return $ result ++ "\n"
591
591
592−listItem :: GenParser Char ParserState a
592+listItem :: Parsec [Char] ParserState a
593− -> GenParser Char ParserState [Block]
593+ -> Parsec [Char] ParserState [Block]
594listItem start = try $ do
594listItem start = try $ do
595 first <- rawListItem start
595 first <- rawListItem start
596 continuations <- many listContinuation
596 continuations <- many listContinuation
@@ -606,7 +606,7 @@ listItem start = try $ do
606 updateState (\st -> st {stateParserContext = oldContext})
606 updateState (\st -> st {stateParserContext = oldContext})
607 return contents
607 return contents
608
608
609−orderedList :: GenParser Char ParserState Block
609+orderedList :: Parsec [Char] ParserState Block
610orderedList = try $ do
610orderedList = try $ do
611 (start, style, delim) <- lookAhead anyOrderedListStart
611 (start, style, delim) <- lookAhead anyOrderedListStart
612 items <- many1 $ listItem $ try $
612 items <- many1 $ listItem $ try $
@@ -615,13 +615,13 @@ orderedList = try $ do
615 orderedListMarker style delim
615 orderedListMarker style delim
616 return $ OrderedList (start, style, delim) $ compactify items
616 return $ OrderedList (start, style, delim) $ compactify items
617
617
618−bulletList :: GenParser Char ParserState Block
618+bulletList :: Parsec [Char] ParserState Block
619bulletList =
619bulletList =
620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
620 many1 (listItem bulletListStart) >>= return . BulletList . compactify
621
621
622-- definition lists
622-- definition lists
623
623
624−defListMarker :: GenParser Char ParserState ()
624+defListMarker :: Parsec [Char] ParserState ()
625defListMarker = do
625defListMarker = do
626 sps <- nonindentSpaces
626 sps <- nonindentSpaces
627 char ':' <|> char '~'
627 char ':' <|> char '~'
@@ -630,10 +630,10 @@ defListMarker = do
630 let remaining = tabStop - (length sps + 1)
630 let remaining = tabStop - (length sps + 1)
631 if remaining > 0
631 if remaining > 0
632 then count remaining (char ' ') <|> string "\t"
632 then count remaining (char ' ') <|> string "\t"
633− else pzero
633+ else mzero
634 return ()
634 return ()
635
635
636−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
636+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
637definitionListItem = try $ do
637definitionListItem = try $ do
638 -- first, see if this has any chance of being a definition list:
638 -- first, see if this has any chance of being a definition list:
639 lookAhead (anyLine >> optional blankline >> defListMarker)
639 lookAhead (anyLine >> optional blankline >> defListMarker)
@@ -647,7 +647,7 @@ definitionListItem = try $ do
647 updateState (\st -> st {stateParserContext = oldContext})
647 updateState (\st -> st {stateParserContext = oldContext})
648 return ((normalizeSpaces term), contents)
648 return ((normalizeSpaces term), contents)
649
649
650−defRawBlock :: GenParser Char ParserState [Char]
650+defRawBlock :: Parsec [Char] ParserState [Char]
651defRawBlock = try $ do
651defRawBlock = try $ do
652 defListMarker
652 defListMarker
653 firstline <- anyLine
653 firstline <- anyLine
@@ -659,7 +659,7 @@ defRawBlock = try $ do
659 return $ unlines lns ++ trl
659 return $ unlines lns ++ trl
660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
660 return $ firstline ++ "\n" ++ unlines rawlines ++ trailing ++ cont
661
661
662−definitionList :: GenParser Char ParserState Block
662+definitionList :: Parsec [Char] ParserState Block
663definitionList = do
663definitionList = do
664 items <- many1 definitionListItem
664 items <- many1 definitionListItem
665 -- "compactify" the definition list:
665 -- "compactify" the definition list:
@@ -688,7 +688,7 @@ isHtmlOrBlank (Space) = True
688isHtmlOrBlank (LineBreak) = True
688isHtmlOrBlank (LineBreak) = True
689isHtmlOrBlank _ = False
689isHtmlOrBlank _ = False
690
690
691−para :: GenParser Char ParserState Block
691+para :: Parsec [Char] ParserState Block
692para = try $ do
692para = try $ do
693 result <- liftM normalizeSpaces $ many1 inline
693 result <- liftM normalizeSpaces $ many1 inline
694 guard $ not . all isHtmlOrBlank $ result
694 guard $ not . all isHtmlOrBlank $ result
@@ -699,17 +699,17 @@ para = try $ do
699 lookAhead (blockQuote <|> header) >> return "")
699 lookAhead (blockQuote <|> header) >> return "")
700 return $ Para result
700 return $ Para result
701
701
702−plain :: GenParser Char ParserState Block
702+plain :: Parsec [Char] ParserState Block
703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
703plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
704
704
705--
705--
706-- raw html
706-- raw html
707--
707--
708
708
709−htmlElement :: GenParser Char ParserState [Char]
709+htmlElement :: Parsec [Char] ParserState [Char]
710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
711
711
712−htmlBlock :: GenParser Char ParserState Block
712+htmlBlock :: Parsec [Char] ParserState Block
713htmlBlock = try $ do
713htmlBlock = try $ do
714 failUnlessBeginningOfLine
714 failUnlessBeginningOfLine
715 first <- htmlElement
715 first <- htmlElement
@@ -717,12 +717,12 @@ htmlBlock = try $ do
717 finalNewlines <- many newline
717 finalNewlines <- many newline
718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
718 return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
719
719
720−strictHtmlBlock :: GenParser Char ParserState [Char]
720+strictHtmlBlock :: Parsec [Char] ParserState [Char]
721strictHtmlBlock = do
721strictHtmlBlock = do
722 failUnlessBeginningOfLine
722 failUnlessBeginningOfLine
723 htmlInBalanced (not . isInlineTag)
723 htmlInBalanced (not . isInlineTag)
724
724
725−rawVerbatimBlock :: GenParser Char ParserState String
725+rawVerbatimBlock :: Parsec [Char] ParserState String
726rawVerbatimBlock = try $ do
726rawVerbatimBlock = try $ do
727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
727 (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
728 t == "pre" || t == "style" || t == "script")
728 t == "pre" || t == "style" || t == "script")
@@ -730,7 +730,7 @@ rawVerbatimBlock = try $ do
730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
730 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
731 return $ open ++ contents ++ renderTags [TagClose tag]
731 return $ open ++ contents ++ renderTags [TagClose tag]
732
732
733−rawTeXBlock :: GenParser Char ParserState Block
733+rawTeXBlock :: Parsec [Char] ParserState Block
734rawTeXBlock = do
734rawTeXBlock = do
735 failIfStrict
735 failIfStrict
736 result <- liftM (RawBlock "latex") rawLaTeXBlock
736 result <- liftM (RawBlock "latex") rawLaTeXBlock
@@ -738,7 +738,7 @@ rawTeXBlock = do
738 spaces
738 spaces
739 return result
739 return result
740
740
741−rawHtmlBlocks :: GenParser Char ParserState Block
741+rawHtmlBlocks :: Parsec [Char] ParserState Block
742rawHtmlBlocks = do
742rawHtmlBlocks = do
743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
743 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
744 liftM snd (htmlTag isBlockTag)
744 liftM snd (htmlTag isBlockTag)
@@ -762,7 +762,7 @@ rawHtmlBlocks = do
762-- Parse a dashed line with optional trailing spaces; return its length
762-- Parse a dashed line with optional trailing spaces; return its length
763-- and the length including trailing space.
763-- and the length including trailing space.
764dashedLine :: Char
764dashedLine :: Char
765− -> GenParser Char st (Int, Int)
765+ -> Parsec [Char] st (Int, Int)
766dashedLine ch = do
766dashedLine ch = do
767 dashes <- many1 (char ch)
767 dashes <- many1 (char ch)
768 sp <- many spaceChar
768 sp <- many spaceChar
@@ -771,7 +771,7 @@ dashedLine ch = do
771-- Parse a table header with dashed lines of '-' preceded by
771-- Parse a table header with dashed lines of '-' preceded by
772-- one (or zero) line of text.
772-- one (or zero) line of text.
773simpleTableHeader :: Bool -- ^ Headerless table
773simpleTableHeader :: Bool -- ^ Headerless table
774− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
774+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
775simpleTableHeader headless = try $ do
775simpleTableHeader headless = try $ do
776 rawContent <- if headless
776 rawContent <- if headless
777 then return ""
777 then return ""
@@ -795,16 +795,16 @@ simpleTableHeader headless = try $ do
795 return (heads, aligns, indices)
795 return (heads, aligns, indices)
796
796
797-- Parse a table footer - dashed lines followed by blank line.
797-- Parse a table footer - dashed lines followed by blank line.
798−tableFooter :: GenParser Char ParserState [Char]
798+tableFooter :: Parsec [Char] ParserState [Char]
799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
799tableFooter = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> blanklines
800
800
801-- Parse a table separator - dashed line.
801-- Parse a table separator - dashed line.
802−tableSep :: GenParser Char ParserState Char
802+tableSep :: Parsec [Char] ParserState Char
803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
803tableSep = try $ skipNonindentSpaces >> many1 (dashedLine '-') >> char '\n'
804
804
805-- Parse a raw line and split it into chunks by indices.
805-- Parse a raw line and split it into chunks by indices.
806rawTableLine :: [Int]
806rawTableLine :: [Int]
807− -> GenParser Char ParserState [String]
807+ -> Parsec [Char] ParserState [String]
808rawTableLine indices = do
808rawTableLine indices = do
809 notFollowedBy' (blanklines <|> tableFooter)
809 notFollowedBy' (blanklines <|> tableFooter)
810 line <- many1Till anyChar newline
810 line <- many1Till anyChar newline
@@ -813,12 +813,12 @@ rawTableLine indices = do
813
813
814-- Parse a table line and return a list of lists of blocks (columns).
814-- Parse a table line and return a list of lists of blocks (columns).
815tableLine :: [Int]
815tableLine :: [Int]
816− -> GenParser Char ParserState [[Block]]
816+ -> Parsec [Char] ParserState [[Block]]
817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
817tableLine indices = rawTableLine indices >>= mapM (parseFromString (many plain))
818
818
819-- Parse a multiline table row and return a list of blocks (columns).
819-- Parse a multiline table row and return a list of blocks (columns).
820multilineRow :: [Int]
820multilineRow :: [Int]
821− -> GenParser Char ParserState [[Block]]
821+ -> Parsec [Char] ParserState [[Block]]
822multilineRow indices = do
822multilineRow indices = do
823 colLines <- many1 (rawTableLine indices)
823 colLines <- many1 (rawTableLine indices)
824 let cols = map unlines $ transpose colLines
824 let cols = map unlines $ transpose colLines
@@ -826,7 +826,7 @@ multilineRow indices = do
826
826
827-- Parses a table caption: inlines beginning with 'Table:'
827-- Parses a table caption: inlines beginning with 'Table:'
828-- and followed by blank lines.
828-- and followed by blank lines.
829−tableCaption :: GenParser Char ParserState [Inline]
829+tableCaption :: Parsec [Char] ParserState [Inline]
830tableCaption = try $ do
830tableCaption = try $ do
831 skipNonindentSpaces
831 skipNonindentSpaces
832 string ":" <|> string "Table:"
832 string ":" <|> string "Table:"
@@ -836,7 +836,7 @@ tableCaption = try $ do
836
836
837-- Parse a simple table with '---' header and one line per row.
837-- Parse a simple table with '---' header and one line per row.
838simpleTable :: Bool -- ^ Headerless table
838simpleTable :: Bool -- ^ Headerless table
839− -> GenParser Char ParserState Block
839+ -> Parsec [Char] ParserState Block
840simpleTable headless = do
840simpleTable headless = do
841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
842 (return ())
842 (return ())
@@ -850,12 +850,12 @@ simpleTable headless = do
850-- which may be multiline, separated by blank lines, and
850-- which may be multiline, separated by blank lines, and
851-- ending with a footer (dashed line followed by blank line).
851-- ending with a footer (dashed line followed by blank line).
852multilineTable :: Bool -- ^ Headerless table
852multilineTable :: Bool -- ^ Headerless table
853− -> GenParser Char ParserState Block
853+ -> Parsec [Char] ParserState Block
854multilineTable headless =
854multilineTable headless =
855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
855 tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
856
856
857multilineTableHeader :: Bool -- ^ Headerless table
857multilineTableHeader :: Bool -- ^ Headerless table
858− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
858+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
859multilineTableHeader headless = try $ do
859multilineTableHeader headless = try $ do
860 if headless
860 if headless
861 then return '\n'
861 then return '\n'
@@ -903,10 +903,10 @@ alignType strLst len =
903 (False, False) -> AlignDefault
903 (False, False) -> AlignDefault
904
904
905gridTable :: Bool -- ^ Headerless table
905gridTable :: Bool -- ^ Headerless table
906− -> GenParser Char ParserState Block
906+ -> Parsec [Char] ParserState Block
907gridTable = gridTableWith block tableCaption
907gridTable = gridTableWith block tableCaption
908
908
909−table :: GenParser Char ParserState Block
909+table :: Parsec [Char] ParserState Block
910table = multilineTable False <|> simpleTable True <|>
910table = multilineTable False <|> simpleTable True <|>
911 simpleTable False <|> multilineTable True <|>
911 simpleTable False <|> multilineTable True <|>
912 gridTable False <|> gridTable True <?> "table"
912 gridTable False <|> gridTable True <?> "table"
@@ -915,10 +915,10 @@ table = multilineTable False <|> simpleTable True <|>
915-- inline
915-- inline
916--
916--
917
917
918−inline :: GenParser Char ParserState Inline
918+inline :: Parsec [Char] ParserState Inline
919inline = choice inlineParsers <?> "inline"
919inline = choice inlineParsers <?> "inline"
920
920
921−inlineParsers :: [GenParser Char ParserState Inline]
921+inlineParsers :: [Parsec [Char] ParserState Inline]
922inlineParsers = [ whitespace
922inlineParsers = [ whitespace
923 , str
923 , str
924 , endline
924 , endline
@@ -945,7 +945,7 @@ inlineParsers = [ whitespace
945 , symbol
945 , symbol
946 , ltSign ]
946 , ltSign ]
947
947
948−escapedChar' :: GenParser Char ParserState Char
948+escapedChar' :: Parsec [Char] ParserState Char
949escapedChar' = try $ do
949escapedChar' = try $ do
950 char '\\'
950 char '\\'
951 state <- getState
951 state <- getState
@@ -953,7 +953,7 @@ escapedChar' = try $ do
953 then oneOf "\\`*_{}[]()>#+-.!~"
953 then oneOf "\\`*_{}[]()>#+-.!~"
954 else satisfy (not . isAlphaNum)
954 else satisfy (not . isAlphaNum)
955
955
956−escapedChar :: GenParser Char ParserState Inline
956+escapedChar :: Parsec [Char] ParserState Inline
957escapedChar = do
957escapedChar = do
958 result <- escapedChar'
958 result <- escapedChar'
959 return $ case result of
959 return $ case result of
@@ -961,7 +961,7 @@ escapedChar = do
961 '\n' -> LineBreak -- "\[newline]" is a linebreak
961 '\n' -> LineBreak -- "\[newline]" is a linebreak
962 _ -> Str [result]
962 _ -> Str [result]
963
963
964−ltSign :: GenParser Char ParserState Inline
964+ltSign :: Parsec [Char] ParserState Inline
965ltSign = do
965ltSign = do
966 st <- getState
966 st <- getState
967 if stateStrict st
967 if stateStrict st
@@ -969,7 +969,7 @@ ltSign = do
969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
969 else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
970 return $ Str ['<']
970 return $ Str ['<']
971
971
972−exampleRef :: GenParser Char ParserState Inline
972+exampleRef :: Parsec [Char] ParserState Inline
973exampleRef = try $ do
973exampleRef = try $ do
974 char '@'
974 char '@'
975 lab <- many1 (alphaNum <|> oneOf "-_")
975 lab <- many1 (alphaNum <|> oneOf "-_")
@@ -977,7 +977,7 @@ exampleRef = try $ do
977 -- later. See the end of parseMarkdown.
977 -- later. See the end of parseMarkdown.
978 return $ Str $ '@' : lab
978 return $ Str $ '@' : lab
979
979
980−symbol :: GenParser Char ParserState Inline
980+symbol :: Parsec [Char] ParserState Inline
981symbol = do
981symbol = do
982 result <- noneOf "<\\\n\t "
982 result <- noneOf "<\\\n\t "
983 <|> try (do lookAhead $ char '\\'
983 <|> try (do lookAhead $ char '\\'
@@ -986,7 +986,7 @@ symbol = do
986 return $ Str [result]
986 return $ Str [result]
987
987
988-- parses inline code, between n `s and n `s
988-- parses inline code, between n `s and n `s
989−code :: GenParser Char ParserState Inline
989+code :: Parsec [Char] ParserState Inline
990code = try $ do
990code = try $ do
991 starts <- many1 (char '`')
991 starts <- many1 (char '`')
992 skipSpaces
992 skipSpaces
@@ -997,26 +997,26 @@ code = try $ do
997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
997 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
998 return $ Code attr $ removeLeadingTrailingSpace $ concat result
999
999
1000−mathWord :: GenParser Char st [Char]
1000+mathWord :: Parsec [Char] st [Char]
1001mathWord = liftM concat $ many1 mathChunk
1001mathWord = liftM concat $ many1 mathChunk
1002
1002
1003−mathChunk :: GenParser Char st [Char]
1003+mathChunk :: Parsec [Char] st [Char]
1004mathChunk = do char '\\'
1004mathChunk = do char '\\'
1005 c <- anyChar
1005 c <- anyChar
1006 return ['\\',c]
1006 return ['\\',c]
1007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1007 <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
1008
1008
1009−math :: GenParser Char ParserState Inline
1009+math :: Parsec [Char] ParserState Inline
1010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1010math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1011 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1012
1012
1013−mathDisplay :: GenParser Char ParserState String
1013+mathDisplay :: Parsec [Char] ParserState String
1014mathDisplay = try $ do
1014mathDisplay = try $ do
1015 failIfStrict
1015 failIfStrict
1016 string "$$"
1016 string "$$"
1017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1017 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1018
1018
1019−mathInline :: GenParser Char ParserState String
1019+mathInline :: Parsec [Char] ParserState String
1020mathInline = try $ do
1020mathInline = try $ do
1021 failIfStrict
1021 failIfStrict
1022 char '$'
1022 char '$'
@@ -1028,7 +1028,7 @@ mathInline = try $ do
1028
1028
1029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1029-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
1030-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1030-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub
1031−fours :: GenParser Char st Inline
1031+fours :: Parsec [Char] st Inline
1032fours = try $ do
1032fours = try $ do
1033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1033 x <- char '*' <|> char '_' <|> char '~' <|> char '^'
1034 count 2 $ satisfy (==x)
1034 count 2 $ satisfy (==x)
@@ -1037,9 +1037,9 @@ fours = try $ do
1037
1037
1038-- | Parses a list of inlines between start and end delimiters.
1038-- | Parses a list of inlines between start and end delimiters.
1039inlinesBetween :: (Show b)
1039inlinesBetween :: (Show b)
1040− => GenParser Char ParserState a
1040+ => Parsec [Char] ParserState a
1041− -> GenParser Char ParserState b
1041+ -> Parsec [Char] ParserState b
1042− -> GenParser Char ParserState [Inline]
1042+ -> Parsec [Char] ParserState [Inline]
1043inlinesBetween start end =
1043inlinesBetween start end =
1044 normalizeSpaces `liftM` try (start >> many1Till inner end)
1044 normalizeSpaces `liftM` try (start >> many1Till inner end)
1045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
1045 where inner = innerSpace <|> (notFollowedBy' whitespace >> inline)
@@ -1047,8 +1047,8 @@ inlinesBetween start end =
1047
1047
1048-- This is used to prevent exponential blowups for things like:
1048-- This is used to prevent exponential blowups for things like:
1049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1049-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1050−nested :: GenParser Char ParserState a
1050+nested :: Parsec [Char] ParserState a
1051− -> GenParser Char ParserState a
1051+ -> Parsec [Char] ParserState a
1052nested p = do
1052nested p = do
1053 nestlevel <- stateMaxNestingLevel `fmap` getState
1053 nestlevel <- stateMaxNestingLevel `fmap` getState
1054 guard $ nestlevel > 0
1054 guard $ nestlevel > 0
@@ -1057,7 +1057,7 @@ nested p = do
1057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1057 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1058 return res
1058 return res
1059
1059
1060−emph :: GenParser Char ParserState Inline
1060+emph :: Parsec [Char] ParserState Inline
1061emph = Emph `fmap` nested
1061emph = Emph `fmap` nested
1062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1062 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1063 where starStart = char '*' >> lookAhead nonspaceChar
1063 where starStart = char '*' >> lookAhead nonspaceChar
@@ -1065,7 +1065,7 @@ emph = Emph `fmap` nested
1065 ulStart = char '_' >> lookAhead nonspaceChar
1065 ulStart = char '_' >> lookAhead nonspaceChar
1066 ulEnd = notFollowedBy' strong >> char '_'
1066 ulEnd = notFollowedBy' strong >> char '_'
1067
1067
1068−strong :: GenParser Char ParserState Inline
1068+strong :: Parsec [Char] ParserState Inline
1069strong = Strong `liftM` nested
1069strong = Strong `liftM` nested
1070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1070 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1071 where starStart = string "**" >> lookAhead nonspaceChar
1071 where starStart = string "**" >> lookAhead nonspaceChar
@@ -1073,32 +1073,32 @@ strong = Strong `liftM` nested
1073 ulStart = string "__" >> lookAhead nonspaceChar
1073 ulStart = string "__" >> lookAhead nonspaceChar
1074 ulEnd = try $ string "__"
1074 ulEnd = try $ string "__"
1075
1075
1076−strikeout :: GenParser Char ParserState Inline
1076+strikeout :: Parsec [Char] ParserState Inline
1077strikeout = Strikeout `liftM`
1077strikeout = Strikeout `liftM`
1078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1078 (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1079 where strikeStart = string "~~" >> lookAhead nonspaceChar
1079 where strikeStart = string "~~" >> lookAhead nonspaceChar
1080 >> notFollowedBy (char '~')
1080 >> notFollowedBy (char '~')
1081 strikeEnd = try $ string "~~"
1081 strikeEnd = try $ string "~~"
1082
1082
1083−superscript :: GenParser Char ParserState Inline
1083+superscript :: Parsec [Char] ParserState Inline
1084superscript = failIfStrict >> enclosed (char '^') (char '^')
1084superscript = failIfStrict >> enclosed (char '^') (char '^')
1085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1085 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1086 return . Superscript
1086 return . Superscript
1087
1087
1088−subscript :: GenParser Char ParserState Inline
1088+subscript :: Parsec [Char] ParserState Inline
1089subscript = failIfStrict >> enclosed (char '~') (char '~')
1089subscript = failIfStrict >> enclosed (char '~') (char '~')
1090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1090 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1091 return . Subscript
1091 return . Subscript
1092
1092
1093−whitespace :: GenParser Char ParserState Inline
1093+whitespace :: Parsec [Char] ParserState Inline
1094whitespace = spaceChar >>
1094whitespace = spaceChar >>
1095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1095 ( (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
1096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1096 <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
1097
1097
1098−nonEndline :: GenParser Char st Char
1098+nonEndline :: Parsec [Char] st Char
1099nonEndline = satisfy (/='\n')
1099nonEndline = satisfy (/='\n')
1100
1100
1101−str :: GenParser Char ParserState Inline
1101+str :: Parsec [Char] ParserState Inline
1102str = do
1102str = do
1103 smart <- stateSmart `fmap` getState
1103 smart <- stateSmart `fmap` getState
1104 a <- alphaNum
1104 a <- alphaNum
@@ -1136,7 +1136,7 @@ likelyAbbrev x =
1136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1136 in map snd $ filter (\(y,_) -> y == x) abbrPairs
1137
1137
1138-- an endline character that can be treated as a space, not a structural break
1138-- an endline character that can be treated as a space, not a structural break
1139−endline :: GenParser Char ParserState Inline
1139+endline :: Parsec [Char] ParserState Inline
1140endline = try $ do
1140endline = try $ do
1141 newline
1141 newline
1142 notFollowedBy blankline
1142 notFollowedBy blankline
@@ -1155,20 +1155,20 @@ endline = try $ do
1155--
1155--
1156
1156
1157-- a reference label for a link
1157-- a reference label for a link
1158−reference :: GenParser Char ParserState [Inline]
1158+reference :: Parsec [Char] ParserState [Inline]
1159reference = do notFollowedBy' (string "[^") -- footnote reference
1159reference = do notFollowedBy' (string "[^") -- footnote reference
1160 result <- inlinesInBalancedBrackets inline
1160 result <- inlinesInBalancedBrackets inline
1161 return $ normalizeSpaces result
1161 return $ normalizeSpaces result
1162
1162
1163-- source for a link, with optional title
1163-- source for a link, with optional title
1164−source :: GenParser Char ParserState (String, [Char])
1164+source :: Parsec [Char] ParserState (String, [Char])
1165source =
1165source =
1166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1166 (try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
1167 -- the following is needed for cases like: [ref](/url(a).
1167 -- the following is needed for cases like: [ref](/url(a).
1168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1168 (enclosed (char '(') (char ')') litChar >>= parseFromString source')
1169
1169
1170-- auxiliary function for source
1170-- auxiliary function for source
1171−source' :: GenParser Char ParserState (String, [Char])
1171+source' :: Parsec [Char] ParserState (String, [Char])
1172source' = do
1172source' = do
1173 skipSpaces
1173 skipSpaces
1174 let nl = char '\n' >>~ notFollowedBy blankline
1174 let nl = char '\n' >>~ notFollowedBy blankline
@@ -1186,7 +1186,7 @@ source' = do
1186 eof
1186 eof
1187 return (escapeURI $ removeTrailingSpace src, tit)
1187 return (escapeURI $ removeTrailingSpace src, tit)
1188
1188
1189−linkTitle :: GenParser Char ParserState String
1189+linkTitle :: Parsec [Char] ParserState String
1190linkTitle = try $ do
1190linkTitle = try $ do
1191 (many1 spaceChar >> option '\n' newline) <|> newline
1191 (many1 spaceChar >> option '\n' newline) <|> newline
1192 skipSpaces
1192 skipSpaces
@@ -1194,7 +1194,7 @@ linkTitle = try $ do
1194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1194 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1195 return $ fromEntities tit
1195 return $ fromEntities tit
1196
1196
1197−link :: GenParser Char ParserState Inline
1197+link :: Parsec [Char] ParserState Inline
1198link = try $ do
1198link = try $ do
1199 lab <- reference
1199 lab <- reference
1200 (src, tit) <- source <|> referenceLink lab
1200 (src, tit) <- source <|> referenceLink lab
@@ -1207,7 +1207,7 @@ delinkify = bottomUp $ concatMap go
1207
1207
1208-- a link like [this][ref] or [this][] or [this]
1208-- a link like [this][ref] or [this][] or [this]
1209referenceLink :: [Inline]
1209referenceLink :: [Inline]
1210− -> GenParser Char ParserState (String, [Char])
1210+ -> Parsec [Char] ParserState (String, [Char])
1211referenceLink lab = do
1211referenceLink lab = do
1212 ref <- option [] (try (optional (char ' ') >>
1212 ref <- option [] (try (optional (char ' ') >>
1213 optional (newline >> skipSpaces) >> reference))
1213 optional (newline >> skipSpaces) >> reference))
@@ -1217,7 +1217,7 @@ referenceLink lab = do
1217 Nothing -> fail "no corresponding key"
1217 Nothing -> fail "no corresponding key"
1218 Just target -> return target
1218 Just target -> return target
1219
1219
1220−autoLink :: GenParser Char ParserState Inline
1220+autoLink :: Parsec [Char] ParserState Inline
1221autoLink = try $ do
1221autoLink = try $ do
1222 char '<'
1222 char '<'
1223 (orig, src) <- uri <|> emailAddress
1223 (orig, src) <- uri <|> emailAddress
@@ -1227,14 +1227,14 @@ autoLink = try $ do
1227 then Link [Str orig] (src, "")
1227 then Link [Str orig] (src, "")
1228 else Link [Code ("",["url"],[]) orig] (src, "")
1228 else Link [Code ("",["url"],[]) orig] (src, "")
1229
1229
1230−image :: GenParser Char ParserState Inline
1230+image :: Parsec [Char] ParserState Inline
1231image = try $ do
1231image = try $ do
1232 char '!'
1232 char '!'
1233 lab <- reference
1233 lab <- reference
1234 (src, tit) <- source <|> referenceLink lab
1234 (src, tit) <- source <|> referenceLink lab
1235 return $ Image lab (src,tit)
1235 return $ Image lab (src,tit)
1236
1236
1237−note :: GenParser Char ParserState Inline
1237+note :: Parsec [Char] ParserState Inline
1238note = try $ do
1238note = try $ do
1239 failIfStrict
1239 failIfStrict
1240 ref <- noteMarker
1240 ref <- noteMarker
@@ -1251,21 +1251,21 @@ note = try $ do
1251 updateState $ \st -> st{ stateNotes = notes }
1251 updateState $ \st -> st{ stateNotes = notes }
1252 return $ Note contents
1252 return $ Note contents
1253
1253
1254−inlineNote :: GenParser Char ParserState Inline
1254+inlineNote :: Parsec [Char] ParserState Inline
1255inlineNote = try $ do
1255inlineNote = try $ do
1256 failIfStrict
1256 failIfStrict
1257 char '^'
1257 char '^'
1258 contents <- inlinesInBalancedBrackets inline
1258 contents <- inlinesInBalancedBrackets inline
1259 return $ Note [Para contents]
1259 return $ Note [Para contents]
1260
1260
1261−rawLaTeXInline' :: GenParser Char ParserState Inline
1261+rawLaTeXInline' :: Parsec [Char] ParserState Inline
1262rawLaTeXInline' = try $ do
1262rawLaTeXInline' = try $ do
1263 failIfStrict
1263 failIfStrict
1264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1264 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1265 RawInline _ s <- rawLaTeXInline
1265 RawInline _ s <- rawLaTeXInline
1266 return $ RawInline "tex" s -- "tex" because it might be context or latex
1266 return $ RawInline "tex" s -- "tex" because it might be context or latex
1267
1267
1268−rawConTeXtEnvironment :: GenParser Char st String
1268+rawConTeXtEnvironment :: Parsec [Char] st String
1269rawConTeXtEnvironment = try $ do
1269rawConTeXtEnvironment = try $ do
1270 string "\\start"
1270 string "\\start"
1271 completion <- inBrackets (letter <|> digit <|> spaceChar)
1271 completion <- inBrackets (letter <|> digit <|> spaceChar)
@@ -1274,14 +1274,14 @@ rawConTeXtEnvironment = try $ do
1274 (try $ string "\\stop" >> string completion)
1274 (try $ string "\\stop" >> string completion)
1275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1275 return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion
1276
1276
1277−inBrackets :: (GenParser Char st Char) -> GenParser Char st String
1277+inBrackets :: (Parsec [Char] st Char) -> Parsec [Char] st String
1278inBrackets parser = do
1278inBrackets parser = do
1279 char '['
1279 char '['
1280 contents <- many parser
1280 contents <- many parser
1281 char ']'
1281 char ']'
1282 return $ "[" ++ contents ++ "]"
1282 return $ "[" ++ contents ++ "]"
1283
1283
1284−rawHtmlInline :: GenParser Char ParserState Inline
1284+rawHtmlInline :: Parsec [Char] ParserState Inline
1285rawHtmlInline = do
1285rawHtmlInline = do
1286 st <- getState
1286 st <- getState
1287 (_,result) <- if stateStrict st
1287 (_,result) <- if stateStrict st
@@ -1291,20 +1291,20 @@ rawHtmlInline = do
1291
1291
1292-- Citations
1292-- Citations
1293
1293
1294−cite :: GenParser Char ParserState Inline
1294+cite :: Parsec [Char] ParserState Inline
1295cite = do
1295cite = do
1296 failIfStrict
1296 failIfStrict
1297 citations <- textualCite <|> normalCite
1297 citations <- textualCite <|> normalCite
1298 return $ Cite citations []
1298 return $ Cite citations []
1299
1299
1300−spnl :: GenParser Char st ()
1300+spnl :: Parsec [Char] st ()
1301spnl = try $ do
1301spnl = try $ do
1302 skipSpaces
1302 skipSpaces
1303 optional newline
1303 optional newline
1304 skipSpaces
1304 skipSpaces
1305 notFollowedBy (char '\n')
1305 notFollowedBy (char '\n')
1306
1306
1307−textualCite :: GenParser Char ParserState [Citation]
1307+textualCite :: Parsec [Char] ParserState [Citation]
1308textualCite = try $ do
1308textualCite = try $ do
1309 (_, key) <- citeKey
1309 (_, key) <- citeKey
1310 let first = Citation{ citationId = key
1310 let first = Citation{ citationId = key
@@ -1319,7 +1319,7 @@ textualCite = try $ do
1319 then option [first] $ bareloc first
1319 then option [first] $ bareloc first
1320 else return $ first : rest
1320 else return $ first : rest
1321
1321
1322−bareloc :: Citation -> GenParser Char ParserState [Citation]
1322+bareloc :: Citation -> Parsec [Char] ParserState [Citation]
1323bareloc c = try $ do
1323bareloc c = try $ do
1324 spnl
1324 spnl
1325 char '['
1325 char '['
@@ -1329,7 +1329,7 @@ bareloc c = try $ do
1329 char ']'
1329 char ']'
1330 return $ c{ citationSuffix = suff } : rest
1330 return $ c{ citationSuffix = suff } : rest
1331
1331
1332−normalCite :: GenParser Char ParserState [Citation]
1332+normalCite :: Parsec [Char] ParserState [Citation]
1333normalCite = try $ do
1333normalCite = try $ do
1334 char '['
1334 char '['
1335 spnl
1335 spnl
@@ -1338,7 +1338,7 @@ normalCite = try $ do
1338 char ']'
1338 char ']'
1339 return citations
1339 return citations
1340
1340
1341−citeKey :: GenParser Char ParserState (Bool, String)
1341+citeKey :: Parsec [Char] ParserState (Bool, String)
1342citeKey = try $ do
1342citeKey = try $ do
1343 suppress_author <- option False (char '-' >> return True)
1343 suppress_author <- option False (char '-' >> return True)
1344 char '@'
1344 char '@'
@@ -1350,7 +1350,7 @@ citeKey = try $ do
1350 guard $ key `elem` stateCitations st
1350 guard $ key `elem` stateCitations st
1351 return (suppress_author, key)
1351 return (suppress_author, key)
1352
1352
1353−suffix :: GenParser Char ParserState [Inline]
1353+suffix :: Parsec [Char] ParserState [Inline]
1354suffix = try $ do
1354suffix = try $ do
1355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
1355 hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
1356 spnl
1356 spnl
@@ -1359,14 +1359,14 @@ suffix = try $ do
1359 then Space : rest
1359 then Space : rest
1360 else rest
1360 else rest
1361
1361
1362−prefix :: GenParser Char ParserState [Inline]
1362+prefix :: Parsec [Char] ParserState [Inline]
1363prefix = liftM normalizeSpaces $
1363prefix = liftM normalizeSpaces $
1364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1364 manyTill inline (char ']' <|> liftM (const ']') (lookAhead citeKey))
1365
1365
1366−citeList :: GenParser Char ParserState [Citation]
1366+citeList :: Parsec [Char] ParserState [Citation]
1367citeList = sepBy1 citation (try $ char ';' >> spnl)
1367citeList = sepBy1 citation (try $ char ';' >> spnl)
1368
1368
1369−citation :: GenParser Char ParserState Citation
1369+citation :: Parsec [Char] ParserState Citation
1370citation = try $ do
1370citation = try $ do
1371 pref <- prefix
1371 pref <- prefix
1372 (suppress_author, key) <- citeKey
1372 (suppress_author, key) <- citeKey
src/Text/Pandoc/Readers/RST.hs+95−95
@@ -33,8 +33,8 @@ module Text.Pandoc.Readers.RST (
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Pandoc.Parsing
35import Text.Pandoc.Parsing
36−import Text.ParserCombinators.Parsec
36+import Text.Parsec
37−import Control.Monad ( when, liftM, guard )
37+import Control.Monad ( when, liftM, guard, mzero )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
39import qualified Data.Map as M
39import qualified Data.Map as M
40import Text.Printf ( printf )
40import Text.Printf ( printf )
@@ -89,7 +89,7 @@ titleTransform ((Header 1 head1):rest) |
89 (promoteHeaders 1 rest, head1)
89 (promoteHeaders 1 rest, head1)
90titleTransform blocks = (blocks, [])
90titleTransform blocks = (blocks, [])
91
91
92−parseRST :: GenParser Char ParserState Pandoc
92+parseRST :: Parsec [Char] ParserState Pandoc
93parseRST = do
93parseRST = do
94 optional blanklines -- skip blank lines at beginning of file
94 optional blanklines -- skip blank lines at beginning of file
95 startPos <- getPosition
95 startPos <- getPosition
@@ -118,10 +118,10 @@ parseRST = do
118-- parsing blocks
118-- parsing blocks
119--
119--
120
120
121−parseBlocks :: GenParser Char ParserState [Block]
121+parseBlocks :: Parsec [Char] ParserState [Block]
122parseBlocks = manyTill block eof
122parseBlocks = manyTill block eof
123
123
124−block :: GenParser Char ParserState Block
124+block :: Parsec [Char] ParserState Block
125block = choice [ codeBlock
125block = choice [ codeBlock
126 , rawBlock
126 , rawBlock
127 , blockQuote
127 , blockQuote
@@ -146,7 +146,7 @@ block = choice [ codeBlock
146-- field list
146-- field list
147--
147--
148
148
149−rawFieldListItem :: String -> GenParser Char ParserState (String, String)
149+rawFieldListItem :: String -> Parsec [Char] ParserState (String, String)
150rawFieldListItem indent = try $ do
150rawFieldListItem indent = try $ do
151 string indent
151 string indent
152 char ':'
152 char ':'
@@ -160,7 +160,7 @@ rawFieldListItem indent = try $ do
160 return (name, raw)
160 return (name, raw)
161
161
162fieldListItem :: String
162fieldListItem :: String
163− -> GenParser Char ParserState (Maybe ([Inline], [[Block]]))
163+ -> Parsec [Char] ParserState (Maybe ([Inline], [[Block]]))
164fieldListItem indent = try $ do
164fieldListItem indent = try $ do
165 (name, raw) <- rawFieldListItem indent
165 (name, raw) <- rawFieldListItem indent
166 let term = [Str name]
166 let term = [Str name]
@@ -187,7 +187,7 @@ extractContents [Plain auth] = auth
187extractContents [Para auth] = auth
187extractContents [Para auth] = auth
188extractContents _ = []
188extractContents _ = []
189
189
190−fieldList :: GenParser Char ParserState Block
190+fieldList :: Parsec [Char] ParserState Block
191fieldList = try $ do
191fieldList = try $ do
192 indent <- lookAhead $ many spaceChar
192 indent <- lookAhead $ many spaceChar
193 items <- many1 $ fieldListItem indent
193 items <- many1 $ fieldListItem indent
@@ -199,7 +199,7 @@ fieldList = try $ do
199-- line block
199-- line block
200--
200--
201
201
202−lineBlockLine :: GenParser Char ParserState [Inline]
202+lineBlockLine :: Parsec [Char] ParserState [Inline]
203lineBlockLine = try $ do
203lineBlockLine = try $ do
204 char '|'
204 char '|'
205 char ' ' <|> lookAhead (char '\n')
205 char ' ' <|> lookAhead (char '\n')
@@ -210,7 +210,7 @@ lineBlockLine = try $ do
210 then normalizeSpaces line
210 then normalizeSpaces line
211 else Str white : normalizeSpaces line
211 else Str white : normalizeSpaces line
212
212
213−lineBlock :: GenParser Char ParserState Block
213+lineBlock :: Parsec [Char] ParserState Block
214lineBlock = try $ do
214lineBlock = try $ do
215 lines' <- many1 lineBlockLine
215 lines' <- many1 lineBlockLine
216 blanklines
216 blanklines
@@ -220,14 +220,14 @@ lineBlock = try $ do
220-- paragraph block
220-- paragraph block
221--
221--
222
222
223−para :: GenParser Char ParserState Block
223+para :: Parsec [Char] ParserState Block
224para = paraBeforeCodeBlock <|> paraNormal <?> "paragraph"
224para = paraBeforeCodeBlock <|> paraNormal <?> "paragraph"
225
225
226−codeBlockStart :: GenParser Char st Char
226+codeBlockStart :: Parsec [Char] st Char
227codeBlockStart = string "::" >> blankline >> blankline
227codeBlockStart = string "::" >> blankline >> blankline
228
228
229-- paragraph that ends in a :: starting a code block
229-- paragraph that ends in a :: starting a code block
230−paraBeforeCodeBlock :: GenParser Char ParserState Block
230+paraBeforeCodeBlock :: Parsec [Char] ParserState Block
231paraBeforeCodeBlock = try $ do
231paraBeforeCodeBlock = try $ do
232 result <- many1 (notFollowedBy' codeBlockStart >> inline)
232 result <- many1 (notFollowedBy' codeBlockStart >> inline)
233 lookAhead (string "::")
233 lookAhead (string "::")
@@ -236,21 +236,21 @@ paraBeforeCodeBlock = try $ do
236 else (normalizeSpaces result) ++ [Str ":"]
236 else (normalizeSpaces result) ++ [Str ":"]
237
237
238-- regular paragraph
238-- regular paragraph
239−paraNormal :: GenParser Char ParserState Block
239+paraNormal :: Parsec [Char] ParserState Block
240paraNormal = try $ do
240paraNormal = try $ do
241 result <- many1 inline
241 result <- many1 inline
242 newline
242 newline
243 blanklines
243 blanklines
244 return $ Para $ normalizeSpaces result
244 return $ Para $ normalizeSpaces result
245
245
246−plain :: GenParser Char ParserState Block
246+plain :: Parsec [Char] ParserState Block
247plain = many1 inline >>= return . Plain . normalizeSpaces
247plain = many1 inline >>= return . Plain . normalizeSpaces
248
248
249--
249--
250-- image block
250-- image block
251--
251--
252
252
253−imageBlock :: GenParser Char ParserState Block
253+imageBlock :: Parsec [Char] ParserState Block
254imageBlock = try $ do
254imageBlock = try $ do
255 string ".. image:: "
255 string ".. image:: "
256 src <- manyTill anyChar newline
256 src <- manyTill anyChar newline
@@ -265,11 +265,11 @@ imageBlock = try $ do
265-- header blocks
265-- header blocks
266--
266--
267
267
268−header :: GenParser Char ParserState Block
268+header :: Parsec [Char] ParserState Block
269header = doubleHeader <|> singleHeader <?> "header"
269header = doubleHeader <|> singleHeader <?> "header"
270
270
271-- a header with lines on top and bottom
271-- a header with lines on top and bottom
272−doubleHeader :: GenParser Char ParserState Block
272+doubleHeader :: Parsec [Char] ParserState Block
273doubleHeader = try $ do
273doubleHeader = try $ do
274 c <- oneOf underlineChars
274 c <- oneOf underlineChars
275 rest <- many (char c) -- the top line
275 rest <- many (char c) -- the top line
@@ -294,7 +294,7 @@ doubleHeader = try $ do
294 return $ Header level (normalizeSpaces txt)
294 return $ Header level (normalizeSpaces txt)
295
295
296-- a header with line on the bottom only
296-- a header with line on the bottom only
297−singleHeader :: GenParser Char ParserState Block
297+singleHeader :: Parsec [Char] ParserState Block
298singleHeader = try $ do
298singleHeader = try $ do
299 notFollowedBy' whitespace
299 notFollowedBy' whitespace
300 txt <- many1 (do {notFollowedBy blankline; inline})
300 txt <- many1 (do {notFollowedBy blankline; inline})
@@ -317,7 +317,7 @@ singleHeader = try $ do
317-- hrule block
317-- hrule block
318--
318--
319
319
320−hrule :: GenParser Char st Block
320+hrule :: Parsec [Char] st Block
321hrule = try $ do
321hrule = try $ do
322 chr <- oneOf underlineChars
322 chr <- oneOf underlineChars
323 count 3 (char chr)
323 count 3 (char chr)
@@ -331,14 +331,14 @@ hrule = try $ do
331--
331--
332
332
333-- read a line indented by a given string
333-- read a line indented by a given string
334−indentedLine :: String -> GenParser Char st [Char]
334+indentedLine :: String -> Parsec [Char] st [Char]
335indentedLine indents = try $ do
335indentedLine indents = try $ do
336 string indents
336 string indents
337 manyTill anyChar newline
337 manyTill anyChar newline
338
338
339-- one or more indented lines, possibly separated by blank lines.
339-- one or more indented lines, possibly separated by blank lines.
340-- any amount of indentation will work.
340-- any amount of indentation will work.
341−indentedBlock :: GenParser Char st [Char]
341+indentedBlock :: Parsec [Char] st [Char]
342indentedBlock = try $ do
342indentedBlock = try $ do
343 indents <- lookAhead $ many1 spaceChar
343 indents <- lookAhead $ many1 spaceChar
344 lns <- many1 $ try $ do b <- option "" blanklines
344 lns <- many1 $ try $ do b <- option "" blanklines
@@ -347,7 +347,7 @@ indentedBlock = try $ do
347 optional blanklines
347 optional blanklines
348 return $ unlines lns
348 return $ unlines lns
349
349
350−codeBlock :: GenParser Char st Block
350+codeBlock :: Parsec [Char] st Block
351codeBlock = try $ do
351codeBlock = try $ do
352 codeBlockStart
352 codeBlockStart
353 result <- indentedBlock
353 result <- indentedBlock
@@ -355,7 +355,7 @@ codeBlock = try $ do
355
355
356-- | The 'code-block' directive (from Sphinx) that allows a language to be
356-- | The 'code-block' directive (from Sphinx) that allows a language to be
357-- specified.
357-- specified.
358−customCodeBlock :: GenParser Char st Block
358+customCodeBlock :: Parsec [Char] st Block
359customCodeBlock = try $ do
359customCodeBlock = try $ do
360 string ".. code-block:: "
360 string ".. code-block:: "
361 language <- manyTill anyChar newline
361 language <- manyTill anyChar newline
@@ -364,7 +364,7 @@ customCodeBlock = try $ do
364 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
364 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
365
365
366
366
367−figureBlock :: GenParser Char ParserState Block
367+figureBlock :: Parsec [Char] ParserState Block
368figureBlock = try $ do
368figureBlock = try $ do
369 string ".. figure::"
369 string ".. figure::"
370 src <- removeLeadingTrailingSpace `fmap` manyTill anyChar newline
370 src <- removeLeadingTrailingSpace `fmap` manyTill anyChar newline
@@ -372,24 +372,24 @@ figureBlock = try $ do
372 caption <- parseFromString extractCaption body
372 caption <- parseFromString extractCaption body
373 return $ Para [Image caption (src,"")]
373 return $ Para [Image caption (src,"")]
374
374
375−extractCaption :: GenParser Char ParserState [Inline]
375+extractCaption :: Parsec [Char] ParserState [Inline]
376extractCaption = try $ do
376extractCaption = try $ do
377 manyTill anyLine blanklines
377 manyTill anyLine blanklines
378 many inline
378 many inline
379
379
380-- | The 'math' directive (from Sphinx) for display math.
380-- | The 'math' directive (from Sphinx) for display math.
381−mathBlock :: GenParser Char st Block
381+mathBlock :: Parsec [Char] st Block
382mathBlock = try $ do
382mathBlock = try $ do
383 string ".. math::"
383 string ".. math::"
384 mathBlockMultiline <|> mathBlockOneLine
384 mathBlockMultiline <|> mathBlockOneLine
385
385
386−mathBlockOneLine :: GenParser Char st Block
386+mathBlockOneLine :: Parsec [Char] st Block
387mathBlockOneLine = try $ do
387mathBlockOneLine = try $ do
388 result <- manyTill anyChar newline
388 result <- manyTill anyChar newline
389 blanklines
389 blanklines
390 return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
390 return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
391
391
392−mathBlockMultiline :: GenParser Char st Block
392+mathBlockMultiline :: Parsec [Char] st Block
393mathBlockMultiline = try $ do
393mathBlockMultiline = try $ do
394 blanklines
394 blanklines
395 result <- indentedBlock
395 result <- indentedBlock
@@ -404,7 +404,7 @@ mathBlockMultiline = try $ do
404 $ filter (not . null) $ splitBy null lns'
404 $ filter (not . null) $ splitBy null lns'
405 return $ Para $ map (Math DisplayMath) eqs
405 return $ Para $ map (Math DisplayMath) eqs
406
406
407−lhsCodeBlock :: GenParser Char ParserState Block
407+lhsCodeBlock :: Parsec [Char] ParserState Block
408lhsCodeBlock = try $ do
408lhsCodeBlock = try $ do
409 failUnlessLHS
409 failUnlessLHS
410 optional codeBlockStart
410 optional codeBlockStart
@@ -418,7 +418,7 @@ lhsCodeBlock = try $ do
418 blanklines
418 blanklines
419 return $ CodeBlock ("", ["sourceCode", "literate", "haskell"], []) $ intercalate "\n" lns'
419 return $ CodeBlock ("", ["sourceCode", "literate", "haskell"], []) $ intercalate "\n" lns'
420
420
421−birdTrackLine :: GenParser Char st [Char]
421+birdTrackLine :: Parsec [Char] st [Char]
422birdTrackLine = do
422birdTrackLine = do
423 char '>'
423 char '>'
424 manyTill anyChar newline
424 manyTill anyChar newline
@@ -427,7 +427,7 @@ birdTrackLine = do
427-- raw html/latex/etc
427-- raw html/latex/etc
428--
428--
429
429
430−rawBlock :: GenParser Char st Block
430+rawBlock :: Parsec [Char] st Block
431rawBlock = try $ do
431rawBlock = try $ do
432 string ".. raw:: "
432 string ".. raw:: "
433 lang <- many1 (letter <|> digit)
433 lang <- many1 (letter <|> digit)
@@ -439,7 +439,7 @@ rawBlock = try $ do
439-- block quotes
439-- block quotes
440--
440--
441
441
442−blockQuote :: GenParser Char ParserState Block
442+blockQuote :: Parsec [Char] ParserState Block
443blockQuote = do
443blockQuote = do
444 raw <- indentedBlock
444 raw <- indentedBlock
445 -- parse the extracted block, which may contain various block elements:
445 -- parse the extracted block, which may contain various block elements:
@@ -450,10 +450,10 @@ blockQuote = do
450-- list blocks
450-- list blocks
451--
451--
452
452
453−list :: GenParser Char ParserState Block
453+list :: Parsec [Char] ParserState Block
454list = choice [ bulletList, orderedList, definitionList ] <?> "list"
454list = choice [ bulletList, orderedList, definitionList ] <?> "list"
455
455
456−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
456+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
457definitionListItem = try $ do
457definitionListItem = try $ do
458 -- avoid capturing a directive or comment
458 -- avoid capturing a directive or comment
459 notFollowedBy (try $ char '.' >> char '.')
459 notFollowedBy (try $ char '.' >> char '.')
@@ -463,11 +463,11 @@ definitionListItem = try $ do
463 contents <- parseFromString parseBlocks $ raw ++ "\n"
463 contents <- parseFromString parseBlocks $ raw ++ "\n"
464 return (normalizeSpaces term, [contents])
464 return (normalizeSpaces term, [contents])
465
465
466−definitionList :: GenParser Char ParserState Block
466+definitionList :: Parsec [Char] ParserState Block
467definitionList = many1 definitionListItem >>= return . DefinitionList
467definitionList = many1 definitionListItem >>= return . DefinitionList
468
468
469-- parses bullet list start and returns its length (inc. following whitespace)
469-- parses bullet list start and returns its length (inc. following whitespace)
470−bulletListStart :: GenParser Char st Int
470+bulletListStart :: Parsec [Char] st Int
471bulletListStart = try $ do
471bulletListStart = try $ do
472 notFollowedBy' hrule -- because hrules start out just like lists
472 notFollowedBy' hrule -- because hrules start out just like lists
473 marker <- oneOf bulletListMarkers
473 marker <- oneOf bulletListMarkers
@@ -477,14 +477,14 @@ bulletListStart = try $ do
477-- parses ordered list start and returns its length (inc following whitespace)
477-- parses ordered list start and returns its length (inc following whitespace)
478orderedListStart :: ListNumberStyle
478orderedListStart :: ListNumberStyle
479 -> ListNumberDelim
479 -> ListNumberDelim
480− -> GenParser Char ParserState Int
480+ -> Parsec [Char] ParserState Int
481orderedListStart style delim = try $ do
481orderedListStart style delim = try $ do
482 (_, markerLen) <- withHorizDisplacement (orderedListMarker style delim)
482 (_, markerLen) <- withHorizDisplacement (orderedListMarker style delim)
483 white <- many1 spaceChar
483 white <- many1 spaceChar
484 return $ markerLen + length white
484 return $ markerLen + length white
485
485
486-- parse a line of a list item
486-- parse a line of a list item
487−listLine :: Int -> GenParser Char ParserState [Char]
487+listLine :: Int -> Parsec [Char] ParserState [Char]
488listLine markerLength = try $ do
488listLine markerLength = try $ do
489 notFollowedBy blankline
489 notFollowedBy blankline
490 indentWith markerLength
490 indentWith markerLength
@@ -492,7 +492,7 @@ listLine markerLength = try $ do
492 return $ line ++ "\n"
492 return $ line ++ "\n"
493
493
494-- indent by specified number of spaces (or equiv. tabs)
494-- indent by specified number of spaces (or equiv. tabs)
495−indentWith :: Int -> GenParser Char ParserState [Char]
495+indentWith :: Int -> Parsec [Char] ParserState [Char]
496indentWith num = do
496indentWith num = do
497 state <- getState
497 state <- getState
498 let tabStop = stateTabStop state
498 let tabStop = stateTabStop state
@@ -502,8 +502,8 @@ indentWith num = do
502 (try (char '\t' >> count (num - tabStop) (char ' '))) ]
502 (try (char '\t' >> count (num - tabStop) (char ' '))) ]
503
503
504-- parse raw text for one list item, excluding start marker and continuations
504-- parse raw text for one list item, excluding start marker and continuations
505−rawListItem :: GenParser Char ParserState Int
505+rawListItem :: Parsec [Char] ParserState Int
506− -> GenParser Char ParserState (Int, [Char])
506+ -> Parsec [Char] ParserState (Int, [Char])
507rawListItem start = try $ do
507rawListItem start = try $ do
508 markerLength <- start
508 markerLength <- start
509 firstLine <- manyTill anyChar newline
509 firstLine <- manyTill anyChar newline
@@ -513,14 +513,14 @@ rawListItem start = try $ do
513-- continuation of a list item - indented and separated by blankline or
513-- continuation of a list item - indented and separated by blankline or
514-- (in compact lists) endline.
514-- (in compact lists) endline.
515-- Note: nested lists are parsed as continuations.
515-- Note: nested lists are parsed as continuations.
516−listContinuation :: Int -> GenParser Char ParserState [Char]
516+listContinuation :: Int -> Parsec [Char] ParserState [Char]
517listContinuation markerLength = try $ do
517listContinuation markerLength = try $ do
518 blanks <- many1 blankline
518 blanks <- many1 blankline
519 result <- many1 (listLine markerLength)
519 result <- many1 (listLine markerLength)
520 return $ blanks ++ concat result
520 return $ blanks ++ concat result
521
521
522−listItem :: GenParser Char ParserState Int
522+listItem :: Parsec [Char] ParserState Int
523− -> GenParser Char ParserState [Block]
523+ -> Parsec [Char] ParserState [Block]
524listItem start = try $ do
524listItem start = try $ do
525 (markerLength, first) <- rawListItem start
525 (markerLength, first) <- rawListItem start
526 rest <- many (listContinuation markerLength)
526 rest <- many (listContinuation markerLength)
@@ -537,14 +537,14 @@ listItem start = try $ do
537 updateState (\st -> st {stateParserContext = oldContext})
537 updateState (\st -> st {stateParserContext = oldContext})
538 return parsed
538 return parsed
539
539
540−orderedList :: GenParser Char ParserState Block
540+orderedList :: Parsec [Char] ParserState Block
541orderedList = try $ do
541orderedList = try $ do
542 (start, style, delim) <- lookAhead (anyOrderedListMarker >>~ spaceChar)
542 (start, style, delim) <- lookAhead (anyOrderedListMarker >>~ spaceChar)
543 items <- many1 (listItem (orderedListStart style delim))
543 items <- many1 (listItem (orderedListStart style delim))
544 let items' = compactify items
544 let items' = compactify items
545 return $ OrderedList (start, style, delim) items'
545 return $ OrderedList (start, style, delim) items'
546
546
547−bulletList :: GenParser Char ParserState Block
547+bulletList :: Parsec [Char] ParserState Block
548bulletList = many1 (listItem bulletListStart) >>=
548bulletList = many1 (listItem bulletListStart) >>=
549 return . BulletList . compactify
549 return . BulletList . compactify
550
550
@@ -552,7 +552,7 @@ bulletList = many1 (listItem bulletListStart) >>=
552-- default-role block
552-- default-role block
553--
553--
554
554
555−defaultRoleBlock :: GenParser Char ParserState Block
555+defaultRoleBlock :: Parsec [Char] ParserState Block
556defaultRoleBlock = try $ do
556defaultRoleBlock = try $ do
557 string ".. default-role::"
557 string ".. default-role::"
558 -- doesn't enforce any restrictions on the role name; embedded spaces shouldn't be allowed, for one
558 -- doesn't enforce any restrictions on the role name; embedded spaces shouldn't be allowed, for one
@@ -570,7 +570,7 @@ defaultRoleBlock = try $ do
570-- unknown directive (e.g. comment)
570-- unknown directive (e.g. comment)
571--
571--
572
572
573−unknownDirective :: GenParser Char st Block
573+unknownDirective :: Parsec [Char] st Block
574unknownDirective = try $ do
574unknownDirective = try $ do
575 string ".."
575 string ".."
576 notFollowedBy (noneOf " \t\n")
576 notFollowedBy (noneOf " \t\n")
@@ -582,7 +582,7 @@ unknownDirective = try $ do
582--- note block
582--- note block
583---
583---
584
584
585−noteBlock :: GenParser Char ParserState [Char]
585+noteBlock :: Parsec [Char] ParserState [Char]
586noteBlock = try $ do
586noteBlock = try $ do
587 startPos <- getPosition
587 startPos <- getPosition
588 string ".."
588 string ".."
@@ -601,7 +601,7 @@ noteBlock = try $ do
601 -- return blanks so line count isn't affected
601 -- return blanks so line count isn't affected
602 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
602 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
603
603
604−noteMarker :: GenParser Char ParserState [Char]
604+noteMarker :: Parsec [Char] ParserState [Char]
605noteMarker = do
605noteMarker = do
606 char '['
606 char '['
607 res <- many1 digit
607 res <- many1 digit
@@ -614,13 +614,13 @@ noteMarker = do
614-- reference key
614-- reference key
615--
615--
616
616
617−quotedReferenceName :: GenParser Char ParserState [Inline]
617+quotedReferenceName :: Parsec [Char] ParserState [Inline]
618quotedReferenceName = try $ do
618quotedReferenceName = try $ do
619 char '`' >> notFollowedBy (char '`') -- `` means inline code!
619 char '`' >> notFollowedBy (char '`') -- `` means inline code!
620 label' <- many1Till inline (char '`')
620 label' <- many1Till inline (char '`')
621 return label'
621 return label'
622
622
623−unquotedReferenceName :: GenParser Char ParserState [Inline]
623+unquotedReferenceName :: Parsec [Char] ParserState [Inline]
624unquotedReferenceName = try $ do
624unquotedReferenceName = try $ do
625 label' <- many1Till inline (lookAhead $ char ':')
625 label' <- many1Till inline (lookAhead $ char ':')
626 return label'
626 return label'
@@ -629,24 +629,24 @@ unquotedReferenceName = try $ do
629-- plus isolated (no two adjacent) internal hyphens, underscores,
629-- plus isolated (no two adjacent) internal hyphens, underscores,
630-- periods, colons and plus signs; no whitespace or other characters
630-- periods, colons and plus signs; no whitespace or other characters
631-- are allowed.
631-- are allowed.
632−simpleReferenceName' :: GenParser Char st String
632+simpleReferenceName' :: Parsec [Char] st String
633simpleReferenceName' = do
633simpleReferenceName' = do
634 x <- alphaNum
634 x <- alphaNum
635 xs <- many $ alphaNum
635 xs <- many $ alphaNum
636 <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
636 <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
637 return (x:xs)
637 return (x:xs)
638
638
639−simpleReferenceName :: GenParser Char st [Inline]
639+simpleReferenceName :: Parsec [Char] st [Inline]
640simpleReferenceName = do
640simpleReferenceName = do
641 raw <- simpleReferenceName'
641 raw <- simpleReferenceName'
642 return [Str raw]
642 return [Str raw]
643
643
644−referenceName :: GenParser Char ParserState [Inline]
644+referenceName :: Parsec [Char] ParserState [Inline]
645referenceName = quotedReferenceName <|>
645referenceName = quotedReferenceName <|>
646 (try $ simpleReferenceName >>~ lookAhead (char ':')) <|>
646 (try $ simpleReferenceName >>~ lookAhead (char ':')) <|>
647 unquotedReferenceName
647 unquotedReferenceName
648
648
649−referenceKey :: GenParser Char ParserState [Char]
649+referenceKey :: Parsec [Char] ParserState [Char]
650referenceKey = do
650referenceKey = do
651 startPos <- getPosition
651 startPos <- getPosition
652 (key, target) <- choice [imageKey, anonymousKey, regularKey]
652 (key, target) <- choice [imageKey, anonymousKey, regularKey]
@@ -658,7 +658,7 @@ referenceKey = do
658 -- return enough blanks to replace key
658 -- return enough blanks to replace key
659 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
659 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
660
660
661−targetURI :: GenParser Char st [Char]
661+targetURI :: Parsec [Char] st [Char]
662targetURI = do
662targetURI = do
663 skipSpaces
663 skipSpaces
664 optional newline
664 optional newline
@@ -667,7 +667,7 @@ targetURI = do
667 blanklines
667 blanklines
668 return $ escapeURI $ removeLeadingTrailingSpace $ contents
668 return $ escapeURI $ removeLeadingTrailingSpace $ contents
669
669
670−imageKey :: GenParser Char ParserState (Key, Target)
670+imageKey :: Parsec [Char] ParserState (Key, Target)
671imageKey = try $ do
671imageKey = try $ do
672 string ".. |"
672 string ".. |"
673 ref <- manyTill inline (char '|')
673 ref <- manyTill inline (char '|')
@@ -676,14 +676,14 @@ imageKey = try $ do
676 src <- targetURI
676 src <- targetURI
677 return (toKey (normalizeSpaces ref), (src, ""))
677 return (toKey (normalizeSpaces ref), (src, ""))
678
678
679−anonymousKey :: GenParser Char st (Key, Target)
679+anonymousKey :: Parsec [Char] st (Key, Target)
680anonymousKey = try $ do
680anonymousKey = try $ do
681 oneOfStrings [".. __:", "__"]
681 oneOfStrings [".. __:", "__"]
682 src <- targetURI
682 src <- targetURI
683 pos <- getPosition
683 pos <- getPosition
684 return (toKey [Str $ "_" ++ printf "%09d" (sourceLine pos)], (src, ""))
684 return (toKey [Str $ "_" ++ printf "%09d" (sourceLine pos)], (src, ""))
685
685
686−regularKey :: GenParser Char ParserState (Key, Target)
686+regularKey :: Parsec [Char] ParserState (Key, Target)
687regularKey = try $ do
687regularKey = try $ do
688 string ".. _"
688 string ".. _"
689 ref <- referenceName
689 ref <- referenceName
@@ -708,31 +708,31 @@ regularKey = try $ do
708-- Grid tables TODO:
708-- Grid tables TODO:
709-- - column spans
709-- - column spans
710
710
711−dashedLine :: Char -> GenParser Char st (Int, Int)
711+dashedLine :: Char -> Parsec [Char] st (Int, Int)
712dashedLine ch = do
712dashedLine ch = do
713 dashes <- many1 (char ch)
713 dashes <- many1 (char ch)
714 sp <- many (char ' ')
714 sp <- many (char ' ')
715 return (length dashes, length $ dashes ++ sp)
715 return (length dashes, length $ dashes ++ sp)
716
716
717−simpleDashedLines :: Char -> GenParser Char st [(Int,Int)]
717+simpleDashedLines :: Char -> Parsec [Char] st [(Int,Int)]
718simpleDashedLines ch = try $ many1 (dashedLine ch)
718simpleDashedLines ch = try $ many1 (dashedLine ch)
719
719
720-- Parse a table row separator
720-- Parse a table row separator
721−simpleTableSep :: Char -> GenParser Char ParserState Char
721+simpleTableSep :: Char -> Parsec [Char] ParserState Char
722simpleTableSep ch = try $ simpleDashedLines ch >> newline
722simpleTableSep ch = try $ simpleDashedLines ch >> newline
723
723
724-- Parse a table footer
724-- Parse a table footer
725−simpleTableFooter :: GenParser Char ParserState [Char]
725+simpleTableFooter :: Parsec [Char] ParserState [Char]
726simpleTableFooter = try $ simpleTableSep '=' >> blanklines
726simpleTableFooter = try $ simpleTableSep '=' >> blanklines
727
727
728-- Parse a raw line and split it into chunks by indices.
728-- 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]
730simpleTableRawLine indices = do
730simpleTableRawLine indices = do
731 line <- many1Till anyChar newline
731 line <- many1Till anyChar newline
732 return (simpleTableSplitLine indices line)
732 return (simpleTableSplitLine indices line)
733
733
734-- Parse a table row and return a list of blocks (columns).
734-- 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]]
736simpleTableRow indices = do
736simpleTableRow indices = do
737 notFollowedBy' simpleTableFooter
737 notFollowedBy' simpleTableFooter
738 firstLine <- simpleTableRawLine indices
738 firstLine <- simpleTableRawLine indices
@@ -746,7 +746,7 @@ simpleTableSplitLine indices line =
746 $ tail $ splitByIndices (init indices) line
746 $ tail $ splitByIndices (init indices) line
747
747
748simpleTableHeader :: Bool -- ^ Headerless table
748simpleTableHeader :: Bool -- ^ Headerless table
749− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
749+ -> Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
750simpleTableHeader headless = try $ do
750simpleTableHeader headless = try $ do
751 optional blanklines
751 optional blanklines
752 rawContent <- if headless
752 rawContent <- if headless
@@ -766,7 +766,7 @@ simpleTableHeader headless = try $ do
766
766
767-- Parse a simple table.
767-- Parse a simple table.
768simpleTable :: Bool -- ^ Headerless table
768simpleTable :: Bool -- ^ Headerless table
769− -> GenParser Char ParserState Block
769+ -> Parsec [Char] ParserState Block
770simpleTable headless = do
770simpleTable headless = do
771 Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter (return [])
771 Table c a _w h l <- tableWith (simpleTableHeader headless) simpleTableRow sep simpleTableFooter (return [])
772 -- Simple tables get 0s for relative column widths (i.e., use default)
772 -- Simple tables get 0s for relative column widths (i.e., use default)
@@ -775,10 +775,10 @@ simpleTable headless = do
775 sep = return () -- optional (simpleTableSep '-')
775 sep = return () -- optional (simpleTableSep '-')
776
776
777gridTable :: Bool -- ^ Headerless table
777gridTable :: Bool -- ^ Headerless table
778− -> GenParser Char ParserState Block
778+ -> Parsec [Char] ParserState Block
779gridTable = gridTableWith block (return [])
779gridTable = gridTableWith block (return [])
780
780
781−table :: GenParser Char ParserState Block
781+table :: Parsec [Char] ParserState Block
782table = gridTable False <|> simpleTable False <|>
782table = gridTable False <|> simpleTable False <|>
783 gridTable True <|> simpleTable True <?> "table"
783 gridTable True <|> simpleTable True <?> "table"
784
784
@@ -787,7 +787,7 @@ table = gridTable False <|> simpleTable False <|>
787 -- inline
787 -- inline
788 --
788 --
789
789
790−inline :: GenParser Char ParserState Inline
790+inline :: Parsec [Char] ParserState Inline
791inline = choice [ whitespace
791inline = choice [ whitespace
792 , link
792 , link
793 , str
793 , str
@@ -805,26 +805,26 @@ inline = choice [ whitespace
805 , escapedChar
805 , escapedChar
806 , symbol ] <?> "inline"
806 , symbol ] <?> "inline"
807
807
808−hyphens :: GenParser Char ParserState Inline
808+hyphens :: Parsec [Char] ParserState Inline
809hyphens = do
809hyphens = do
810 result <- many1 (char '-')
810 result <- many1 (char '-')
811 option Space endline
811 option Space endline
812 -- don't want to treat endline after hyphen or dash as a space
812 -- don't want to treat endline after hyphen or dash as a space
813 return $ Str result
813 return $ Str result
814
814
815−escapedChar :: GenParser Char st Inline
815+escapedChar :: Parsec [Char] st Inline
816escapedChar = do c <- escaped anyChar
816escapedChar = do c <- escaped anyChar
817 return $ if c == ' ' -- '\ ' is null in RST
817 return $ if c == ' ' -- '\ ' is null in RST
818 then Str ""
818 then Str ""
819 else Str [c]
819 else Str [c]
820
820
821−symbol :: GenParser Char ParserState Inline
821+symbol :: Parsec [Char] ParserState Inline
822symbol = do
822symbol = do
823 result <- oneOf specialChars
823 result <- oneOf specialChars
824 return $ Str [result]
824 return $ Str [result]
825
825
826-- parses inline code, between codeStart and codeEnd
826-- parses inline code, between codeStart and codeEnd
827−code :: GenParser Char ParserState Inline
827+code :: Parsec [Char] ParserState Inline
828code = try $ do
828code = try $ do
829 string "``"
829 string "``"
830 result <- manyTill anyChar (try (string "``"))
830 result <- manyTill anyChar (try (string "``"))
@@ -832,7 +832,7 @@ code = try $ do
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
833
833
834-- succeeds only if we're not right after a str (ie. in middle of word)
834-- 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
836atStart p = do
836atStart p = do
837 pos <- getPosition
837 pos <- getPosition
838 st <- getState
838 st <- getState
@@ -840,18 +840,18 @@ atStart p = do
840 guard $ stateLastStrPos st /= Just pos
840 guard $ stateLastStrPos st /= Just pos
841 p
841 p
842
842
843−emph :: GenParser Char ParserState Inline
843+emph :: Parsec [Char] ParserState Inline
844emph = enclosed (atStart $ char '*') (char '*') inline >>=
844emph = enclosed (atStart $ char '*') (char '*') inline >>=
845 return . Emph . normalizeSpaces
845 return . Emph . normalizeSpaces
846
846
847−strong :: GenParser Char ParserState Inline
847+strong :: Parsec [Char] ParserState Inline
848strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
848strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
849 return . Strong . normalizeSpaces
849 return . Strong . normalizeSpaces
850
850
851-- Parses inline interpreted text which is required to have the given role.
851-- Parses inline interpreted text which is required to have the given role.
852-- This decision is based on the role marker (if present),
852-- This decision is based on the role marker (if present),
853-- and the current default interpreted text role.
853-- and the current default interpreted text role.
854−interpreted :: [Char] -> GenParser Char ParserState [Char]
854+interpreted :: [Char] -> Parsec [Char] ParserState [Char]
855interpreted role = try $ do
855interpreted role = try $ do
856 state <- getState
856 state <- getState
857 if role == stateRstDefaultRole state
857 if role == stateRstDefaultRole state
@@ -868,19 +868,19 @@ interpreted role = try $ do
868 result <- enclosed (atStart $ char '`') (char '`') anyChar
868 result <- enclosed (atStart $ char '`') (char '`') anyChar
869 return result
869 return result
870
870
871−superscript :: GenParser Char ParserState Inline
871+superscript :: Parsec [Char] ParserState Inline
872superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])
872superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])
873
873
874−subscript :: GenParser Char ParserState Inline
874+subscript :: Parsec [Char] ParserState Inline
875subscript = interpreted "sub" >>= \x -> return (Subscript [Str x])
875subscript = interpreted "sub" >>= \x -> return (Subscript [Str x])
876
876
877−math :: GenParser Char ParserState Inline
877+math :: Parsec [Char] ParserState Inline
878math = interpreted "math" >>= \x -> return (Math InlineMath x)
878math = interpreted "math" >>= \x -> return (Math InlineMath x)
879
879
880−whitespace :: GenParser Char ParserState Inline
880+whitespace :: Parsec [Char] ParserState Inline
881whitespace = many1 spaceChar >> return Space <?> "whitespace"
881whitespace = many1 spaceChar >> return Space <?> "whitespace"
882
882
883−str :: GenParser Char ParserState Inline
883+str :: Parsec [Char] ParserState Inline
884str = do
884str = do
885 let strChar = noneOf ("\t\n " ++ specialChars)
885 let strChar = noneOf ("\t\n " ++ specialChars)
886 result <- many1 strChar
886 result <- many1 strChar
@@ -888,7 +888,7 @@ str = do
888 return $ Str result
888 return $ Str result
889
889
890-- an endline character that can be treated as a space, not a structural break
890-- 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
892endline = try $ do
892endline = try $ do
893 newline
893 newline
894 notFollowedBy blankline
894 notFollowedBy blankline
@@ -904,10 +904,10 @@ endline = try $ do
904-- links
904-- links
905--
905--
906
906
907−link :: GenParser Char ParserState Inline
907+link :: Parsec [Char] ParserState Inline
908link = choice [explicitLink, referenceLink, autoLink] <?> "link"
908link = choice [explicitLink, referenceLink, autoLink] <?> "link"
909
909
910−explicitLink :: GenParser Char ParserState Inline
910+explicitLink :: Parsec [Char] ParserState Inline
911explicitLink = try $ do
911explicitLink = try $ do
912 char '`'
912 char '`'
913 notFollowedBy (char '`') -- `` marks start of inline code
913 notFollowedBy (char '`') -- `` marks start of inline code
@@ -919,7 +919,7 @@ explicitLink = try $ do
919 return $ Link (normalizeSpaces label')
919 return $ Link (normalizeSpaces label')
920 (escapeURI $ removeLeadingTrailingSpace src, "")
920 (escapeURI $ removeLeadingTrailingSpace src, "")
921
921
922−referenceLink :: GenParser Char ParserState Inline
922+referenceLink :: Parsec [Char] ParserState Inline
923referenceLink = try $ do
923referenceLink = try $ do
924 label' <- (quotedReferenceName <|> simpleReferenceName) >>~ char '_'
924 label' <- (quotedReferenceName <|> simpleReferenceName) >>~ char '_'
925 state <- getState
925 state <- getState
@@ -931,7 +931,7 @@ referenceLink = try $ do
931 do char '_'
931 do char '_'
932 let anonKeys = sort $ filter isAnonKey $ M.keys keyTable
932 let anonKeys = sort $ filter isAnonKey $ M.keys keyTable
933 if null anonKeys
933 if null anonKeys
934− then pzero
934+ then mzero
935 else return (head anonKeys)
935 else return (head anonKeys)
936 (src,tit) <- case lookupKeySrc keyTable key of
936 (src,tit) <- case lookupKeySrc keyTable key of
937 Nothing -> fail "no corresponding key"
937 Nothing -> fail "no corresponding key"
@@ -940,21 +940,21 @@ referenceLink = try $ do
940 when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
940 when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
941 return $ Link (normalizeSpaces label') (src, tit)
941 return $ Link (normalizeSpaces label') (src, tit)
942
942
943−autoURI :: GenParser Char ParserState Inline
943+autoURI :: Parsec [Char] ParserState Inline
944autoURI = do
944autoURI = do
945 (orig, src) <- uri
945 (orig, src) <- uri
946 return $ Link [Str orig] (src, "")
946 return $ Link [Str orig] (src, "")
947
947
948−autoEmail :: GenParser Char ParserState Inline
948+autoEmail :: Parsec [Char] ParserState Inline
949autoEmail = do
949autoEmail = do
950 (orig, src) <- emailAddress
950 (orig, src) <- emailAddress
951 return $ Link [Str orig] (src, "")
951 return $ Link [Str orig] (src, "")
952
952
953−autoLink :: GenParser Char ParserState Inline
953+autoLink :: Parsec [Char] ParserState Inline
954autoLink = autoURI <|> autoEmail
954autoLink = autoURI <|> autoEmail
955
955
956-- For now, we assume that all substitution references are for images.
956-- For now, we assume that all substitution references are for images.
957−image :: GenParser Char ParserState Inline
957+image :: Parsec [Char] ParserState Inline
958image = try $ do
958image = try $ do
959 char '|'
959 char '|'
960 ref <- manyTill inline (char '|')
960 ref <- manyTill inline (char '|')
@@ -965,7 +965,7 @@ image = try $ do
965 Just target -> return target
965 Just target -> return target
966 return $ Image (normalizeSpaces ref) (src, tit)
966 return $ Image (normalizeSpaces ref) (src, tit)
967
967
968−note :: GenParser Char ParserState Inline
968+note :: Parsec [Char] ParserState Inline
969note = try $ do
969note = try $ do
970 ref <- noteMarker
970 ref <- noteMarker
971 char '_'
971 char '_'
src/Text/Pandoc/Readers/Textile.hs+69−69
@@ -60,7 +60,7 @@ import Text.Pandoc.Shared
60import Text.Pandoc.Parsing
60import Text.Pandoc.Parsing
61import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
61import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
62import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
62import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
63−import Text.ParserCombinators.Parsec
63+import Text.Parsec
64import Text.HTML.TagSoup.Match
64import Text.HTML.TagSoup.Match
65import Data.Char ( digitToInt, isUpper )
65import Data.Char ( digitToInt, isUpper )
66import Control.Monad ( guard, liftM )
66import Control.Monad ( guard, liftM )
@@ -75,7 +75,7 @@ readTextile state s =
75
75
76
76
77-- | Generate a Pandoc ADT from a textile document
77-- | Generate a Pandoc ADT from a textile document
78−parseTextile :: GenParser Char ParserState Pandoc
78+parseTextile :: Parsec [Char] ParserState Pandoc
79parseTextile = do
79parseTextile = do
80 -- textile allows raw HTML and does smart punctuation by default
80 -- textile allows raw HTML and does smart punctuation by default
81 updateState (\state -> state { stateParseRaw = True, stateSmart = True })
81 updateState (\state -> state { stateParseRaw = True, stateSmart = True })
@@ -93,10 +93,10 @@ parseTextile = do
93 blocks <- parseBlocks
93 blocks <- parseBlocks
94 return $ Pandoc (Meta [] [] []) blocks -- FIXME
94 return $ Pandoc (Meta [] [] []) blocks -- FIXME
95
95
96−noteMarker :: GenParser Char ParserState [Char]
96+noteMarker :: Parsec [Char] ParserState [Char]
97noteMarker = skipMany spaceChar >> string "fn" >> manyTill digit (char '.')
97noteMarker = skipMany spaceChar >> string "fn" >> manyTill digit (char '.')
98
98
99−noteBlock :: GenParser Char ParserState [Char]
99+noteBlock :: Parsec [Char] ParserState [Char]
100noteBlock = try $ do
100noteBlock = try $ do
101 startPos <- getPosition
101 startPos <- getPosition
102 ref <- noteMarker
102 ref <- noteMarker
@@ -111,11 +111,11 @@ noteBlock = try $ do
111 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
111 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
112
112
113-- | Parse document blocks
113-- | Parse document blocks
114−parseBlocks :: GenParser Char ParserState [Block]
114+parseBlocks :: Parsec [Char] ParserState [Block]
115parseBlocks = manyTill block eof
115parseBlocks = manyTill block eof
116
116
117-- | Block parsers list tried in definition order
117-- | Block parsers list tried in definition order
118−blockParsers :: [GenParser Char ParserState Block]
118+blockParsers :: [Parsec [Char] ParserState Block]
119blockParsers = [ codeBlock
119blockParsers = [ codeBlock
120 , header
120 , header
121 , blockQuote
121 , blockQuote
@@ -128,20 +128,20 @@ blockParsers = [ codeBlock
128 , nullBlock ]
128 , nullBlock ]
129
129
130-- | Any block in the order of definition of blockParsers
130-- | Any block in the order of definition of blockParsers
131−block :: GenParser Char ParserState Block
131+block :: Parsec [Char] ParserState Block
132block = choice blockParsers <?> "block"
132block = choice blockParsers <?> "block"
133
133
134−codeBlock :: GenParser Char ParserState Block
134+codeBlock :: Parsec [Char] ParserState Block
135codeBlock = codeBlockBc <|> codeBlockPre
135codeBlock = codeBlockBc <|> codeBlockPre
136
136
137−codeBlockBc :: GenParser Char ParserState Block
137+codeBlockBc :: Parsec [Char] ParserState Block
138codeBlockBc = try $ do
138codeBlockBc = try $ do
139 string "bc. "
139 string "bc. "
140 contents <- manyTill anyLine blanklines
140 contents <- manyTill anyLine blanklines
141 return $ CodeBlock ("",[],[]) $ unlines contents
141 return $ CodeBlock ("",[],[]) $ unlines contents
142
142
143-- | Code Blocks in Textile are between <pre> and </pre>
143-- | Code Blocks in Textile are between <pre> and </pre>
144−codeBlockPre :: GenParser Char ParserState Block
144+codeBlockPre :: Parsec [Char] ParserState Block
145codeBlockPre = try $ do
145codeBlockPre = try $ do
146 htmlTag (tagOpen (=="pre") null)
146 htmlTag (tagOpen (=="pre") null)
147 result' <- manyTill anyChar (try $ htmlTag (tagClose (=="pre")) >> blockBreak)
147 result' <- manyTill anyChar (try $ htmlTag (tagClose (=="pre")) >> blockBreak)
@@ -156,7 +156,7 @@ codeBlockPre = try $ do
156 return $ CodeBlock ("",[],[]) result'''
156 return $ CodeBlock ("",[],[]) result'''
157
157
158-- | Header of the form "hN. content" with N in 1..6
158-- | Header of the form "hN. content" with N in 1..6
159−header :: GenParser Char ParserState Block
159+header :: Parsec [Char] ParserState Block
160header = try $ do
160header = try $ do
161 char 'h'
161 char 'h'
162 level <- digitToInt <$> oneOf "123456"
162 level <- digitToInt <$> oneOf "123456"
@@ -165,14 +165,14 @@ header = try $ do
165 return $ Header level name
165 return $ Header level name
166
166
167-- | Blockquote of the form "bq. content"
167-- | Blockquote of the form "bq. content"
168−blockQuote :: GenParser Char ParserState Block
168+blockQuote :: Parsec [Char] ParserState Block
169blockQuote = try $ do
169blockQuote = try $ do
170 string "bq" >> optional attributes >> char '.' >> whitespace
170 string "bq" >> optional attributes >> char '.' >> whitespace
171 BlockQuote . singleton <$> para
171 BlockQuote . singleton <$> para
172
172
173-- Horizontal rule
173-- Horizontal rule
174
174
175−hrule :: GenParser Char st Block
175+hrule :: Parsec [Char] st Block
176hrule = try $ do
176hrule = try $ do
177 skipSpaces
177 skipSpaces
178 start <- oneOf "-*"
178 start <- oneOf "-*"
@@ -187,39 +187,39 @@ hrule = try $ do
187-- | Can be a bullet list or an ordered list. This implementation is
187-- | Can be a bullet list or an ordered list. This implementation is
188-- strict in the nesting, sublist must start at exactly "parent depth
188-- strict in the nesting, sublist must start at exactly "parent depth
189-- plus one"
189-- plus one"
190−anyList :: GenParser Char ParserState Block
190+anyList :: Parsec [Char] ParserState Block
191anyList = try $ ( (anyListAtDepth 1) <* blanklines )
191anyList = try $ ( (anyListAtDepth 1) <* blanklines )
192
192
193-- | This allow one type of list to be nested into an other type,
193-- | This allow one type of list to be nested into an other type,
194-- provided correct nesting
194-- provided correct nesting
195−anyListAtDepth :: Int -> GenParser Char ParserState Block
195+anyListAtDepth :: Int -> Parsec [Char] ParserState Block
196anyListAtDepth depth = choice [ bulletListAtDepth depth,
196anyListAtDepth depth = choice [ bulletListAtDepth depth,
197 orderedListAtDepth depth,
197 orderedListAtDepth depth,
198 definitionList ]
198 definitionList ]
199
199
200-- | Bullet List of given depth, depth being the number of leading '*'
200-- | 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
202bulletListAtDepth depth = try $ BulletList <$> many1 (bulletListItemAtDepth depth)
202bulletListAtDepth depth = try $ BulletList <$> many1 (bulletListItemAtDepth depth)
203
203
204-- | Bullet List Item of given depth, depth being the number of
204-- | Bullet List Item of given depth, depth being the number of
205-- leading '*'
205-- leading '*'
206−bulletListItemAtDepth :: Int -> GenParser Char ParserState [Block]
206+bulletListItemAtDepth :: Int -> Parsec [Char] ParserState [Block]
207bulletListItemAtDepth = genericListItemAtDepth '*'
207bulletListItemAtDepth = genericListItemAtDepth '*'
208
208
209-- | Ordered List of given depth, depth being the number of
209-- | Ordered List of given depth, depth being the number of
210-- leading '#'
210-- leading '#'
211−orderedListAtDepth :: Int -> GenParser Char ParserState Block
211+orderedListAtDepth :: Int -> Parsec [Char] ParserState Block
212orderedListAtDepth depth = try $ do
212orderedListAtDepth depth = try $ do
213 items <- many1 (orderedListItemAtDepth depth)
213 items <- many1 (orderedListItemAtDepth depth)
214 return (OrderedList (1, DefaultStyle, DefaultDelim) items)
214 return (OrderedList (1, DefaultStyle, DefaultDelim) items)
215
215
216-- | Ordered List Item of given depth, depth being the number of
216-- | Ordered List Item of given depth, depth being the number of
217-- leading '#'
217-- leading '#'
218−orderedListItemAtDepth :: Int -> GenParser Char ParserState [Block]
218+orderedListItemAtDepth :: Int -> Parsec [Char] ParserState [Block]
219orderedListItemAtDepth = genericListItemAtDepth '#'
219orderedListItemAtDepth = genericListItemAtDepth '#'
220
220
221-- | Common implementation of list items
221-- | Common implementation of list items
222−genericListItemAtDepth :: Char -> Int -> GenParser Char ParserState [Block]
222+genericListItemAtDepth :: Char -> Int -> Parsec [Char] ParserState [Block]
223genericListItemAtDepth c depth = try $ do
223genericListItemAtDepth c depth = try $ do
224 count depth (char c) >> optional attributes >> whitespace
224 count depth (char c) >> optional attributes >> whitespace
225 p <- inlines
225 p <- inlines
@@ -227,22 +227,22 @@ genericListItemAtDepth c depth = try $ do
227 return ((Plain p):sublist)
227 return ((Plain p):sublist)
228
228
229-- | A definition list is a set of consecutive definition items
229-- | A definition list is a set of consecutive definition items
230−definitionList :: GenParser Char ParserState Block
230+definitionList :: Parsec [Char] ParserState Block
231definitionList = try $ DefinitionList <$> many1 definitionListItem
231definitionList = try $ DefinitionList <$> many1 definitionListItem
232
232
233-- | A definition list item in textile begins with '- ', followed by
233-- | A definition list item in textile begins with '- ', followed by
234-- the term defined, then spaces and ":=". The definition follows, on
234-- the term defined, then spaces and ":=". The definition follows, on
235-- the same single line, or spaned on multiple line, after a line
235-- the same single line, or spaned on multiple line, after a line
236-- break.
236-- break.
237−definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
237+definitionListItem :: Parsec [Char] ParserState ([Inline], [[Block]])
238definitionListItem = try $ do
238definitionListItem = try $ do
239 string "- "
239 string "- "
240 term <- many1Till inline (try (whitespace >> string ":="))
240 term <- many1Till inline (try (whitespace >> string ":="))
241 def <- inlineDef <|> multilineDef
241 def <- inlineDef <|> multilineDef
242 return (term, def)
242 return (term, def)
243− where inlineDef :: GenParser Char ParserState [[Block]]
243+ where inlineDef :: Parsec [Char] ParserState [[Block]]
244 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
244 inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
245− multilineDef :: GenParser Char ParserState [[Block]]
245+ multilineDef :: Parsec [Char] ParserState [[Block]]
246 multilineDef = try $ do
246 multilineDef = try $ do
247 optional whitespace >> newline
247 optional whitespace >> newline
248 s <- many1Till anyChar (try (string "=:" >> newline))
248 s <- many1Till anyChar (try (string "=:" >> newline))
@@ -252,57 +252,57 @@ definitionListItem = try $ do
252
252
253-- | This terminates a block such as a paragraph. Because of raw html
253-- | This terminates a block such as a paragraph. Because of raw html
254-- blocks support, we have to lookAhead for a rawHtmlBlock.
254-- blocks support, we have to lookAhead for a rawHtmlBlock.
255−blockBreak :: GenParser Char ParserState ()
255+blockBreak :: Parsec [Char] ParserState ()
256blockBreak = try (newline >> blanklines >> return ()) <|>
256blockBreak = try (newline >> blanklines >> return ()) <|>
257 (lookAhead rawHtmlBlock >> return ())
257 (lookAhead rawHtmlBlock >> return ())
258
258
259-- raw content
259-- raw content
260
260
261-- | A raw Html Block, optionally followed by blanklines
261-- | A raw Html Block, optionally followed by blanklines
262−rawHtmlBlock :: GenParser Char ParserState Block
262+rawHtmlBlock :: Parsec [Char] ParserState Block
263rawHtmlBlock = try $ do
263rawHtmlBlock = try $ do
264 (_,b) <- htmlTag isBlockTag
264 (_,b) <- htmlTag isBlockTag
265 optional blanklines
265 optional blanklines
266 return $ RawBlock "html" b
266 return $ RawBlock "html" b
267
267
268-- | Raw block of LaTeX content
268-- | Raw block of LaTeX content
269−rawLaTeXBlock' :: GenParser Char ParserState Block
269+rawLaTeXBlock' :: Parsec [Char] ParserState Block
270rawLaTeXBlock' = do
270rawLaTeXBlock' = do
271 failIfStrict
271 failIfStrict
272 RawBlock "latex" <$> (rawLaTeXBlock <* spaces)
272 RawBlock "latex" <$> (rawLaTeXBlock <* spaces)
273
273
274
274
275-- | In textile, paragraphs are separated by blank lines.
275-- | In textile, paragraphs are separated by blank lines.
276−para :: GenParser Char ParserState Block
276+para :: Parsec [Char] ParserState Block
277para = try $ Para . normalizeSpaces <$> manyTill inline blockBreak
277para = try $ Para . normalizeSpaces <$> manyTill inline blockBreak
278
278
279
279
280-- Tables
280-- Tables
281
281
282-- | A table cell spans until a pipe |
282-- | A table cell spans until a pipe |
283−tableCell :: GenParser Char ParserState TableCell
283+tableCell :: Parsec [Char] ParserState TableCell
284tableCell = do
284tableCell = do
285 c <- many1 (noneOf "|\n")
285 c <- many1 (noneOf "|\n")
286 content <- parseFromString (many1 inline) c
286 content <- parseFromString (many1 inline) c
287 return $ [ Plain $ normalizeSpaces content ]
287 return $ [ Plain $ normalizeSpaces content ]
288
288
289-- | A table row is made of many table cells
289-- | A table row is made of many table cells
290−tableRow :: GenParser Char ParserState [TableCell]
290+tableRow :: Parsec [Char] ParserState [TableCell]
291tableRow = try $ ( char '|' *> (endBy1 tableCell (char '|')) <* newline)
291tableRow = try $ ( char '|' *> (endBy1 tableCell (char '|')) <* newline)
292
292
293-- | Many table rows
293-- | Many table rows
294−tableRows :: GenParser Char ParserState [[TableCell]]
294+tableRows :: Parsec [Char] ParserState [[TableCell]]
295tableRows = many1 tableRow
295tableRows = many1 tableRow
296
296
297-- | Table headers are made of cells separated by a tag "|_."
297-- | Table headers are made of cells separated by a tag "|_."
298−tableHeaders :: GenParser Char ParserState [TableCell]
298+tableHeaders :: Parsec [Char] ParserState [TableCell]
299tableHeaders = let separator = (try $ string "|_.") in
299tableHeaders = let separator = (try $ string "|_.") in
300 try $ ( separator *> (sepBy1 tableCell separator) <* char '|' <* newline )
300 try $ ( separator *> (sepBy1 tableCell separator) <* char '|' <* newline )
301
301
302-- | A table with an optional header. Current implementation can
302-- | A table with an optional header. Current implementation can
303-- handle tables with and without header, but will parse cells
303-- handle tables with and without header, but will parse cells
304-- alignment attributes as content.
304-- alignment attributes as content.
305−table :: GenParser Char ParserState Block
305+table :: Parsec [Char] ParserState Block
306table = try $ do
306table = try $ do
307 headers <- option [] tableHeaders
307 headers <- option [] tableHeaders
308 rows <- tableRows
308 rows <- tableRows
@@ -318,8 +318,8 @@ table = try $ do
318-- | Blocks like 'p' and 'table' do not need explicit block tag.
318-- | Blocks like 'p' and 'table' do not need explicit block tag.
319-- However, they can be used to set HTML/CSS attributes when needed.
319-- However, they can be used to set HTML/CSS attributes when needed.
320maybeExplicitBlock :: String -- ^ block tag name
320maybeExplicitBlock :: String -- ^ block tag name
321− -> GenParser Char ParserState Block -- ^ implicit block
321+ -> Parsec [Char] ParserState Block -- ^ implicit block
322− -> GenParser Char ParserState Block
322+ -> Parsec [Char] ParserState Block
323maybeExplicitBlock name blk = try $ do
323maybeExplicitBlock name blk = try $ do
324 optional $ try $ string name >> optional attributes >> char '.' >>
324 optional $ try $ string name >> optional attributes >> char '.' >>
325 ((try whitespace) <|> endline)
325 ((try whitespace) <|> endline)
@@ -333,15 +333,15 @@ maybeExplicitBlock name blk = try $ do
333
333
334
334
335-- | Any inline element
335-- | Any inline element
336−inline :: GenParser Char ParserState Inline
336+inline :: Parsec [Char] ParserState Inline
337inline = choice inlineParsers <?> "inline"
337inline = choice inlineParsers <?> "inline"
338
338
339-- | List of consecutive inlines before a newline
339-- | List of consecutive inlines before a newline
340−inlines :: GenParser Char ParserState [Inline]
340+inlines :: Parsec [Char] ParserState [Inline]
341inlines = manyTill inline newline
341inlines = manyTill inline newline
342
342
343-- | Inline parsers tried in order
343-- | Inline parsers tried in order
344−inlineParsers :: [GenParser Char ParserState Inline]
344+inlineParsers :: [Parsec [Char] ParserState Inline]
345inlineParsers = [ autoLink
345inlineParsers = [ autoLink
346 , str
346 , str
347 , whitespace
347 , whitespace
@@ -362,7 +362,7 @@ inlineParsers = [ autoLink
362 ]
362 ]
363
363
364-- | Inline markups
364-- | Inline markups
365−inlineMarkup :: GenParser Char ParserState Inline
365+inlineMarkup :: Parsec [Char] ParserState Inline
366inlineMarkup = choice [ simpleInline (string "??") (Cite [])
366inlineMarkup = choice [ simpleInline (string "??") (Cite [])
367 , simpleInline (string "**") Strong
367 , simpleInline (string "**") Strong
368 , simpleInline (string "__") Emph
368 , simpleInline (string "__") Emph
@@ -375,29 +375,29 @@ inlineMarkup = choice [ simpleInline (string "??") (Cite [])
375 ]
375 ]
376
376
377-- | Trademark, registered, copyright
377-- | Trademark, registered, copyright
378−mark :: GenParser Char st Inline
378+mark :: Parsec [Char] st Inline
379mark = try $ char '(' >> (try tm <|> try reg <|> copy)
379mark = try $ char '(' >> (try tm <|> try reg <|> copy)
380
380
381−reg :: GenParser Char st Inline
381+reg :: Parsec [Char] st Inline
382reg = do
382reg = do
383 oneOf "Rr"
383 oneOf "Rr"
384 char ')'
384 char ')'
385 return $ Str "\174"
385 return $ Str "\174"
386
386
387−tm :: GenParser Char st Inline
387+tm :: Parsec [Char] st Inline
388tm = do
388tm = do
389 oneOf "Tt"
389 oneOf "Tt"
390 oneOf "Mm"
390 oneOf "Mm"
391 char ')'
391 char ')'
392 return $ Str "\8482"
392 return $ Str "\8482"
393
393
394−copy :: GenParser Char st Inline
394+copy :: Parsec [Char] st Inline
395copy = do
395copy = do
396 oneOf "Cc"
396 oneOf "Cc"
397 char ')'
397 char ')'
398 return $ Str "\169"
398 return $ Str "\169"
399
399
400−note :: GenParser Char ParserState Inline
400+note :: Parsec [Char] ParserState Inline
401note = try $ do
401note = try $ do
402 ref <- (char '[' *> many1 digit <* char ']')
402 ref <- (char '[' *> many1 digit <* char ']')
403 notes <- stateNotes <$> getState
403 notes <- stateNotes <$> getState
@@ -421,7 +421,7 @@ wordBoundaries :: [Char]
421wordBoundaries = markupChars ++ stringBreakers
421wordBoundaries = markupChars ++ stringBreakers
422
422
423-- | Parse a hyphened sequence of words
423-- | Parse a hyphened sequence of words
424−hyphenedWords :: GenParser Char ParserState String
424+hyphenedWords :: Parsec [Char] ParserState String
425hyphenedWords = try $ do
425hyphenedWords = try $ do
426 hd <- noneOf wordBoundaries
426 hd <- noneOf wordBoundaries
427 tl <- many ( (noneOf wordBoundaries) <|>
427 tl <- many ( (noneOf wordBoundaries) <|>
@@ -431,7 +431,7 @@ hyphenedWords = try $ do
431 (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
431 (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
432
432
433-- | Any string
433-- | Any string
434−str :: GenParser Char ParserState Inline
434+str :: Parsec [Char] ParserState Inline
435str = do
435str = do
436 baseStr <- hyphenedWords
436 baseStr <- hyphenedWords
437 -- RedCloth compliance : if parsed word is uppercase and immediatly
437 -- RedCloth compliance : if parsed word is uppercase and immediatly
@@ -444,34 +444,34 @@ str = do
444 return $ Str fullStr
444 return $ Str fullStr
445
445
446-- | Textile allows HTML span infos, we discard them
446-- | Textile allows HTML span infos, we discard them
447−htmlSpan :: GenParser Char ParserState Inline
447+htmlSpan :: Parsec [Char] ParserState Inline
448htmlSpan = try $ Str <$> ( char '%' *> attributes *> manyTill anyChar (char '%') )
448htmlSpan = try $ Str <$> ( char '%' *> attributes *> manyTill anyChar (char '%') )
449
449
450-- | Some number of space chars
450-- | Some number of space chars
451−whitespace :: GenParser Char ParserState Inline
451+whitespace :: Parsec [Char] ParserState Inline
452whitespace = many1 spaceChar >> return Space <?> "whitespace"
452whitespace = many1 spaceChar >> return Space <?> "whitespace"
453
453
454-- | In Textile, an isolated endline character is a line break
454-- | In Textile, an isolated endline character is a line break
455−endline :: GenParser Char ParserState Inline
455+endline :: Parsec [Char] ParserState Inline
456endline = try $ do
456endline = try $ do
457 newline >> notFollowedBy blankline
457 newline >> notFollowedBy blankline
458 return LineBreak
458 return LineBreak
459
459
460−rawHtmlInline :: GenParser Char ParserState Inline
460+rawHtmlInline :: Parsec [Char] ParserState Inline
461rawHtmlInline = RawInline "html" . snd <$> htmlTag isInlineTag
461rawHtmlInline = RawInline "html" . snd <$> htmlTag isInlineTag
462
462
463-- | Raw LaTeX Inline
463-- | Raw LaTeX Inline
464−rawLaTeXInline' :: GenParser Char ParserState Inline
464+rawLaTeXInline' :: Parsec [Char] ParserState Inline
465rawLaTeXInline' = try $ do
465rawLaTeXInline' = try $ do
466 failIfStrict
466 failIfStrict
467 rawLaTeXInline
467 rawLaTeXInline
468
468
469-- | Textile standard link syntax is "label":target. But we
469-- | Textile standard link syntax is "label":target. But we
470-- can also have ["label":target].
470-- can also have ["label":target].
471−link :: GenParser Char ParserState Inline
471+link :: Parsec [Char] ParserState Inline
472link = linkB <|> linkNoB
472link = linkB <|> linkNoB
473
473
474−linkNoB :: GenParser Char ParserState Inline
474+linkNoB :: Parsec [Char] ParserState Inline
475linkNoB = try $ do
475linkNoB = try $ do
476 name <- surrounded (char '"') inline
476 name <- surrounded (char '"') inline
477 char ':'
477 char ':'
@@ -479,7 +479,7 @@ linkNoB = try $ do
479 url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
479 url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
480 return $ Link name (url, "")
480 return $ Link name (url, "")
481
481
482−linkB :: GenParser Char ParserState Inline
482+linkB :: Parsec [Char] ParserState Inline
483linkB = try $ do
483linkB = try $ do
484 char '['
484 char '['
485 name <- surrounded (char '"') inline
485 name <- surrounded (char '"') inline
@@ -488,13 +488,13 @@ linkB = try $ do
488 return $ Link name (url, "")
488 return $ Link name (url, "")
489
489
490-- | Detect plain links to http or email.
490-- | Detect plain links to http or email.
491−autoLink :: GenParser Char ParserState Inline
491+autoLink :: Parsec [Char] ParserState Inline
492autoLink = do
492autoLink = do
493 (orig, src) <- (try uri <|> try emailAddress)
493 (orig, src) <- (try uri <|> try emailAddress)
494 return $ Link [Str orig] (src, "")
494 return $ Link [Str orig] (src, "")
495
495
496-- | image embedding
496-- | image embedding
497−image :: GenParser Char ParserState Inline
497+image :: Parsec [Char] ParserState Inline
498image = try $ do
498image = try $ do
499 char '!' >> notFollowedBy space
499 char '!' >> notFollowedBy space
500 src <- manyTill anyChar (lookAhead $ oneOf "!(")
500 src <- manyTill anyChar (lookAhead $ oneOf "!(")
@@ -502,49 +502,49 @@ image = try $ do
502 char '!'
502 char '!'
503 return $ Image [Str alt] (src, alt)
503 return $ Image [Str alt] (src, alt)
504
504
505−escapedInline :: GenParser Char ParserState Inline
505+escapedInline :: Parsec [Char] ParserState Inline
506escapedInline = escapedEqs <|> escapedTag
506escapedInline = escapedEqs <|> escapedTag
507
507
508−escapedEqs :: GenParser Char ParserState Inline
508+escapedEqs :: Parsec [Char] ParserState Inline
509escapedEqs = Str <$> (try $ string "==" *> manyTill anyChar (try $ string "=="))
509escapedEqs = Str <$> (try $ string "==" *> manyTill anyChar (try $ string "=="))
510
510
511-- | literal text escaped btw <notextile> tags
511-- | literal text escaped btw <notextile> tags
512−escapedTag :: GenParser Char ParserState Inline
512+escapedTag :: Parsec [Char] ParserState Inline
513escapedTag = Str <$>
513escapedTag = Str <$>
514 (try $ string "<notextile>" *> manyTill anyChar (try $ string "</notextile>"))
514 (try $ string "<notextile>" *> manyTill anyChar (try $ string "</notextile>"))
515
515
516-- | Any special symbol defined in wordBoundaries
516-- | Any special symbol defined in wordBoundaries
517−symbol :: GenParser Char ParserState Inline
517+symbol :: Parsec [Char] ParserState Inline
518symbol = Str . singleton <$> oneOf wordBoundaries
518symbol = Str . singleton <$> oneOf wordBoundaries
519
519
520-- | Inline code
520-- | Inline code
521−code :: GenParser Char ParserState Inline
521+code :: Parsec [Char] ParserState Inline
522code = code1 <|> code2
522code = code1 <|> code2
523
523
524−code1 :: GenParser Char ParserState Inline
524+code1 :: Parsec [Char] ParserState Inline
525code1 = Code nullAttr <$> surrounded (char '@') anyChar
525code1 = Code nullAttr <$> surrounded (char '@') anyChar
526
526
527−code2 :: GenParser Char ParserState Inline
527+code2 :: Parsec [Char] ParserState Inline
528code2 = do
528code2 = do
529 htmlTag (tagOpen (=="tt") null)
529 htmlTag (tagOpen (=="tt") null)
530 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
530 Code nullAttr <$> manyTill anyChar (try $ htmlTag $ tagClose (=="tt"))
531
531
532-- | Html / CSS attributes
532-- | Html / CSS attributes
533−attributes :: GenParser Char ParserState String
533+attributes :: Parsec [Char] ParserState String
534attributes = choice [ enclosed (char '(') (char ')') anyChar,
534attributes = choice [ enclosed (char '(') (char ')') anyChar,
535 enclosed (char '{') (char '}') anyChar,
535 enclosed (char '{') (char '}') anyChar,
536 enclosed (char '[') (char ']') anyChar]
536 enclosed (char '[') (char ']') anyChar]
537
537
538-- | Parses material surrounded by a parser.
538-- | Parses material surrounded by a parser.
539−surrounded :: GenParser Char st t -- ^ surrounding parser
539+surrounded :: Parsec [Char] st t -- ^ surrounding parser
540− -> GenParser Char st a -- ^ content parser (to be used repeatedly)
540+ -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
541− -> GenParser Char st [a]
541+ -> Parsec [Char] st [a]
542surrounded border = enclosed border (try border)
542surrounded border = enclosed border (try border)
543
543
544-- | Inlines are most of the time of the same form
544-- | 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
546 -> ([Inline] -> Inline) -- ^ Inline constructor
546 -> ([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)
548simpleInline border construct = surrounded border (inlineWithAttribute) >>=
548simpleInline border construct = surrounded border (inlineWithAttribute) >>=
549 return . construct . normalizeSpaces
549 return . construct . normalizeSpaces
550 where inlineWithAttribute = (try $ optional attributes) >> inline
550 where inlineWithAttribute = (try $ optional attributes) >> inline
src/Text/Pandoc/Templates.hs+12−12
@@ -68,8 +68,8 @@ module Text.Pandoc.Templates ( renderTemplate
68 , TemplateTarget
68 , TemplateTarget
69 , getDefaultTemplate ) where
69 , getDefaultTemplate ) where
70
70
71−import Text.ParserCombinators.Parsec
71+import Text.Parsec
72−import Control.Monad (liftM, when, forM)
72+import Control.Monad (liftM, when, forM, mzero)
73import System.FilePath
73import System.FilePath
74import Data.List (intercalate, intersperse)
74import Data.List (intercalate, intersperse)
75#if MIN_VERSION_blaze_html(0,5,0)
75#if MIN_VERSION_blaze_html(0,5,0)
@@ -98,7 +98,7 @@ getDefaultTemplate user writer = do
98
98
99data TemplateState = TemplateState Int [(String,String)]
99data TemplateState = TemplateState Int [(String,String)]
100
100
101−adjustPosition :: String -> GenParser Char TemplateState String
101+adjustPosition :: String -> Parsec [Char] TemplateState String
102adjustPosition str = do
102adjustPosition str = do
103 let lastline = takeWhile (/= '\n') $ reverse str
103 let lastline = takeWhile (/= '\n') $ reverse str
104 updateState $ \(TemplateState pos x) ->
104 updateState $ \(TemplateState pos x) ->
@@ -132,21 +132,21 @@ renderTemplate vals templ =
132reservedWords :: [String]
132reservedWords :: [String]
133reservedWords = ["else","endif","for","endfor","sep"]
133reservedWords = ["else","endif","for","endfor","sep"]
134
134
135−parseTemplate :: GenParser Char TemplateState [String]
135+parseTemplate :: Parsec [Char] TemplateState [String]
136parseTemplate =
136parseTemplate =
137 many $ (plaintext <|> escapedDollar <|> conditional <|> for <|> variable)
137 many $ (plaintext <|> escapedDollar <|> conditional <|> for <|> variable)
138 >>= adjustPosition
138 >>= adjustPosition
139
139
140−plaintext :: GenParser Char TemplateState String
140+plaintext :: Parsec [Char] TemplateState String
141plaintext = many1 $ noneOf "$"
141plaintext = many1 $ noneOf "$"
142
142
143−escapedDollar :: GenParser Char TemplateState String
143+escapedDollar :: Parsec [Char] TemplateState String
144escapedDollar = try $ string "$$" >> return "$"
144escapedDollar = try $ string "$$" >> return "$"
145
145
146−skipEndline :: GenParser Char st ()
146+skipEndline :: Parsec [Char] st ()
147skipEndline = try $ skipMany (oneOf " \t") >> newline >> return ()
147skipEndline = try $ skipMany (oneOf " \t") >> newline >> return ()
148
148
149−conditional :: GenParser Char TemplateState String
149+conditional :: Parsec [Char] TemplateState String
150conditional = try $ do
150conditional = try $ do
151 TemplateState pos vars <- getState
151 TemplateState pos vars <- getState
152 string "$if("
152 string "$if("
@@ -170,7 +170,7 @@ conditional = try $ do
170 then ifContents
170 then ifContents
171 else elseContents
171 else elseContents
172
172
173−for :: GenParser Char TemplateState String
173+for :: Parsec [Char] TemplateState String
174for = try $ do
174for = try $ do
175 TemplateState pos vars <- getState
175 TemplateState pos vars <- getState
176 string "$for("
176 string "$for("
@@ -193,16 +193,16 @@ for = try $ do
193 setState $ TemplateState pos vars
193 setState $ TemplateState pos vars
194 return $ concat $ intersperse sep contents
194 return $ concat $ intersperse sep contents
195
195
196−ident :: GenParser Char TemplateState String
196+ident :: Parsec [Char] TemplateState String
197ident = do
197ident = do
198 first <- letter
198 first <- letter
199 rest <- many (alphaNum <|> oneOf "_-")
199 rest <- many (alphaNum <|> oneOf "_-")
200 let id' = first : rest
200 let id' = first : rest
201 if id' `elem` reservedWords
201 if id' `elem` reservedWords
202− then pzero
202+ then mzero
203 else return id'
203 else return id'
204
204
205−variable :: GenParser Char TemplateState String
205+variable :: Parsec [Char] TemplateState String
206variable = try $ do
206variable = try $ do
207 char '$'
207 char '$'
208 id' <- ident
208 id' <- ident
src/Text/Pandoc/Writers/AsciiDoc.hs+2−2
@@ -41,7 +41,7 @@ import Text.Pandoc.Definition
41import Text.Pandoc.Templates (renderTemplate)
41import Text.Pandoc.Templates (renderTemplate)
42import Text.Pandoc.Shared
42import Text.Pandoc.Shared
43import Text.Pandoc.Parsing hiding (blankline)
43import Text.Pandoc.Parsing hiding (blankline)
44−import Text.ParserCombinators.Parsec ( runParser, GenParser )
44+import Text.Parsec ( Parsec, runParser )
45import Data.List ( isPrefixOf, intersperse, intercalate )
45import Data.List ( isPrefixOf, intersperse, intercalate )
46import Text.Pandoc.Pretty
46import Text.Pandoc.Pretty
47import Control.Monad.State
47import Control.Monad.State
@@ -93,7 +93,7 @@ escapeString = escapeStringUsing escs
93 where escs = backslashEscapes "{"
93 where escs = backslashEscapes "{"
94
94
95-- | Ordered list start parser for use in Para below.
95-- | Ordered list start parser for use in Para below.
96−olMarker :: GenParser Char ParserState Char
96+olMarker :: Parsec [Char] ParserState Char
97olMarker = do (start, style', delim) <- anyOrderedListMarker
97olMarker = do (start, style', delim) <- anyOrderedListMarker
98 if delim == Period &&
98 if delim == Period &&
99 (style' == UpperAlpha || (style' == UpperRoman &&
99 (style' == UpperAlpha || (style' == UpperRoman &&
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -36,7 +36,7 @@ import Text.Pandoc.Generic
36import Text.Pandoc.Templates (renderTemplate)
36import Text.Pandoc.Templates (renderTemplate)
37import Text.Pandoc.Shared
37import Text.Pandoc.Shared
38import Text.Pandoc.Parsing hiding (blankline)
38import Text.Pandoc.Parsing hiding (blankline)
39−import Text.ParserCombinators.Parsec ( runParser, GenParser )
39+import Text.Parsec ( Parsec, runParser )
40import Data.List ( group, isPrefixOf, find, intersperse, transpose )
40import Data.List ( group, isPrefixOf, find, intersperse, transpose )
41import Text.Pandoc.Pretty
41import Text.Pandoc.Pretty
42import Control.Monad.State
42import Control.Monad.State
@@ -188,7 +188,7 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
188 <> "=\"" <> text v <> "\"") ks
188 <> "=\"" <> text v <> "\"") ks
189
189
190-- | Ordered list start parser for use in Para below.
190-- | Ordered list start parser for use in Para below.
191−olMarker :: GenParser Char ParserState Char
191+olMarker :: Parsec [Char] ParserState Char
192olMarker = do (start, style', delim) <- anyOrderedListMarker
192olMarker = do (start, style', delim) <- anyOrderedListMarker
193 if delim == Period &&
193 if delim == Period &&
194 (style' == UpperAlpha || (style' == UpperRoman &&
194 (style' == UpperAlpha || (style' == UpperRoman &&