问题
Visual Studio has a plugin that allows one to copy code from any editor (C#, HTML, XML) and then paste it with HTML formatting that preserves the syntax highlighting, etc.
This is very handy for publishing code samples/examples to a wep page/blog. I have seen one old (2006?) plugin for java to html conversion, but are there any broader solutions similar to the Visual studio plugin.
Really what I am looking for is a way to select and copy a syntax-colored block of text in Eclipse and paste it as formatted html+css.
Does such a thing exist?
回答1:
Eclipse based solutions
Use the Java2Html plugin (this is maybe the plugin you were referring to):
This tool converts Java source code to HTML, XHTML and LaTeX with syntax highlighting.
There is also the CodeSnippet plugin:
CodeSnippet is a set of Eclipse plug-ins to convert Ant, Java, Properties, CSS, DTD, HTML, and XML source code (complete files or snippets) to HTML with syntax highlighting
Non Eclipse based
Use the online Source Code Formatter for Blogger, Blogspot, Blog & Blogging, Format Formatting Tool:
Source Code Beautifier And Formatter For Blogger and Websites, Format Source Code , Format Source code for blog or blogging & website, Online line source code formatter tool, blogger code format tool, Format source code for blogspot,Insert formatted source code
回答2:
Although I don't know of such plug-ins, but generally pasting the syntax-highlighted text into Word or OpenOffice maintains its formatting, so using their HTML export (possibly the one of OpenOffice is useful here, as it provides simpler result, AFAIK).
回答3:
The Copy as HTML eclipse IDE plugin allows us to directly copy our code as HTML and paste it to our blogs or forums without any formatting.
Steps to install the plugin:
Download the Copy as HTML eclipse plugin Copy it to the 'dropins' folder of your eclipse installation If 'dropins' folder is not present then copy it to the 'plugins' folder of your eclipse installation Restart eclipse IDE That's it
来源:https://stackoverflow.com/questions/3515390/format-eclipse-code-snippets-for-blog-publishing