Skip to content

Commit 8978410

Browse files
authored
feat: Support #|, # | and ##| for quarto metadata comment indicators
1 parent 6975f07 commit 8978410

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/parse-codeblock.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@ export function parseCodeBlock(
8888

8989
/**
9090
* Loop through all the lines and extract lines at the beginning which start
91-
* with Quarto parameter comments and have the format "#| " as `quartoArgs`,
92-
* and strip those lines from the result. Also remove up to one empty line
93-
* after any args.
91+
* with Quarto parameter comments and have the format "#| ", "# | " or "##|"
92+
* as `quartoArgs`, and strip those lines from the result. Also remove up to
93+
* one empty line after any args.
9494
*/
9595
export function processQuartoArgs(lines: string[]): {
9696
lines: string[];
9797
quartoArgs: QuartoArgs;
9898
} {
9999
let i = 0;
100+
const rgxQuartoComment = /^(# ?|##)\| /;
100101
while (i < lines.length) {
101102
const line = lines[i];
102-
if (!line.match(/^#\| /)) {
103+
if (!line.match(rgxQuartoComment)) {
103104
// Remove up to one blank line after finding any args.
104105
if (line === "") {
105106
i++;
@@ -114,7 +115,7 @@ export function processQuartoArgs(lines: string[]): {
114115
// Extract the lines that start with "#| " and remove that comment prefix.
115116
const argCommentLines = lines
116117
.slice(0, i)
117-
.map((line) => line.replace(/^#\| /, ""));
118+
.map((line) => line.replace(rgxQuartoComment, ""));
118119

119120
// Parse the args as YAML.
120121
const quartoArgs: QuartoArgs = yamlLoad(

0 commit comments

Comments
 (0)