Skip to content

Commit

Permalink
Some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Oct 8, 2024
1 parent 41377ac commit 2c770d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions server/remark-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,24 @@ export function parseParamDefaults(expr: string): ParameterAssignments {
}

const possibleAssignmentRegexp = new RegExp("{{ (.*) }}", "g");
const paramUseRegexp = new RegExp("{{ (w+) }}");
const paramUseRegexp = new RegExp("{{ (\\w+) }}", "g");
const firstLine = expr.split("\n", 1)[0];
const firstLineMatches = possibleAssignmentRegexp.exec(firstLine);
const paramUses = paramUseRegexp.exec(expr);
const paramUses = Array.from(expr.matchAll(paramUseRegexp));

let assignments: ParameterAssignments = {};
// Treat this as an attempted default parameter assignment
if (!!firstLineMatches && firstLineMatches[1].includes("=")) {
assignments = parseAssignments(firstLineMatches[1]);
}
if (!paramUses) {
console.log("paramUses", paramUses);
if (paramUses.length == 0) {
return assignments;
}
// The default value for parameters without a default is the empty string.
paramUses.slice(1).forEach((use) => {
if (!assignments[use]) {
assignments[use] = "";
paramUses.forEach((use) => {
if (!assignments[use[1]]) {
assignments[use[1]] = "";
}
});

Expand Down
4 changes: 2 additions & 2 deletions uvu-tests/remark-includes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Suite("parsePartialParams correctly parses parameter assignments", () => {
});
});

Suite(
Suite.only(
"parseParamDefaults correctly parses default parameter assignments",
() => {
interface testCase {
Expand Down Expand Up @@ -430,7 +430,7 @@ It also includes the {{ second }} param.`,
This is a partial with a {{ first }}.
It also includes the {{ second }} param.
Finally, there is {{ three }}.
Finally, there is {{ third }}.
`,
expected: {
first: "1",
Expand Down

0 comments on commit 2c770d9

Please sign in to comment.