💲 fix: Prevent Single-dollar LaTeX for abbrev. Currency (K, M, B) (#9293)

This commit is contained in:
Danny Avila 2025-08-26 23:33:56 -04:00 committed by GitHub
parent 9a210971f5
commit a820863e8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -239,4 +239,16 @@ y$ which spans lines`;
const expected = 'Bitcoin: \\$0.00001234, Gas: \\$3.999, Rate: \\$1.234567890';
expect(preprocessLaTeX(content)).toBe(expected);
});
test('escapes abbreviated currency notation', () => {
const content = '$250k is 25% of $1M';
const expected = '\\$250k is 25% of \\$1M';
expect(preprocessLaTeX(content)).toBe(expected);
});
test('handles various abbreviated currency formats', () => {
const content = 'Revenue: $5M to $10M, funding: $1.5B, price: $5K';
const expected = 'Revenue: \\$5M to \\$10M, funding: \\$1.5B, price: \\$5K';
expect(preprocessLaTeX(content)).toBe(expected);
});
});

View file

@ -3,7 +3,8 @@ const MHCHEM_CE_REGEX = /\$\\ce\{/g;
const MHCHEM_PU_REGEX = /\$\\pu\{/g;
const MHCHEM_CE_ESCAPED_REGEX = /\$\\\\ce\{[^}]*\}\$/g;
const MHCHEM_PU_ESCAPED_REGEX = /\$\\\\pu\{[^}]*\}\$/g;
const CURRENCY_REGEX = /(?<![\\$])\$(?!\$)(?=\d+(?:,\d{3})*(?:\.\d+)?(?:\s|$|[^a-zA-Z\d]))/g;
const CURRENCY_REGEX =
/(?<![\\$])\$(?!\$)(?=\d+(?:,\d{3})*(?:\.\d+)?(?:[KMBkmb])?(?:\s|$|[^a-zA-Z\d]))/g;
const SINGLE_DOLLAR_REGEX = /(?<!\\)\$(?!\$)((?:[^$\n]|\\[$])+?)(?<!\\)(?<!`)\$(?!\$)/g;
/**