Skip to content

Commit

Permalink
RST writer: filter out empty inlines, closes jgm#4434
Browse files Browse the repository at this point in the history
  • Loading branch information
danse committed Mar 9, 2018
1 parent 6198363 commit cc97a7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Text/Pandoc/Writers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,23 @@ blockListToRST :: PandocMonad m
blockListToRST = blockListToRST' False

transformInlines :: [Inline] -> [Inline]
transformInlines = removeSpaceAfterDisplayMath . insertBS
where -- remove spaces after displaymath, as they screw up indentation:
transformInlines = filter hasContents . removeSpaceAfterDisplayMath . insertBS
where -- empty inlines are not valid RST syntax
hasContents :: Inline -> Bool
hasContents (Str "") = False
hasContents (Emph []) = False
hasContents (Strong []) = False
hasContents (Strikeout []) = False
hasContents (Superscript []) = False
hasContents (Subscript []) = False
hasContents (SmallCaps []) = False
hasContents (Quoted _ []) = False
hasContents (Cite _ []) = False
hasContents (Span _ []) = False
hasContents (Link _ [] ("", "")) = False
hasContents (Image _ [] ("", "")) = False
hasContents _ = True
-- remove spaces after displaymath, as they screw up indentation:
removeSpaceAfterDisplayMath (Math DisplayMath x : zs) =
Math DisplayMath x : dropWhile (==Space) zs
removeSpaceAfterDisplayMath (x:xs) = x : removeSpaceAfterDisplayMath xs
Expand Down
4 changes: 4 additions & 0 deletions test/Tests/Writers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ tests = [ testGroup "rubrics"
, ""
, " quoted"]
]
, testGroup "inlines"
[ "are removed when empty" =: -- #4434
plain (strong (str "")) =?> ""
]
, testGroup "headings"
[ "normal heading" =:
header 1 (text "foo") =?>
Expand Down

0 comments on commit cc97a7b

Please sign in to comment.