[elinks-users] user protocols and current document

Grzegorz Adam Hankiewicz gradha at titanium.sabren.com
Sat Mar 11 10:48:58 PST 2006

On 2006-03-11, Ben Kibbey <bjk at luxsci.net> wrote:
> Is there a way to send the current document content to a user
> protocol and have the user protocol return the new content
> that elinks will parse? So say I type 'filterlinks' in the goto
> dialog. The a script/smartprefix(?) is ran named 'filterlinks' that
> returns a document that contains all of the links of the document.

I do something relatively similar with elinks to send opened torrents
to an mldonkey server. This is the code I have in my hooks.lua:

    -- Save displayed torrent and tell daemon to download it.
    function save_torrent ()
        -- See if we can obtain the local document.
        local doc = current_document()
        if doc then
            -- Create a temporary file
            local tmp = tmpname () ..".torrent"
            -- Write document into the temporary file.
            writeto (tmp) write (doc) writeto()
            -- Tell elinks to delete after this function.
            table.insert (tmp_files, tmp)
            -- Call the mldonkey daemon on the local temporary file.
            return "goto_url", mldonkey_host.."dllink%20"..url_donkey(tmp)
    -- Table of expressions which are recognised by our lua_console_hook.
    console_hook_functions = {
        torrent = save_torrent,
This works like this: you navigate your way to get a torrent, and
instead of offering a download it shows itself on the screen. Then I
press the console key, type "torrent" and the function is called. You
can modify the code of the save_torrent function to save the file,
call an external program to process it, then reopen it again as a
link to the local hard disk.

If you don't mind processing the web page in lua, you can do this
directly without temporary files in the pre_format_html_hooks,
which are precisely to clean HTML and stuff that looks odd in elinks.

Note, I'm using last pre-git version of elinks. This may have
changed a lot in the meantime.

More information about the elinks-users mailing list