@@ -41,16 +41,17 @@ export function partitionCellOptions(
4141 source : string [ ] ,
4242) {
4343 const commentChars = langCommentChars ( language ) ;
44- const optionPrefix = optionCommentPrefix ( commentChars [ 0 ] ) ;
44+ const optionPattern = optionCommentPattern ( commentChars [ 0 ] ) ;
4545 const optionSuffix = commentChars [ 1 ] || "" ;
4646
4747 // find the yaml lines
4848 const optionsSource : string [ ] = [ ] ;
4949 const yamlLines : string [ ] = [ ] ;
5050 for ( const line of source ) {
51- if ( line . startsWith ( optionPrefix ) ) {
51+ const optionMatch = line . match ( optionPattern ) ;
52+ if ( optionMatch ) {
5253 if ( ! optionSuffix || line . trimRight ( ) . endsWith ( optionSuffix ) ) {
53- let yamlOption = line . substring ( optionPrefix . length ) ;
54+ let yamlOption = line . substring ( optionMatch [ 0 ] . length ) ;
5455 if ( optionSuffix ) {
5556 yamlOption = yamlOption . trimRight ( ) ;
5657 yamlOption = yamlOption . substring (
@@ -150,7 +151,7 @@ export function partitionCellOptionsText(
150151 source : MappedString ,
151152) {
152153 const commentChars = langCommentChars ( language ) ;
153- const optionPrefix = optionCommentPrefix ( commentChars [ 0 ] ) ;
154+ const optionPattern = optionCommentPattern ( commentChars [ 0 ] ) ;
154155 const optionSuffix = commentChars [ 1 ] || "" ;
155156
156157 // find the yaml lines
@@ -159,22 +160,24 @@ export function partitionCellOptionsText(
159160
160161 let endOfYaml = 0 ;
161162 for ( const line of rangedLines ( source . value , true ) ) {
162- if ( line . substring . startsWith ( optionPrefix ) ) {
163+ const optionMatch = line . substring . match ( optionPattern ) ;
164+ if ( optionMatch ) {
163165 if ( ! optionSuffix || line . substring . trimRight ( ) . endsWith ( optionSuffix ) ) {
164- let yamlOption = line . substring . substring ( optionPrefix . length ) ;
166+ let yamlOption = line . substring . substring ( optionMatch [ 0 ] . length ) ;
165167 if ( optionSuffix ) {
166168 yamlOption = yamlOption . trimRight ( ) ;
167169 yamlOption = yamlOption . substring (
168170 0 ,
169171 yamlOption . length - optionSuffix . length ,
170172 ) ;
171173 }
172- endOfYaml = line . range . start + optionPrefix . length + yamlOption . length -
174+ endOfYaml = line . range . start + optionMatch [ 0 ] . length +
175+ yamlOption . length -
173176 optionSuffix . length ;
174177 const rangedYamlOption = {
175178 substring : yamlOption ,
176179 range : {
177- start : line . range . start + optionPrefix . length ,
180+ start : line . range . start + optionMatch [ 0 ] . length ,
178181 end : endOfYaml ,
179182 } ,
180183 } ;
@@ -252,8 +255,8 @@ export function langCommentChars(lang: string): string[] {
252255 return chars ;
253256 }
254257}
255- export function optionCommentPrefix ( comment : string ) {
256- return comment + "| " ;
258+ export function optionCommentPattern ( comment : string ) {
259+ return new RegExp ( "^" + comment + "\\s*\\ | " ) ;
257260}
258261
259262// FIXME this is an awkward spot for this particular entry point
@@ -264,8 +267,8 @@ export function addLanguageComment(
264267 kLangCommentChars [ language ] = comment ;
265268}
266269
267- export function optionCommentPrefixFromLanguage ( language : string ) {
268- return optionCommentPrefix ( langCommentChars ( language ) [ 0 ] ) ;
270+ export function optionCommentPatternFromLanguage ( language : string ) {
271+ return optionCommentPattern ( langCommentChars ( language ) [ 0 ] ) ;
269272}
270273
271274export const kLangCommentChars : Record < string , string | [ string , string ] > = {
0 commit comments