From: Zach Dennis Date: 2004-09-25T02:35:52+09:00 Subject: Re: Ruby Code to HTML A better version might be: -------------------------------------------------------------- input = File.open("baselayout_test.rb") output = File.new( "baselayout_test.html" , "w+" ) input.each_byte{ |c| c=c.chr c.gsub!(/\n/ , "
\n" ) and output.write( c ) and next if( c=~/\n/ ) c.gsub!(/\s/ , " " ) and output.write( c ) and next if( c=~/\s/ ) c.gsub!(/\t/ , "    " ) and output.write( c ) and next if( c=~/\t/ ) output.write( c ) } Zach Dennis wrote: > A quick and dirty way might be: > > #!/usr/bin/ruby > > input = File.open( "file.rb" , "r" ) > output = File.new( "file.html" , "w+" ) > > input.each_byte{ |c| > case c.chr! > when "\n" > output.write( "
\n" ) > when "\s" > output.write( " " ) > when "\t" > output.write( 4.times{ "nbsp;" } ) > else > output.write( c ) > end } > > > Zach > > >