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
This commit is contained in:
parent
fce48c392a
commit
9d20eeb019
3 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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 ":"]
|
||||
|
|
|
@ -101,6 +101,13 @@ And::
|
|||
|
||||
These should not be escaped: \$ \\ \> \[ \{
|
||||
|
||||
And:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def my_function(x):
|
||||
return x + 1
|
||||
|
||||
Lists
|
||||
=====
|
||||
|
||||
|
|
Loading…
Reference in a new issue