From 79c84c6dca847f823b468ec4604b641476d4f74a Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Thu, 20 Jul 2023 11:24:47 -0700 Subject: [PATCH 1/2] fix: dont variable-ize escaped sequences --- __tests__/codeMirror.test.js | 6 ++++++ src/codeMirror/index.jsx | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/__tests__/codeMirror.test.js b/__tests__/codeMirror.test.js index 0803d37..1d4a19b 100644 --- a/__tests__/codeMirror.test.js +++ b/__tests__/codeMirror.test.js @@ -97,6 +97,12 @@ describe('variable substitution', () => { 'APIKEY NAME' ); }); + + it('should NOT tokenize escaped variables', () => { + expect(mount(syntaxHighlighter('\\<>', 'json', { tokenizeVariables: true })).text()).toBe('<>'); + expect(mount(syntaxHighlighter('<>', 'json', { tokenizeVariables: true })).text()).toBe('<>'); + expect(mount(syntaxHighlighter('\\<>', 'json', { tokenizeVariables: true })).text()).toBe('<>'); + }); }); describe('Supported languages', () => { diff --git a/src/codeMirror/index.jsx b/src/codeMirror/index.jsx index 513589c..1865ecd 100644 --- a/src/codeMirror/index.jsx +++ b/src/codeMirror/index.jsx @@ -52,7 +52,7 @@ StructuredOutput.propTypes = { /** * Generate an array of classNames * - * @arg {[][]{line: Int}} ranges + * @arg \{[][]{line: Int}} ranges * @return {[String]} Consumable classNames */ const highlightedLines = (ranges, totalLength) => { @@ -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(/^\\<>$/, '>>'); + if (unescaped !== match) { + return unescaped; + } + variables.push({ text: capture, offset: offset - offsetDelta }); - offsetDelta += length; + offsetDelta += match.length; return ''; }; From eb7363287214542175e6bbb5e61e0f89b995d219 Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Thu, 20 Jul 2023 11:31:20 -0700 Subject: [PATCH 2/2] chore: oops --- src/codeMirror/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codeMirror/index.jsx b/src/codeMirror/index.jsx index 1865ecd..d76fe1d 100644 --- a/src/codeMirror/index.jsx +++ b/src/codeMirror/index.jsx @@ -52,7 +52,7 @@ StructuredOutput.propTypes = { /** * Generate an array of classNames * - * @arg \{[][]{line: Int}} ranges + * @arg {[][]{line: Int}} ranges * @return {[String]} Consumable classNames */ const highlightedLines = (ranges, totalLength) => {