Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Fix frontmatter parameter interpolation in markdown scripts#1905

Merged
pelikhan merged 5 commits into
devfrom
copilot/fix-d36dafd4-8226-4148-947a-96023624f1bc
Aug 22, 2025
Merged

Fix frontmatter parameter interpolation in markdown scripts#1905
pelikhan merged 5 commits into
devfrom
copilot/fix-d36dafd4-8226-4148-947a-96023624f1bc

Conversation

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown

Fixes the issue where frontmatter parameters defined in markdown scripts were not being used for variable interpolation with {{ param }} syntax.

Problem

When markdown scripts defined parameters in frontmatter like this:

---
parameters:
  name:
    type: string
    default: "World"
---
Hello {{name}}!

The {{name}} variable was not being replaced with the default value "World" during interpolation. The frontmatter parameters were being parsed but never connected to the variable resolution system.

Root Cause

The interpolateVariables() function in mustache.ts was calling splitMarkdown() to extract content and discard frontmatter, meaning frontmatter parameters never made it into the variable interpolation process.

Solution

This PR modifies both mustache.ts and template.ts to properly extract and use frontmatter parameters during variable interpolation:

  1. Enhanced interpolateVariables() to extract frontmatter parameters and merge them with provided data
  2. Added support for both formats: standard parameters and prompty inputs + sample formats
  3. Implemented proper precedence: provided data overrides frontmatter defaults
  4. Maintained backward compatibility with existing functionality

Supported Formats

Standard format:

---
parameters:
  name:
    type: string
    default: "World"
  count:
    type: number
    default: 3
---
Hello {{name}}! This message will repeat {{count}} times.

Prompty format:

---
inputs:
  question:
    type: string
sample:
  "question": "What is the capital of France?"
---
Question: {{question}}

Key Features

  • Frontmatter parameter defaults are used when no data is provided for that parameter
  • Provided data takes precedence over frontmatter defaults
  • Works with both Mustache and Jinja templating formats
  • Supports both standard parameters and prompty inputs + sample formats
  • Comprehensive test coverage for all scenarios including edge cases

Testing

Added 6 new test cases covering:

  • Using frontmatter defaults when no data provided
  • Partial data override scenarios
  • Prompty format support
  • Jinja templating compatibility
  • Edge cases and backward compatibility

All existing functionality remains unchanged and working as expected.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /home/REDACTED/.local/share/pnpm/.tools/pnpm/10.12.3/bin/pnpm install (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits August 22, 2025 15:07
… fix

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Q: markdown scripts in this project support params and vars, but when i defined params using frontmatter, and use the defined params as {{ param }}, the value doesn't get replaced A: The frontmatter parameters are being parsed but never connected to t... Fix frontmatter parameter interpolation in markdown scripts Aug 22, 2025
Copilot AI requested a review from pelikhan August 22, 2025 15:16
@pelikhan pelikhan marked this pull request as ready for review August 22, 2025 16:16
@github-actions

Copy link
Copy Markdown
Contributor

Warning

LLM error (403): error

AI-generated content by docs may be incorrect.

@pelikhan pelikhan merged commit 8f135fb into dev Aug 22, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants