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