[TxMt] Export selected text to HTML?

Allan Odgaard allan at macromates.com
Sat Feb 5 20:25:16 UTC 2005


On Feb 5, 2005, at 20:46, Xavier Noria wrote:

> Just for the record, there are some utilities out there that can help:
>     GNU Source-highlight
>     http://www.gnu.org/software/src-highlite/

Ah cool, and this is in Darwin Ports, so I did (Terminal.app):
% sudo port install source-highlight

And after a minute of installing then I made this command (in TextMate):
    expand -3 | source-highlight -scpp -fhtml

With input: Selected text and output: Show as HTML (beta 5 has the 
“Open as new document”).

Since the OP wanted line numbers, I also did a small awk script to 
insert these, only tested with C++ output though:
expand -3 | source-highlight -scpp -fhtml \
| awk '

  /^<pre><tt>/     {
     sub("<pre><tt>", "<pre><tt>  1: ");
     print $0; next;
  }

  /^<\/tt><\/pre>/ {
     print $0; next;
  }

  { printf("%3d: %s\n", ++line + 1, $0); }
'

Remember that you may need to specify full path for source-highlight. 
And 'expand -3' is to convert tabs into spaces.




More information about the textmate mailing list