Skip to content

Commit

Permalink
⚙️ ExpensiMark: Updated image raw data attributes for short image syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kidroca committed Apr 5, 2024
1 parent 7a7c075 commit 046b6ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,12 @@ describe('Image markdown conversion to html tag', () => {
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});

test('Single short syntax image with raw data attributes', () => {
const testString = '!(https://example.com/image.png)';
const resultString = '<img src="https://example.com/image.png" data-raw-href="https://example.com/image.png" data-link-variant="auto" />';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
})

test('Image with invalid url should remain unchanged', () => {
const testString = '![test](invalid)';
expect(parser.replace(testString)).toBe(testString);
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class ExpensiMark {
name: 'image',
regex: MARKDOWN_IMAGE_REGEX,
replacement: (match, g1, g2) => `<img src="${Str.sanitizeURL(g2)}"${g1 ? ` alt="${this.escapeAttributeContent(g1)}"` : ''} />`,
rawInputReplacement: (match, g1, g2) => `<img src="${Str.sanitizeURL(g2)}"${g1 ? ` alt="${this.escapeAttributeContent(g1)}"` : ''} data-raw-href="${g2}" data-link-variant="labeled" />`
rawInputReplacement: (match, g1, g2) => `<img src="${Str.sanitizeURL(g2)}"${g1 ? ` alt="${this.escapeAttributeContent(g1)}"` : ''} data-raw-href="${g2}" data-link-variant="${typeof(g1) === 'string' ? 'labeled': 'auto'}" />`
},

/**
Expand Down

0 comments on commit 046b6ec

Please sign in to comment.