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GACRwB,EAAOI,OAAOQ,iBAAiB,kBAC/BY,QAAQhD,MAAMA,YAMhBwB,EAAOI,OAAO0B,uBAAuB,0BAKvChC,EAAQ4C,cAAcpE,KAAKyB,IAI5B,2B","sources":["webpack://wikipedia-hyperlinker/./node_modules/markdown-escape/index.js","webpack://wikipedia-hyperlinker/./src/requests.ts","webpack://wikipedia-hyperlinker/external commonjs \"vscode\"","webpack://wikipedia-hyperlinker/external node-commonjs \"https\"","webpack://wikipedia-hyperlinker/external node-commonjs \"querystring\"","webpack://wikipedia-hyperlinker/external node-commonjs \"url\"","webpack://wikipedia-hyperlinker/./node_modules/html-escaper/cjs/index.js","webpack://wikipedia-hyperlinker/webpack/bootstrap","webpack://wikipedia-hyperlinker/./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]\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","https","qs","url","opts","body","data","headers","JSON","stringify","parse","Promise","resolve","reject","URL","request","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__","markdownEscape","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","showWarningMessage","subscriptions"],"sourceRoot":""}
|