Extending Org Links and Youtube

Charanjit Singh has an interesting post on extending org-mode to handle youtube links. His goal was two-fold:

  1. Have an Org link type for Youtube videos that opened the video in mpv instead of the browwser
  2. When exporting to HTML the link should result in an embedded video rather than a link to Youtube

Most folks probably aren’t going to have those requirements, of course, but Singh’s post is still useful because it’s a great go-by for how to define and implement special links in Org-mode. The TL;DR is that you define a link type and two actions associated with it. The first action is what to do when the link is followed (Ctrl+c Ctrl+o). The second is how to export the link (Ctrl+c Ctrl+e).

In Singh’s case, the follow action is to display the video with mpv unless the follow is invoked with the universal argument in which case the browser is used. For export, Singh cares only about HTML for which the necessary markup for an embedded video is output.

The code is easy to follow so if you have a case for a special Org link, it’s worthwhile taking a look at Singh’s post to see how things are done.

This entry was posted in General and tagged , . Bookmark the permalink.