git.iko.soy/typeable/pandoc
on master help sign in
parse RST quoted literal blocks

closes #65 RST quoted literal blocks are the same as indented literal blocks (which pandoc already supports) except that the quote character is preserved in each line. This includes test cases for the quoted literal block, as well as additional tests for line blocks and indented literal blocks, to verify that these are unaffected by the changes.

commit2cdfa5eb207ca07d96235eb018928812f21da593 authorDaniel Bergey <bergey@alum.mit.edu> dateMon 1 Dec 2014, 16:27 (12 years ago) parent4d296f7
2 files changed+25−2
src/Text/Pandoc/Readers/RST.hs+9−1 tests/Tests/Readers/RST.hs+16−1
src/Text/Pandoc/Readers/RST.hs+9−1
@@ -335,6 +335,13 @@ indentedBlock = try $ do
335335 optional blanklines
336336 return $ unlines lns
337337
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+
338345codeBlockStart :: Parser [Char] st Char
339346codeBlockStart = string "::" >> blankline >> blankline
340347
@@ -342,7 +349,8 @@ codeBlock :: Parser [Char] st Blocks
342349codeBlock = try $ codeBlockStart >> codeBlockBody
343350
344351codeBlockBody :: Parser [Char] st Blocks
345−codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$> indentedBlock
352+codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$>
353+ (indentedBlock <|> quotedBlock)
346354
347355lhsCodeBlock :: RSTParser Blocks
348356lhsCodeBlock = try $ do
tests/Tests/Readers/RST.hs+16−1
@@ -67,5 +67,20 @@ tests = [ "line block with blank line" =:
6767 link "http://foo.bar.baz" "" "http://foo.bar.baz" <> ". " <>
6868 link "http://foo.bar/baz_(bam)" "" "http://foo.bar/baz_(bam)"
6969 <> " (" <> 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"
7086 ]
71−