Skip to content

Commit

Permalink
Apply indentedTrim to mustache output in paginated lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Feb 4, 2025
1 parent bdaff66 commit 47c9b73
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mwdb/web/src/components/RichAttribute/builtinLambdas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,22 @@ const indicator = lambdaRenderer(function (
);
});

function indentedTrim(text: string) {
let trimmed = "";
for (let line of text.split(/\r?\n/)) {
if (!trimmed && !line.trim()) continue;
trimmed += line + "\n";
}
return trimmed.trimEnd();
}

const paginatedHeader = lambdaRenderer(function (
text: any,
options: LambdaRendererOptions
) {
// TODO: This removes also indentation that may be necessary
options.context.lambdaContext["paginatedHeader"] = options
.mustacheRenderer(text)
.trim();
options.context.lambdaContext["paginatedHeader"] = indentedTrim(
options.mustacheRenderer(text)
);
return "";
});

Expand All @@ -238,8 +246,7 @@ const paginated = lambdaRenderer(function (

if (!Array.isArray(this)) return [];
const elements = this.slice(0, limit).map((element) => {
// TODO: This removes also indentation that may be necessary
return options.mustacheRenderer(text, element).trim();
return indentedTrim(options.mustacheRenderer(text, element));
});
const partialElement = options.markdownRenderer(
(header ? header + "\n" : "") + elements.join("\n")
Expand Down

0 comments on commit 47c9b73

Please sign in to comment.