Skip to content
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
6 changes: 6 additions & 0 deletions __tests__/codeMirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ describe('variable substitution', () => {
'APIKEY NAME'
);
});

it('should NOT tokenize escaped variables', () => {
expect(mount(syntaxHighlighter('\\<<wat>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
expect(mount(syntaxHighlighter('<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
expect(mount(syntaxHighlighter('\\<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
});
});

describe('Supported languages', () => {
Expand Down
9 changes: 7 additions & 2 deletions src/codeMirror/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ const extractVariables = (code, opts) => {
let offsetDelta = 0;
const variables = [];

const extracter = ({ length }, capture, offset) => {
const extracter = (match, capture, offset) => {
const unescaped = match.replace(/^\\<</, '<<').replace(/\\>>$/, '>>');
if (unescaped !== match) {
return unescaped;
}

variables.push({ text: capture, offset: offset - offsetDelta });
offsetDelta += length;
offsetDelta += match.length;

return '';
};
Expand Down