Markdown writer: update escaping rules for \
.
We now escape `\` only if `raw_tex` is enabled or it is followed by a non-alphanumeric.
This commit is contained in:
parent
abffe63274
commit
9b5ec100e5
3 changed files with 15 additions and 20 deletions
|
@ -68,8 +68,16 @@ escapeText opts = T.pack . go' . T.unpack
|
|||
go [] = []
|
||||
go (c:cs) =
|
||||
case c of
|
||||
_ | c `elem` ['\\','`','*','_','[',']'] ->
|
||||
'\\':c:go cs
|
||||
'[' -> '\\':c:go cs
|
||||
']' -> '\\':c:go cs
|
||||
'`' -> '\\':c:go cs
|
||||
'*' -> '\\':c:go cs
|
||||
'_' -> '\\':c:go cs
|
||||
'\\' | isEnabled Ext_raw_tex opts -> '\\':c:go cs
|
||||
| otherwise ->
|
||||
case cs of -- don't escape \ if we don't have to:
|
||||
d:_ | isAlphaNum d -> c:go cs
|
||||
_ -> '\\':c:go cs
|
||||
'>' | isEnabled Ext_all_symbols_escapable opts -> '\\':'>':go cs
|
||||
| otherwise -> ">" ++ go cs
|
||||
'<' | isEnabled Ext_all_symbols_escapable opts -> '\\':'<':go cs
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
# Raw TeX blocks in CommonMark with and without raw_tex
|
||||
|
||||
This command comes through as regular text:
|
||||
```
|
||||
% pandoc -f latex+raw_tex -t commonmark-raw_tex
|
||||
\someunknowncommand
|
||||
|
||||
Hello.
|
||||
% pandoc -f latex+raw_tex -t native
|
||||
\maketitle
|
||||
^D
|
||||
Hello.
|
||||
[ RawBlock (Format "latex") "\\maketitle" ]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex+raw_tex -t commonmark+raw_tex
|
||||
\someunknowncommand
|
||||
|
||||
Hello.
|
||||
^D
|
||||
\someunknowncommand
|
||||
|
||||
Hello.
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f latex -t native
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
</outline>
|
||||
<outline text="Smart quotes, ellipses, dashes" _note="“Hello,” said the spider. “‘Shelob’ is my name.” ‘A’, ‘B’, and ‘C’ are letters. ‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’ ‘He said, “I want to go.”’ Were you alive in the 70’s? Here is some quoted ‘`code`’ and a “[quoted link](http://example.com/?foo=1&bar=2)”. Some dashes: one—two — three—four — five. Dashes between numbers: 5–7, 255–66, 1987–1999. Ellipses…and…and…. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="LaTeX" _note="- - 2 + 2 = 4 - *x* ∈ *y* - *α* ∧ *ω* - 223 - *p*-Tree - Here’s some display math: $$\\frac{d}{dx}f(x)=\\lim\_{h\\to 0}\\frac{f(x+h)-f(x)}{h}$$ - Here’s one that has a line break in it: *α* + *ω* × *x*². These shouldn’t be math: - To get the famous equation, write `$e = mc^2$`. - $22,000 is a *lot* of money. So is $34,000. (It worked if “lot” is emphasized.) - Shoes ($20) and socks ($5). - Escaped `$`: $73 *this should be emphasized* 23$. Here’s a LaTeX table: ------------------------------------------------------------------------">
|
||||
<outline text="LaTeX" _note="- - 2 + 2 = 4 - *x* ∈ *y* - *α* ∧ *ω* - 223 - *p*-Tree - Here’s some display math: $$\frac{d}{dx}f(x)=\lim\_{h\to 0}\frac{f(x+h)-f(x)}{h}$$ - Here’s one that has a line break in it: *α* + *ω* × *x*². These shouldn’t be math: - To get the famous equation, write `$e = mc^2$`. - $22,000 is a *lot* of money. So is $34,000. (It worked if “lot” is emphasized.) - Shoes ($20) and socks ($5). - Escaped `$`: $73 *this should be emphasized* 23$. Here’s a LaTeX table: ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Special Characters" _note="Here is some unicode: - I hat: Î - o umlaut: ö - section: § - set membership: ∈ - copyright: © AT&T has an ampersand in their name. AT&T is another way to write it. This & that. 4 &lt; 5. 6 &gt; 5. Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: { Right brace: } Left bracket: \[ Right bracket: \] Left paren: ( Right paren: ) Greater-than: &gt; Hash: \# Period: . Bang: ! Plus: + Minus: - ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
|
|
Loading…
Reference in a new issue