[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
0

Configure Feed

Select the types of activity you want to include in your feed.

copy-markdown-as-html / extension.js
2.6 kB 57 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 MarkdownIt = require('markdown-it'); 5const clipboardy = require('clipboardy'); 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.copyMarkdownAsHtml', function () { 19 // The code you place here will be executed every time your command is executed 20 21 this.configurations = vscode.workspace.getConfiguration("copyMarkdownAsHtml"); 22 23 var editor = vscode.window.activeTextEditor; 24 var selection = editor.selection; 25 26 var text = ''; 27 28 if (selection.isEmpty) 29 text = editor.document.getText(); 30 else 31 text = editor.document.getText(selection); 32 33 var settings = {}; 34 if (this.configurations.has('html')) { settings.html = this.configurations.get('html'); } 35 if (this.configurations.has('xhtmlOut')) { settings.xhtmlOut = this.configurations.get('xhtmlOut'); } 36 if (this.configurations.has('breaks')) { settings.breaks = this.configurations.get('breaks'); } 37 if (this.configurations.has('langPrefix')) { settings.langPrefix = this.configurations.get('langPrefix'); } 38 if (this.configurations.has('linkify')) { settings.linkify = this.configurations.get('linkify'); } 39 if (this.configurations.has('typographer')) { settings.typographer = this.configurations.get('typographer'); } 40 if (this.configurations.has('quotes')) { settings.quotes = this.configurations.get('quotes'); } 41 42 if (settings.quotes === '') { settings.quotes = '“”‘’'; } 43 44 var md = new MarkdownIt(settings); 45 var result = md.render(text); 46 47 clipboardy.writeSync(result); 48 }); 49 50 context.subscriptions.push(disposable); 51} 52exports.activate = activate; 53 54// this method is called when your extension is deactivated 55function deactivate() { 56} 57exports.deactivate = deactivate;