Skip to content

Use regular D2 variable scoping in Markdown - #3057

Merged
alixander merged 2 commits into
masterfrom
fix-markdown-variable-scope
Nov 26, 2026
Merged

alixander merged 2 commits into
masterfrom
fix-markdown-variable-scope

Conversation

@alixander

Copy link
Copy Markdown
Collaborator

Human


AI

Markdown labels now resolve D2 variable references using the same lexical lookup as plain labels. A container can override a root variable, a missing path can fall back to an outer scope, and quoted keyword names retain their distinct bindings.

vars: {env: production}
service: {
  vars: {env: staging}
  plain: ${env}
  markdown: |md
    ${env}
  |
}
Label Before After
Plain staging staging
Markdown production staging

A nested variable such as db.host is addressed by its full path. Markdown code spans, fenced code, and unresolved placeholders stay literal. Imported modules and interpolated animation frames keep already-substituted text literal while resolving their remaining references in the appropriate scope.

  • sent from alixander's Codex

@alixander
alixander merged commit 0381623 into master Nov 26, 2026
11 checks passed
@alixander
alixander deleted the fix-markdown-variable-scope branch November 26, 2026 14:26
alixander added a commit that referenced this pull request Nov 26, 2026
Master resolves Markdown variables with D2's scope rules and fixes
variable resolution in templates, globs, Markdown links and steps
(#3057, #3060); lib/textmeasure now does the substitution, so
d2ir/compile.go no longer imports it and keeps this branch's htmlentity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant