git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Folded default-role parser into directive.
93600ecJohn MacFarlane
src/Text/Pandoc/Readers/RST.hs+8−21
@@ -137,7 +137,6 @@ block = choice [ codeBlock
137 , imageBlock
137 , imageBlock
138 , figureBlock
138 , figureBlock
139 , customCodeBlock
139 , customCodeBlock
140− , defaultRoleBlock
141 , directive
140 , directive
142 , header
141 , header
143 , hrule
142 , hrule
@@ -532,24 +531,6 @@ orderedList = try $ do
532bulletList :: RSTParser Blocks
531bulletList :: RSTParser Blocks
533bulletList = B.bulletList . compactify' <$> many1 (listItem bulletListStart)
532bulletList = B.bulletList . compactify' <$> many1 (listItem bulletListStart)
534
533
535−--
536−-- default-role block
537−--
538−
539−defaultRoleBlock :: RSTParser Blocks
540−defaultRoleBlock = try $ do
541− string ".. default-role::"
542− -- doesn't enforce any restrictions on the role name; embedded spaces shouldn't be allowed, for one
543− role <- manyTill anyChar newline >>= return . trim
544− updateState $ \s -> s { stateRstDefaultRole =
545− if null role
546− then stateRstDefaultRole defaultParserState
547− else role
548− }
549− -- skip body of the directive if it exists
550− skipMany $ blanklines <|> (spaceChar >> manyTill anyChar newline)
551− return mempty
552−
553--
534--
554-- directive (e.g. comment, container, compound-paragraph)
535-- directive (e.g. comment, container, compound-paragraph)
555--
536--
@@ -559,7 +540,8 @@ directive = try $ do
559 string ".."
540 string ".."
560 lookAhead (char '\n') <|> spaceChar
541 lookAhead (char '\n') <|> spaceChar
561 skipMany spaceChar
542 skipMany spaceChar
543+ label <- option "" $ try
562− label <- option "" $ try $ many1Till letter (try $ string "::")
544+ $ many1Till (letter <|> char '-') (try $ string "::")
563 skipMany spaceChar
545 skipMany spaceChar
564 top <- many $ satisfy (/='\n')
546 top <- many $ satisfy (/='\n')
565 <|> try (char '\n' <* notFollowedBy blankline <*
547 <|> try (char '\n' <* notFollowedBy blankline <*
@@ -572,7 +554,7 @@ directive = try $ do
572 body <- option "" indentedBlock
554 body <- option "" indentedBlock
573 let body' = body ++ "\n\n"
555 let body' = body ++ "\n\n"
574 case label of
556 case label of
575− "" -> return mempty
557+ "" -> return mempty -- comment
576 "container" -> parseFromString parseBlocks body'
558 "container" -> parseFromString parseBlocks body'
577 "compound" -> parseFromString parseBlocks body'
559 "compound" -> parseFromString parseBlocks body'
578 "pull-quote" -> B.blockQuote <$> parseFromString parseBlocks body'
560 "pull-quote" -> B.blockQuote <$> parseFromString parseBlocks body'
@@ -580,6 +562,11 @@ directive = try $ do
580 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
562 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
581 "rubric" -> B.para . B.strong <$> parseFromString
563 "rubric" -> B.para . B.strong <$> parseFromString
582 (trimInlines . mconcat <$> many inline) top
564 (trimInlines . mconcat <$> many inline) top
565+ "default-role" -> mempty <$ updateState (\s ->
566+ s { stateRstDefaultRole =
567+ case trim top of
568+ "" -> stateRstDefaultRole def
569+ role -> role })
583 "math" -> return $ B.para $ mconcat $ map B.displayMath
570 "math" -> return $ B.para $ mconcat $ map B.displayMath
584 $ toChunks $ top ++ "\n\n" ++ body
571 $ toChunks $ top ++ "\n\n" ++ body
585 _ -> return mempty
572 _ -> return mempty