Skip to content

Commit

Permalink
convert attachment tags to [Attachment]
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Dec 31, 2024
1 parent a19e7ca commit df1f538
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion __tests__/ExpensiMark-HTMLToText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ test('Mention report html to text', () => {
expect(parser.htmlToText(testString, extras)).toBe('#room-name');
});

test('Test replacement for <img> tags', () => {
test('Test replacement for attachment tags', () => {
const testString = '<img src="https://example.com/image.png" alt="Image description" />';
const testString2 = '<video data-expensify-source="https://www.expensify.com/chat-attachments/123/test.mp4" data-expensify-width=720 data-expensify-height=1640 data-expensify-duration=20>test.mp4</video>';
const testString3 = '<a href="https://www.expensify.com/chat-attachments/123/test.csv" data-expensify-source="https://www.expensify.com/chat-attachments/123/test.csv">test.csv</a>';
expect(parser.htmlToText(testString)).toBe('[Attachment]');
expect(parser.htmlToText(testString2)).toBe('[Attachment]');
expect(parser.htmlToText(testString3)).toBe('[Attachment]');
});
10 changes: 10 additions & 0 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ export default class ExpensiMark {
regex: /<img[^><]*src\s*=\s*(['"])(.*?)\1(?:[^><]*alt\s*=\s*(['"])(.*?)\3)?[^><]*>*(?![^<][\s\S]*?(<\/pre>|<\/code>))/gi,
replacement: '[Attachment]',
},
{
name: 'video',
regex: /<video[^><]*data-expensify-source\s*=\s*(['"])(\S*?)\1(.*?)>([^><]*)<\/video>*(?![^<][\s\S]*?(<\/pre>|<\/code>))/gi,
replacement: '[Attachment]',
},
{
name: 'otherAttachments',
regex: /<a[^><]*data-expensify-source\s*=\s*(['"])(\S*?)\1(.*?)>([^><]*)<\/a>*(?![^<][\s\S]*?(<\/pre>|<\/code>))/gi,
replacement: '[Attachment]',
},
{
name: 'reportMentions',
regex: /<mention-report reportID="(\d+)" *\/>/gi,
Expand Down

0 comments on commit df1f538

Please sign in to comment.