Markdown writer: improved escaping.
`<` should not be escaped as `\<`, for compatibility with original Markdown. We now escape `<` and `>` with entities. Also, we now backslash-escape square brackets. Closes #2086.
This commit is contained in:
parent
0b80073e7c
commit
d20152e011
4 changed files with 20 additions and 19 deletions
|
@ -246,7 +246,8 @@ noteToMarkdown opts num blocks = do
|
|||
-- | Escape special characters for Markdown.
|
||||
escapeString :: WriterOptions -> String -> String
|
||||
escapeString opts = escapeStringUsing markdownEscapes
|
||||
where markdownEscapes = backslashEscapes specialChars
|
||||
where markdownEscapes = ('<', "<") : ('>', ">") :
|
||||
backslashEscapes specialChars
|
||||
specialChars =
|
||||
(if isEnabled Ext_superscript opts
|
||||
then ('^':)
|
||||
|
@ -257,7 +258,7 @@ escapeString opts = escapeStringUsing markdownEscapes
|
|||
(if isEnabled Ext_tex_math_dollars opts
|
||||
then ('$':)
|
||||
else id) $
|
||||
"\\`*_<>#"
|
||||
"\\`*_[]#"
|
||||
|
||||
-- | Construct table of contents from list of header blocks.
|
||||
tableOfContents :: WriterOptions -> [Block] -> Doc
|
||||
|
|
|
@ -84,13 +84,13 @@ shortcutLinkRefsTests =
|
|||
]
|
||||
, "Reference link is followed by text in brackets"
|
||||
=: (para ((link "/url" "" "link") <> "[text in brackets]"))
|
||||
=?> unlines [ "[link][][text in brackets]"
|
||||
=?> unlines [ "[link][]\\[text in brackets\\]"
|
||||
, ""
|
||||
, " [link]: /url"
|
||||
]
|
||||
, "Reference link is followed by space and text in brackets"
|
||||
=: (para ((link "/url" "" "link") <> " [text in brackets]"))
|
||||
=?> unlines [ "[link][] [text in brackets]"
|
||||
=?> unlines [ "[link][] \\[text in brackets\\]"
|
||||
, ""
|
||||
, " [link]: /url"
|
||||
]
|
||||
|
|
|
@ -80,7 +80,7 @@ E-mail style:
|
|||
>
|
||||
> > nested
|
||||
|
||||
This should not be a block quote: 2 \> 1.
|
||||
This should not be a block quote: 2 > 1.
|
||||
|
||||
And a following paragraph.
|
||||
|
||||
|
@ -581,9 +581,9 @@ AT&T is another way to write it.
|
|||
|
||||
This & that.
|
||||
|
||||
4 \< 5.
|
||||
4 < 5.
|
||||
|
||||
6 \> 5.
|
||||
6 > 5.
|
||||
|
||||
Backslash: \\
|
||||
|
||||
|
@ -597,15 +597,15 @@ Left brace: {
|
|||
|
||||
Right brace: }
|
||||
|
||||
Left bracket: [
|
||||
Left bracket: \[
|
||||
|
||||
Right bracket: ]
|
||||
Right bracket: \]
|
||||
|
||||
Left paren: (
|
||||
|
||||
Right paren: )
|
||||
|
||||
Greater-than: \>
|
||||
Greater-than: >
|
||||
|
||||
Hash: \#
|
||||
|
||||
|
@ -652,7 +652,7 @@ Foo [bar](/url/).
|
|||
|
||||
Foo [bar](/url/).
|
||||
|
||||
With [embedded [brackets]](/url/).
|
||||
With [embedded \[brackets\]](/url/).
|
||||
|
||||
[b](/url/) by itself should be a link.
|
||||
|
||||
|
@ -662,7 +662,7 @@ Indented [twice](/url).
|
|||
|
||||
Indented [thrice](/url).
|
||||
|
||||
This should [not][] be a link.
|
||||
This should \[not\]\[\] be a link.
|
||||
|
||||
[not]: /url
|
||||
|
||||
|
@ -716,8 +716,8 @@ Footnotes
|
|||
=========
|
||||
|
||||
Here is a footnote reference,[^1] and another.[^2] This should *not* be a
|
||||
footnote reference, because it contains a space.[\^my note] Here is an inline
|
||||
note.[^3]
|
||||
footnote reference, because it contains a space.\[\^my note\] Here is an
|
||||
inline note.[^3]
|
||||
|
||||
> Notes can go in quotes.[^4]
|
||||
|
||||
|
@ -740,7 +740,7 @@ This paragraph should not be part of the note, as it is not indented.
|
|||
|
||||
[^3]: This is *easier* to type. Inline notes may contain
|
||||
[links](http://google.com) and `]` verbatim characters, as well as
|
||||
[bracketed text].
|
||||
\[bracketed text\].
|
||||
|
||||
[^4]: In quote.
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</outline>
|
||||
<outline text="Paragraphs" _note="Here’s a regular paragraph. In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item. Here’s one with a bullet. \* criminey. There should be a hard line break\ here. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Block Quotes" _note="E-mail style: > This is a block quote. It is pretty short. > Code in a block quote: > > sub status { > print "working"; > } > > A list: > > 1. item one > 2. item two > > Nested block quotes: > > > nested > > > nested This should not be a block quote: 2 \> 1. And a following paragraph. ------------------------------------------------------------------------">
|
||||
<outline text="Block Quotes" _note="E-mail style: > This is a block quote. It is pretty short. > Code in a block quote: > > sub status { > print "working"; > } > > A list: > > 1. item one > 2. item two > > Nested block quotes: > > > nested > > > nested This should not be a block quote: 2 &gt; 1. And a following paragraph. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Code Blocks" _note="Code: ---- (should be four hyphens) sub status { print "working"; } this code block is indented by one tab And: this code block is indented by two tabs These should not be escaped: \$ \\ \> \[ \{ ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
|
@ -52,12 +52,12 @@
|
|||
</outline>
|
||||
<outline text="LaTeX" _note="- \cite[22-23]{smith.1899} - $2+2=4$ - $x \in y$ - $\alpha \wedge \omega$ - $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: $\alpha + \omega \times x^2$. 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: \begin{tabular}{|l|l|}\hline Animal & Number \\ \hline Dog & 2 \\ Cat & 1 \\ \hline \end{tabular} ------------------------------------------------------------------------">
|
||||
</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 \< 5. 6 \> 5. Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: { Right brace: } Left bracket: [ Right bracket: ] Left paren: ( Right paren: ) Greater-than: \> Hash: \# Period: . Bang: ! Plus: + Minus: - ------------------------------------------------------------------------">
|
||||
<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>
|
||||
<outline text="Links">
|
||||
<outline text="Explicit" _note="Just a [URL](/url/). [URL and title](/url/ "title"). [URL and title](/url/ "title preceded by two spaces"). [URL and title](/url/ "title preceded by a tab"). [URL and title](/url/ "title with "quotes" in it") [URL and title](/url/ "title with single quotes") [with\_underscore](/url/with_underscore) [Email link](mailto:nobody@nowhere.net) [Empty]().">
|
||||
</outline>
|
||||
<outline text="Reference" _note="Foo [bar](/url/). Foo [bar](/url/). Foo [bar](/url/). With [embedded [brackets]](/url/). [b](/url/) by itself should be a link. Indented [once](/url). Indented [twice](/url). Indented [thrice](/url). This should [not][] be a link. [not]: /url Foo [bar](/url/ "Title with "quotes" inside"). Foo [biz](/url/ "Title with "quote" inside").">
|
||||
<outline text="Reference" _note="Foo [bar](/url/). Foo [bar](/url/). Foo [bar](/url/). With [embedded \[brackets\]](/url/). [b](/url/) by itself should be a link. Indented [once](/url). Indented [twice](/url). Indented [thrice](/url). This should \[not\]\[\] be a link. [not]: /url Foo [bar](/url/ "Title with "quotes" inside"). Foo [biz](/url/ "Title with "quote" inside").">
|
||||
</outline>
|
||||
<outline text="With ampersands" _note="Here’s a [link with an ampersand in the URL](http://example.com/?foo=1&bar=2). Here’s a link with an amersand in the link text: [AT&T](http://att.com/ "AT&T"). Here’s an [inline link](/script?foo=1&bar=2). Here’s an [inline link in pointy braces](/script?foo=1&bar=2).">
|
||||
</outline>
|
||||
|
@ -66,7 +66,7 @@
|
|||
</outline>
|
||||
<outline text="Images" _note="From “Voyage dans la Lune” by Georges Melies (1902): ![lalune](lalune.jpg "Voyage dans la Lune") Here is a movie ![movie](movie.jpg) icon. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Footnotes" _note="Here is a footnote reference,[^1] and another.[^2] This should *not* be a footnote reference, because it contains a space.[\^my note] Here is an inline note.[^3] > Notes can go in quotes.[^4] 1. And in list items.[^5] This paragraph should not be part of the note, as it is not indented. [^1]: Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. [^2]: Here’s the long note. This one contains multiple blocks. Subsequent blocks are indented to show that they belong to the footnote (as with list items). { <code> } If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. [^3]: This is *easier* to type. Inline notes may contain [links](http://google.com) and `]` verbatim characters, as well as [bracketed text]. [^4]: In quote. [^5]: In list.">
|
||||
<outline text="Footnotes" _note="Here is a footnote reference,[^1] and another.[^2] This should *not* be a footnote reference, because it contains a space.\[\^my note\] Here is an inline note.[^3] > Notes can go in quotes.[^4] 1. And in list items.[^5] This paragraph should not be part of the note, as it is not indented. [^1]: Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. [^2]: Here’s the long note. This one contains multiple blocks. Subsequent blocks are indented to show that they belong to the footnote (as with list items). { <code> } If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. [^3]: This is *easier* to type. Inline notes may contain [links](http://google.com) and `]` verbatim characters, as well as \[bracketed text\]. [^4]: In quote. [^5]: In list.">
|
||||
</outline>
|
||||
</body>
|
||||
</opml>
|
||||
|
|
Loading…
Reference in a new issue