diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index 103237cf..297c8971 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -891,3 +891,23 @@ describe('Video tag conversion to markdown', () => { expect(cacheVideoAttributes).toHaveBeenCalledWith("https://example.com/video.mp4", ' data-expensify-width="100" data-expensify-height="500" data-expensify-thumbnail-url="https://image.com/img.jpg"') }) }) + +describe('Tag names starting with common charaters', () => { + test('Italic and emoji', () => { + const testString = '😄 italic'; + const resultString = '😄 _italic_'; + expect(parser.htmlToMarkdown(testString)).toBe(resultString); + }); + + test('Blockquote and bold', () => { + const testString = '
quote bold
'; + const resultString = '> quote *bold*'; + expect(parser.htmlToMarkdown(testString)).toBe(resultString); + }); + + test('Line break and bold', () => { + const testString = '
bold'; + const resultString = '\n*bold*'; + expect(parser.htmlToMarkdown(testString)).toBe(resultString); + }); +}); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 80bc415c..0dbbcd2d 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -556,12 +556,12 @@ export default class ExpensiMark { // Use [\s\S]* instead of .* to match newline { name: 'italic', - regex: /<(em|i)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, + regex: /<(em|i)\b(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, replacement: '_$2_', }, { name: 'bold', - regex: /<(b|strong)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, + regex: /<(b|strong)\b(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, replacement: (extras, match, tagName, innerContent) => { // To check if style attribute contains bold font-weight const isBoldFromStyle = (style: string | null) => {