diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-05-16 12:23:34 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-05-16 12:23:34 -0700 |
commit | 5a6399d9f62c4306fa073ae1311675158dd6a203 (patch) | |
tree | 7c6de23b363b602090587ef3548c390a4817d184 /src/Text/Pandoc/Writers/Markdown | |
parent | 39a69c4f93d46e059c48a740b69dfff219a5d715 (diff) | |
download | pandoc-5a6399d9f62c4306fa073ae1311675158dd6a203.tar.gz |
Markdown writer: fewer unneeded escapes for `#`.
See #6259.
Diffstat (limited to 'src/Text/Pandoc/Writers/Markdown')
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown/Inline.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index ced5fbacb..e6c6da5a9 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -43,7 +43,11 @@ import Text.Pandoc.Writers.Markdown.Types (MarkdownVariant(..), -- | Escape special characters for Markdown. escapeText :: WriterOptions -> Text -> Text escapeText opts = T.pack . go . T.unpack - where + where + startsWithSpace (' ':_) = True + startsWithSpace ('\t':_) = True + startsWithSpace [] = True + startsWithSpace _ = False go [] = [] go (c:cs) = case c of @@ -59,7 +63,10 @@ escapeText opts = T.pack . go . T.unpack | isAlphaNum d || d == '_' || d == '{' -> '\\':'@':go cs _ -> '@':go cs - _ | c `elem` ['\\','`','*','_','[',']','#'] -> + '#' | isEnabled Ext_space_in_atx_header opts + , startsWithSpace cs + -> '\\':'#':go cs + _ | c `elem` ['\\','`','*','_','[',']'] -> '\\':c:go cs '|' | isEnabled Ext_pipe_tables opts -> '\\':'|':go cs '^' | isEnabled Ext_superscript opts -> '\\':'^':go cs @@ -81,6 +88,8 @@ escapeText opts = T.pack . go . T.unpack | isEnabled Ext_intraword_underscores opts , isAlphaNum c , isAlphaNum x -> c : '_' : x : go xs + '#':xs -> c : '#' : go xs + '>':xs -> c : '>' : go xs _ -> c : go cs attrsToMarkdown :: Attr -> Doc Text |