Skip to content

Commit 7f4ff96

Browse files
committed
Bring up-to-date, directly call Viz from extension.ts, bump 0.1.0
This simplifies the setup, I assume old versions of vscode still required a lot of workarounds. Move to new Viz library which is a real module, so we can directly call it from `extension.ts` instead of the workaround. This speeds up things considerably, because we don’t have to initialize the wasm library on each call, instead do it once on extension init. The `<pre style="all:unset">` trick is the same as the one used by the preview code generated by the mermaid extension. I removed the test stubs. I moved to npm lockfiles and removed yarn. This bumps the extension version to 0.1.0.
1 parent ef63f4c commit 7f4ff96

8 files changed

+81
-617
lines changed

graphviz-render.js

-31
This file was deleted.

package-lock.json

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "graphviz-markdown-preview",
33
"displayName": "Graphviz Markdown Preview",
44
"description": "Adds Graphviz support to VSCode's builtin markdown preview",
5-
"version": "0.0.8",
5+
"version": "0.1.0",
66
"publisher": "geeklearningio",
77
"engines": {
88
"vscode": "^1.20.0"
@@ -19,28 +19,22 @@
1919
"markdown.previewStyles": [
2020
"./graphviz.css"
2121
],
22-
"markdown.previewScripts": [
23-
"./node_modules/viz.js/viz.js",
24-
"./node_modules/viz.js/full.render.js",
25-
"./graphviz-render.js"
26-
],
2722
"markdown.markdownItPlugins": true
2823
},
2924
"scripts": {
3025
"vscode:prepublish": "npm run compile",
3126
"compile": "tsc -p ./",
3227
"watch": "tsc -watch -p ./",
33-
"postinstall": "node ./node_modules/vscode/bin/install",
34-
"test": "npm run compile && node ./node_modules/vscode/bin/test"
28+
"test": "npm run compile"
3529
},
3630
"devDependencies": {
3731
"@types/mocha": "^2.2.42",
3832
"@types/node": "^7.0.43",
39-
"typescript": "^3.5.2",
40-
"vscode": "^1.1.35"
33+
"@types/vscode": "^1.20.0",
34+
"typescript": "^5.7.2"
4135
},
4236
"dependencies": {
43-
"viz.js": "^2.1.2"
37+
"@viz-js/viz": "^3.11.0"
4438
},
4539
"repository": {
4640
"type": "git",

src/extension.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// The module 'vscode' contains the VS Code extensibility API
33
// Import the module and reference it with the alias vscode in your code below
44
import * as vscode from 'vscode';
5+
import * as vizMod from '@viz-js/viz';
6+
57

68
// this method is called when your extension is activated
79
// your extension is activated the very first time the command is executed
8-
export function activate(context: vscode.ExtensionContext) {
10+
export async function activate(context: vscode.ExtensionContext) {
11+
const viz = await vizMod.instance()
912

1013
// Use the console to output diagnostic information (console.log) and errors (console.error)
1114
// This line of code will only be executed once when your extension is activated
@@ -20,7 +23,9 @@ export function activate(context: vscode.ExtensionContext) {
2023

2124
if (lang && lang.match(/\bgraphviz\b/i)) {
2225

23-
return `<div class="graphviz">${code}</div>`;
26+
return '<pre style="all:unset;">'
27+
+ viz.renderString(code, { engine: 'dot', format: 'svg' })
28+
+ '</pre>';
2429
}
2530

2631
return highlight(code, lang);
@@ -36,4 +41,4 @@ export function activate(context: vscode.ExtensionContext) {
3641

3742
// this method is called when your extension is deactivated
3843
export function deactivate() {
39-
}
44+
}

src/test/extension.test.ts

-22
This file was deleted.

src/test/index.ts

-22
This file was deleted.

tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"es6"
88
],
99
"sourceMap": true,
10-
"rootDir": "src"
10+
"rootDir": "src",
11+
"skipLibCheck": true
1112
},
1213
"exclude": [
1314
"node_modules",
1415
".vscode-test"
1516
]
16-
}
17+
}

0 commit comments

Comments
 (0)