On 12/18/12 20:36, Cesar Romani wrote: > If I have the following line: > <a href="http://www.whatever.com">SomeTitle</a> > > How to create the file SomeTitle.txt with the content (without the > dashes): > -------------------- > [InternetShortcut] > URL=http://www.whatever.com > --------------------
The other pair of answers I saw come back on this extract the information that you request, but don't write out the content to files of the name contained in the <a>...</a> tag. You might try the following: function! WriteShortcut(whole, name, url) call writefile(['[InternetShortcut]', 'URL='.(a:url), ''], (a:name).'.txt') return a:whole endfunction with which you can then use %s/\c<\s*a\s\+href\s*=\(['"]\)\(\%(\1\@![^/]\)\+\)\1\s*>\([^<]*\)</\=WriteShortcut(submatch(0), submatch(3), submatch(2))/g as a rough approximation to extract the various bits, create a file with the corresponding name, and then populate it with the associated contents. It should be fairly forgiving on whitespace and single-vs-double-quotes around the URL. Places that I know it falls over: - <a> tags with other attributes such as class='...' - <a>...</a> nodes with sub-elements in them such as <a href="http://example.com>My <b>COOL</b> site!!!</a> It also doesn't trim off whitespace, so it uses the entire text node as the filename, meaning that if you have <a href="..."> text </a> it will name the file "<space><space>text<space><space>.txt" so you may want to sanitize the filename before passing it to writefile() -tim -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
