Chapter 9. Introduction to MIME handling
Prev |  | Next

## Chapter 9. Introduction to MIME handling

At some time along the 0.4 prereleases, ELinks replaced the old Links file configuration system with its own one. Now, the configuration is stored in elinks.conf, much more complete and featuring a new syntax. You can set most options from the UI (so usually there is no need to deal with elinks.conf), and that used to be true for setting MIME handlers and extensions as well; but now the associations menu is gone temporarily, forcing you to set the handlers from the configuration file.

The comments provided within elinks.conf for the MIME options are not much helpful, and those options may seem a bit obscure or confusing at first. This document is a basic introduction to setting of MIME associations for ELinks. If you want to know how to automatically launch a program to view some kind of file (like images), then read on. Some basic knowledge of MIME is recommended.

## Handling MIME types, the ELinks way

### What are MIME types and why may you want to use them?

If, while browsing with ELinks, you need to display files that it can't show (like images or PDF documents), then you will likely want to pass them to other programs that are suitable for this task. While you may do it manually (saving the file to disk, running the auxiliary program to show it and then removing the file when finished), ELinks provides a method to do this automatically using MIME types.

ELinks usually knows what the MIME type is for any file (which is a kind of description of its format), thus you only need to specify how to manage the MIME types for the files you want to open. If you don't tell ELinks how to manage a given MIME type then it will show you on screen the contents of the file (as if it was ASCII text) instead of calling an external program to show them.

### Associating files to MIME types

If the file is fetched from a web server then this web server should tell ELinks what its MIME type is, so you should have generally no need to care about it. However, the web server might send an incorrect type, or you may be retrieving it by FTP or from your local filesystem, so sometimes ELinks needs to guess it.

The easiest method to guess a MIME type for a file is to just look at its name trusting it was given the right extension. ELinks supports this, letting you to specify a type for any given extension.

### Managing a given MIME type

This usually means specifying programs to open files of this type and the conditions in which those programs may be used. For instance, you may want to use zgv (a popular svgalib image viewer) when you are using the text console, but xli (a image viewer for X) when running the X window system.

#### Binding it to a handler

Instead of directly attaching a program to a MIME type, ELinks lets you associate an abstract handler to each type. Then you can specify which programs implement the handler and how are they used.

For instance, you may create an image_viewer handler and assign it to MIME types image/jpeg, image/png and image/gif. Then you would associate to image_viewer the programs you would like to use for viewing images and the details on how to use them. This is less cumbersome than repeating all these details for each MIME type.

### Specifying the details for a handler

There are three issues to specify for a handler: the program associated to it, whether you want confirmation before using it and whether you want the terminal to be blocked while it is being used.

When specifying any of these issues, you must tell ELinks the situation in which it gets applied, which is typically either the text console or the X window system. So you can specify that you don't want confirmation before running the program when running X, and that you want it otherwise. Similarly, when you are attaching a program (name it foo) to this handler you must tell if it's for X or not (you can attach a second program for the other choice if you want).

Attaching a program to it
  You must tell ELinks the exact command for running it (with any options you wish). In place of the filename you must enter %.
Choosing whether you want confirmation before applying it
  This is rather simple. If you choose not to do so, then the handler will be automatically called upon when you demand ELinks to show something attached to this handler. Otherwise, if you ask for confirmation, you will be prompted to open it with a external program, with additional choices that include cancelling the operation and viewing it with ELinks. E.g: you may use this option for programs written in C so that you may always choose if you want to read the source with ELinks, or if you want to save it, or if you want to use indent to display it with less.
Choosing whether to block the terminal
  If you don't want to allow going back to ELinks (or any other program from the same terminal) before the external program ends, then you should ask to block the terminal.

Prev |  | Next
Terminal Configurations | Home | Setting up elinks.conf