Tool to add code highlighting and export to HTML [closed]
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 opening the html page the code looks just like with the IDE.
You can do this with Vim at least, with this command:
:TOhtml
You can also use code2html (project page) to color source code.
code2html file.c > code.html
Emacs supports exporting code to html using http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el.cgi
To be independent of editors, you can simply use the ruby syntax gem. Here is an excerpt of the user guide, which shows the feature you are looking for:
require 'syntax/convertors/html'
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
html = convertor.convert( File.read( "program.rb" ) )
puts html
highlight_file would be fast, although 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?
Textmate can do it too. See "Create HTML From Document" in the TextMate bundle.
精彩评论