diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-09-29 19:35:49 -0400 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-09-29 19:35:49 -0400 |
commit | d3b52e42eb88b1cff6ce2f4fca05f86b5651f83d (patch) | |
tree | 61f16c0117a71cae29ee1a54fa98d6403f4e8a24 | |
parent | 1948c55914c4fa61a3590c1572d3ad025c19075f (diff) | |
download | pandoc-d3b52e42eb88b1cff6ce2f4fca05f86b5651f83d.tar.gz |
RST reader: Made comments a separate parser.
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 4b18d0da6..95bd6d9c7 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -136,6 +136,7 @@ block = choice [ codeBlock , fieldList , figureBlock , directive + , comment , header , hrule , lineBlock -- must go before definitionList @@ -492,6 +493,19 @@ bulletList = B.bulletList . compactify' <$> many1 (listItem bulletListStart) -- directive (e.g. comment, container, compound-paragraph) -- +comment :: RSTParser Blocks +comment = try $ do + getPosition >>= guard . (==1) . sourceColumn + string ".." + skipMany1 spaceChar <|> (() <$ lookAhead newline) + notFollowedBy' directiveLabel + manyTill anyChar blanklines + optional indentedBlock + return mempty + +directiveLabel :: RSTParser String +directiveLabel = many1Till (letter <|> char '-') (try $ string "::") + directive :: RSTParser Blocks directive = try $ do getPosition >>= guard . (==1) . sourceColumn @@ -500,10 +514,8 @@ directive = try $ do directive' :: RSTParser Blocks directive' = do - lookAhead (char '\n') <|> spaceChar - skipMany spaceChar - label <- option "" $ try - $ many1Till (letter <|> char '-') (try $ string "::") + skipMany1 spaceChar + label <- directiveLabel skipMany spaceChar top <- many $ satisfy (/='\n') <|> try (char '\n' <* notFollowedBy blankline <* @@ -516,7 +528,6 @@ directive' = do body <- option "" indentedBlock let body' = body ++ "\n\n" case label of - "" -> return mempty -- comment "container" -> parseFromString parseBlocks body' "compound" -> parseFromString parseBlocks body' "pull-quote" -> B.blockQuote <$> parseFromString parseBlocks body' @@ -653,7 +664,7 @@ substKey = try $ do skipMany1 spaceChar (alt,ref) <- withRaw $ trimInlines . mconcat <$> enclosed (char '|') (char '|') inline - res <- B.toList <$> directive' + res <- B.toList <$> (directive' <|> para) il <- case res of -- use alt unless :alt: attribute on image: [Para [Image [Str "image"] (src,tit)]] -> |