<commit_before>'use strict';

import { window, StatusBarItem, StatusBarAlignment, Position, Range } from 'vscode';
import * as vscode from 'vscode';
import * as copyPaste from 'copy-paste';
import * as getTitle from 'get-title';
import * as hyperquest from 'hyperquest';

export function activate(context: vscode.ExtensionContext) {

    let paster = new Paster();
    let disposable = vscode.commands.registerCommand('extension.pasteURL', () => {
        paster.paste()
    });

    context.subscriptions.push(disposable);
}

export class Paster {
    private _statusBarItem: vscode.StatusBarItem;

    public paste() {
        if (!this._statusBarItem) {
            this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
        }

        copyPaste.paste((error, content) => {
            if (content) {
                this.generateMarkDownStyleLink(content)
            } else {
                this.showMessage('Not a URL.')
            }
        })
    }

    generateMarkDownStyleLink(url) {
        var _this = this
        var headers = {
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12"
        }<commit_msg>Use selected text as title if allow<commit_after>'use strict';

import { window, StatusBarItem, StatusBarAlignment, Position, Range } from 'vscode';
import * as vscode from 'vscode';
import * as copyPaste from 'copy-paste';
import * as getTitle from 'get-title';
import * as hyperquest from 'hyperquest';

export function activate(context: vscode.ExtensionContext) {

    let paster = new Paster();
    let disposable = vscode.commands.registerCommand('extension.pasteURL', () => {
        paster.paste()
    });

    context.subscriptions.push(disposable);
}

export class Paster {
    private _statusBarItem: vscode.StatusBarItem;

    public paste() {
        if (!this._statusBarItem) {
            this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
        }

        copyPaste.paste((error, content) => {
            if (content) {
                this.generateMarkDownStyleLink(content)
            } else {
                this.showMessage('Not a URL.')
            }
        })
    }

    generateMarkDownStyleLink(url) {
        var selection = vscode.window.activeTextEditor.selection
        var isSelectionEmpty = selection.start == selection.end

        if (isSelectionEmpty) {
            this.composeTitleAndSelection(url)
        } else {
            this.replaceSelectionWithTitleURL(selection, url)
        }
    }

    replaceSelectionWithTitleURL(selection, url) {
        var text = vscode.window.activeTextEditor.document.getText(selection)
        var markdownLink = '[' + text + ']' + '(' + url + ')'
        vscode.window.activeTextEditor.edit((editBuilder) => {
            editBuilder.replace(selection, markdownLink);
        }) 
    }

    composeTitleAndSelection(url) {
        var _this = this
        var headers = {
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12"
        }
{'fraction_non_alphanumeric': 0.1128625472887768, 'fraction_numerical': 0.014501891551071878, 'mean_word_length': 2.593431483578709, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1826249', 'n_tokens_mistral': 979, 'n_tokens_neox': 922, 'n_words': 200}