aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorBrian Leung <bkleung89@gmail.com>2019-01-10 07:19:26 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2019-01-09 22:19:26 -0800
commit35971495abbc15342f0035040f964ed4dd3b0c5d (patch)
treeadbe19d99871c61399ba2de708e0b87fe3ecf374 /src/Text/Pandoc
parent483012552aa4ac8fccd733f81110dcebcf1afdd4 (diff)
downloadpandoc-35971495abbc15342f0035040f964ed4dd3b0c5d.tar.gz
RST reader: change treatment of `number-lines` directives. (#5207)
Directives of this type without numeric inputs should not have a `startFrom` attribute; with a blank value, the writers can produce extra whitespace.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs30
1 files changed, 15 insertions, 15 deletions
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