Skip to content

Allow importing/including markdown files #2710

@etiennecollin

Description

@etiennecollin

Hi!
Thanks for the excellent project.

I’m currently working on a state diagram for a flight sequencer and would like to attach detailed documentation to each state. While D2’s inline Markdown support works functionally, embedding large blocks of documentation directly in the diagram quickly makes the file difficult to read and maintain.

documentation: |md
  Imagine this is a large amount of documentation...
|
documentation.shape: rectangle

It would be extremely helpful to be able to import a Markdown file, similar to how D2 files can already be imported, rather than inlining the documentation. Compared to placing documentation in a node in a separate D2 file and importing it, importing Markdown directly has the advantage of allowing the documentation to be reused elsewhere, avoiding the need to maintain parallel .d2 and .md versions of the same content. In my case, that documentation already has to exist as Markdown, it's cleaner to reuse it! For example:

documentation: @documentation_file.md
documentation.shape: rectangle

or via variables:

vars: {
  mydocument: @documentation_file.md
}
documentation: ${mydocument}
documentation.shape: rectangle

The same capability would also be useful for tooltips:

x: { tooltip: @documentation_file.md }

I believe much of the existing import infrastructure could potentially be reused, given that D2 already supports importing other D2 files.

Thanks again for your time and for building such an amazing project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions