开发者

Tool to add code highlighting and export to HTML [closed]

开发者 https://www.devze.com 2022-12-26 02:34 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the he开发者_运维知识库lp center for guidance. Closed 10 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号