Skip to content

Commit

Permalink
Merge pull request #829 from software-mansion-labs/@Skalakid/remove-n…
Browse files Browse the repository at this point in the history
…bsp-from-inline-code-blocks
  • Loading branch information
blimpich authored Jan 16, 2025
2 parents 569c1e5 + be19fef commit 43581a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
28 changes: 28 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,34 @@ describe('when should keep raw input flag is enabled', () => {
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
});

describe('inline code blocks', () => {
test('empty content', () => {
const testString = '``';
const resultString = '``';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
test('single whitespace as a content', () => {
const testString = '` `';
const resultString = '<code> </code>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
test('multiple whitespaces as a content', () => {
const testString = '` `';
const resultString = '<code> </code>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
test('text content', () => {
const testString = 'hello `world`';
const resultString = 'hello <code>world</code>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
test('text and whitespaces as a content', () => {
const testString = '` hello world `';
const resultString = '<code> hello world </code>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
});
});

test('Test code fence within inline code', () => {
Expand Down
5 changes: 3 additions & 2 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,14 @@ export default class ExpensiMark {
// At least one non-whitespace character or a specific whitespace character (" " and "\u00A0")
// must be present inside the backticks.
regex: /(\B|_|)&#x60;(.*?)&#x60;(\B|_|)(?!(?!<pre>)[^<]*(?:<(?!pre>)[^<]*)*<\/pre>|[^<]*<\/video>)/gm,
replacement: (_extras, _match, g1, g2, g3) => {
replacement: (_extras, match, g1, g2, g3) => {
const g2Value = g2.trim() === '' ? g2.replaceAll(' ', '&nbsp;') : g2;
if (!g2Value) {
return _match;
return match;
}
return `${g1}<code>${g2Value}</code>${g3}`;
},
rawInputReplacement: (_extras, match, g1, g2, g3) => (g2 ? `${g1}<code>${g2}</code>${g3}` : match),
},

/**
Expand Down

0 comments on commit 43581a7

Please sign in to comment.