git.iko.soy/typeable/pandoc
on master help sign in
parse RST quoted literal blocks
2cdfa5eDaniel Bergey
src/Text/Pandoc/Readers/RST.hs+9−1
@@ -335,6 +335,13 @@ indentedBlock = try $ do
335 optional blanklines
335 optional blanklines
336 return $ unlines lns
336 return $ unlines lns
337
337
338+quotedBlock :: Parser [Char] st [Char]
339+quotedBlock = try $ do
340+ quote <- lookAhead $ oneOf "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
341+ lns <- many1 $ lookAhead (char quote) >> anyLine
342+ optional blanklines
343+ return $ unlines lns
344+
338codeBlockStart :: Parser [Char] st Char
345codeBlockStart :: Parser [Char] st Char
339codeBlockStart = string "::" >> blankline >> blankline
346codeBlockStart = string "::" >> blankline >> blankline
340
347
@@ -342,7 +349,8 @@ codeBlock :: Parser [Char] st Blocks
342codeBlock = try $ codeBlockStart >> codeBlockBody
349codeBlock = try $ codeBlockStart >> codeBlockBody
343
350
344codeBlockBody :: Parser [Char] st Blocks
351codeBlockBody :: Parser [Char] st Blocks
345−codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$> indentedBlock
352+codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
353+ (indentedBlock <|> quotedBlock)
346
354
347lhsCodeBlock :: RSTParser Blocks
355lhsCodeBlock :: RSTParser Blocks
348lhsCodeBlock = try $ do
356lhsCodeBlock = try $ do
tests/Tests/Readers/RST.hs+16−1
@@ -67,5 +67,20 @@ tests = [ "line block with blank line" =:
67 link "http://foo.bar.baz" "" "http://foo.bar.baz" <> ". " <>
67 link "http://foo.bar.baz" "" "http://foo.bar.baz" <> ". " <>
68 link "http://foo.bar/baz_(bam)" "" "http://foo.bar/baz_(bam)"
68 link "http://foo.bar/baz_(bam)" "" "http://foo.bar/baz_(bam)"
69 <> " (" <> link "http://foo.bar" "" "http://foo.bar" <> ")")
69 <> " (" <> link "http://foo.bar" "" "http://foo.bar" <> ")")
70+ , "indented literal block" =: unlines
71+ [ "::"
72+ , ""
73+ , " block quotes"
74+ , ""
75+ , " can go on for many lines"
76+ , "but must stop here"]
77+ =?> (doc $
78+ codeBlock "block quotes\n\ncan go on for many lines" <>
79+ para "but must stop here")
80+ , "line block with 3 lines" =: "| a\n| b\n| c"
81+ =?> para ("a" <> linebreak <> "b" <> linebreak <> "c")
82+ , "quoted literal block using >" =: "::\n\n> quoted\n> block\n\nOrdinary paragraph"
83+ =?> codeBlock "> quoted\n> block" <> para "Ordinary paragraph"
84+ , "quoted literal block using | (not a line block)" =: "::\n\n| quoted\n| block\n\nOrdinary paragraph"
85+ =?> codeBlock "| quoted\n| block" <> para "Ordinary paragraph"
70 ]
86 ]
71−