Skip to content

Commit

Permalink
Merge pull request #760 from gijoe0295/gijoe/45635
Browse files Browse the repository at this point in the history
Fix `<emoji>` is mistaken as `<em>`
  • Loading branch information
cristipaval authored Jul 26, 2024
2 parents c1c47fd + a018db6 commit 4cc5e30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<emoji>😄</emoji> <em>italic</em>';
const resultString = '😄 _italic_';
expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});

test('Blockquote and bold', () => {
const testString = '<blockquote> quote <b>bold</b></blockquote>';
const resultString = '> quote *bold*';
expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});

test('Line break and bold', () => {
const testString = '<br/><b>bold</b>';
const resultString = '\n*bold*';
expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});
});
4 changes: 2 additions & 2 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 4cc5e30

Please sign in to comment.