aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pandoc.cabal1
-rw-r--r--src/Text/Pandoc/Readers/RST.hs30
-rw-r--r--test/Tests/Readers/RST.hs4
-rw-r--r--test/command/5182.md6
-rw-r--r--test/command/5182.txt5
5 files changed, 29 insertions, 17 deletions
diff --git a/pandoc.cabal b/pandoc.cabal
index d1d9e6b02..c7d61cde8 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -189,6 +189,7 @@ extra-source-files:
test/command/*.md
test/command/3533-rst-csv-tables.csv
test/command/3880.txt
+ test/command/5182.txt
test/command/abbrevs
test/command/SVG_logo-without-xml-declaration.svg
test/command/SVG_logo.svg
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index ee2c2e904..d374846fb 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -41,7 +41,7 @@ import Data.Char (isHexDigit, isSpace, toLower, toUpper, isAlphaNum)
import Data.List (deleteFirstsBy, elemIndex, intercalate, isInfixOf, isSuffixOf,
nub, sort, transpose)
import qualified Data.Map as M
-import Data.Maybe (fromMaybe, isJust)
+import Data.Maybe (fromMaybe)
import Data.Sequence (ViewR (..), viewr)
import Data.Text (Text)
import qualified Data.Text as T
@@ -503,12 +503,9 @@ includeDirective top fields body = do
case lookup "code" fields of
Just lang -> do
let numberLines = lookup "number-lines" fields
- let classes = trimr lang : ["numberLines" | isJust numberLines] ++
- maybe [] words (lookup "class" fields)
- let kvs = maybe [] (\n -> [("startFrom", trimr n)]) numberLines
+ let classes = maybe [] words (lookup "class" fields)
let ident = maybe "" trimr $ lookup "name" fields
- let attribs = (ident, classes, kvs)
- return $ B.codeBlockWith attribs contents'
+ codeblock ident classes numberLines (trimr lang) contents' False
Nothing -> case lookup "literal" fields of
Just _ -> return $ B.rawBlock "rst" contents'
Nothing -> do
@@ -739,7 +736,7 @@ directive' = do
role -> role })
x | x == "code" || x == "code-block" || x == "sourcecode" ->
codeblock name classes
- (lookup "number-lines" fields) (trim top) body
+ (lookup "number-lines" fields) (trim top) body True
"aafig" -> do
let attribs = (name, ["aafig"], map (second trimr) fields)
return $ B.codeBlockWith attribs $ stripTrailingNewlines body
@@ -990,18 +987,21 @@ toChunks = dropWhile null
then "\\begin{aligned}\n" ++ s ++ "\n\\end{aligned}"
else s
-codeblock :: String -> [String] -> Maybe String -> String -> String
+codeblock :: String -> [String] -> Maybe String -> String -> String -> Bool
-> RSTParser m Blocks
-codeblock ident classes numberLines lang body =
- return $ B.codeBlockWith attribs $ stripTrailingNewlines body
- where attribs = (ident, classes', kvs)
+codeblock ident classes numberLines lang body rmTrailingNewlines =
+ return $ B.codeBlockWith attribs $ stripTrailingNewlines' body
+ where stripTrailingNewlines' = if rmTrailingNewlines
+ then stripTrailingNewlines
+ else id
+ attribs = (ident, classes', kvs)
classes' = lang
: maybe [] (const ["numberLines"]) numberLines
++ classes
- kvs = case numberLines of
- Just "" -> []
- Nothing -> []
- Just n -> [("startFrom",trim n)]
+ kvs = maybe [] (\n -> case trimr n of
+ [] -> []
+ xs -> [("startFrom", xs)])
+ numberLines
---
--- note block
diff --git a/test/Tests/Readers/RST.hs b/test/Tests/Readers/RST.hs
index d69440843..9e2253cc4 100644
--- a/test/Tests/Readers/RST.hs
+++ b/test/Tests/Readers/RST.hs
@@ -112,7 +112,7 @@ tests = [ "line block with blank line" =:
"def func(x):\n return y")
, "Code directive with number-lines, no line specified" =: T.unlines
[ ".. code::python"
- , " :number-lines: "
+ , " :number-lines:"
, ""
, " def func(x):"
, " return y"
@@ -120,7 +120,7 @@ tests = [ "line block with blank line" =:
doc (codeBlockWith
( ""
, ["python", "numberLines"]
- , [ ("startFrom", "") ]
+ , []
)
"def func(x):\n return y")
, testGroup "literal / line / code blocks"
diff --git a/test/command/5182.md b/test/command/5182.md
new file mode 100644
index 000000000..dc30a12ce
--- /dev/null
+++ b/test/command/5182.md
@@ -0,0 +1,6 @@
+```
+pandoc -f rst -t native
+.. include:: command/5182.txt
+^D
+[CodeBlock ("",["python","numberLines"],[]) "def func(x):\n return y"]
+```
diff --git a/test/command/5182.txt b/test/command/5182.txt
new file mode 100644
index 000000000..f1580ef0e
--- /dev/null
+++ b/test/command/5182.txt
@@ -0,0 +1,5 @@
+.. code::python
+ :number-lines:
+
+ def func(x):
+ return y