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.
This commit is contained in:
parent
e5845f33ad
commit
ba965d1736
2 changed files with 29 additions and 10 deletions
|
@ -378,9 +378,24 @@ blockListToRST :: PandocMonad m
|
||||||
blockListToRST = blockListToRST' False
|
blockListToRST = blockListToRST' False
|
||||||
|
|
||||||
transformInlines :: [Inline] -> [Inline]
|
transformInlines :: [Inline] -> [Inline]
|
||||||
transformInlines =
|
transformInlines = removeLeadingTrailingSpace . insertBS
|
||||||
removeLeadingTrailingSpace . removeSpaceAfterDisplayMath . insertBS
|
. filter hasContents . removeSpaceAfterDisplayMath
|
||||||
where -- remove spaces after displaymath, as they screw up indentation:
|
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) =
|
removeSpaceAfterDisplayMath (Math DisplayMath x : zs) =
|
||||||
Math DisplayMath x : dropWhile (==Space) zs
|
Math DisplayMath x : dropWhile (==Space) zs
|
||||||
removeSpaceAfterDisplayMath (x:xs) = x : removeSpaceAfterDisplayMath xs
|
removeSpaceAfterDisplayMath (x:xs) = x : removeSpaceAfterDisplayMath xs
|
||||||
|
|
|
@ -50,14 +50,18 @@ tests = [ testGroup "rubrics"
|
||||||
, ""
|
, ""
|
||||||
, " quoted"]
|
, " quoted"]
|
||||||
]
|
]
|
||||||
, testGroup "spaces are stripped within inlines"
|
, testGroup "inlines"
|
||||||
-- pandoc issue 4327 "The text within inline markup may not
|
[ "are removed when empty" =: -- #4434
|
||||||
-- begin or end with whitespace"
|
plain (strong (str "")) =?> ""
|
||||||
-- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup
|
, "do not cause the introduction of extra spaces when removed" =:
|
||||||
[ "multiple" =:
|
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**"
|
strong (space <> str "text" <> space <> space) =?> "**text**"
|
||||||
, "single" =:
|
, "single space stripped" =:
|
||||||
strong (space) =?> "****"
|
strong (space) =?> ""
|
||||||
]
|
]
|
||||||
, testGroup "headings"
|
, testGroup "headings"
|
||||||
[ "normal heading" =:
|
[ "normal heading" =:
|
||||||
|
|
Loading…
Add table
Reference in a new issue