Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove   from inline code block in raw input mode #829

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replicated logic from line 234 to don't break #827 solution and enable it also for the Live Markdown in raw input mode

},

/**
Expand Down
Loading