aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-07-09 12:27:41 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-07-09 12:27:41 -0700
commitae22b1e977cfb1357bb21fabc227e76a6adb0599 (patch)
tree61c666692c7115a4f693cdee6d0482819b77a4f2 /src/Text
parent565330033a623ed7bf4d0a3b57dd14710cf27703 (diff)
downloadpandoc-ae22b1e977cfb1357bb21fabc227e76a6adb0599.tar.gz
RST reader: fix regression with code includes.
With the recent changes to include infrastructure, included code blocks were getting an extra newline. Closes #7436. Added regression test.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 35292d949..3990f0cb5 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -474,6 +474,7 @@ includeDirective top fields body = do
case lookup "literal" fields of
Just _ -> B.rawBlock "rst" . sourcesToText <$> getInput
Nothing -> parseBlocks
+ let isLiteral = isJust (lookup "code" fields `mplus` lookup "literal" fields)
let selectLines =
(case trim <$> lookup "end-before" fields of
Just patt -> takeWhile (not . (patt `T.isInfixOf`))
@@ -482,8 +483,11 @@ includeDirective top fields body = do
Just patt -> drop 1 .
dropWhile (not . (patt `T.isInfixOf`))
Nothing -> id)
+
let toStream t =
- toSources [(f, T.unlines . selectLines . T.lines $ t)]
+ Sources [(initialPos f,
+ (T.unlines . selectLines . T.lines $ t) <>
+ if isLiteral then mempty else "\n")] -- see #7436
currentDir <- takeDirectory . sourceName <$> getPosition
insertIncludedFile parser toStream [currentDir] f startLine endLine