Markdown writer: Avoid inline surround-marking with empty content.

E.g. we don't want `<strong></strong>` to become `****`.
Similarly for emphasis, super/subscript, strikeout.

Closes #3715.
This commit is contained in:
John MacFarlane 2017-06-01 12:30:58 +02:00
parent 9396f1fb67
commit c366fab2cb
2 changed files with 20 additions and 0 deletions

View file

@ -931,12 +931,14 @@ inlineToMarkdown opts (Span attrs ils) = do
isEnabled Ext_native_spans opts ->
tagWithAttrs "span" attrs <> contents <> text "</span>"
| otherwise -> contents
inlineToMarkdown _ (Emph []) = return empty
inlineToMarkdown opts (Emph lst) = do
plain <- asks envPlain
contents <- inlineListToMarkdown opts lst
return $ if plain
then "_" <> contents <> "_"
else "*" <> contents <> "*"
inlineToMarkdown _ (Strong []) = return empty
inlineToMarkdown opts (Strong lst) = do
plain <- asks envPlain
if plain
@ -944,6 +946,7 @@ inlineToMarkdown opts (Strong lst) = do
else do
contents <- inlineListToMarkdown opts lst
return $ "**" <> contents <> "**"
inlineToMarkdown _ (Strikeout []) = return empty
inlineToMarkdown opts (Strikeout lst) = do
contents <- inlineListToMarkdown opts lst
return $ if isEnabled Ext_strikeout opts
@ -951,6 +954,7 @@ inlineToMarkdown opts (Strikeout lst) = do
else if isEnabled Ext_raw_html opts
then "<s>" <> contents <> "</s>"
else contents
inlineToMarkdown _ (Superscript []) = return empty
inlineToMarkdown opts (Superscript lst) =
local (\env -> env {envEscapeSpaces = True}) $ do
contents <- inlineListToMarkdown opts lst
@ -963,6 +967,7 @@ inlineToMarkdown opts (Superscript lst) =
in case mapM toSuperscript rendered of
Just r -> text r
Nothing -> text $ "^(" ++ rendered ++ ")"
inlineToMarkdown _ (Subscript []) = return empty
inlineToMarkdown opts (Subscript lst) =
local (\env -> env {envEscapeSpaces = True}) $ do
contents <- inlineListToMarkdown opts lst

15
test/command/3715.md Normal file
View file

@ -0,0 +1,15 @@
```
% pandoc -t markdown -f html --wrap=preserve
x<em></em>x
y<strong></strong>y
z<sup></sup>z
w<sub></sub>w
q<s></s>q
^D
xx
yy
zz
ww
qq
```