Skip to content

Feature: Prepend lines to D2 code blocks, global config or presentation level #896

Description

@shanscendent

It would be neat to have a way to easily prepend lines of code to D2 code blocks, either in the global config or presentation wide.

For example, if I'd like sketch mode and transparent fill for all my D2 diagrams, I'd need to add this to the start of every D2 block, which gets pretty repetitive.

vars: { d2-config: { sketch: true } }
style.fill: transparent

Actually, maybe this feature could be helpful for any other code blocks in other languages as well, like import statements for example?

I suggest the following for UX:

Global config

prepend:
  d2: |
    vars: { d2-config: { sketch: true } }
    style.fill: transparent

Presentation front matter

---
title: D2
author: shanscendent
prepend:
  d2: |
    vars: { d2-config: { sketch: true } }
    style.fill: transparent
---

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions