GitHub - fcardinaux/PasteAnchor: Paste an URL to Sublime Text and get an HTML or Markdown anchor. The webpage title is automatically read and becomes the text of the link.

3 min read Original article ↗

The Paste Anchor Plugin for Sublime Text 2

  • Author: François Cardinaux, CH 1207 Genève
  • Creation date: 2013-06-14, last updated on 2013-07-28

Description

This Sublime Text plugin allows you to get an anchor with a text when you paste an URL to a Markdown or HTML file. The text corresponds to the page title.

For instance, if you paste the link "http://www.sublimetext.com/docs/2/api_reference.html" to an HTML or Markdown file, you get this link: “API Reference - Sublime Text 2 Documentation”.

Here is the exact syntax you get in a Markdown file:

[API Reference - Sublime Text 2 Documentation](http://www.sublimetext.com/docs/2/api_reference.html)

Here is the exact syntax you get in an HTML file:

<a href="http://www.sublimetext.com/docs/2/api_reference.html">API Reference - Sublime Text 2 Documentation</a>

Pasting URLs of Hacker News threads

When you paste a link to a thread on Hacker News or on a similar site, you get two anchors: one to the thread itself, and one to the related article. For instance, if you paste the link "https://news.ycombinator.com/item?id=4161610" to an HTML or Markdown file, you get this link: “Sublime Blog » Sublime Text 2.0 Released via Hacker News”.

Here is the exact syntax you get in a Markdown file:

[Sublime Blog » Sublime Text 2.0 Released](http://www.sublimetext.com/blog/articles/sublime-text-2-0-released) via [Hacker News](https://news.ycombinator.com/item?id=4161610)

Here is the exact syntax you get in an HTML file:

<a href="http://www.sublimetext.com/blog/articles/sublime-text-2-0-released">Sublime Blog » Sublime Text 2.0 Released</a> via <a href="https://news.ycombinator.com/item?id=4161610">Hacker News</a>

The syntax "anchor 1 via anchor 2" is configured in the PasteAnchor.sublime-settings file and can be easily modified.

Note that the same system works for the following sites as well:

Installation

Go to your Sublime Text package directory and clone the present repository.

Linux (untested, copied from joneshf/sublime-chaplinjs)

$ cd ~/.config/sublime-text-2/Packages
$ git clone https://github.com/fcardinaux/PasteAnchor

Macosx

$ cd "~/Library/Application Support/Sublime Text 2/Packages"
$ git clone https://github.com/fcardinaux/PasteAnchor

Windows (untested, copied from joneshf/sublime-chaplinjs)

$ cd "%APPDATA%\Sublime Text 2"
$ git clone https://github.com/fcardinaux/PasteAnchor

Dependency

You need to install the BeautifulSoup for Sublime Text plugin.

How to run the command

Copy or cut the URL, and paste it by pressing the following keys:

  • ctrl + alt + v on Windows and Linux
  • cmd + alt + v on Mac OSX

You may also run the command from the Sublime Text Console:

view.run_command("paste_anchor")

Configuration

Here is a description of the parameters in the PasteAnchor.sublime-settings file:

Setting name Description
extensions A dictionary of recognized extensions, with the types they correspond to
anchor-syntaxes The syntax of each extension type
default-title This default title is used if the link isn't a valid URL, or if anything else goes wrong.
inaccessible-sites A list of url patterns that are known not to be accessible for Paste Anchor. To each pattern is associated a replacement title:
  • url-regexp: the regular expression to use in order to identify the inaccessible site
  • title: the text to put in the anchor
hn-like-site-syntax The syntax to use for Hacker-News-like sites. You may want to replace the value with a text in your language, e.g. "{0} depuis {1}" in French
hn-like-sites A list of Hacker-News-like sites, with the following settings:
  • url-regexp: the regular expression to use in order to detect the Hacker-News-like site
  • title-anchor-selector: the css selector to use in order to locate the anchor of the page title
  • site-name: the name of the Hacker-News-like site

License

This software is released under the GNU General Public License (GPL) version 3.

Copyright: François Cardinaux © 2013