diff options
author | Francesco Occhipinti <focchi.pinti@gmail.com> | 2018-03-18 04:39:26 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-03-17 20:39:26 -0700 |
commit | ba965d17365f3b6d14f3fd652d0a0d03a491057f (patch) | |
tree | da4a605f99dfebc6b8760e1f60722e894d579801 | |
parent | e5845f33ad071dbea142ef1ff96d689fe7a71b86 (diff) | |
download | pandoc-ba965d17365f3b6d14f3fd652d0a0d03a491057f.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 21 | ||||
-rw-r--r-- | test/Tests/Writers/RST.hs | 18 |
2 files changed, 29 insertions, 10 deletions
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 diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs index b8778f995..884281af2 100644 --- a/test/Tests/Writers/RST.hs +++ b/test/Tests/Writers/RST.hs @@ -50,14 +50,18 @@ tests = [ testGroup "rubrics" , "" , " quoted"] ] - , testGroup "spaces are stripped within inlines" - -- pandoc issue 4327 "The text within inline markup may not - -- begin or end with whitespace" - -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup - [ "multiple" =: + , 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*" + , "spaces are stripped at beginning and end" =: + -- pandoc issue 4327 "The text within inline markup may not + -- begin or end with whitespace" + -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup strong (space <> str "text" <> space <> space) =?> "**text**" - , "single" =: - strong (space) =?> "****" + , "single space stripped" =: + strong (space) =?> "" ] , testGroup "headings" [ "normal heading" =: |