|
@@ -2,22 +2,17 @@
|
|
|
|
|
|
import * as vscode from 'vscode';
|
|
|
import { escape as htmlEscape } from 'html-escaper';
|
|
|
-import request = require('@endom8rix/async-request');
|
|
|
-import markdownEscape = require("markdown-escape");
|
|
|
+import { request } from './requests';
|
|
|
+const markdownEscape = require("markdown-escape");
|
|
|
|
|
|
|
|
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- console.log('Congratulations, your extension "wikipedia-hyperlinker" is now active!');
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
let disposable = vscode.commands.registerCommand('wikipedia-hyperlinker.addHyperlink', () => {
|
|
|
-
|
|
|
+
|
|
|
var editor = vscode.window.activeTextEditor;
|
|
|
if (editor !== undefined) {
|
|
|
const currentSelection = editor.selection;
|
|
@@ -32,9 +27,9 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
title: 'Loading article from wikipedia...'
|
|
|
}, async (progress) => {
|
|
|
progress.report({ increment: 0 });
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
- const response = await request(`https://en.wikipedia.org/w/api.php?format=json&action=query&prop=info|extracts&exintro&explaintext&&inprop=url&redirects=1&titles=${encodeURIComponent(text)}`);
|
|
|
+
|
|
|
const body = JSON.parse(response.body);
|
|
|
progress.report({ increment: 100 });
|
|
|
console.log(response);
|
|
@@ -44,7 +39,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
vscode.window
|
|
|
.showInformationMessage(
|
|
|
`There are multiple articles under the term ${text}. Do you want to see all the possible articles in wikipedia inside your browser?`,
|
|
|
- {modal: true},
|
|
|
+ { modal: true },
|
|
|
...["Yes", "No"]
|
|
|
)
|
|
|
.then((answer) => {
|
|
@@ -57,7 +52,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
return false;
|
|
|
}
|
|
|
var currentLanguage = editor?.document.languageId;
|
|
|
-
|
|
|
+
|
|
|
if (currentLanguage === "markdown") {
|
|
|
editor?.edit(editBuilder => {
|
|
|
editBuilder.replace(currentSelection,
|
|
@@ -70,9 +65,9 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
`<a href="${url}" title="${htmlEscape(summary)}">${htmlEscape(text)}</a>`
|
|
|
);
|
|
|
});
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
vscode.window.showWarningMessage(`The current language (${currentLanguage}) is not supported`,
|
|
|
- ...["Use HTML", "Use Markdown", "Cancel"]
|
|
|
+ ...["Use HTML", "Use Markdown", "Cancel"]
|
|
|
).then((answer) => {
|
|
|
if (answer === "Use HTML") {
|
|
|
editor?.edit(editBuilder => {
|
|
@@ -80,7 +75,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
`<a href="${url}" title="${htmlEscape(summary)}">${htmlEscape(text)}</a>`
|
|
|
);
|
|
|
});
|
|
|
- } else if (answer === "Use Markdown"){
|
|
|
+ } else if (answer === "Use Markdown") {
|
|
|
editor?.edit(editBuilder => {
|
|
|
editBuilder.replace(currentSelection,
|
|
|
`[${markdownEscape(text)}](${url} "${markdownEscape(summary)}")`
|
|
@@ -95,7 +90,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
}
|
|
|
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
vscode.window.showInformationMessage('No window is active');
|
|
|
|
|
@@ -107,3 +102,4 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
|
|
|
|
|
|
export function deactivate() { }
|
|
|
+g
|