Git Product home page Git Product logo

terrastruct / d2-obsidian Goto Github PK

View Code? Open in Web Editor NEW
194.0 4.0 11.0 1.3 MB

The official D2 plugin for Obsidian. D2 is a modern diagram scripting language thats turns text to diagrams.

Home Page: https://d2lang.com

License: Mozilla Public License 2.0

JavaScript 8.15% TypeScript 85.14% CSS 4.16% Makefile 1.32% Shell 1.22%
diagramming diagrams obsidian software-architecture text-to-diagram

d2-obsidian's Introduction

D2

D2 Obsidian Plugin

D2 is a modern diagram scripting language thats turns text to diagrams. The source code for D2, as well as install instructions and all other information, can be found at https://github.com/terrastruct/d2.

ci ci license discord

d2_obsidian_example.mp4

Installation

Settings > Community plugins > Browse > Search for "D2"

important: D2 must be installed for this plugin to work currently. We will later on introduce a remote API as an option, but currently this plugin calls your local installation of D2.

Configurations

  • Layout engine: D2 supports multiple layout engines, which can significantly affect the look of your diagram.
  • Theme ID: For a list of available themes, visit the D2 repository.
  • Pad: Number of pixels padded around the rendered diagram.
  • Sketch mode: Render the diagram to look like it was sketched by hand.
  • Container height: Diagram max render height in pixels (Requires d2 v0.2.2 and up).
  • Debounce: Number of milliseconds to wait after a change has made to refresh the diagram (min 100).
  • Path: Customize the path to d2 (optional). We check common places D2 might be installed, along with your system path. However, your OS or setup may require you to input your path to d2 manually. To do so, type where d2 into your terminal, and copy everything in the path up until /d2 and paste it into this configuration.

Usage

Create a fenced codeblock with d2 as the language tag:

Hello -> World

How to run this plugin locally

  • Clone this repo.
  • Run yarn to install dependencies.
  • Run yarn run dev to start compilation in watch mode.
  • Copy over main.js, styles.css, manifest.json to your vault [VaultFolder]/.obsidian/plugins/d2/.

FAQ

  • I have D2 installed but I'm running into D2 Compilation Error: d2: command not found
    • The Obsidian plugin may not be able to locate your D2 installation. Get the path to the D2 installation by executing where d2 in the command line, then copy that path minus the executable itself into the Path plugin setting (so if the path is /usr/local/bin/d2, then you want to copy /usr/local/bin).
  • I have a question or need help.
    • The best way to get help is to ask on D2 Discord.
  • I'd like to contribute.
    • We welcome contributions! Please pick one from an existing Issue, or open one if none exists.
  • I have a feature request, proposal, or bug report.
    • Please open up a Github Issue. If it's D2-specific, please open it in the D2 repository. If it's specific to this plugin, please open it here.
  • I have a private inquiry.

d2-obsidian's People

Contributors

alixander avatar cs-qyzhang avatar dlecklider avatar gavin-ts avatar nhooyr avatar portevent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

d2-obsidian's Issues

Support custom fonts

It's possible to specify fonts as input to D2 via the CLI arguments:

  • --font-regular
  • --font-italic
  • --font-bold

It would be very nice, if I could use the same from within Obsidian, since the default font d2 uses is very ugly.

Smaller output, or custom size?

I'm grateful for d2 in Obsidian, as it makes more sense and is easier to use than mermaid--thanks for creating this!

One drawback I'm finding is that the output is very large:

image

image

Are there parameters I should tweak to make this a more reasonably sized two-box graph?

[feature request] Consistent zoom level for diagrams

A diagram containing only a few elements is zoomed in quite a lot so that the diagram width fits the available reading width. Once the diagram gets larger the elements seem to get smaller because the zoom level changes to fit everything into the canvas. This is absolutely unpractical because I need the element sizes to be visually consistent across a document. For example, if I have only one package in the first diagram and I want to show the relations to other packages in the second diagram the elements will have different sizes.

image

Here's PlantUML for comparison:

image

Feature Request: JavaScript Implementation

I realise that this is a big ask, but the current plugin is really just a wrapper for a command line application. It would be great if it was a JS plugin that worked out of the box and worked on mobile devices too. I think there would be broader benefits to D2 as well.

D2 Compilation error: The operation was aborted

I see this very often when working with files containing more but one diagram which is simultaneously displayed on screen. Sometimes it helps to switch into code view and back to make it render correctly, sometimes I have to re-open obisidian.

Feature Request: Embed rendered diagrams in scrollable/zoomable window

Currently as diagrams get larger their content can quickly become to small to easily read. It would be awesome to have diagrams become scrollable and potentially zoomable within the note itself once they've reached a certain size, allowing for effectively infinitely large diagrams.

Allow zooming like on the D2 playground

The plugin does not support image zooming or grabbing and moving the image around. This makes the plugin almost unusable as large diagrams result in them being unreadable.

D2 does not appear as community plugin

Hi, thanks for developing this!

I have problems finding the plugin among the Obsidian community plugins though, inside obsidian as well as on the web page:

Inside Obsidian:
image

Webpage:
image

Handle .d2 files

Hello,

Thanks for this plugin. I'm testing it in a cross-stack context : obsidian to create content, and mkdocs to build and publish content.
the mkdocs part is stable and working, but in obsidian I'm still missing the possibility to edit .d2 files, not just add d2 in markdown files.

Could this be handled?

Thanks!

Please support iOS

Please update this to remove the need for a local D2, which doesn't appear possible on my iOS devices. Can't sync my notes with my iPad or iPhone because D2 plugin doesn't function on iOS

Enhancement: control size of rendered image

When I create a diagram in a note, I have no way to control how big the resulting image is in the note, and the default is currently way too large.

Maybe allow a max-height or scale property to provide user control

Custom arguments to d2 compiler

Hi, first of all thanks for this great plugin and diagram tool!

I am using this plugin in my notebook and I am trying to center the diagram generated instead of left aligning. I found that there is a --center flag for this in the compiler, but the plugin doesn't provide a way to pass arguments to the compiler. Would it be possible to allow users to pass arguments? Thank you.
Screenshot 2023-10-29 at 1 54 07 PM
I would like this to be centered intead of being left aligned.

[Question] How to set the Theme to dark

Hey there,

i want to set my Themes in Obsidian to dark. Sadly i have not found any setting for this in the Plugin's Settings. Is there a way to override it or to add such an option?

Thanks!

Internal Links

Hey, thank you for developing this plug-in!!
Have you planned to integrate obsidian links into the diagrams?

I currently use mermaid, what is great but integrating obsidian links is cumbersome and the layout options are more limited.
Having fast internal link options to integrate with diagrams would open up new workflows currently not possible, at least for me.
Best regards!

Setup for Ipad

Any idea how one would get this running locally on an ipad? I currently write docs in bed at night with mermaid and obsidian, and would love to switch over to D2. Any way I can help let me know. Will start looking for ways to contribute tomorrow. Thanks for all of y'alls work.

Failing to update (or re-install)

  • Previously had D2 installed with Obsidian & was working
  • Tried updating D2 because I wanted to see whether the position/dimension sync feature worked in the Obsidian pugin
  • Failed to update
  • Tried uninstalling and reinstalling; failed to install
  • Tried restarting; no difference
  • Other plugins are working (2 other plugins updated fine)

Screenshots

Screenshot 2023-02-28 at 5 12 22 PM

Screenshot 2023-02-28 at 5 07 42 PM

Screenshot 2023-02-28 at 5 14 37 PM

Ability to scale diagrams

Is it possible to scale a diagram within Obsidian?

Generated diagrams can span multiple pages when exporting to PDF. It would be nice to have the ability to scale diagrams similar to the way Obsidian scales images.

[bug] Extra whitespace at bottom of diagram

When rendering a simple diagram I get a lot of extra space below the diagram. I can see that the actual rendered image has the expected height. The extra spacing must come from the plugin.

image

Flatpak support

Flatpak is a package manager that installs applications in a sandbox, which is great for developers as they can package their applications with their dependencies without having them missing or conflicting with the dependencies of other applications but for extensions it may be painful as there is no way for users to install d2 package inside the sandbox. Even tho it is possible to share directories with the sandbox, common binary locations like /bin or /usr/bin are blacklisted and cannot be shared from the host to the sandbox.

The solution would be to use flatpak-spawn and run flatpak spawn --host /usr/bin/d2 within the sandbox instead of plain d2, it would be nice if this plugin allowed in the settings to provide a custom executable instead of just the path. Looking at the code I didn't found any way to do that currently, but it could be achieved.

Workaround

In the meantime I copied the d2 executable into the sandbox with this command, however it will get removed the next time Obsidian gets updated.

sudo move /usr/bin/d2 /var/lib/flatpak/app/md.obsidian.Obsidian/current/active/files/bin

error when importing .d2 files from same folder as the .md

Steps

  1. create x.d2
    x: {
    shape: circle
    }

  2. create x.md
    ```d2
    ...@x
    ```

Expected:

x.md preview renders circle with x
(see behaviour of VS Code plugin, open same files in VS Code and preview x.md)

Actual:

error

D2 Compilation Error:
err: failed to compile -: -:1:1: failed to import "x.d2": open x.d2: no such file or directory

Environment

(btw: i'm also using Unitade plugin to edit .d2 files directly in Obsidian)

Obsidian 1.4.14

  • D2 plugin 1.1.4
  • Unitade 1.0.2

macOS Sonoma 14.1.2

VS Code 1.84

  • D2 plugin 0.8.8

Explicit path to executable not used?

Is there a chance the plugin is not yet actually reading/consuming the path to the executable? I have it installed via ObsidianBRAT and am having the following experience:

image

Here is the path to my d2 installation on my Mac:

image

And here's the setting as defined in the d2-obsidian plugin settings:

image

Obsidian Insider version 1.1.6, MacOS Ventura 13.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.