* John Magolske <b79...@gmail.com> [120814 23:02]: > I'm looking for a way to pipe the HTML of a page open in ELinks to > another application without having to re-download the page. > > I have a ELinks mapping & script that automates saving a web-page > to text -- with two keypresses the HTML is converted to text and > automatically opened in Vim for editing & saving to an appropriate > location. Very handy, but this approach uses URI passing and %c, > which involves re-downloading the HTML source over the net. > [...] > What I'd like to be able to do is pipe the source of an open page > through `elinks -dump` without an internet connection, and without > having to manually save it somewhere first.
After reading a few helpful threads [1] from the archives of this list and looking over the contrib/lua/hooks.lua file, I pieced together a solution which seems to work fairly well. Not having much experience with Lua, it's quite possible this can be more correct/clean. Any suggestions for improvement are welcome. Might be time to pick up the Programming in Lua book... The relevant bits from my ~/.elinks/hooks.lua file: -- Convert HTML to plaintext & open file in Vim function save_to_text () -- See if we can obtain the local document. local doc = current_document() if doc then -- Create a temporary file local tmp = tmpname () -- Write document into the temporary file. writeto (tmp) write (doc) writeto() -- convert HTML to plaintext and open Vim in a new tmux window execute( "elinks -dump -no-references -no-numbering " ..tmp.. ">|" ..tmp..".txt ;\ echo \"\n\n[saved on: `date +%Y\/%m\/%d\\ %a\\ %k:%M\\ %Z` ]\" >>" ..tmp..".txt ;\ echo " ..current_url ().. " >>" ..tmp..".txt;\ tmux new-window -n vim-elink \"vim \""..tmp..".txt") -- Tell elinks to delete after this function. table.insert (tmp_files, tmp) end end -- Convert HTML to markdown & open file in Vim function save_to_markd () -- See if we can obtain the local document. local doc = current_document() if doc then -- Create a temporary file local tmp = tmpname () -- Write document into the temporary file. writeto (tmp) write (doc) writeto() -- convert HTML to markdown and open Vim in a new tmux window execute( "pandoc -r html -w markdown --no-wrap --reference-links " ..tmp.. ">|" ..tmp..".txt ;\ echo \"\n\n[saved on: `date +%Y\/%m\/%d\\ %a\\ %k:%M\\ %Z` ]\" >>" ..tmp..".txt ;\ echo " ..current_url ().. " >>" ..tmp..".txt ;\ tmux new-window -n vim-elink \"vim \"" ..tmp..".txt") -- Tell elinks to delete after this function. table.insert (tmp_files, tmp) end end console_hook_functions = { txt = save_to_text, mkd = save_to_markd, } bind_key ("main", "Ctrl-H", save_to_text) bind_key ("main", "Ctrl-G", save_to_markd) ---- [1] http://archives.linuxfromscratch.org/mail-archives/elinks-users/2006-March/001109.html http://archives.linuxfromscratch.org/mail-archives/elinks-users/2006-April/001120.html Regards, John -- John Magolske http://B79.net/contact _______________________________________________ elinks-users mailing list elinks-users@linuxfromscratch.org http://linuxfromscratch.org/mailman/listinfo/elinks-users