diff options
| author | John MacFarlane <[email protected]> | 2025-03-17 09:56:49 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-03-17 09:56:49 -0700 |
| commit | f717d1bccc9448b588e279e5f101b2f4963b57a7 (patch) | |
| tree | a22eb5803bc9240daf9d0bb29dfa24279b87f4f8 /src | |
| parent | 6af1459a2bd9956000341d629672911f23c7b309 (diff) | |
Markdown writer: avoid spaces after/before open/close delimiters.
E.g. instead of rendering `x<em> space </em>y` as `x* space *y`
we render it as `x *space* y`.
Closes #10696.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown/Inline.hs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index c45132bea..0f6c74597 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -372,9 +372,9 @@ inlineToMarkdown opts (Emph lst) = do contents <- inlineListToMarkdown opts lst return $ case variant of PlainText - | isEnabled Ext_gutenberg opts -> "_" <> contents <> "_" + | isEnabled Ext_gutenberg opts -> surroundInlines "_" "_" contents | otherwise -> contents - _ -> "*" <> contents <> "*" + _ -> surroundInlines "*" "*" contents inlineToMarkdown _ (Underline []) = return empty inlineToMarkdown opts (Underline lst) = do variant <- asks envVariant @@ -382,7 +382,7 @@ inlineToMarkdown opts (Underline lst) = do case variant of PlainText -> return contents _ | isEnabled Ext_bracketed_spans opts -> - return $ "[" <> contents <> "]" <> "{.underline}" + return $ surroundInlines "[" "]{.underline}" contents | isEnabled Ext_native_spans opts -> return $ tagWithAttrs "span" ("", ["underline"], []) <> contents @@ -401,12 +401,12 @@ inlineToMarkdown opts (Strong lst) = do else lst _ -> do contents <- inlineListToMarkdown opts lst - return $ "**" <> contents <> "**" + return $ surroundInlines "**" "**" contents inlineToMarkdown _ (Strikeout []) = return empty inlineToMarkdown opts (Strikeout lst) = do contents <- inlineListToMarkdown opts lst return $ if isEnabled Ext_strikeout opts - then "~~" <> contents <> "~~" + then surroundInlines "~~" "~~" contents else if isEnabled Ext_raw_html opts then "<s>" <> contents <> "</s>" else contents @@ -415,7 +415,7 @@ inlineToMarkdown opts (Superscript lst) = local (\env -> env {envEscapeSpaces = envVariant env == Markdown}) $ do contents <- inlineListToMarkdown opts lst if isEnabled Ext_superscript opts - then return $ "^" <> contents <> "^" + then return $ surroundInlines "^" "^" contents else if isEnabled Ext_raw_html opts then return $ "<sup>" <> contents <> "</sup>" else @@ -433,7 +433,7 @@ inlineToMarkdown opts (Subscript lst) = local (\env -> env {envEscapeSpaces = envVariant env == Markdown}) $ do contents <- inlineListToMarkdown opts lst if isEnabled Ext_subscript opts - then return $ "~" <> contents <> "~" + then return $ surroundInlines "~" "~" contents else if isEnabled Ext_raw_html opts then return $ "<sub>" <> contents <> "</sub>" else @@ -511,7 +511,7 @@ inlineToMarkdown opts (Math InlineMath str) = do _ | isEnabled Ext_tex_math_gfm opts -> return $ "$`" <> literal str <> "`$" | isEnabled Ext_tex_math_dollars opts -> - return $ "$" <> literal str <> "$" + return $ surroundInlines "$" "$" (literal str) | isEnabled Ext_tex_math_single_backslash opts -> return $ "\\(" <> literal str <> "\\)" | isEnabled Ext_tex_math_double_backslash opts -> @@ -540,7 +540,7 @@ inlineToMarkdown opts (Math DisplayMath str) = do $$ literal str $$ literal "```") <> cr | isEnabled Ext_tex_math_dollars opts -> - return $ "$$" <> literal str <> "$$" + return $ surroundInlines "$$" "$$" (literal str) | isEnabled Ext_tex_math_single_backslash opts -> return $ "\\[" <> literal str <> "\\]" | isEnabled Ext_tex_math_double_backslash opts -> |
