Click here to Skip to main content
Click here to Skip to main content

Syntax Highlighter

By , 5 Feb 2002
Rate this:
Please Sign up or sign in to vote.
<!-- Download Links -->

Description

How often would we like to insert coloured code in our documents? I know it's not that important but, first, it looks much nicer and, second, it's much easy to understand a piece of source code when it is coloured. At least for me.

What this little application does is exporting Rich Text Format syntax coloured code. To do that, special text files are used defining the each of the languages that the application will handle and colour. These files are found in the application folder.

Sample Image

Language files

Let's have now a look into this language files. From all the sections, only the first one is not optional, the rest of them are, though it doesn't make a lot of sense not including them.

Section Description
§ Language extensions File extensions for which the language file will be used
§ Comment line Comment line indicator (e.g.: // in C++)
§ Comment block Opening and closing comment block symbols (in different lines)
§ String marks Characters that can enclose a string (e.g.: ")
§ Operators Single characters that act as operators in the described language in a single line. (blank spaces can be added)
§ Keywords Language keywords.
§ Colours (normal, comment, string, keyword, operator) Colour in hexadecimal that will be used. One per line.

Note that an empty line is required after the last element of each section and the section names must be exactly like they appear in the table above.

Notes

First of all, saying that the application may have bugs. I'm not speaking about memory leaks or something like that, just pointing out the possibility that somebody gets a bad coloured output for a given source file. I haven't so far anyway.

I've only tested the app under Windows 2000, but it should work as well under Windows 98 and I guess also in WindowsXP (?)

Two of those language files are included in both of the downloads. One for C/C++ and the other one for Visual Basic

The code to transfer the rtf information to a CString object was borrowed from the article Painless streaming with CRichEditCtrl, that can be found in the Docs sections in http://www.calcaria.net.

I'm posting the source code along with the application. I hope this article helps, in the same way many of the articles found here, in the Code Project, helped me.

Salu2, Samuel.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Samuel Gonzalo
Software Developer (Senior)
Spain Spain
I studied Telecommunication with spezialization in Sound & Image. I was always very interested in programming at university as well and that is how I earn a living.
 
Since some years ago, I am also succesfully involved in software architecture and design.

Comments and Discussions

 
GeneralThanks for the ref PinmemberPaulMdx31-Oct-05 1:51 
GeneralCrash if no valid language extension found PinmemberUTO7-Jun-04 23:41 
Generalsource files link is not working :-((( PinmemberAnonymous6-Feb-02 21:23 
GeneralRe: source files link is not working :-((( PinmemberSamuel Gonzalo6-Feb-02 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 6 Feb 2002
Article Copyright 2002 by Samuel Gonzalo
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid