diff --git a/actions/setup/js/render_template.cjs b/actions/setup/js/render_template.cjs index 162a07c97bd..c90f039c8a6 100644 --- a/actions/setup/js/render_template.cjs +++ b/actions/setup/js/render_template.cjs @@ -73,7 +73,11 @@ function renderMarkdownTemplate(markdown) { } else { removedBlocks++; core.info(`[renderMarkdownTemplate] Action: Removing entire block`); - return ""; + // Keep the leading newline so the line before the block stays separated + // from the line after it (the closing tag's trailing newline is already + // consumed by the match). Dropping it merges unrelated lines together, + // e.g. "Before\n{{#if false}}...{{/if}}\nAfter" -> "BeforeAfter". + return leadNL; } }); diff --git a/actions/setup/js/render_template.test.cjs b/actions/setup/js/render_template.test.cjs index 171686cd50e..819e7f68f4e 100644 --- a/actions/setup/js/render_template.test.cjs +++ b/actions/setup/js/render_template.test.cjs @@ -52,6 +52,10 @@ describe("renderMarkdownTemplate", () => { const output = renderMarkdownTemplate("Start\n\n{{#if false}}\nBlock 1\n{{/if}}\n\n{{#if false}}\nBlock 2\n{{/if}}\n\n{{#if false}}\nBlock 3\n{{/if}}\n\nEnd"); (expect(output).not.toMatch(/\n{3,}/), expect(output).toContain("Start"), expect(output).toContain("End")); }), + it("should not merge the surrounding lines when a single-newline-separated falsy block is removed", () => { + const output = renderMarkdownTemplate("Line1\n{{#if false}}\nRemoved\n{{/if}}\nLine2\n"); + expect(output).toBe("Line1\nLine2\n"); + }), it("should preserve leading spaces with truthy block", () => { const output = renderMarkdownTemplate(" {{#if true}}\n Content with leading spaces\n {{/if}}"); expect(output).toBe(" Content with leading spaces\n");