Skip to content

Commit

Permalink
✨ Preview HTML link in editor
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
stef-levesque committed Oct 21, 2018
1 parent 55bd85c commit b9c166a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
"Other"
],
"activationEvents": [
"onCommand:extension.openLink"
"onCommand:extension.openLink",
"onCommand:extension.previewLink",
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "extension.openLink",
"title": "link: Open link in editor (read-only)"
},
{
"command": "extension.previewLink",
"title": "link: Preview link in editor"
}
]
},
Expand Down
13 changes: 13 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export function activate(context: vscode.ExtensionContext) {
let provider = new LinkContentProvider();
let registration = vscode.workspace.registerTextDocumentContentProvider(linkScheme, provider);

let disposable0 = vscode.commands.registerCommand('extension.previewLink', () => {
let ibo = <vscode.InputBoxOptions>{
prompt: "url to preview",
placeHolder: "https://..."
}
vscode.window.showInputBox(ibo).then( async (link) => {
let webPanel = vscode.window.createWebviewPanel('PreviewHtml', 'Preview Link', -1, {enableFindWidget: true, enableScripts: true });
const response = await got(link);
webPanel.webview.html = response.body;
webPanel.reveal();
});
});

let disposable1 = vscode.commands.registerCommand('extension.openLink', () => {
var ibo = <vscode.InputBoxOptions>{
prompt: "url to download",
Expand Down

0 comments on commit b9c166a

Please sign in to comment.