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.
This commit is contained in:
parent
6e55e6837a
commit
79855ef934
2 changed files with 38 additions and 1 deletions
|
@ -821,7 +821,8 @@ inlineListToMarkdown opts lst = do
|
|||
where go [] = return empty
|
||||
go (i:is) = case i of
|
||||
(Link _ _ _) -> case is of
|
||||
-- If a link is followed by another link or '[' we don't shortcut
|
||||
-- If a link is followed by another link, or '[', '(' or ':'
|
||||
-- then we don't shortcut
|
||||
(Link _ _ _):_ -> unshortcutable
|
||||
Space:(Link _ _ _):_ -> unshortcutable
|
||||
Space:(Str('[':_)):_ -> unshortcutable
|
||||
|
@ -831,9 +832,17 @@ inlineListToMarkdown opts lst = do
|
|||
SoftBreak:(Str('[':_)):_ -> unshortcutable
|
||||
SoftBreak:(RawInline _ ('[':_)):_ -> unshortcutable
|
||||
SoftBreak:(Cite _ _):_ -> unshortcutable
|
||||
LineBreak:(Link _ _ _):_ -> unshortcutable
|
||||
LineBreak:(Str('[':_)):_ -> unshortcutable
|
||||
LineBreak:(RawInline _ ('[':_)):_ -> unshortcutable
|
||||
LineBreak:(Cite _ _):_ -> unshortcutable
|
||||
(Cite _ _):_ -> unshortcutable
|
||||
Str ('[':_):_ -> unshortcutable
|
||||
Str ('(':_):_ -> unshortcutable
|
||||
Str (':':_):_ -> unshortcutable
|
||||
(RawInline _ ('[':_)):_ -> unshortcutable
|
||||
(RawInline _ ('(':_)):_ -> unshortcutable
|
||||
(RawInline _ (':':_)):_ -> unshortcutable
|
||||
(RawInline _ (' ':'[':_)):_ -> unshortcutable
|
||||
_ -> shortcutable
|
||||
_ -> shortcutable
|
||||
|
|
28
test/command/3619.md
Normal file
28
test/command/3619.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
```
|
||||
% pandoc -f html -t markdown --reference-links
|
||||
<a href="foo">bar</a>: baz
|
||||
^D
|
||||
[bar][]: baz
|
||||
|
||||
[bar]: foo
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t markdown --reference-links
|
||||
<a href="foo">bar</a>(baz)
|
||||
^D
|
||||
[bar][](baz)
|
||||
|
||||
[bar]: foo
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t markdown_strict --reference-links
|
||||
<a href="a">foo</a><br/><a href="b">bar</a>
|
||||
^D
|
||||
[foo][]
|
||||
[bar]
|
||||
|
||||
[foo]: a
|
||||
[bar]: b
|
||||
```
|
Loading…
Add table
Reference in a new issue