git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: fewer unneeded escapes for `#`.

See #6259.

commit5a6399d9f62c4306fa073ae1311675158dd6a203 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 16 May 2021, 12:23 (5 years ago) parent39a69c4
6 files changed+16−7
src/Text/Pandoc/Writers/Markdown/Inline.hs+11−2 test/command/3792.md+1−1 test/command/4164.md+1−1 test/command/7208.md+1−1 test/command/biblatex-sigfridsson.md+1−1 test/writer.opml+1−1
src/Text/Pandoc/Writers/Markdown/Inline.hs+11−2
@@ -43,7 +43,11 @@ import Text.Pandoc.Writers.Markdown.Types (MarkdownVariant(..),
4343-- | Escape special characters for Markdown.
4444escapeText :: WriterOptions -> Text -> Text
4545escapeText opts = T.pack . go . T.unpack
46− where
46+ where
47+ startsWithSpace (' ':_) = True
48+ startsWithSpace ('\t':_) = True
49+ startsWithSpace [] = True
50+ startsWithSpace _ = False
4751 go [] = []
4852 go (c:cs) =
4953 case c of
@@ -59,7 +63,10 @@ escapeText opts = T.pack . go . T.unpack
5963 | isAlphaNum d || d == '_' || d == '{'
6064 -> '\\':'@':go cs
6165 _ -> '@':go cs
62− _ | c `elem` ['\\','`','*','_','[',']','#'] ->
66+ '#' | isEnabled Ext_space_in_atx_header opts
67+ , startsWithSpace cs
68+ -> '\\':'#':go cs
69+ _ | c `elem` ['\\','`','*','_','[',']'] ->
6370 '\\':c:go cs
6471 '|' | isEnabled Ext_pipe_tables opts -> '\\':'|':go cs
6572 '^' | isEnabled Ext_superscript opts -> '\\':'^':go cs
@@ -81,6 +88,8 @@ escapeText opts = T.pack . go . T.unpack
8188 | isEnabled Ext_intraword_underscores opts
8289 , isAlphaNum c
8390 , isAlphaNum x -> c : '_' : x : go xs
91+ '#':xs -> c : '#' : go xs
92+ '>':xs -> c : '>' : go xs
8493 _ -> c : go cs
8594
8695attrsToMarkdown :: Attr -> Doc Text
test/command/3792.md+1−1
@@ -6,7 +6,7 @@ and properly escaped.
66ok
77^D
88---
9−title: \<this\> \*that\*
9+title: \<this> \*that\*
1010---
1111
1212ok
test/command/4164.md+1−1
@@ -26,6 +26,6 @@ Here is inline html:
2626
2727Here is inline html:
2828
29−\<div\> \<balise\> bla bla \</div\>
29+\<div> \<balise> bla bla \</div>
3030
3131```
test/command/7208.md+1−1
@@ -2,5 +2,5 @@
22% pandoc -t gfm
33\<hi\>
44^D
5−\<hi\>
5+\<hi>
66```
test/command/biblatex-sigfridsson.md+1−1
@@ -90,7 +90,7 @@ references:
9090 - family: Ryde
9191 given: Ulf
9292 container-title: Journal of Computational Chemistry
93− doi: "10.1002/(SICI)1096-987X(199803)19:4\\<377::AID-JCC1\\>3.0.CO;2-P"
93+ doi: "10.1002/(SICI)1096-987X(199803)19:4\\<377::AID-JCC1>3.0.CO;2-P"
9494 id: sigfridsson
9595 issue: 4
9696 issued: 1998
test/writer.opml+1−1
@@ -52,7 +52,7 @@
5252</outline>
5353<outline text="LaTeX" _note="- &#10;- 2 + 2 = 4&#10;- *x* ∈ *y*&#10;- *α* ∧ *ω*&#10;- 223&#10;- *p*-Tree&#10;- Here’s some display math:&#10; $$\\frac{d}{dx}f(x)=\\lim\_{h\\to 0}\\frac{f(x+h)-f(x)}{h}$$&#10;- Here’s one that has a line break in it: *α* + *ω* × *x*².&#10;&#10;These shouldn’t be math:&#10;&#10;- To get the famous equation, write `$e = mc^2$`.&#10;- $22,000 is a *lot* of money. So is $34,000. (It worked if “lot” is&#10; emphasized.)&#10;- Shoes ($20) and socks ($5).&#10;- Escaped `$`: $73 *this should be emphasized* 23$.&#10;&#10;Here’s a LaTeX table:&#10;&#10;------------------------------------------------------------------------">
5454</outline>
55−<outline text="Special Characters" _note="Here is some unicode:&#10;&#10;- I hat: Î&#10;- o umlaut: ö&#10;- section: §&#10;- set membership: ∈&#10;- copyright: ©&#10;&#10;AT&amp;T has an ampersand in their name.&#10;&#10;AT&amp;T is another way to write it.&#10;&#10;This &amp; that.&#10;&#10;4 &amp;lt; 5.&#10;&#10;6 &amp;gt; 5.&#10;&#10;Backslash: \\&#10;&#10;Backtick: \`&#10;&#10;Asterisk: \*&#10;&#10;Underscore: \_&#10;&#10;Left brace: {&#10;&#10;Right brace: }&#10;&#10;Left bracket: \[&#10;&#10;Right bracket: \]&#10;&#10;Left paren: (&#10;&#10;Right paren: )&#10;&#10;Greater-than: &amp;gt;&#10;&#10;Hash: \#&#10;&#10;Period: .&#10;&#10;Bang: !&#10;&#10;Plus: +&#10;&#10;Minus: -&#10;&#10;------------------------------------------------------------------------">
55+<outline text="Special Characters" _note="Here is some unicode:&#10;&#10;- I hat: Î&#10;- o umlaut: ö&#10;- section: §&#10;- set membership: ∈&#10;- copyright: ©&#10;&#10;AT&amp;T has an ampersand in their name.&#10;&#10;AT&amp;T is another way to write it.&#10;&#10;This &amp; that.&#10;&#10;4 &amp;lt; 5.&#10;&#10;6 &amp;gt; 5.&#10;&#10;Backslash: \\&#10;&#10;Backtick: \`&#10;&#10;Asterisk: \*&#10;&#10;Underscore: \_&#10;&#10;Left brace: {&#10;&#10;Right brace: }&#10;&#10;Left bracket: \[&#10;&#10;Right bracket: \]&#10;&#10;Left paren: (&#10;&#10;Right paren: )&#10;&#10;Greater-than: &amp;gt;&#10;&#10;Hash: #&#10;&#10;Period: .&#10;&#10;Bang: !&#10;&#10;Plus: +&#10;&#10;Minus: -&#10;&#10;------------------------------------------------------------------------">
5656</outline>
5757<outline text="Links">
5858 <outline text="Explicit" _note="Just a [URL](/url/).&#10;&#10;[URL and title](/url/ &quot;title&quot;).&#10;&#10;[URL and title](/url/ &quot;title preceded by two spaces&quot;).&#10;&#10;[URL and title](/url/ &quot;title preceded by a tab&quot;).&#10;&#10;[URL and title](/url/ &quot;title with &quot;quotes&quot; in it&quot;)&#10;&#10;[URL and title](/url/ &quot;title with single quotes&quot;)&#10;&#10;[with\_underscore](/url/with_underscore)&#10;&#10;[Email link](mailto:nobody@nowhere.net)&#10;&#10;[Empty]().">