Skip to content

feat(mdxish): resolve variables in code blocks#1350

Merged
kevinports merged 31 commits into
nextfrom
dimas/RM-15239-variable-resolution
Feb 20, 2026
Merged

feat(mdxish): resolve variables in code blocks#1350
kevinports merged 31 commits into
nextfrom
dimas/RM-15239-variable-resolution

Conversation

@eaglethrost

@eaglethrost eaglethrost commented Feb 19, 2026

Copy link
Copy Markdown
Contributor
PR App Fix RM-XYZ

🧰 Changes

As a follow up of #1339, we want to resolve variables in inline code & code blocks, and the tokenizer couldn't do that. This PR adds an additional argument to the engine for the project variables, and a transformer to visit code nodes & use regexes to resolve legacy & MDX variables to their value.

🧬 QA & Testing

The variables in this should get resolved, test with code blocks

`<<name>> {user.name}`

// Remove the \, basically make it a code block
\```
My name is <<name>>

My other name is {user.name}
\```

[block:code]
{
  "codes": [
    {
      "code": "My name is <<name>> and {user.name}",
      "language": "js"
    }
  ]
}
[/block]

commit e657a21
Author: eagletrhost <dimazanugrah12@gmail.com>
Date:   Mon Feb 16 19:51:12 2026 +1100

    refactor: clean code & comment

commit c28853d
Author: eagletrhost <dimazanugrah12@gmail.com>
Date:   Mon Feb 16 19:40:18 2026 +1100

    test: fix legacy

commit 7574b19
Author: eagletrhost <dimazanugrah12@gmail.com>
Date:   Mon Feb 16 18:36:04 2026 +1100

    feat: glossary adjustments

commit 6e92df0
Author: eagletrhost <dimazanugrah12@gmail.com>
Date:   Mon Feb 16 18:13:02 2026 +1100

    feat: parse legacy vars in codes & api header block
@eaglethrost
eaglethrost marked this pull request as draft February 19, 2026 13:01
@eaglethrost
eaglethrost marked this pull request as ready for review February 19, 2026 13:27
@eaglethrost
eaglethrost requested review from kevinports and removed request for maximilianfalco February 19, 2026 14:06

@kevinports kevinports left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Just had a question regarding the transformer placement in the pipeline.

Comment thread lib/mdxish.ts Outdated
.use(mdxishHtmlBlocks)
.use(newEditorTypes ? mdxishJsxToMdast : undefined) // Convert JSX elements to MDAST types
.use(safeMode ? undefined : evaluateExpressions, { context: jsxContext }) // Evaluate MDX expressions using jsxContext
.use(variablesCodeTransformer, { variables }) // Resolve <<...>> and {user.*} inside code and inline code nodes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to happen in mdxishAstProcessor?

The mdxish pipeline handles "rendering" and we only need to resolve vars at that time. So could we put it in mdxish and avoid having to have an arg in mdxishAstProcessor for this?

We'll want to keep these unresolved in mdxishAstProcessor for the editor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes better sense yeah

);
}

const variablesCodeTransformer: Plugin<[Options?]> = ({ variables }: Options = {}) => tree => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A JSDoc describing what this transformer is and why need it might be helpful here.

@eaglethrost

eaglethrost commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

One sec a test failing

Update: Done!

@kevinports
kevinports merged commit a6460f8 into next Feb 20, 2026
11 checks passed
@kevinports
kevinports deleted the dimas/RM-15239-variable-resolution branch February 20, 2026 15:36
rafegoldberg pushed a commit that referenced this pull request Feb 20, 2026
## Version 13.3.0
### ✨ New & Improved

* **mdxish:** add legacy variable tokenizer ([#1339](#1339)) ([8e8b11b](8e8b11b))
* add option to perserve variable syntax in plain text compiler ([#1345](#1345)) ([5ab350e](5ab350e))
* **mdxish:** resolve variables in code blocks ([#1350](#1350)) ([a6460f8](a6460f8))
* **mdxish:** use variable name for heading slug generation ([#1340](#1340)) ([61a97d3](61a97d3))

<!--SKIP CI-->
@rafegoldberg

Copy link
Copy Markdown
Collaborator

This PR was released!

🚀 Changes included in v13.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants