git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: better escaping for links (#3628)
79855efDavid A Roberts
src/Text/Pandoc/Writers/Markdown.hs+10−1
@@ -821,7 +821,8 @@ inlineListToMarkdown opts lst = do
821 where go [] = return empty
821 where go [] = return empty
822 go (i:is) = case i of
822 go (i:is) = case i of
823 (Link _ _ _) -> case is of
823 (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
825 (Link _ _ _):_ -> unshortcutable
826 (Link _ _ _):_ -> unshortcutable
826 Space:(Link _ _ _):_ -> unshortcutable
827 Space:(Link _ _ _):_ -> unshortcutable
827 Space:(Str('[':_)):_ -> unshortcutable
828 Space:(Str('[':_)):_ -> unshortcutable
@@ -831,9 +832,17 @@ inlineListToMarkdown opts lst = do
831 SoftBreak:(Str('[':_)):_ -> unshortcutable
832 SoftBreak:(Str('[':_)):_ -> unshortcutable
832 SoftBreak:(RawInline _ ('[':_)):_ -> unshortcutable
833 SoftBreak:(RawInline _ ('[':_)):_ -> unshortcutable
833 SoftBreak:(Cite _ _):_ -> unshortcutable
834 SoftBreak:(Cite _ _):_ -> unshortcutable
835+ LineBreak:(Link _ _ _):_ -> unshortcutable
836+ LineBreak:(Str('[':_)):_ -> unshortcutable
837+ LineBreak:(RawInline _ ('[':_)):_ -> unshortcutable
838+ LineBreak:(Cite _ _):_ -> unshortcutable
834 (Cite _ _):_ -> unshortcutable
839 (Cite _ _):_ -> unshortcutable
835 Str ('[':_):_ -> unshortcutable
840 Str ('[':_):_ -> unshortcutable
841+ Str ('(':_):_ -> unshortcutable
842+ Str (':':_):_ -> unshortcutable
836 (RawInline _ ('[':_)):_ -> unshortcutable
843 (RawInline _ ('[':_)):_ -> unshortcutable
844+ (RawInline _ ('(':_)):_ -> unshortcutable
845+ (RawInline _ (':':_)):_ -> unshortcutable
837 (RawInline _ (' ':'[':_)):_ -> unshortcutable
846 (RawInline _ (' ':'[':_)):_ -> unshortcutable
838 _ -> shortcutable
847 _ -> shortcutable
839 _ -> shortcutable
848 _ -> 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+```