git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: better escaping for links (#3628)

Previously the Markdown writer would sometimes create links where there were none in the source. This is now avoided by selectively escaping bracket characters when they occur in a place where a link might be created. Closes #3619.

commit79855ef934175c9a8890653375e05735d8b05a8d authorDavid A Roberts <d@vidr.cc> dateWed 3 May 2017, 20:19 (10 years ago) parent6e55e68
2 files changed+38−1
src/Text/Pandoc/Writers/Markdown.hs+10−1 test/command/3619.md+28
src/Text/Pandoc/Writers/Markdown.hs+10−1
@@ -821,7 +821,8 @@ inlineListToMarkdown opts lst = do
821821 where go [] = return empty
822822 go (i:is) = case i of
823823 (Link _ _ _) -> case is of
824− -- If a link is followed by another link or '[' we don't shortcut
824+ -- If a link is followed by another link, or '[', '(' or ':'
825+ -- then we don't shortcut
825826 (Link _ _ _):_ -> unshortcutable
826827 Space:(Link _ _ _):_ -> unshortcutable
827828 Space:(Str('[':_)):_ -> unshortcutable
@@ -831,9 +832,17 @@ inlineListToMarkdown opts lst = do
831832 SoftBreak:(Str('[':_)):_ -> unshortcutable
832833 SoftBreak:(RawInline _ ('[':_)):_ -> unshortcutable
833834 SoftBreak:(Cite _ _):_ -> unshortcutable
835+ LineBreak:(Link _ _ _):_ -> unshortcutable
836+ LineBreak:(Str('[':_)):_ -> unshortcutable
837+ LineBreak:(RawInline _ ('[':_)):_ -> unshortcutable
838+ LineBreak:(Cite _ _):_ -> unshortcutable
834839 (Cite _ _):_ -> unshortcutable
835840 Str ('[':_):_ -> unshortcutable
841+ Str ('(':_):_ -> unshortcutable
842+ Str (':':_):_ -> unshortcutable
836843 (RawInline _ ('[':_)):_ -> unshortcutable
844+ (RawInline _ ('(':_)):_ -> unshortcutable
845+ (RawInline _ (':':_)):_ -> unshortcutable
837846 (RawInline _ (' ':'[':_)):_ -> unshortcutable
838847 _ -> shortcutable
839848 _ -> shortcutable
test/command/3619.mdnew file+28
@@ -0,0 +1,28 @@
1+```
2+% pandoc -f html -t markdown --reference-links
3+<a href="foo">bar</a>: baz
4+^D
5+[bar][]: baz
6+
7+ [bar]: foo
8+```
9+
10+```
11+% pandoc -f html -t markdown --reference-links
12+<a href="foo">bar</a>(baz)
13+^D
14+[bar][](baz)
15+
16+ [bar]: foo
17+```
18+
19+```
20+% pandoc -f html -t markdown_strict --reference-links
21+<a href="a">foo</a><br/><a href="b">bar</a>
22+^D
23+[foo][]
24+[bar]
25+
26+ [foo]: a
27+ [bar]: b
28+```