Syntax::Highlight::Engine::Kate - a port to Perl of the syntax highlight engine of the Kate texteditor.
my $hl = new Syntax::Highlight::Engine::Kate( language => 'Perl', substitutions => { "<" => "<", ">" => ">", "&" => "&", " " => " ", "\t" => " ", "\n" => "<BR>\n", }, format_table => { Alert => ["<font color=\"#0000ff\">", "</font>"], BaseN => ["<font color=\"#007f00\">", "</font>"], BString => ["<font color=\"#c9a7ff\">", "</font>"], Char => ["<font color=\"#ff00ff\">", "</font>"], Comment => ["<font color=\"#7f7f7f\"><i>", "</i></font>"], DataType => ["<font color=\"#0000ff\">", "</font>"], DecVal => ["<font color=\"#00007f\">", "</font>"], Error => ["<font color=\"#ff0000\"><b><i>", "</i></b></font>"], Float => ["<font color=\"#00007f\">", "</font>"], Function => ["<font color=\"#007f00\">", "</font>"], IString => ["<font color=\"#ff0000\">", ""], Keyword => ["<b>", "</b>"], Normal => ["", ""], Operator => ["<font color=\"#ffa500\">", "</font>"], Others => ["<font color=\"#b03060\">", "</font>"], RegionMarker => ["<font color=\"#96b9ff\"><i>", "</i></font>"], Reserved => ["<font color=\"#9b30ff\"><b>", "</b></font>"], String => ["<font color=\"#ff0000\">", "</font>"], Variable => ["<font color=\"#0000ff\"><b>", "</b></font>"], Warning => ["<font color=\"#0000ff\"><b><i>", "</b></i></font>"], }, ); print "<html>\n<head>\n</head>\n<body>\n"; while (my $in = <>) { print $hl->highlightText($in); } print "</body>\n</html>\n";
Syntax::Highlight::Engine::Kate is a port to perl of the syntax highlight engine of the Kate text editor.
The language xml files of kate have been rewritten to perl modules using a script. These modules function as plugins to this module.
Specify the language you want highlighted. Currently the following languages are supported:
.desktop 4GL 4GL-PER AHDL ANSI C89 ASP AVR Assembler AWK Ada Alerts Asm6502 BaseTest BaseTestchild Bash BibTeX C C# C++ CGiS CMake CSS CUE Sheet Cg ChangeLog Cisco Clipper ColdFusion Common Lisp Component-Pascal D Debian Changelog Debian Control Diff Doxygen E Language Eiffel Euphoria Fortran GDL GLSL GNU Assembler GNU Gettext HTML Haskell IDL ILERPG INI Files Inform Intel x86 (NASM) JSP Java JavaScript Javadoc KBasic LDIF LPC LaTeX Lex/Flex LilyPond Literate Haskell Lua MAB-DB MIPS Assembler Makefile Mason Matlab Modula-2 Music Publisher Octave PHP (HTML) PHP/PHP POV-Ray Pascal Perl PicAsm Pike PostScript Prolog PureBasic Python Quake Script R Script REXX RPM Spec RSI IDL RenderMan RIB Ruby SGML SML SQL SQL (MySQL) SQL (PostgreSQL) Sather Scheme Sieve Spice Stata TI Basic Tcl/Tk UnrealScript VHDL VRML Velocity Verilog WINE Config XML XML (Debug) Yacc/Bison ferite progress scilab txt2tags xHarbour xslt yacas
If you created your own language plugins you may specify a list of them with this option.
plugins => [ ["MyModuleName", "MyLanguageName", "*,ext1;*.ext2", "Section"], .... ]
This option must be specified if the highlightText method needs to do anything usefull for you. All mentioned keys in the synopsis must be specified.
With this option you can specify additional formatting options.
returns the column position in the line that is currently highlighted.
Called by the plugins after a test succeeds. if $context has following values:
#pop returns to the previous context, removes to top item in the stack. Can also be specified as #pop#pop etc. #stay does nothing. ##.... Switches to the plugin specified in .... and assumes it's basecontext. .... Swtiches to the context specified in ....
returns a reference to the extensions hash,
returns true if the current line did not contain a non-spatial character so far and the first character in $string is also a spatial character.
sets and returns the instance variable format_table. See also the option format_table
highlights $text. It does so by selecting the proper callback from the commands hash and invoke it. It will do so untill $text has been reduced to an empty string. returns a paired list of snippets of text and the attribute with which they should be highlighted.
highlights $text and reformats it using the format_table and substitutions
Sets and returns the current language that is highlighted. when setting the language a reset is also done.
returns a list of languages for which plugins have been defined.
returns the module name of the plugin for $language
return the last character that was processed.
returns true if the last character processed was a deliminator.
returns the string of text in the current line that has been processed so far,
returns true if processing is currently at the beginning of a line.
sets and returns the instance variable 'out'.
Returns a reference to a plugin object for the specified language. Creating an instance if needed.
Resets the highlight engine to a fresh state, does not change the syntx.
Returns a reference to the sections hash.
Contains the current snippet of text that will have one attribute. The moment the attribute changes it will be parsed.
appends $string to the current snippet.
Sets and returns the used attribute.
Forces the current snippet to be parsed.
If attribute is defined and differs from the current attribute it does a snippetForce and sets the current attribute to $attribute. Then it does a snippetAppend of $text
sets and returns the instance variable 'stack', a reference to an array
retrieves the element that is on top of the stack, decrements stacksize by 1.
puts $tagname on top of the stack, increments stacksize by 1
Retrieves the element that is on top of the stack.
Compares two lists, \@state and the stack. returns true if they match.
Returns a list containing the entire stack.
Accepts @list as the current stack.
sets and returns a reference to the substitutions hash.
In the kate XML syntax files you find under the section <itemDatas> entries like <itemData name="Unknown Property" defStyleNum="dsError" italic="1"/>. Kate is an editor so it is ok to have definitions for forground and background colors and so on. However, since this Module is supposed to be a more universal highlight engine, the attributes need to be fully abstract. In which case, Kate does not have enough default attributes defined to fullfill all needs. Kate defines the following standard attributes: dsNormal, dsKeyword, dsDataType, dsDecVal, dsBaseN, dsFloat, dsChar, dsString, dsComment, dsOthers, dsAlert, dsFunction, dsRegionMarker, dsError. This module leaves out the "ds" part and uses following additional attributes: BString, IString, Operator, Reserved, Variable. I have modified the XML files so that each highlight mode would get it's own attribute. In quite a few cases still not enough attributes were defined. So in some languages different modes have the same attribute.
Float is detected differently than in the Kate editor.
The regular expression engine of the Kate editor, qregexp, appears to be more tolerant to mistakes in regular expressions than perl. This might lead to error messages and differences in behaviour. Most of the problems were sorted out while developing, because error messages appeared. For as far as differences in behaviour is concerned, testing is the only way to find out, so i hope the users out there will be able to tell me more.
This module is mimicking the behaviour of the syntax highlight engine of the Kate editor. If you find a bug/mistake in the highlighting, please check if Kate behaves in the same way. If yes, the cause is likely to be found there.
All the people who wrote Kate and the syntax highlight xml files.
This module is written and maintained by:
Hans Jeuken < haje at toneel dot demon dot nl >
Copyright (c) 2006 by Hans Jeuken, all rights reserved.
You may freely distribute and/or modify this module under the same terms as Perl itself.
Synax::Highlight::Engine::Kate::Template http:://www.kate-editor.org
To install Syntax::Highlight::Engine::Kate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Syntax::Highlight::Engine::Kate
CPAN shell
perl -MCPAN -e shell install Syntax::Highlight::Engine::Kate
For more information on module installation, please visit the detailed CPAN module installation guide.