', '',1)
end
-- remove the first spacer
html = string.gsub (html, '', '', 1)
html = string.gsub (html, '
\n
', '>', 1)
end
html = string.gsub (html, '", "")
-- emphasis in text is lost
html = string.gsub (html, 'text="#002244"', 'text="#001133"', 1)
return html,true
end
table.insert(pre_format_html_hooks, mangle_linuxtoday)
function mangle_dictionary_dot_com (url, html)
local t = { t = "" }
local n
if not sstrfind (url, "dictionary.com/cgi-bin/dict.pl") then return nil,nil end
_,n = string.gsub (html, "resultItemStart %-%-%>(.-)%<%!%-%- resultItemEnd",
function (x) t.t = t.t..""..x.." |
" end)
if n == 0 then
-- we've already mangled this page before
return nil,true
end
html = "Dictionary.com lookup"..
""..
""
return html,true
end
table.insert(pre_format_html_hooks, mangle_dictionary_dot_com)
function mangle_allmusic_dot_com (url, html)
if not sstrfind (url, "allmusic.com") then return nil,nil end
html = string.gsub(html, "javascript:z%('(.-)'%)", "/cg/amg.dll?p=amg&sql=%1")
return html,true
end
table.insert(pre_format_html_hooks, mangle_allmusic_dot_com)
-- Handle gzip'd files within reasonable size.
-- Note that this is not needed anymore since we have a support for this
-- in core ELinks. I still keep it here for a reference (as an example),
-- though. If you will add something similiar using pipe_read(), feel free
-- to remove this. --pasky
function decompress_html (url, html)
local tmp
if not string.find (url, "%.gz$") or string.len (html) >= 65536 then
return nil,nil
end
tmp = tmpname ()
writeto (tmp) write (html) writeto ()
html = pipe_read ("(gzip -dc "..tmp.." || cat "..tmp..") 2>/dev/null")
os.remove (tmp)
return html,nil
end
--table.insert(pre_format_html_hooks, decompress_html)
----------------------------------------------------------------------
-- Miscellaneous functions, accessed with the Lua Console.
----------------------------------------------------------------------
-- Reload this file (hooks.lua) from within Links.
function reload ()
dofile (hooks_file)
end
-- Helper function.
function catto (output)
local doc = current_document_formatted (79)
if doc then writeto (output) write (doc) writeto () end
end
-- Email the current document, using Mutt (http://www.mutt.org).
-- This only works when called from lua_console_hook, below.
function mutt ()
local tmp = tmpname ()
writeto (tmp) write (current_document ()) writeto ()
table.insert (tmp_files, tmp)
return "run", "mutt -a "..tmp
end
-- Table of expressions which are recognised by our lua_console_hook.
console_hook_functions = {
reload = "reload ()",
mutt = mutt,
}
function lua_console_hook (expr)
local x = console_hook_functions[expr]
if type (x) == "function" then
return x ()
else
return "eval", x or expr
end
end
----------------------------------------------------------------------
-- quit_hook
----------------------------------------------------------------------
-- We need to delete the temporary files that we create.
if not tmp_files then
tmp_files = {}
end
function delete_tmp_files ()
if tmp_files and os.remove then
tmp_files.n = nil
for i,v in tmp_files do os.remove (v) end
end
end
table.insert(quit_hooks, delete_tmp_files)
----------------------------------------------------------------------
-- Examples of keybinding
----------------------------------------------------------------------
-- Bind Ctrl-H to a "Home" page.
-- bind_key ("main", "Ctrl-H",
-- function () return "goto_url", "http://www.google.com/" end)
-- Bind Alt-p to print.
-- bind_key ("main", "Alt-p", lpr)
-- Bind Alt-m to toggle ALT="" mangling.
bind_key ("main", "Alt-m",
function () mangle_blank_alt = not mangle_blank_alt end)
-- vim: shiftwidth=4 softtabstop=4