git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Fixed `..include::` directive.

Closes #3880.

commit8fcf66453cc4f9d1cf9413aa466477e56290d733 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 27 Aug 2017, 17:01 (9 years ago) parent6437695
4 files changed+17−9
pandoc.cabal+1 src/Text/Pandoc/Readers/RST.hs+9−9 test/command/3880.md+6 test/command/3880.txt+1
pandoc.cabal+1
@@ -138,6 +138,7 @@ Extra-Source-Files:
138138 test/*.native
139139 test/command/*.md
140140 test/command/3533-rst-csv-tables.csv
141+ test/command/3880.txt
141142 test/command/abbrevs
142143 test/command/SVG_logo-without-xml-declaration.svg
143144 test/command/SVG_logo.svg
src/Text/Pandoc/Readers/RST.hs+9−9
@@ -219,7 +219,6 @@ block = choice [ codeBlock
219219 , directive
220220 , anchor
221221 , comment
222− , include
223222 , header
224223 , hrule
225224 , lineBlock -- must go before definitionList
@@ -460,16 +459,16 @@ tab-width
460459encoding
461460-}
462461
463−include :: PandocMonad m => RSTParser m Blocks
464−include = try $ do
465− string ".. include::"
466− skipMany spaceChar
467− f <- trim <$> anyLine
468− fields <- many $ rawFieldListItem 3
462+includeDirective :: PandocMonad m
463+ => String -> [(String, String)] -> String
464+ -> RSTParser m Blocks
465+includeDirective top fields body = do
466+ let f = trim top
467+ guard $ not (null f)
468+ guard $ null (trim body)
469469 -- options
470470 let (startLine :: Maybe Int) = lookup "start-line" fields >>= safeRead
471471 let (endLine :: Maybe Int) = lookup "end-line" fields >>= safeRead
472− guard $ not (null f)
473472 oldPos <- getPosition
474473 oldInput <- getInput
475474 containers <- stateContainers <$> getState
@@ -501,7 +500,7 @@ include = try $ do
501500 Just patt -> drop 1 .
502501 dropWhile (not . (patt `isInfixOf`))
503502 Nothing -> id) $ contentLines'
504− let contents' = unlines contentLines''
503+ let contents' = unlines contentLines'' ++ "\n"
505504 case lookup "code" fields of
506505 Just lang -> do
507506 let numberLines = lookup "number-lines" fields
@@ -687,6 +686,7 @@ directive' = do
687686 $ lookup "height" fields >>=
688687 (lengthToDim . filter (not . isSpace))
689688 case label of
689+ "include" -> includeDirective top fields body'
690690 "table" -> tableDirective top fields body'
691691 "list-table" -> listTableDirective top fields body'
692692 "csv-table" -> csvTableDirective top fields body'
test/command/3880.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+pandoc -f rst -t native
3+.. include:: command/3880.txt
4+^D
5+[Para [Str "hi"]]
6+```
test/command/3880.txtnew file+1
@@ -0,0 +1 @@
1+hi