File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ describe('variable substitution', () => {
9797 'APIKEY NAME'
9898 ) ;
9999 } ) ;
100+
101+ it ( 'should NOT tokenize escaped variables' , ( ) => {
102+ expect ( mount ( syntaxHighlighter ( '\\<<wat>>' , 'json' , { tokenizeVariables : true } ) ) . text ( ) ) . toBe ( '<<wat>>' ) ;
103+ expect ( mount ( syntaxHighlighter ( '<<wat\\>>' , 'json' , { tokenizeVariables : true } ) ) . text ( ) ) . toBe ( '<<wat>>' ) ;
104+ expect ( mount ( syntaxHighlighter ( '\\<<wat\\>>' , 'json' , { tokenizeVariables : true } ) ) . text ( ) ) . toBe ( '<<wat>>' ) ;
105+ } ) ;
100106} ) ;
101107
102108describe ( 'Supported languages' , ( ) => {
Original file line number Diff line number Diff line change @@ -169,9 +169,14 @@ const extractVariables = (code, opts) => {
169169 let offsetDelta = 0 ;
170170 const variables = [ ] ;
171171
172- const extracter = ( { length } , capture , offset ) => {
172+ const extracter = ( match , capture , offset ) => {
173+ const unescaped = match . replace ( / ^ \\ < < / , '<<' ) . replace ( / \\ > > $ / , '>>' ) ;
174+ if ( unescaped !== match ) {
175+ return unescaped ;
176+ }
177+
173178 variables . push ( { text : capture , offset : offset - offsetDelta } ) ;
174- offsetDelta += length ;
179+ offsetDelta += match . length ;
175180
176181 return '' ;
177182 } ;
You can’t perform that action at this time.
0 commit comments