Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ function hardbreak (str, mark, force, len = str.length) {
}

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

function isAnyListItem (chr0, str, mode = 'test', match = chr0 in LIST_MARKERS && ListItemRx[mode](str)) {
Expand Down
16 changes: 16 additions & 0 deletions test/downdoc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4311,6 +4311,22 @@ describe('downdoc()', () => {
`
expect(downdoc(input)).to.equal(expected)
})

it('should wrap image in link if link attribute is set', () => {
const input = heredoc`
= Title

image::images/screenshot.png[Screenshot,link=https://example.com]
image::images/screenshot.png[Screenshot,link="https://example.com"]
`
const expected = heredoc`
# Title

[![Screenshot](images/screenshot.png)](https://example.com)
[![Screenshot](images/screenshot.png)](https://example.com)
`
expect(downdoc(input)).to.equal(expected)
})
})

describe('blockquotes', () => {
Expand Down