Repository navigation
Build D2 text from typed syntax nodes and parse values up front - #14
Merged
Merged
Conversation
All D2 text is now produced in one module, d2._syntax, from frozen dataclasses
(Key, Label, Url, Quoted, Keyword, Color, Array, Text, Field, BlockField, Edge,
Comment) and a single emit function. Quoting and escaping rules live there only.
helpers.py is removed.
Style colors are parsed into d2.Color (CSS names, 3 or 6 digit hex, gradients,
${variables}); numeric ranges D2 enforces raise ValueError at construction; the
fill-pattern, text-transform and label position sets match D2 0.9.0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All D2 text now comes from one internal module,
d2/_syntax.py. The classes build typed statements instead of strings. Every quoting, escaping and indentation rule is in that one module. Values are parsed into real types when an object is built.Syntax
emitfunction writes them out.|run in their text, so code that contains|no longer breaks the output.Typed values
d2.Coloraccepts a CSS color name, a 3 or 6 digit hex code with or without#, a gradient, or a${variable}. It always writes the D2 form, e.g."#dbeafe". A bad color raisesValueErrorwhen theStyleis built.text_transform="title"is now"capitalize".inside-*label positions are replaced by the nine plain positions that d2 0.9.0 accepts.Compatibility: every public name, constructor parameter and test expectation is unchanged.
Output differences
styleblock inside a layer or scenario was indented wrongly before. It's correct now.'"a.b"', is now treated as literal text. Style values you quoted yourself still work.id: "". The oldid:was invalid D2.Checked locally:
uv lock --checkare clean.🤖 Generated with Claude Code