Skip to content

Commit

Permalink
RST reader: change treatment of number-lines directives.
Browse files Browse the repository at this point in the history
Directives of this type without numeric inputs should not have a
`startFrom` attribute; with a blank value, the writers can produce
extra whitespace.
  • Loading branch information
leungbk committed Jan 9, 2019
1 parent 253f342 commit 954434a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ includeDirective top fields body = 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 kvs = maybe [] (\n -> let tn = trimr n
in if tn == ""
then []
else [("startFrom", tn)])
numberLines
let ident = maybe "" trimr $ lookup "name" fields
let attribs = (ident, classes, kvs)
return $ B.codeBlockWith attribs contents'
Expand Down Expand Up @@ -999,9 +1003,11 @@ codeblock ident classes numberLines lang body =
: maybe [] (const ["numberLines"]) numberLines
++ classes
kvs = case numberLines of
Just "" -> []
Nothing -> []
Just n -> [("startFrom",trim n)]
Just n
| trn == "" -> []
| otherwise -> [("startFrom", trn)]
where trn = trimr n

---
--- note block
Expand Down
4 changes: 2 additions & 2 deletions test/Tests/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ 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"
] =?>
doc (codeBlockWith
( ""
, ["python", "numberLines"]
, [ ("startFrom", "") ]
, []
)
"def func(x):\n return y")
, testGroup "literal / line / code blocks"
Expand Down
6 changes: 6 additions & 0 deletions test/command/5182.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
pandoc -f rst -t native
.. include:: command/5182.txt
^D
[CodeBlock ("",["python","numberLines"],[]) "def func(x):\n return y"]
```
5 changes: 5 additions & 0 deletions test/command/5182.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. code::python
:number-lines:

def func(x):
return y

0 comments on commit 954434a

Please sign in to comment.