Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created May 7, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/88956b1c50f173eda072f2488fcad682 to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/88956b1c50f173eda072f2488fcad682 to your computer and use it in GitHub Desktop.
Markdium-VSCode extension inside a nx workspace
const html = await fs.readFile(join(context.extensionPath, 'studio/index.html'), 'utf-8');
// 1. Get all link prefixed by href or src
const matchLinks = /(href|src)="([^"]*)"/g;
// 2. Transform the result of the regex into a vscode's URI format
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)}"`;
};
// 3. Replace the all link from the index.html into a URI format
panel.webview.html = html.replace(matchLinks, toUri);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment