Skip to content

Commit

Permalink
feat: Support #|, # | and ##| for quarto metadata comment indic…
Browse files Browse the repository at this point in the history
…ators (#197)

* feat: Support `#|`, `# |` and `##|` for quarto metadata comment indicators

* chore: update comment
  • Loading branch information
gadenbuie authored Jan 22, 2025
1 parent 6af0f17 commit 17d3bc6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/parse-codeblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ export function parseCodeBlock(

/**
* Loop through all the lines and extract lines at the beginning which start
* with Quarto parameter comments and have the format "#| " as `quartoArgs`,
* and strip those lines from the result. Also remove up to one empty line
* after any args.
* with Quarto parameter comments and have the format "#| ", "# | " or "##| "
* as `quartoArgs`, and strip those lines from the result. Also remove up to
* one empty line after any args.
*/
export function processQuartoArgs(lines: string[]): {
lines: string[];
quartoArgs: QuartoArgs;
} {
let i = 0;
const rgxQuartoComment = /^(# ?|##)\| /;
while (i < lines.length) {
const line = lines[i];
if (!line.match(/^#\| /)) {
if (!line.match(rgxQuartoComment)) {
// Remove up to one blank line after finding any args.
if (line === "") {
i++;
Expand All @@ -114,7 +115,7 @@ export function processQuartoArgs(lines: string[]): {
// Extract the lines that start with "#| " and remove that comment prefix.
const argCommentLines = lines
.slice(0, i)
.map((line) => line.replace(/^#\| /, ""));
.map((line) => line.replace(rgxQuartoComment, ""));

// Parse the args as YAML.
const quartoArgs: QuartoArgs = yamlLoad(
Expand Down

0 comments on commit 17d3bc6

Please sign in to comment.