From c366fab2cba3238a4d262fefdfe03d8acf813cf1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 1 Jun 2017 12:30:58 +0200 Subject: [PATCH] Markdown writer: Avoid inline surround-marking with empty content. E.g. we don't want `` to become `****`. Similarly for emphasis, super/subscript, strikeout. Closes #3715. --- src/Text/Pandoc/Writers/Markdown.hs | 5 +++++ test/command/3715.md | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/command/3715.md diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index efdf3852b..989d5af9d 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -931,12 +931,14 @@ inlineToMarkdown opts (Span attrs ils) = do isEnabled Ext_native_spans opts -> tagWithAttrs "span" attrs <> contents <> text "" | 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 "" <> contents <> "" 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 diff --git a/test/command/3715.md b/test/command/3715.md new file mode 100644 index 000000000..9d74779cb --- /dev/null +++ b/test/command/3715.md @@ -0,0 +1,15 @@ +``` +% pandoc -t markdown -f html --wrap=preserve +xx +yy +zz +ww +qq +^D +xx +yy +zz +ww +qq +``` +