[READ-ONLY] Mirror of https://github.com/mrgnw/copy-markdown-as-html. VS Code plugin which copies the selected markdown text to the clipboard as HTML
1.7 kB
44 lines
1// The module 'vscode' contains the VS Code extensibility API
2// Import the module and reference it with the alias vscode in your code below
3var vscode = require('vscode');
4var marked = require('marked');
5var copyPaste = require('copy-paste');
6
7// this method is called when your extension is activated
8// your extension is activated the very first time the command is executed
9function activate(context) {
10
11 // Use the console to output diagnostic information (console.log) and errors (console.error)
12 // This line of code will only be executed once when your extension is activated
13 console.log('Congratulations, your extension "copy-markdown-as-html" is now active!');
14
15 // The command has been defined in the package.json file
16 // Now provide the implementation of the command with registerCommand
17 // The commandId parameter must match the command field in package.json
18 var disposable = vscode.commands.registerCommand('extension.copyAsHtml', function () {
19 // The code you place here will be executed every time your command is executed
20
21 // Display a message box to the user
22 //vscode.window.showInformationMessage('Hello World!');
23
24 var editor = vscode.window.activeTextEditor;
25 var selection = editor.selection;
26
27 var text = '';
28
29 if (selection.isEmpty)
30 text = editor.document.getText();
31 else
32 text = editor.document.getText(selection);
33
34 copyPaste.copy(marked(text));
35 });
36
37 context.subscriptions.push(disposable);
38}
39exports.activate = activate;
40
41// this method is called when your extension is deactivated
42function deactivate() {
43}
44exports.deactivate = deactivate;