Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading