git.iko.soy/typeable/pandoc
on master help sign in
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

commit9d20eeb019a6c5208342bfc3f03ae47c9aa83483 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateTue 17 Nov 2009, 03:36 (17 years ago) parentfce48c3
3 files changed+20
src/Text/Pandoc/Readers/RST.hs+11 tests/rst-reader.native+2 tests/rst-reader.rst+7
src/Text/Pandoc/Readers/RST.hs+11
@@ -122,6 +122,7 @@ block = choice [ codeBlock
122122 , fieldList
123123 , blockQuote
124124 , imageBlock
125+ , customCodeBlock
125126 , unknownDirective
126127 , header
127128 , hrule
@@ -331,6 +332,16 @@ codeBlock = try $ do
331332 result <- indentedBlock
332333 return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
333334
335+-- | The 'code-block' directive (from Sphinx) that allows a language to be
336+-- specified.
337+customCodeBlock :: GenParser Char st Block
338+customCodeBlock = try $ do
339+ string ".. code-block:: "
340+ language <- manyTill anyChar newline
341+ blanklines
342+ result <- indentedBlock
343+ return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
344+
334345lhsCodeBlock :: GenParser Char ParserState Block
335346lhsCodeBlock = try $ do
336347 failUnlessLHS
tests/rst-reader.native+2
@@ -43,6 +43,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str
4343, CodeBlock ("",[],[]) "this code block is indented by one tab"
4444, Para [Str "And",Str ":"]
4545, CodeBlock ("",[],[]) "this block is indented by two tabs\n\nThese should not be escaped: \\$ \\\\ \\> \\[ \\{"
46+, Para [Str "And",Str ":"]
47+, CodeBlock ("",["sourceCode","python"],[]) "def my_function(x):\n return x + 1"
4648, Header 1 [Str "Lists"]
4749, Header 2 [Str "Unordered"]
4850, Para [Str "Asterisks",Space,Str "tight",Str ":"]
tests/rst-reader.rst+7
@@ -101,6 +101,13 @@ And::
101101
102102 These should not be escaped: \$ \\ \> \[ \{
103103
104+And:
105+
106+.. code-block:: python
107+
108+ def my_function(x):
109+ return x + 1
110+
104111Lists
105112=====
106113