From 93600ec9b82f9e7ffd2b9b25eb910f022b1a8e6a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 29 Sep 2012 17:25:14 -0400 Subject: RST reader: Folded default-role parser into directive. --- src/Text/Pandoc/Readers/RST.hs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/Text/Pandoc/Readers/RST.hs') diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 2dfdd5377..a9c31b64c 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -137,7 +137,6 @@ block = choice [ codeBlock , imageBlock , figureBlock , customCodeBlock - , defaultRoleBlock , directive , header , hrule @@ -532,24 +531,6 @@ orderedList = try $ do bulletList :: RSTParser Blocks bulletList = B.bulletList . compactify' <$> many1 (listItem bulletListStart) --- --- default-role block --- - -defaultRoleBlock :: RSTParser Blocks -defaultRoleBlock = try $ do - string ".. default-role::" - -- doesn't enforce any restrictions on the role name; embedded spaces shouldn't be allowed, for one - role <- manyTill anyChar newline >>= return . trim - updateState $ \s -> s { stateRstDefaultRole = - if null role - then stateRstDefaultRole defaultParserState - else role - } - -- skip body of the directive if it exists - skipMany $ blanklines <|> (spaceChar >> manyTill anyChar newline) - return mempty - -- -- directive (e.g. comment, container, compound-paragraph) -- @@ -559,7 +540,8 @@ directive = try $ do string ".." lookAhead (char '\n') <|> spaceChar skipMany spaceChar - label <- option "" $ try $ many1Till letter (try $ string "::") + label <- option "" $ try + $ many1Till (letter <|> char '-') (try $ string "::") skipMany spaceChar top <- many $ satisfy (/='\n') <|> try (char '\n' <* notFollowedBy blankline <* @@ -572,7 +554,7 @@ directive = try $ do body <- option "" indentedBlock let body' = body ++ "\n\n" case label of - "" -> return mempty + "" -> return mempty -- comment "container" -> parseFromString parseBlocks body' "compound" -> parseFromString parseBlocks body' "pull-quote" -> B.blockQuote <$> parseFromString parseBlocks body' @@ -580,6 +562,11 @@ directive = try $ do "highlights" -> B.blockQuote <$> parseFromString parseBlocks body' "rubric" -> B.para . B.strong <$> parseFromString (trimInlines . mconcat <$> many inline) top + "default-role" -> mempty <$ updateState (\s -> + s { stateRstDefaultRole = + case trim top of + "" -> stateRstDefaultRole def + role -> role }) "math" -> return $ B.para $ mconcat $ map B.displayMath $ toChunks $ top ++ "\n\n" ++ body _ -> return mempty -- cgit v1.2.3