Tool to add code highlighting and export to HTML

I'm looking for a tool that can highlight code (Ruby, PHP, JavaScript ...) like with an IDE, and then export the code to html format so that when the html page is opened, the code looks just like it does with the IDE.

+2


source to share


6 answers


You can do it with Vim at least with this command:



:TOhtml

      

+3


source


You can also use code2html ( project page ) for colored source code.



code2html file.c > code.html

      

+3


source


Emacs supports exporting code to html using http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el.cgi

+2


source


To be editor independent you can just use the ruby syntax gem. Here is an excerpt from the user manual showing the function you are looking for:

require 'syntax/convertors/html'

convertor = Syntax::Convertors::HTML.for_syntax "ruby"
html = convertor.convert( File.read( "program.rb" ) )

puts html

      

+1


source


highlight_file will be quick, although a PHP only solution.

<?php highlight_file("somefile.php"); // basic usage
highlight_file(__FILE__);
$out = highlight_file("file.php") // string variable, can be written to file etc.
?>

      

Other than that, have you tried GeSHi ?

+1


source


Textmate can do that too. See "Generating HTML from a Document" in the TextMate package.

0


source







All Articles