Skip to content

Commit

Permalink
feat: add support for link attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Feb 1, 2024
1 parent 0a82230 commit 948ce91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 948ce91

Please sign in to comment.