Skip to content

Commit

Permalink
Merge branch 'main' into snyk-upgrade-bd59fc36721ca9bf2914bee89f1618a3
Browse files Browse the repository at this point in the history
  • Loading branch information
bondydaa authored Aug 21, 2024
2 parents a99ec0b + 975fd8c commit b7710d4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 134 deletions.
18 changes: 18 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,24 @@ test('Test for backticks with suffix', () => {
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it', () => {
const testString = 'a `;` abc `:` a';
const resultString = 'a <code>;</code> abc <code>:</code> a';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it without prefix and suffix', () => {
const testString = '`#` abc `:`';
const resultString = '<code>#</code> abc <code>:</code>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with complete escaped backtick characters inside it', () => {
const testString = 'a `&` b `#` c `x` d `6` e `0` f `;` g `test` h';
const resultString = 'a <code>&amp;</code> b <code>#</code> c <code>x</code> d <code>6</code> e <code>0</code> f <code>;</code> g <code>test</code> h';
expect(parser.replace(testString)).toBe(resultString);
});

// Backticks with no content are not replaced with <code>
test('Test for backticks with no content', () => {
const testString = '` `';
Expand Down
2 changes: 2 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ test('Test bold HTML replacement', () => {
const boldTestStartString = 'This is a <strong>sentence,</strong> and it has some <strong>punctuation, words, and spaces</strong>. '
+ '<strong>test</strong> * testing* test*test*test. * testing * *testing * '
+ 'This is a <b>sentence,</b> and it has some <b>punctuation, words, and spaces</b>. '
+ 'This is a <b style="font-size: 20px;">bold sentence with style</b> '
+ '<b>test</b> * testing* test*test*test. * testing * *testing *';
const boldTestReplacedString = 'This is a *sentence,* and it has some *punctuation, words, and spaces*. '
+ '*test* * testing* test*test*test. * testing * *testing * '
+ 'This is a *sentence,* and it has some *punctuation, words, and spaces*. '
+ 'This is a *bold sentence with style* '
+ '*test* * testing* test*test*test. * testing * *testing *';

expect(parser.htmlToMarkdown(boldTestStartString)).toBe(boldTestReplacedString);
Expand Down
9 changes: 5 additions & 4 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export default class ExpensiMark {
// Use the url escaped version of a backtick (`) symbol. Mobile platforms do not support lookbehinds,
// so capture the first and third group and place them in the replacement.
// but we should not replace backtick symbols if they include <pre> tags between them.
regex: /(\B|_|)&#x60;(.*?(?![&#x60;])\S.*?)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2</code>$3',
regex: /(\B|_|)&#x60;((?:&#x60;)*)(?!&#x60;)(.*?\S+?.*?)(?<!&#x60;)((?:&#x60;)*)(&#x60;)(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2$3$4</code>$6',
},

/**
Expand Down Expand Up @@ -576,13 +576,14 @@ export default class ExpensiMark {
};

// Determine if the outer tag is bold
const styleAttributeMatch = match.match(/style="(.*?)"/);
const fontWeightRegex = /style="([^"]*?\bfont-weight:\s*(\d+|bold|normal)[^"]*?)"/;
const styleAttributeMatch = match.match(fontWeightRegex);
const isFontWeightBold = isBoldFromStyle(styleAttributeMatch ? styleAttributeMatch[1] : null);
const isBold = styleAttributeMatch ? isFontWeightBold : tagName === 'b' || tagName === 'strong';

// Process nested spans with potential bold style
const processedInnerContent = innerContent.replace(/<span(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/span>/gi, (nestedMatch, nestedContent) => {
const nestedStyleMatch = nestedMatch.match(/style="(.*?)"/);
const nestedStyleMatch = nestedMatch.match(fontWeightRegex);
const isNestedBold = isBoldFromStyle(nestedStyleMatch ? nestedStyleMatch[1] : null);
return updateSpacesAndWrapWithAsterisksIfBold(nestedContent, isNestedBold);
});
Expand Down
138 changes: 10 additions & 128 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expensify-common",
"version": "2.0.76",
"version": "2.0.79",
"author": "Expensify, Inc.",
"description": "Expensify libraries and components shared across different repos",
"homepage": "https://expensify.com",
Expand Down Expand Up @@ -52,7 +52,7 @@
"@types/react-dom": "^18.3.0",
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/parser": "^7.18.0",
"babel-jest": "^29.0.0",
"babelify": "10.0.0",
"eslint": "^8.57.0",
Expand Down

0 comments on commit b7710d4

Please sign in to comment.