Skip to content

Commit

Permalink
fix: match sections with comments (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 authored May 30, 2024
1 parent 2f08efa commit 77d4f58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/myst-cli/src/project/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export function yamlLineIndent(line: string): number | undefined {
*
**/
function matchesYAMLSection(name: string, line: string): boolean {
// NB this is not escaped!
return !!line.match(new RegExp(`^\\s*${name}:\\s*`));
// NB the name is not escaped!
return !!line.match(new RegExp(`^\\s*${name}:\\s*(#.*)?$`));
}

/**
Expand Down
26 changes: 19 additions & 7 deletions packages/myst-cli/src/project/utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cases:
- foo
section:
body: "hi"
result:
result:
start: 1
stop: 1
- title: Empty section at end
Expand All @@ -20,7 +20,7 @@ cases:
- baz
- foo
section:
result:
result:
start: 5
stop: 5
- title: Section at beginning
Expand All @@ -31,8 +31,8 @@ cases:
foo: bar
bar:
- baz
- foo
result:
- foo
result:
start: 1
stop: 2
indent: 2
Expand All @@ -44,9 +44,21 @@ cases:
- baz
- foo
section:
body: "hi"
result:
body: "hi"
result:
start: 5
stop: 6
indent: 2
- title: Section with comment
name: section
source: |-
foo: bar
bar:
- baz
- foo
section: # This is a section
body: "hi"
result:
start: 5
stop: 6
indent: 2

0 comments on commit 77d4f58

Please sign in to comment.