git.iko.soy/typeable/pandoc
on master help sign in
Move manyUntil to Text.Pandoc.Parsing and use it in Txt2Tags reader
5a9d7d2Alexander Krotov
src/Text/Pandoc/Parsing.hs+15
@@ -40,6 +40,7 @@ module Text.Pandoc.Parsing ( takeWhileP,
40 anyLineNewline,
40 anyLineNewline,
41 indentWith,
41 indentWith,
42 many1Till,
42 many1Till,
43+ manyUntil,
43 notFollowedBy',
44 notFollowedBy',
44 oneOfStrings,
45 oneOfStrings,
45 oneOfStringsCI,
46 oneOfStringsCI,
@@ -325,6 +326,20 @@ many1Till p end = do
325 rest <- manyTill p end
326 rest <- manyTill p end
326 return (first:rest)
327 return (first:rest)
327
328
329+-- | Like @manyTill@, but also returns the result of end parser.
330+manyUntil :: (Stream s m t)
331+ => ParserT s u m a
332+ -> ParserT s u m b
333+ -> ParserT s u m ([a], b)
334+manyUntil p end = scan
335+ where scan =
336+ (do e <- end
337+ return ([], e)
338+ ) <|>
339+ (do x <- p
340+ (xs, e) <- scan
341+ return (x:xs, e))
342+
328-- | A more general form of @notFollowedBy@. This one allows any
343-- | A more general form of @notFollowedBy@. This one allows any
329-- type of parser to be specified, and succeeds only if that parser fails.
344-- type of parser to be specified, and succeeds only if that parser fails.
330-- It does not consume any input.
345-- It does not consume any input.
src/Text/Pandoc/Readers/Muse.hs−14
@@ -189,20 +189,6 @@ atStart p = do
189 guard $ museLastStrPos st /= Just pos
189 guard $ museLastStrPos st /= Just pos
190 p
190 p
191
191
192−-- Like manyTill, but also returns result of end parser
193−manyUntil :: (Stream s m t)
194− => ParserT s u m a
195− -> ParserT s u m b
196− -> ParserT s u m ([a], b)
197−manyUntil p end = scan
198− where scan =
199− (do e <- end
200− return ([], e)
201− ) <|>
202− (do x <- p
203− (xs, e) <- scan
204− return (x:xs, e))
205−
206someUntil :: (Stream s m t)
192someUntil :: (Stream s m t)
207 => ParserT s u m a
193 => ParserT s u m a
208 -> ParserT s u m b
194 -> ParserT s u m b
src/Text/Pandoc/Readers/Txt2Tags.hs+1−2
@@ -529,8 +529,7 @@ image = try $ do
529 -- List taken from txt2tags source
529 -- List taken from txt2tags source
530 let extensions = [".jpg", ".jpeg", ".gif", ".png", ".eps", ".bmp"]
530 let extensions = [".jpg", ".jpeg", ".gif", ".png", ".eps", ".bmp"]
531 char '['
531 char '['
532− path <- manyTill (noneOf "\n\t\r ") (try $ lookAhead (oneOfStrings extensions))
532+ (path, ext) <- manyUntil (noneOf "\n\t\r ") (oneOfStrings extensions)
533− ext <- oneOfStrings extensions
534 char ']'
533 char ']'
535 return $ B.image (path ++ ext) "" mempty
534 return $ B.image (path ++ ext) "" mempty
536
535
test/Tests/Readers/Txt2Tags.hs+4−1
@@ -96,9 +96,12 @@ tests =
96 , "Autolink" =:
96 , "Autolink" =:
97 "http://www.google.com" =?>
97 "http://www.google.com" =?>
98 para (link "http://www.google.com" "" (str "http://www.google.com"))
98 para (link "http://www.google.com" "" (str "http://www.google.com"))
99− , "Image" =:
99+ , "JPEG Image" =:
100 "[image.jpg]" =?>
100 "[image.jpg]" =?>
101 para (image "image.jpg" "" mempty)
101 para (image "image.jpg" "" mempty)
102+ , "PNG Image" =:
103+ "[image.png]" =?>
104+ para (image "image.png" "" mempty)
102
105
103 , "Link" =:
106 , "Link" =:
104 "[title http://google.com]" =?>
107 "[title http://google.com]" =?>