Post source code in blog

Source: Internet
Author: User
Tags processing text

Source Address: http://blog.daviesliu.net/article/entry20050519-224302

Post to blogProgramCodeIt is a common task to facilitate exchanges and sharing with Germany.

Program code is usually formatted, such as indentation, to show the machine (compiler), and to make it easier for people to see. If you simply putSource codePaste it into the text box of the browser, and then view it again, the format is lost. By default, HTML compresses multiple blank characters into one. At this time, the tab indentation in the source program is gone. To retain the character format in the Code, there is a simple method, that is, the code is surrounded by a tag <PRE>, so that it will not process the internal blank characters, the format (such as alignment) in the code can be displayed normally.

The popular ide now has the syntax brightening function, which can automatically analyze the syntax of program code and display different characters in different colors, making it easier to read the source code, it is not prone to errors during writing. When you use a browser to view program code, it is best to highlight the syntax, but the browser does not understand the syntax of various programming languages. It can only understand the syntax of HTML, etc, this requires the use of third-party tools to convert the program code to the corresponding HTML code according to the language and regulations, to enable the syntax to be highlighted.

Currently, there are several feasible solutions:

1. letax2html is one of the most powerful functions. It is used not only for program code, but also for many documents on the Internet. Letax has a syntax analysis and highlighted the macro package, which is not a problem. But there is a way to kill the chicken with a knife :), unless it is to deal with a lot of code and documentation.

2. Use an editor that supports syntax brightening to export the display effect to HTML format, such as vim, which is convenient, but the code generated by the editor is ugly. Vim not only brightens the syntax for various advanced languages, but also supports various configuration documents and script programs in Linux. It can be used when these special documents are pasted.

3. Use specialized conversion tools, such as webcpp, code2html, and highlight, which support all languages.

Webcpp is a program written in C ++. The generated code is clean and CSS is used. However, the generated code is HTML 4.0 standard, not XHTML. I wanted to make some changes to it to output XHTML, but because of its complicated processing mechanism, the program stability was not very good and it was not successful.

Code2html is written in Perl, and processing text is the strength of Perl. However, the HTML code generated by it is also ugly and abandoned.

The third seems unstable and marked ~ X86 cannot be installed on my Gentoo box.

I used webcpp to paste a few pieces of code in the blog and it looks okay. However, considering that blogs need to move closer to the XHTML standard, we hope to have better tools.

There are other solutions. Please add them. We look forward to the following :-)

I'm going to write one in Python, And the progress is quite smooth :)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.