Skip to content

Commit c3ccdc4

Browse files
author
Bernard Xie
authored
Merge pull request #25 from terrastruct/bernie/fix-readme
Update readme, add additional default PATHs
2 parents 11e9824 + d82aeb5 commit c3ccdc4

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

README.md

+10-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
D2 Obsidian Plugin
55
</h2>
66

7-
D2 is a modern diagram scripting language thats turns text to diagrams. The source code
8-
for D2, as well as install instructions and all other information, can be found at
7+
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
98
[https://github.com/terrastruct/d2](https://github.com/terrastruct/d2).
109

1110
[![ci](https://github.com/terrastruct/d2-obsidian/actions/workflows/ci.yml/badge.svg)](https://github.com/terrastruct/d2-obsidian/actions/workflows/ci.yml)
@@ -21,19 +20,16 @@ https://user-images.githubusercontent.com/6413609/205414613-5b2559f1-0645-4432-b
2120

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

24-
**important**: [D2](https://github.com/terrastruct/d2) must be installed for this plugin
25-
to work currently. We will later on introduce a remote API as an option, but currently
26-
this plugin calls your local installation of D2.
23+
**important**: [D2](https://github.com/terrastruct/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.
2724

2825
## Configurations
2926

3027
- `Layout engine`: D2 supports multiple layout engines, which can significantly affect the look of your diagram.
3128
- `Theme ID`: For a list of available themes, visit the [D2 repository](https://github.com/terrastruct/d2/tree/master/d2themes).
32-
- `Debounce`: Number of milliseconds to wait after a change has made to refresh the
33-
diagram (min 100).
34-
- `Path`: Customize the path to `d2` (optional). We check common places D2 might be
35-
installed, along with your system path. However, your OS or setup may require you to
36-
input your path to `d2` manually.
29+
- `Pad`: Number of pixels padded around the rendered diagram.
30+
- `Sketch mode`: Render the diagram to look like it was sketched by hand.
31+
- `Debounce`: Number of milliseconds to wait after a change has made to refresh the diagram (min 100).
32+
- `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.
3733

3834
## Usage
3935

@@ -52,14 +48,13 @@ Hello -> World
5248

5349
## FAQ
5450

51+
- I have D2 installed but I'm running into `D2 Compilation Error: d2: command not found`
52+
- 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`).
5553
- I have a question or need help.
5654
- The best way to get help is to ask on [D2 Discord](https://discord.gg/NF6X8K4eDq).
5755
- I'd like to contribute.
58-
- We welcome contributions! Please pick one from an existing Issue, or open one if none
59-
exists.
56+
- We welcome contributions! Please pick one from an existing Issue, or open one if none exists.
6057
- I have a feature request, proposal, or bug report.
61-
- Please open up a Github Issue. If it's D2-specific, please open it in the [D2
62-
repository](https://github.com/terrastruct/d2). If it's specific to this plugin,
63-
please open it here.
58+
- Please open up a Github Issue. If it's D2-specific, please open it in the [D2 repository](https://github.com/terrastruct/d2). If it's specific to this plugin, please open it here.
6459
- I have a private inquiry.
6560
- Please reach out at [hi@d2lang.com](hi@d2lang.com).

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "d2-obsidian",
33
"name": "D2",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"minAppVersion": "0.15.0",
66
"description": "The official D2 plugin for Obsidian. D2 is a modern diagram scripting language that turns text to diagrams.",
77
"author": "Terrastruct",

src/processor.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { MarkdownPostProcessorContext, ButtonComponent } from "obsidian";
22
import { exec, execSync } from "child_process";
33
import { delimiter } from "path";
44
import debounce from "lodash.debounce";
5+
import os from "os";
56

67
import D2Plugin from "./main";
78

@@ -124,7 +125,15 @@ export class D2Processor {
124125
};
125126

126127
async generatePreview(source: string, signal: AbortSignal): Promise<string> {
127-
const pathArray = [process.env.PATH, "/opt/homebrew/bin"];
128+
const pathArray = [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin"];
129+
130+
// platform will be win32 even on 64 bit windows
131+
if (os.platform() === "win32") {
132+
pathArray.push(`C:\Program Files\D2`);
133+
} else {
134+
pathArray.push(`${process.env.HOME}/.local/bin`);
135+
}
136+
128137
let GOPATH = "";
129138
try {
130139
GOPATH = execSync("go env GOPATH", {
@@ -143,6 +152,7 @@ export class D2Processor {
143152
if (this.plugin.settings.d2Path) {
144153
pathArray.push(this.plugin.settings.d2Path);
145154
}
155+
146156
const options: any = {
147157
...process.env,
148158
env: {

versions.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"1.1.1": "0.15.0",
23
"1.1.0": "0.15.0",
34
"1.0.1": "0.15.0",
45
"1.0.0": "0.15.0"

0 commit comments

Comments
 (0)