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QoC,MAAKC,IACZA,EAAYrF,QAAQmD,EACnB,IAAImC,EAAejC,OAAUpD,KAC7B,GAEH,GAGH,CAAE,MAAOqB,GACRuB,EAAOI,OAAOQ,iBAAiB,kBAC/BY,QAAQ/C,MAAMA,EACf,IAIF,MACCuB,EAAOI,OAAO0B,uBAAuB,sBAEtC,IAGDhC,EAAQ6C,cAAcpE,KAAKwB,EAC5B,EAGA,wBAA+B,EArG/B,eACA,SACA,SACM0C,EAAiB,EAAQ,G","sources":["webpack://wikipedia-link/./node_modules/markdown-escape/index.js","webpack://wikipedia-link/./src/requests.ts","webpack://wikipedia-link/external commonjs \"vscode\"","webpack://wikipedia-link/external node-commonjs \"https\"","webpack://wikipedia-link/external node-commonjs \"querystring\"","webpack://wikipedia-link/external node-commonjs \"url\"","webpack://wikipedia-link/./node_modules/html-escaper/cjs/index.js","webpack://wikipedia-link/webpack/bootstrap","webpack://wikipedia-link/./src/extension.ts"],"sourcesContent":["var replacements = [\n [/\\*/g, '\\\\*', 'asterisks'],\n [/#/g, '\\\\#', 'number signs'],\n [/\\//g, '\\\\/', 'slashes'],\n [/\\(/g, '\\\\(', 'parentheses'],\n [/\\)/g, '\\\\)', 'parentheses'],\n [/\\[/g, '\\\\[', 'square brackets'],\n [/\\]/g, '\\\\]', 'square brackets'],\n [/</g, '<', 'angle brackets'],\n [/>/g, '>', 'angle brackets'],\n [/_/g, '\\\\_', 'underscores'],\n [/`/g, '\\\\`', 'codeblocks']\n]\n\nmodule.exports = function (string, skips) {\n skips = skips || []\n return replacements.reduce(function (string, replacement) {\n var name = replacement[2]\n return name && skips.indexOf(name) !== -1\n ? string\n : string.replace(replacement[0], replacement[1])\n }, string)\n}\n","import { URL } from \"url\";\n\nconst https = require('https');\nconst qs = require('querystring');\n\nexport interface RequestOptions {\n headers?: { [key: string]: string | number }\n}\n\n/**\n * Parse a request body based on known MIME types, based on the Content-Type\n * header. If unknown or undefined, will return the original request body.\n * @param {Object} opts - The request options.\n * @param {Object|string} body - The request body.\n * @returns {Object|string} A parsed request body for known MIME types, or the original request body.\n */\nfunction parse(opts: RequestOptions = {}, body: Object | string) {\n if (opts.headers == null) {\n return body;\n }\n\n switch (opts.headers['Content-Type']) {\n case 'application/json': return JSON.stringify(body);\n case 'application/x-www-form-urlencoded': return qs.stringify(body);\n default: return body;\n }\n}\n\n/**\n * Make an asynchronous request to an HTTP or HTTPS address. Automatically\n * derives protocol from URL input, and content length from the request body.\n * @param {URL|string} url - The request URL.\n * @param {Object} opts - The request options.\n * @param {Object|string} body - The request body.\n * @returns {Promise} A promise to return either a response object, or an error.\n */\nexport function request(url: URL | string, opts: RequestOptions = {}, body: Object | string = ''): Promise<any> {\n const data = parse(opts, body);\n\n if (opts.headers == null) {\n opts.headers = {};\n }\n return new Promise((resolve, reject) => {\n if (!(url instanceof URL)) {\n url = new URL(url);\n }\n const request = https.request(url, opts, (response: any) => {\n const chunks: any[] = [];\n\n response.on('data', (chunk: any) => {\n chunks.push(chunk);\n });\n\n response.on('end', () => {\n try {\n const { headers } = response;\n const body = chunks.join('');\n resolve({ headers, body });\n }\n catch (error) {\n reject(error);\n }\n });\n\n response.on('error', (error: Error) => {\n reject(error);\n });\n });\n\n request.write(data);\n request.end();\n });\n}\n","module.exports = require(\"vscode\");","module.exports = require(\"https\");","module.exports = require(\"querystring\");","module.exports = require(\"url\");","'use strict';\n/**\n * Copyright (C) 2017-present by Andrea Giammarchi - @WebReflection\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nconst {replace} = '';\n\n// escape\nconst es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;\nconst ca = /[&<>'\"]/g;\n\nconst esca = {\n '&': '&',\n '<': '<',\n '>': '>',\n \"'\": ''',\n '\"': '"'\n};\nconst pe = m => esca[m];\n\n/**\n * Safely escape HTML entities such as `&`, `<`, `>`, `\"`, and `'`.\n * @param {string} es the input to safely escape\n * @returns {string} the escaped input, and it **throws** an error if\n * the input type is unexpected, except for boolean and numbers,\n * converted as string.\n */\nconst escape = es => replace.call(es, ca, pe);\nexports.escape = escape;\n\n\n// unescape\nconst unes = {\n '&': '&',\n '&': '&',\n '<': '<',\n '<': '<',\n '>': '>',\n '>': '>',\n ''': \"'\",\n ''': \"'\",\n '"': '\"',\n '"': '\"'\n};\nconst cape = m => unes[m];\n\n/**\n * Safely unescape previously escaped entities such as `&`, `<`, `>`, `\"`,\n * and `'`.\n * @param {string} un a previously escaped string\n * @returns {string} the unescaped input, and it **throws** an error if\n * the input type is unexpected, except for boolean and numbers,\n * converted as string.\n */\nconst unescape = un => replace.call(un, es, cape);\nexports.unescape = unescape;\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// The module 'vscode' contains the VS Code extensibility API\n// Import the module and reference it with the alias vscode in your code below\nimport * as vscode from 'vscode';\nimport { escape as htmlEscape } from 'html-escaper';\nimport { request } from './requests';\nconst markdownEscape = require(\"markdown-escape\");\n\n// this method is called when your extension is activated\n// your extension is activated the very first time the command is executed\nexport function activate(context: vscode.ExtensionContext) {\n\n\n\n\tlet disposable = vscode.commands.registerCommand('wikipedia-hyperlinker.addHyperlink', () => {\n\n\t\tvar editor = vscode.window.activeTextEditor;\n\t\tif (editor !== undefined) {\n\t\t\tconst currentSelection = editor.selection;\n\t\t\tconst text = editor.document.getText(currentSelection);\n\t\t\tif (text.trim() === '') {\n\t\t\t\tvscode.window.showErrorMessage('No text is selected');\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tvscode.window.withProgress({\n\t\t\t\tlocation: vscode.ProgressLocation.Window,\n\t\t\t\tcancellable: false,\n\t\t\t\ttitle: 'Loading article from wikipedia...'\n\t\t\t}, async (progress) => {\n\t\t\t\tprogress.report({ increment: 0 });\n\n\t\t\t\ttry {\n\t\t\t\t\tconst 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)}`);\n\t\t\t\t\tconst body = JSON.parse(response.body);\n\t\t\t\t\tprogress.report({ increment: 100 });\n\t\t\t\t\tconsole.log(response);\n\t\t\t\t\tconst summary: string = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['extract'];\n\t\t\t\t\tconst url: string = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['fullurl'];\n\t\t\t\t\tif (summary.includes(\"may refer to:\")) {\n\t\t\t\t\t\tvscode.window\n\t\t\t\t\t\t\t.showInformationMessage(\n\t\t\t\t\t\t\t\t`There are multiple articles under the term ${text}. Do you want to see all the possible articles in wikipedia inside your browser?`,\n\t\t\t\t\t\t\t\t{ modal: true },\n\t\t\t\t\t\t\t\t...[\"Yes\", \"No\"]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.then((answer) => {\n\t\t\t\t\t\t\t\tif (answer === \"Yes\") {\n\t\t\t\t\t\t\t\t\tvscode.env.openExternal(vscode.Uri.parse(url));\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tvscode.window.showInformationMessage(\"Okay, you can refine your text anytime and use the command again\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tvar currentLanguage = editor?.document.languageId;\n\n\t\t\t\t\tif (currentLanguage === \"markdown\") {\n\t\t\t\t\t\teditor?.edit(editBuilder => {\n\t\t\t\t\t\t\teditBuilder.replace(currentSelection,\n\t\t\t\t\t\t\t\t`[${markdownEscape(text)}](${url})`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (currentLanguage === \"html\" || currentLanguage === \"jinja\") {\n\t\t\t\t\t\teditor?.edit(editBuilder => {\n\t\t\t\t\t\t\teditBuilder.replace(currentSelection,\n\t\t\t\t\t\t\t\t`<a href=\"${url}\" title=\"${htmlEscape(summary)}\">${htmlEscape(text)}</a>`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvscode.window.showWarningMessage(`The current language (${currentLanguage}) is not supported`,\n\t\t\t\t\t\t\t...[\"Use HTML\", \"Use Markdown\", \"Cancel\"]\n\t\t\t\t\t\t).then((answer) => {\n\t\t\t\t\t\t\tif (answer === \"Use HTML\") {\n\t\t\t\t\t\t\t\teditor?.edit(editBuilder => {\n\t\t\t\t\t\t\t\t\teditBuilder.replace(currentSelection,\n\t\t\t\t\t\t\t\t\t\t`<a href=\"${url}\" title=\"${htmlEscape(summary)}\">${htmlEscape(text)}</a>`\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else if (answer === \"Use Markdown\") {\n\t\t\t\t\t\t\t\teditor?.edit(editBuilder => {\n\t\t\t\t\t\t\t\t\teditBuilder.replace(currentSelection,\n\t\t\t\t\t\t\t\t\t\t`[${markdownEscape(text)}](${url})`\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tvscode.window.showErrorMessage(`Request failed`);\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\n\t\t\t});\n\n\t\t} else {\n\t\t\tvscode.window.showInformationMessage('No window is active');\n\n\t\t}\n\t});\n\n\tcontext.subscriptions.push(disposable);\n}\n\n// this method is called when your extension is deactivated\nexport function deactivate() { }\n"],"names":["replacements","module","exports","string","skips","reduce","replacement","name","indexOf","replace","url","opts","body","data","headers","JSON","stringify","qs","parse","Promise","resolve","reject","URL","request","https","response","chunks","on","chunk","push","join","error","write","end","require","es","ca","esca","pe","m","escape","call","unes","cape","unescape","un","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","context","disposable","vscode","commands","registerCommand","editor","window","activeTextEditor","currentSelection","selection","text","document","getText","trim","showErrorMessage","withProgress","location","ProgressLocation","Window","cancellable","title","async","progress","report","increment","encodeURIComponent","console","log","summary","Object","keys","includes","showInformationMessage","modal","then","answer","env","openExternal","Uri","currentLanguage","languageId","edit","editBuilder","markdownEscape","showWarningMessage","subscriptions"],"sourceRoot":""}
|