Skip to content

Commit 948ce91

Browse files
committed
feat: add support for link attribute
1 parent 0a82230 commit 948ce91

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ function hardbreak (str, mark, force, len = str.length) {
311311
}
312312

313313
function image (_, target, attrlist, _idx, _str, alt = attrlist.split(',')[0] || /(.*\/)?(.*?)($|\.)/.exec(target)[2]) {
314-
return '![' + alt + '](' + (this.get('imagesdir') ? this.get('imagesdir') + '/' : '') + target + ')'
314+
const link = attrlist.split(',').map((it) => /link="{0,1}(.+?)"{0,1}$/.exec(it)?.[1]).find((it) => it)
315+
const image = '![' + alt + '](' + (this.get('imagesdir') ? this.get('imagesdir') + '/' : '') + target + ')'
316+
return link ? '[' + image + '](' + link + ')' : image
315317
}
316318

317319
function isAnyListItem (chr0, str, mode = 'test', match = chr0 in LIST_MARKERS && ListItemRx[mode](str)) {

test/downdoc-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,22 @@ describe('downdoc()', () => {
43114311
`
43124312
expect(downdoc(input)).to.equal(expected)
43134313
})
4314+
4315+
it('should wrap image in link if link attribute is set', () => {
4316+
const input = heredoc`
4317+
= Title
4318+
4319+
image::images/screenshot.png[Screenshot,link=https://example.com]
4320+
image::images/screenshot.png[Screenshot,link="https://example.com"]
4321+
`
4322+
const expected = heredoc`
4323+
# Title
4324+
4325+
[![Screenshot](images/screenshot.png)](https://example.com)
4326+
[![Screenshot](images/screenshot.png)](https://example.com)
4327+
`
4328+
expect(downdoc(input)).to.equal(expected)
4329+
})
43144330
})
43154331

43164332
describe('blockquotes', () => {

0 commit comments

Comments
 (0)