We often need to convert source code into html format. We use the pre tag; however, the default tab values are to wide. For instance:
this is one tab this is another
If we were to put some of our funner source code up, it would push the right margin over too far. Well, we wrote about tidy in this article. It turns out that along with tidy there is a nice utility called tab2space that is just what we need. Say we have a script called source1.pl:
u-1@srv-1 t2s $ cat source1.pl while (<>){ if (/ruk/) { print; } else { print "no go\n"; } } u-1@srv-1 t2s $ u-1@srv-1 t2s $ cat fl ruk here ruk there ruk everywhere not here not there but ruk here u-1@srv-1 t2s $ perl source1.pl < fl ruk here ruk there ruk everywhere no go no go but ruk here u-1@srv-1 t2s $ |
We can make the source easier to read with tab2space:
u-1@srv-1 t2s $ tab2space -h tab2space: [options] [infile [outfile]] ... Utility to expand tabs and ensure consistent line endings options for tab2space vers: 6th February 2003 -help or -h display this help message -dos or -crlf set line ends to CRLF (PC-DOS/Windows - default) -mac or -cr set line ends to CR (classic Mac OS) -unix or -lf set line ends to LF (Unix) -tabs preserve tabs, e.g. for Makefile -t set tabs to (default is 4) spaces Note this utility doesn't map spaces to tabs! u-1@srv-1 t2s $ tab2space -t2 source1.pl while (<>){ if (/ruk/) { print; } else { print "no go\n"; } } u-1@srv-1 t2s $ |