Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Markdium-VSCode extension inside a nx workspace
import { commands, ExtensionContext, window, ViewColumn, Uri } from 'vscode';
import { promises as fs } from 'fs';
import { join } from 'path';
// On activation
export function activate(context: ExtensionContext) {
// Register command "start"
commands.registerCommand('start', async () => {
const panel = window.createWebviewPanel(
'studio',
'Studio',
ViewColumn.Active,
{
enableScripts: true,
localResourceRoots: [Uri.file(join(context.extensionPath, 'studio'))]
});
const html = await fs.readFile(join(context.extensionPath, 'studio/index.html'), 'utf-8');
const matchLinks = /(href|src)="([^"]*)"/g;
const toUri = (_, prefix: 'href' | 'src', link: string) => {
// For
if (link === '#') {
return `${prefix}="${link}"`;
}
// For scripts & links
const path = join(context.extensionPath, 'studio', link);
const uri = Uri.file(path);
return `${prefix}="${panel.webview['asWebviewUri'](uri)}"`;
};
panel.webview.html = html.replace(matchLinks, toUri);
context.subscriptions.push(panel);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.