aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-29 17:37:38 -0400
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-29 17:37:38 -0400
commit720a7ba0fcbc21411bb6d4da57d64b7a05a58ed8 (patch)
treee1cf0ef1f2807c89188058f24ee377c316bd7c2b /src/Text
parent93600ec9b82f9e7ffd2b9b25eb910f022b1a8e6a (diff)
downloadpandoc-720a7ba0fcbc21411bb6d4da57d64b7a05a58ed8.tar.gz
RST reader: Folded code block parsers into directive.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index a9c31b64c..b742c9d02 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -136,7 +136,6 @@ block = choice [ codeBlock
, fieldList
, imageBlock
, figureBlock
- , customCodeBlock
, directive
, header
, hrule
@@ -234,9 +233,9 @@ para = try $ do
blanklines
case viewr (B.unMany result) of
ys :> (Str xs) | "::" `isSuffixOf` xs -> do
- codeblock <- option mempty codeBlockBody
+ raw <- option mempty codeBlockBody
return $ B.para (B.Many ys <> B.str (take (length xs - 1) xs))
- <> codeblock
+ <> raw
_ -> return (B.para result)
plain :: RSTParser Blocks
@@ -362,21 +361,6 @@ codeBlock = try $ codeBlockStart >> codeBlockBody
codeBlockBody :: Parser [Char] st Blocks
codeBlockBody = try $ B.codeBlock . stripTrailingNewlines <$> indentedBlock
--- | The 'code-block' directive (from Sphinx) that allows a language to be
--- specified.
-customCodeBlock :: Parser [Char] st Blocks
-customCodeBlock = try $ do
- string ".. "
- string "code"
- optional $ string "-block"
- string "::"
- skipSpaces
- language <- manyTill anyChar newline
- blanklines
- result <- indentedBlock
- return $ B.codeBlockWith ("", ["sourceCode", language], [])
- $ stripTrailingNewlines result
-
figureBlock :: RSTParser Blocks
figureBlock = try $ do
string ".. figure::"
@@ -567,6 +551,8 @@ directive = try $ do
case trim top of
"" -> stateRstDefaultRole def
role -> role })
+ "code" -> codeblock (lookup "number-lines" fields) (trim top) body
+ "code-block" -> codeblock (lookup "number-lines" fields) (trim top) body
"math" -> return $ B.para $ mconcat $ map B.displayMath
$ toChunks $ top ++ "\n\n" ++ body
_ -> return mempty
@@ -577,6 +563,17 @@ toChunks = dropWhile null
. map (trim . unlines)
. splitBy (all (`elem` " \t")) . lines
+codeblock :: Maybe String -> String -> String -> RSTParser Blocks
+codeblock numberLines lang body =
+ return $ B.codeBlockWith attribs $ stripTrailingNewlines body
+ where attribs = ("", classes, kvs)
+ classes = "sourceCode" : lang
+ : maybe [] (\_ -> ["numberLines"]) numberLines
+ kvs = case numberLines of
+ Just "" -> []
+ Nothing -> []
+ Just n -> [("startFrom",n)]
+
---
--- note block
---