Note that I changed the name from Code Colorizer from Code Formatter to remove the impression that code is actually reformatted with respect to whitespace.
8085 Assembler, X86 Assembler, StarBasic, C++, C#, Java, PERL, Python, R, and XML can be color coded for a better appearance.
StarBasic is formatted like the OOo IDE. Java colors mimic those in Eclipse.
A block of code is assumed to be formatted based on the following paragraph styles: _OOoComputerCode, _OOoComputerCodeLastLine, _code, _code_first_line, _code_last_line, or _code_one_line.
Numerous color code examples are shown in AndrewMacro.odt, along with a complete description of the add-in.
I received a special request for Python support. I spent about an hour adding support and I have only tested this on two samples.
Python, however, I added by special request, I have only spent about an hour working on the code. Also, I have not used Python, so I cannot easily test the code.
This extension provides the ability to colorize code segments. There are two modes of operation. The first mode (the least used mode for me) is to select the code that you want to colorize, and then use the menu options under: Tools > Add-Ons > MacroFormatterADP
I use a specific paragraph style for my code. I usually use _OOoComputerCodeLastLine for the last line of code in a segment, and _OOoComputerCode for the rest. So, for four lines of code, the first three use _OOoComputerCode and then the last line uses _OOoComputerCodeLastLine. This group then defines an entire code snippet.
Character styles are used for each portion of the code; for example, there is a character style for keywords, and another for literals. This is how color is assigned.
The code that identifies the specific portions is certainly not complete. In other words, I did not write a complete grammar interpreter for each supported language. My intention is to provide something that is "close enough" for regular use. That said, if you find glaring issues, be certain to let me know so that I can fix them. Also, if you fix errors, please share your solution. This latest version supports PERL. I use variable names such as "shall_print", and I noticed that "print" was colorized as a keyword. I corrected this for PERL. If you find something similar in another language, let me know and I will fix it.
When I say that I am only looking for "good enough" support, this means that I may fail under strange situations. An example of an untested, but expected failure is as follows:
Create a single line of code such as "a = 1; // line comment".
If you select the code inside the double quotes, I expect that the single line comment will continue to the end of the paragraph without verifying that this runs past the ends of the selected text. If this is tested and found to be in error, I will fix the problem.
Final note: although a later version of OOo is specified as required, this is only because of the method that the extension uses to set menus. If you must use an older version of OOo, feel free to download the extension, use "unzip" to extract the libraries, and then manually import the libraries; they should work just fine on most any version of OOo.
If a language that you desire to color code is not supported, feel free to contact me directly and ask. Some languages are easy to add.