From ba965d17365f3b6d14f3fd652d0a0d03a491057f Mon Sep 17 00:00:00 2001 From: Francesco Occhipinti Date: Sun, 18 Mar 2018 04:39:26 +0100 Subject: RST writer: filter out empty inline containers (#4434). There is nothing in RST that corresponds to e.g. `Emph []`, so we just filter out elements like this. --- src/Text/Pandoc/Writers/RST.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 28d44533a..db914a849 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -378,9 +378,24 @@ blockListToRST :: PandocMonad m blockListToRST = blockListToRST' False transformInlines :: [Inline] -> [Inline] -transformInlines = - removeLeadingTrailingSpace . removeSpaceAfterDisplayMath . insertBS - where -- remove spaces after displaymath, as they screw up indentation: +transformInlines = removeLeadingTrailingSpace . 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 -- cgit v1.2.3