diff --git a/server/remark-includes.ts b/server/remark-includes.ts index 35321a8605..7792514ce7 100644 --- a/server/remark-includes.ts +++ b/server/remark-includes.ts @@ -155,8 +155,6 @@ export function parsePartialParams(expr: string): ParameterAssignments { // The default assignments expression must be on the first line of a partial. // Values must be wrapped in double quotes and separated by single spaces. export function parseParamDefaults(expr: string): ParameterAssignments { - const defaultAssignmentRegexp = new RegExp("{{ (.*) }}", "g"); - // Callers should handle empty values before they get here. // parseParamDefaults has no idea whether this case is acceptable or not. if (expr === "") { @@ -167,13 +165,28 @@ export function parseParamDefaults(expr: string): ParameterAssignments { return {}; } + const possibleAssignmentRegexp = new RegExp("{{ (.*) }}", "g"); + const paramUseRegexp = new RegExp("{{ (w+) }}"); const firstLine = expr.split("\n", 1)[0]; - const matches = defaultAssignmentRegexp.exec(firstLine); + const firstLineMatches = possibleAssignmentRegexp.exec(firstLine); + const paramUses = paramUseRegexp.exec(expr); - if (!matches) { - return {}; + let assignments: ParameterAssignments = {}; + // Treat this as an attempted default parameter assignment + if (!!firstLineMatches && firstLineMatches[1].includes("=")) { + assignments = parseAssignments(firstLineMatches[1]); + } + if (!paramUses) { + return assignments; } - return parseAssignments(matches[1]); + // The default value for parameters without a default is the empty string. + paramUses.slice(1).forEach((use) => { + if (!assignments[use]) { + assignments[use] = ""; + } + }); + + return assignments; } // resolveParamValue takes the quoted value of a template variable within a