From 265d4967d6238589b47f1fa195e766279f6dd2c4 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 5 Aug 2024 12:47:14 +0700 Subject: [PATCH 1/4] fix: no trimming for link name --- __tests__/ExpensiMark-HTML-test.js | 10 ++++++---- lib/ExpensiMark.ts | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index ab3cd854..f514229e 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -389,7 +389,8 @@ test('Test critical markdown style links', () => { '[link with [brackets] inside of it](https://google.com) ' + '[link with smart quotes ‘’“”](https://google.com) ' + '[link with someone@expensify.com email in it](https://google.com)' + - '[Localhost](http://a:3030)'; + '[Localhost](http://a:3030)' + + '[ name with rear spaces ](https://example.com)'; const resultString = 'Testing ' + 'strikethrough bold italic ' + @@ -407,7 +408,8 @@ test('Test critical markdown style links', () => { 'link with [brackets] inside of it ' + 'link with smart quotes ‘’“” ' + 'link with someone@expensify.com email in it' + - 'Localhost'; + 'Localhost' + + ' name with rear spaces '; expect(parser.replace(testString)).toBe(resultString); }); @@ -1032,7 +1034,7 @@ test('Test markdown and url links with inconsistent starting and closing parens' '[Text text] more text (link [square brackets within] here)' + '[Text text] more text (link (parenthesis within) here)' + '[Text text] more text link here' + - '[Text text] more text (link here)' + + '[Text text] more text (link here )' + '[Text text] more text ((link here))' + '[Text text] more text [(link here)]' + '[Text text] more text (link here)[Text text] more text (link here)'; @@ -2270,7 +2272,7 @@ describe('room mentions', () => { test('room mention with space inside link should not be rendered', () => { const testString = '[ #room](google.com/sub#111)'; - const resultString = '#room'; + const resultString = ' #room'; expect(parser.replace(testString)).toBe(resultString); }); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 34b437ed..9b63f4bb 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -261,13 +261,13 @@ export default class ExpensiMark { if (!g1.trim()) { return match; } - return `${g1.trim()}`; + return `${g1}`; }, rawInputReplacement: (_extras, match, g1, g2) => { if (!g1.trim()) { return match; } - return `${g1.trim()}`; + return `${g1}`; }, }, @@ -298,10 +298,9 @@ export default class ExpensiMark { { name: 'reportMentions', - regex: /(?|<\/code>))/gimu, - replacement: '$1', + regex: /(?|<\/code>|<\/a>))/gimu, + replacement: '$1' }, - /** * This regex matches a valid user mention in a string. * A user mention is a string that starts with the '@' symbol and is followed by a valid user's primary From 303cd94dddd774382622bb0e14637721dc6d1151 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 5 Aug 2024 13:07:58 +0700 Subject: [PATCH 2/4] fix: prettier --- lib/ExpensiMark.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 9b63f4bb..d714ee19 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -299,7 +299,7 @@ export default class ExpensiMark { name: 'reportMentions', regex: /(?|<\/code>|<\/a>))/gimu, - replacement: '$1' + replacement: '$1', }, /** * This regex matches a valid user mention in a string. From ec546ab7588a243ddf62d393b36a006395e86116 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 5 Aug 2024 16:51:58 +0700 Subject: [PATCH 3/4] fix: only keep spaces if shouldKeepRawInput=true --- __tests__/ExpensiMark-HTML-test.js | 16 ++++++++++------ lib/ExpensiMark.ts | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index f514229e..0b03ec1c 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -389,8 +389,7 @@ test('Test critical markdown style links', () => { '[link with [brackets] inside of it](https://google.com) ' + '[link with smart quotes ‘’“”](https://google.com) ' + '[link with someone@expensify.com email in it](https://google.com)' + - '[Localhost](http://a:3030)' + - '[ name with rear spaces ](https://example.com)'; + '[Localhost](http://a:3030)'; const resultString = 'Testing ' + 'strikethrough bold italic ' + @@ -408,8 +407,7 @@ test('Test critical markdown style links', () => { 'link with [brackets] inside of it ' + 'link with smart quotes ‘’“” ' + 'link with someone@expensify.com email in it' + - 'Localhost' + - ' name with rear spaces '; + 'Localhost'; expect(parser.replace(testString)).toBe(resultString); }); @@ -1034,7 +1032,7 @@ test('Test markdown and url links with inconsistent starting and closing parens' '[Text text] more text (link [square brackets within] here)' + '[Text text] more text (link (parenthesis within) here)' + '[Text text] more text link here' + - '[Text text] more text (link here )' + + '[Text text] more text (link here)' + '[Text text] more text ((link here))' + '[Text text] more text [(link here)]' + '[Text text] more text (link here)[Text text] more text (link here)'; @@ -1042,6 +1040,12 @@ test('Test markdown and url links with inconsistent starting and closing parens' expect(parser.replace(testString)).toBe(resultString); }); +test('Test link: Keep spaces at both end for shouldKeepRawInput=true', () => { + const testString = '[ link ](https://www.expensify.com)'; + const resultString = ' link '; + expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString); +}); + test('Test autolink replacement to avoid parsing nested links', () => { const testString = '[click google.com *here*](google.com) ' + @@ -2272,7 +2276,7 @@ describe('room mentions', () => { test('room mention with space inside link should not be rendered', () => { const testString = '[ #room](google.com/sub#111)'; - const resultString = ' #room'; + const resultString = '#room'; expect(parser.replace(testString)).toBe(resultString); }); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index d714ee19..ae41ab4d 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -261,7 +261,7 @@ export default class ExpensiMark { if (!g1.trim()) { return match; } - return `${g1}`; + return `${g1.trim()}`; }, rawInputReplacement: (_extras, match, g1, g2) => { if (!g1.trim()) { From a6109cb85d8616bea0f23937f6d9c18e15bb44b3 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 5 Aug 2024 17:04:37 +0700 Subject: [PATCH 4/4] fix: add extra line --- lib/ExpensiMark.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index ae41ab4d..8b97487c 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -301,6 +301,7 @@ export default class ExpensiMark { regex: /(?|<\/code>|<\/a>))/gimu, replacement: '$1', }, + /** * This regex matches a valid user mention in a string. * A user mention is a string that starts with the '@' symbol and is followed by a valid user's primary