diff options
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 11 | ||||
-rw-r--r-- | tests/rst-reader.native | 2 | ||||
-rw-r--r-- | tests/rst-reader.rst | 7 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 89c30ff5d..9e38b1872 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -122,6 +122,7 @@ block = choice [ codeBlock , fieldList , blockQuote , imageBlock + , customCodeBlock , unknownDirective , header , hrule @@ -331,6 +332,16 @@ codeBlock = try $ do result <- indentedBlock return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result +-- | The 'code-block' directive (from Sphinx) that allows a language to be +-- specified. +customCodeBlock :: GenParser Char st Block +customCodeBlock = try $ do + string ".. code-block:: " + language <- manyTill anyChar newline + blanklines + result <- indentedBlock + return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result + lhsCodeBlock :: GenParser Char ParserState Block lhsCodeBlock = try $ do failUnlessLHS diff --git a/tests/rst-reader.native b/tests/rst-reader.native index 8848fa111..294be318c 100644 --- a/tests/rst-reader.native +++ b/tests/rst-reader.native @@ -43,6 +43,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str , CodeBlock ("",[],[]) "this code block is indented by one tab" , Para [Str "And",Str ":"] , CodeBlock ("",[],[]) "this block is indented by two tabs\n\nThese should not be escaped: \\$ \\\\ \\> \\[ \\{" +, Para [Str "And",Str ":"] +, CodeBlock ("",["sourceCode","python"],[]) "def my_function(x):\n return x + 1" , Header 1 [Str "Lists"] , Header 2 [Str "Unordered"] , Para [Str "Asterisks",Space,Str "tight",Str ":"] diff --git a/tests/rst-reader.rst b/tests/rst-reader.rst index 2cc99d294..676698430 100644 --- a/tests/rst-reader.rst +++ b/tests/rst-reader.rst @@ -101,6 +101,13 @@ And:: These should not be escaped: \$ \\ \> \[ \{ +And: + +.. code-block:: python + + def my_function(x): + return x + 1 + Lists ===== |