Skip to content

Commit

Permalink
Merge pull request #1683 from UziTech/image-links
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 20, 2020
2 parents 8cfa29c + d57c89d commit 04ea199
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Tokenizer.js
Expand Up @@ -9,22 +9,23 @@ const {
function outputLink(cap, link, raw) {
const href = link.href;
const title = link.title ? escape(link.title) : null;
const text = cap[1].replace(/\\([\[\]])/g, '$1');

if (cap[0].charAt(0) !== '!') {
return {
type: 'link',
raw,
href,
title,
text: cap[1]
text
};
} else {
return {
type: 'image',
raw,
text: escape(cap[1]),
href,
title
title,
text: escape(text)
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules.js
Expand Up @@ -198,7 +198,7 @@ inline.tag = edit(inline.tag)
.replace('attribute', inline._attribute)
.getRegex();

inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;

Expand Down
11 changes: 11 additions & 0 deletions test/specs/new/image_links.html
@@ -0,0 +1,11 @@
<p>
<a href="https://example.com/">
<img src="https://example.com/image.jpg" alt="test" title="title" />
</a>
</p>

<p>
<a href="https://example.com/">
<img src="https://example.com/image.jpg" alt="[test]" title="[title]" />
</a>
</p>
3 changes: 3 additions & 0 deletions test/specs/new/image_links.md
@@ -0,0 +1,3 @@
[![test](https://example.com/image.jpg "title")](https://example.com/)

[![\[test\]](https://example.com/image.jpg "[title]")](https://example.com/)

1 comment on commit 04ea199

@vercel
Copy link

@vercel vercel bot commented on 04ea199 May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.