Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow us to specify import sources within the diagram #1817

Closed
dunkelziffer opened this issue Jan 28, 2024 · 1 comment
Closed

Allow us to specify import sources within the diagram #1817

dunkelziffer opened this issue Jan 28, 2024 · 1 comment

Comments

@dunkelziffer
Copy link

A common use case for D2 is inline usage within Markdown. As we don't have real files here and only a single block of text, we can't use imports at all:

```d2
# not a real file, no imports :(
```

Allow us to define hidden nodes, that will be considered when resolving imports. Previously, we had to do:

# main.d2
container: @children

and

# children.d2
child_1 -> child_2

The following should be equivalent:

# main.d2
d2_imports: {
  children: {
    child_1 -> child_2
  }
}
container: @children

This would allow us to actually use imports within a single file and it would use the same syntax as the already existing imports. But wait, why would you even want that? Why import, if everything is in the same file already? Because imports allow to reuse a defined diagram part multiple times.

@cyborg-ts cyborg-ts added this to D2 Jan 28, 2024
@alixander
Copy link
Collaborator

vars should cover this capability.

vars: {
  x: {
    a
    b
    c
  }
}

hello: ${x}

https://play.d2lang.com/?script=KkssKrZSqOZSUKiAUAoKiWAyCUwmcyko1HLVcnFlpObk5FspqFRX1HIBAgAA__8%3D&

Screenshot 2024-07-18 at 4 34 30 PM

@github-project-automation github-project-automation bot moved this to Done in D2 Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants