diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-11-17 03:36:04 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-11-17 03:36:04 +0000 |
commit | 9d20eeb019a6c5208342bfc3f03ae47c9aa83483 (patch) | |
tree | 5cef381c2f813eb272c7a3bb7d0787557a3c213e | |
parent | fce48c392acd5c56141ce924f4aaa8fadd10085d (diff) | |
download | pandoc-9d20eeb019a6c5208342bfc3f03ae47c9aa83483.tar.gz |
Support for "..code-block" directive in RST reader.
Not core RST, but used in Sphinx for code blocks annotated with
syntax information. Thanks to Luke Plant for the patch.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1619 788f1e2b-df1e-0410-8736-df70ead52e1b
-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 ===== |