@@ -3,8 +3,11 @@ import { position_at_offset } from '../positioning';
33import { replacer } from '../overrides/tokens' ;
44import { CodeEditor } from '@jupyterlab/codeeditor' ;
55
6-
7- export function getIndexOfCaptureGroup ( expression : RegExp , matched_string : string , value_of_captured_group : string ) : number {
6+ export function getIndexOfCaptureGroup (
7+ expression : RegExp ,
8+ matched_string : string ,
9+ value_of_captured_group : string
10+ ) : number {
811 // TODO: use https://github.com/tc39/proposal-regexp-match-indices once supported in >95% of browsers
912 // (probably around 2025)
1013
@@ -16,7 +19,6 @@ export function getIndexOfCaptureGroup(expression: RegExp, matched_string: strin
1619 let full_matched = captured_groups [ 0 ] ;
1720
1821 for ( let group of captured_groups . slice ( 1 ) ) {
19-
2022 if ( typeof group === 'undefined' ) {
2123 continue ;
2224 }
@@ -69,8 +71,14 @@ export class RegExpForeignCodeExtractor implements IForeignCodeExtractor {
6971 let match : RegExpExecArray = this . global_expression . exec ( code ) ;
7072 let host_code_fragment : string ;
7173
72- let new_api_replacer = typeof this . options . foreign_replacer !== 'undefined' ? this . options . foreign_replacer : ( '$' + this . options . foreign_capture_group ) ;
73- const replacer = typeof this . options . extract_to_foreign !== 'undefined' ? this . options . extract_to_foreign : new_api_replacer ;
74+ let new_api_replacer =
75+ typeof this . options . foreign_replacer !== 'undefined'
76+ ? this . options . foreign_replacer
77+ : '$' + this . options . foreign_capture_group ;
78+ const replacer =
79+ typeof this . options . extract_to_foreign !== 'undefined'
80+ ? this . options . extract_to_foreign
81+ : new_api_replacer ;
7482
7583 while ( match != null ) {
7684 let matched_string = match [ 0 ] ;
@@ -118,11 +126,12 @@ export class RegExpForeignCodeExtractor implements IForeignCodeExtractor {
118126 }
119127
120128 const foreign_group_index_in_match = getIndexOfCaptureGroup (
121- this . expression , matched_string , foreign_code_group_value
129+ this . expression ,
130+ matched_string ,
131+ foreign_code_group_value
122132 ) ;
123133
124- let start_offset =
125- match . index + foreign_group_index_in_match ;
134+ let start_offset = match . index + foreign_group_index_in_match ;
126135
127136 let start = position_at_offset ( start_offset , lines ) ;
128137 let end = position_at_offset (
0 commit comments