1 Introduction to MIME handling
2 -----------------------------
4 At some time along the 0.4 prereleases, ELinks replaced the old Links file
5 configuration system with its own one. Now, the configuration is stored in
6 elinks.conf, much more complete and featuring a new syntax. You can set most
7 options from the UI (so usually there is no need to deal with elinks.conf),
8 and that used to be true for setting MIME handlers and extensions as well; but
9 now the associations menu is gone temporarily, forcing you to set the handlers
10 from the configuration file.
12 The comments provided within elinks.conf for the MIME options are not much
13 helpful, and those options may seem a bit obscure or confusing at first. This
14 document is a basic introduction to setting of MIME associations for ELinks.
15 If you want to know how to automatically launch a program to view some kind of
16 file (like images), then read on. Some basic knowledge of MIME is recommended.
19 Handling MIME types, the ELinks way
20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 What are MIME types and why may you want to use them?
23 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 If, while browsing with ELinks, you need to display files that it can't show
26 (like images or PDF documents), then you will likely want to pass them to
27 other programs that are suitable for this task. While you may do it manually
28 (saving the file to disk, running the auxiliary program to show it and then
29 removing the file when finished), ELinks provides a method to do this
30 automatically using MIME types.
32 ELinks usually knows what the MIME type is for any file (which is a kind of
33 description of its format), thus you only need to specify how to manage the
34 MIME types for the files you want to open. If you don't tell ELinks how to
35 manage a given MIME type then it will show you on screen the contents of the
36 file (as if it was ASCII text) instead of calling an external program to show
39 Associating files to MIME types
40 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42 If the file is fetched from a web server then this web server should tell
43 ELinks what its MIME type is, so you should have generally no need to care
44 about it. However, the web server might send an incorrect type, or you may be
45 retrieving it by FTP or from your local filesystem, so sometimes ELinks needs
48 The easiest method to guess a MIME type for a file is to just look at its name
49 trusting it was given the right extension. ELinks supports this, letting you
50 to specify a type for any given extension.
52 Managing a given MIME type
53 ^^^^^^^^^^^^^^^^^^^^^^^^^^
55 This usually means specifying programs to open files of this type and the
56 conditions in which those programs may be used. For instance, you may want to
57 use zgv (a popular svgalib image viewer) when you are using the text console,
58 but xli (a image viewer for X) when running the X window system.
61 Binding it to a handler
62 +++++++++++++++++++++++
64 Instead of directly attaching a program to a MIME type, ELinks lets you
65 associate an abstract handler to each type. Then you can specify which
66 programs implement the handler and how are they used.
68 For instance, you may create an image_viewer handler and assign it to MIME
69 types image/jpeg, image/png and image/gif. Then you would associate to
70 image_viewer the programs you would like to use for viewing images and the
71 details on how to use them. This is less cumbersome than repeating all these
72 details for each MIME type.
75 Specifying the details for a handler
76 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78 There are three issues to specify for a handler: the program associated to it,
79 whether you want confirmation before using it and whether you want the
80 terminal to be blocked while it is being used.
82 When specifying any of these issues, you must tell ELinks the situation in
83 which it gets applied, which is typically either the text console or the X
84 window system. So you can specify that you don't want confirmation before
85 running the program when running X, and that you want it otherwise.
86 Similarly, when you are attaching a program (name it foo) to this handler you
87 must tell if it's for X or not (you can attach a second program for the other
90 Attaching a program to it::
92 You must tell ELinks the exact command for running it (with any
93 options you wish). In place of the filename you must enter %.
95 Choosing whether you want confirmation before applying it::
97 This is rather simple. If you choose not to do so, then the handler
98 will be automatically called upon when you demand ELinks to show
99 something attached to this handler. Otherwise, if you ask for
100 confirmation, you will be prompted to open it with a external program,
101 with additional choices that include cancelling the operation and
102 viewing it with ELinks. E.g: you may use this option for programs
103 written in C so that you may always choose if you want to read the
104 source with ELinks, or if you want to save it, or if you want to use
105 indent to display it with less.
107 Choosing whether to block the terminal::
109 If you don't want to allow going back to ELinks (or any other program
110 from the same terminal) before the external program ends, then you
111 should ask to block the terminal.
114 Setting up elinks.conf
115 ~~~~~~~~~~~~~~~~~~~~~~
117 If you have old configuration files from old ELinks versions or from Links,
118 then you may use the conf-links2elinks.pl script (which is placed at
119 contrib/conv/ on the source distribution) to convert them to the new format.
120 If you don't use it you will need to edit the configuration file, and here you
123 Associating a file extension to a MIME type
124 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126 You can still do this with the UI, from the the Setup->File Extensions
129 If you want to do so from the configuration file, enter set mime.extension.ext
130 = "type", replacing ext with the appropriate file extension, and type with its
131 MIME type. E.g. you may want to have set mime.extension.jpg = "image/jpeg".
137 For each handler you must define three items, specifying in what context the
138 value of the item should be applied. You must enter set
139 mime.handler.handler-name.item.context = value, replacing handler-name with
140 the name for the handler you are defining, item with the item you are defining
141 for this handler, context with the context this item value is to be applied,
142 and value with the value you want to assign to the item. You must do so for
143 each of the available items: program, ask and block.
145 The value for program is a string with the exact command you want to be issued
146 to view the file, placing % were you would put the file name. The values for
147 ask and block are either 0 (no) or 1 (yes). Available contexts include unix
148 and unix-xwin, which mean UNIX text terminal and X respectively (others can be
149 os2, win32, beos, riscos, ...). The latter does not mean you are running
150 ELinks from X, just that the DISPLAY variable is set so that ELinks may run an
153 To illustrate it, here is an example. Suppose you want to define the
154 image_viewer handler which should be used to view images. The configuration
155 file may look like this:
157 --------------------------------------------------------------------------------
158 set mime.handler.image_viewer.unix.ask = 1
159 set mime.handler.image_viewer.unix-xwin.ask = 0
161 set mime.handler.image_viewer.unix.block = 1
162 set mime.handler.image_viewer.unix-xwin.block = 0
164 set mime.handler.image_viewer.unix.program = "zgv %"
165 set mime.handler.image_viewer.unix-xwin.program = "xli %"
166 --------------------------------------------------------------------------------
168 In this example the image_viewer handler uses the svgalib image viewer zgv
169 when X is not available, and the X image viewer xli when it is. The terminal
170 would be blocked when X is not available and it would not be when it's
171 available. Finally, ELinks would ask for confirmation before using the handler
172 only with X not available.
174 Associating a MIME type to a handler
175 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177 Just enter set mime.type.class.name = "handler", replacing class with the
178 class for the mime type, name with the specific name within that class, and
179 handler with the name for the handler you want to assign to the MIME type.
180 E.g. you may want to have set mime.type.image.jpeg = "image_viewer".