diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index d93f5e8e5fca..015728fe251b 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -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 = insertBS . filter hasContents . removeSpaceAfterDisplayMath + 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 diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs index 4c0a926bb556..dd7c715dcfcd 100644 --- a/test/Tests/Writers/RST.hs +++ b/test/Tests/Writers/RST.hs @@ -50,6 +50,12 @@ tests = [ testGroup "rubrics" , "" , " quoted"] ] + , testGroup "inlines" + [ "are removed when empty" =: -- #4434 + plain (strong (str "")) =?> "" + , "do not cause the introduction of extra spaces when removed" =: + plain (strong (str "") <> emph (str "text")) =?> "*text*" + ] , testGroup "headings" [ "normal heading" =: header 1 (text "foo") =?>