Skip to content

Add newer D2 features, validate and fmt - #13

Merged
h0rv merged 3 commits into
mainfrom
d2-features
Oct 23, 2026
Merged

h0rv merged 3 commits into
mainfrom
d2-features

Conversation

@h0rv

@h0rv h0rv commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Adds the D2 features released since py-d2 stopped (v0.6.7 to v0.9.0), plus older ones the library never had. Existing names, parameters and test expectations don't change. Every new parameter is keyword-only.

New functions

  • d2.validate(diagram_or_source) runs d2 validate and raises D2Error with d2's message. It helps code or an LLM that writes D2 check it.
  • d2.fmt(diagram_or_source) returns the source formatted by d2 fmt.

Render options

  • Formats: adds gif and pptx.
  • New keyword options: dark_theme, sketch, pad, scale, center, omit_version, no_xml_tag, salt, animate_interval, ascii_mode and timeout.

Object model

  • Labels: shape and connection labels can be Markdown, LaTeX or code, through Text. label_near and icon_near place them, and LabelPosition is a typed set of positions.
  • Positions: fixed top and left positions, which need TALA.
  • Grids: separate vertical_gap and horizontal_gap.
  • Connections: gain icon, link and classes.
  • Shape type: ShapeType.c4_person.
  • Legends: d2.Legend, with a title and a typed near position.
  • Variables: Diagram(variables=...), which you use with ${name} substitution.
  • Board titles: Layer(label=...) titles scenarios and steps.

Not modeled yet:

  • glob filters (&connected, level)
  • suspend and unsuspend
  • imports
  • connection references like (a -> b)[0]
  • theme-overrides
  • tala-seeds

Plain globs already work through Shape(name="*").

There are six new examples, 20 in total, and new tests for each feature.

Checked locally: all 133 tests pass, ruff, ty and uv lock --check are clean, and all 20 examples run. That includes the GIF, PPTX and TALA outputs.

🤖 Generated with Claude Code

h0rv and others added 3 commits October 23, 2026 10:54
…ables and render options

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the d2 fmt command and stops shadowing the format builtin, which
removes two lint suppressions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h0rv
h0rv merged commit aa253cb into main Oct 23, 2026
9 checks passed
@h0rv
h0rv deleted the d2-features branch October 23, 2026 14:56
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