123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- /******/ (() => { // webpackBootstrap
- /******/ var __webpack_modules__ = ([
- /* 0 */,
- /* 1 */
- /***/ ((module) => {
- "use strict";
- module.exports = require("vscode");
- /***/ }),
- /* 2 */
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- /**
- * Copyright (C) 2017-present by Andrea Giammarchi - @WebReflection
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- const {replace} = '';
- // escape
- const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
- const ca = /[&<>'"]/g;
- const esca = {
- '&': '&',
- '<': '<',
- '>': '>',
- "'": ''',
- '"': '"'
- };
- const pe = m => esca[m];
- /**
- * Safely escape HTML entities such as `&`, `<`, `>`, `"`, and `'`.
- * @param {string} es the input to safely escape
- * @returns {string} the escaped input, and it **throws** an error if
- * the input type is unexpected, except for boolean and numbers,
- * converted as string.
- */
- const escape = es => replace.call(es, ca, pe);
- exports.escape = escape;
- // unescape
- const unes = {
- '&': '&',
- '&': '&',
- '<': '<',
- '<': '<',
- '>': '>',
- '>': '>',
- ''': "'",
- ''': "'",
- '"': '"',
- '"': '"'
- };
- const cape = m => unes[m];
- /**
- * Safely unescape previously escaped entities such as `&`, `<`, `>`, `"`,
- * and `'`.
- * @param {string} un a previously escaped string
- * @returns {string} the unescaped input, and it **throws** an error if
- * the input type is unexpected, except for boolean and numbers,
- * converted as string.
- */
- const unescape = un => replace.call(un, es, cape);
- exports.unescape = unescape;
- /***/ }),
- /* 3 */
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.request = void 0;
- const url_1 = __webpack_require__(4);
- const https = __webpack_require__(5);
- const qs = __webpack_require__(6);
- /**
- * Parse a request body based on known MIME types, based on the Content-Type
- * header. If unknown or undefined, will return the original request body.
- * @param {Object} opts - The request options.
- * @param {Object|string} body - The request body.
- * @returns {Object|string} A parsed request body for known MIME types, or the original request body.
- */
- function parse(opts = {}, body) {
- if (opts.headers == null) {
- return body;
- }
- switch (opts.headers['Content-Type']) {
- case 'application/json': return JSON.stringify(body);
- case 'application/x-www-form-urlencoded': return qs.stringify(body);
- default: return body;
- }
- }
- /**
- * Make an asynchronous request to an HTTP or HTTPS address. Automatically
- * derives protocol from URL input, and content length from the request body.
- * @param {URL|string} url - The request URL.
- * @param {Object} opts - The request options.
- * @param {Object|string} body - The request body.
- * @returns {Promise} A promise to return either a response object, or an error.
- */
- function request(url, opts = {}, body = '') {
- const data = parse(opts, body);
- if (opts.headers == null) {
- opts.headers = {};
- }
- return new Promise((resolve, reject) => {
- if (!(url instanceof url_1.URL)) {
- url = new url_1.URL(url);
- }
- const request = https.request(url, opts, (response) => {
- const chunks = [];
- response.on('data', (chunk) => {
- chunks.push(chunk);
- });
- response.on('end', () => {
- try {
- const { headers } = response;
- const body = chunks.join('');
- resolve({ headers, body });
- }
- catch (error) {
- reject(error);
- }
- });
- response.on('error', (error) => {
- reject(error);
- });
- });
- request.write(data);
- request.end();
- });
- }
- exports.request = request;
- /***/ }),
- /* 4 */
- /***/ ((module) => {
- "use strict";
- module.exports = require("url");
- /***/ }),
- /* 5 */
- /***/ ((module) => {
- "use strict";
- module.exports = require("https");
- /***/ }),
- /* 6 */
- /***/ ((module) => {
- "use strict";
- module.exports = require("querystring");
- /***/ }),
- /* 7 */
- /***/ ((module) => {
- var replacements = [
- [/\*/g, '\\*', 'asterisks'],
- [/#/g, '\\#', 'number signs'],
- [/\//g, '\\/', 'slashes'],
- [/\(/g, '\\(', 'parentheses'],
- [/\)/g, '\\)', 'parentheses'],
- [/\[/g, '\\[', 'square brackets'],
- [/\]/g, '\\]', 'square brackets'],
- [/</g, '<', 'angle brackets'],
- [/>/g, '>', 'angle brackets'],
- [/_/g, '\\_', 'underscores']
- ]
- module.exports = function (string, skips) {
- skips = skips || []
- return replacements.reduce(function (string, replacement) {
- var name = replacement[2]
- return name && skips.indexOf(name) !== -1
- ? string
- : string.replace(replacement[0], replacement[1])
- }, string)
- }
- /***/ })
- /******/ ]);
- /************************************************************************/
- /******/ // The module cache
- /******/ var __webpack_module_cache__ = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
- /******/ if (cachedModule !== undefined) {
- /******/ return cachedModule.exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = __webpack_module_cache__[moduleId] = {
- /******/ // no module.id needed
- /******/ // no module.loaded needed
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /************************************************************************/
- var __webpack_exports__ = {};
- // This entry need to be wrapped in an IIFE because it need to be in strict mode.
- (() => {
- "use strict";
- var exports = __webpack_exports__;
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.deactivate = exports.activate = void 0;
- // The module 'vscode' contains the VS Code extensibility API
- // Import the module and reference it with the alias vscode in your code below
- const vscode = __webpack_require__(1);
- const html_escaper_1 = __webpack_require__(2);
- const requests_1 = __webpack_require__(3);
- const markdownEscape = __webpack_require__(7);
- // this method is called when your extension is activated
- // your extension is activated the very first time the command is executed
- function activate(context) {
- let disposable = vscode.commands.registerCommand('wikipedia-hyperlinker.addHyperlink', () => {
- var editor = vscode.window.activeTextEditor;
- if (editor !== undefined) {
- const currentSelection = editor.selection;
- const text = editor.document.getText(currentSelection);
- if (text.trim() === '') {
- vscode.window.showErrorMessage('No text is selected');
- return false;
- }
- vscode.window.withProgress({
- location: vscode.ProgressLocation.Window,
- cancellable: false,
- title: 'Loading article from wikipedia...'
- }, async (progress) => {
- progress.report({ increment: 0 });
- try {
- const response = await (0, requests_1.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);
- const summary = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['extract'];
- const url = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['fullurl'];
- if (summary.includes("may refer to:")) {
- 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 }, ...["Yes", "No"])
- .then((answer) => {
- if (answer === "Yes") {
- vscode.env.openExternal(vscode.Uri.parse(url));
- }
- else {
- vscode.window.showInformationMessage("Okay, you can refine your text anytime and use the command again");
- }
- });
- return false;
- }
- var currentLanguage = editor?.document.languageId;
- if (currentLanguage === "markdown") {
- editor?.edit(editBuilder => {
- editBuilder.replace(currentSelection, `[${markdownEscape(text)}](${url})`);
- });
- }
- else if (currentLanguage === "html" || currentLanguage === "jinja") {
- editor?.edit(editBuilder => {
- editBuilder.replace(currentSelection, `<a href="${url}" title="${(0, html_escaper_1.escape)(summary)}">${(0, html_escaper_1.escape)(text)}</a>`);
- });
- }
- else {
- vscode.window.showWarningMessage(`The current language (${currentLanguage}) is not supported`, ...["Use HTML", "Use Markdown", "Cancel"]).then((answer) => {
- if (answer === "Use HTML") {
- editor?.edit(editBuilder => {
- editBuilder.replace(currentSelection, `<a href="${url}" title="${(0, html_escaper_1.escape)(summary)}">${(0, html_escaper_1.escape)(text)}</a>`);
- });
- }
- else if (answer === "Use Markdown") {
- editor?.edit(editBuilder => {
- editBuilder.replace(currentSelection, `[${markdownEscape(text)}](${url})`);
- });
- }
- });
- }
- }
- catch (error) {
- vscode.window.showErrorMessage(`Request failed`);
- console.error(error);
- }
- });
- }
- else {
- vscode.window.showInformationMessage('No window is active');
- }
- });
- context.subscriptions.push(disposable);
- }
- exports.activate = activate;
- // this method is called when your extension is deactivated
- function deactivate() { }
- exports.deactivate = deactivate;
- })();
- module.exports = __webpack_exports__;
- /******/ })()
- ;
- //# sourceMappingURL=extension.js.map
|