Syntax...e::Kate(3pm)

πŸ’– Syntax::Highlight::Engine::Kate β€” bestie edition πŸ’–

okay so this is Syntax::Highlight::Engine::Kate(3pm), a Perl module from the User Contributed Perl Documentation, and it's literally a port to Perl of the syntax highlight engine from the Kate text editor. it's giving "I took Kate's whole vibe and made it Perl". no cap. ✨


✨ NAME ✨

Syntax::Highlight::Engine::Kate β€” a port to Perl of the syntax highlight engine of the Kate text editor. that's it, that's the name, periodt. πŸŽ€


🌸 SYNOPSIS 🌸

like, here's how you'd actually use her:

 #if you want to create a compiled executable, you may want to do this:
 use Syntax::Highlight::Engine::Kate::All;

 use Syntax::Highlight::Engine::Kate;
 my $hl = Syntax::Highlight::Engine::Kate->new(
     language      => 'Perl',
     substitutions => {
         "<"  => "&lt;",
         ">"  => "&gt;",
         "&"  => "&amp;",
         " "  => "&nbsp;",
         "\t" => "&nbsp;&nbsp;&nbsp;",
         "\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>" ],
     },
 );

 #or

 my $hl = Syntax::Highlight::Engine::Kate::Perl->new(
     substitutions => {
         # ...
     },
     format_table => {
         # ...
     },
 );

 print "<html>\n<head>\n</head>\n<body>\n";
 while ( my $in = <> ) {
     print $hl->highlightText($in);
 }
 print "</body>\n</html>\n";

so yeah, two ways to flex: one big generic object with a language key, or the per-language subclass route (::Perl in the example). both devour STDIN line by line and spit out highlighted output. iconic. πŸ¦‹


πŸ’€ DESCRIPTION πŸ’€

okay bestie, deep breath. 😭

This module is now deprecated.

like… she's retired. she's living her best life on a beach somewhere. she's been superseded and replaced by Syntax::Kamelon. for new projects, bestie, use Syntax::Kamelon. that's the move. no cap. πŸ™ˆ

for the historical record tho: 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.

and yes, Syntax::Highlight::Engine::Kate inherits Syntax::Highlight::Engine::Kate::Template. family tree moment. πŸ‘‘


πŸ’… OPTIONS πŸ’…

these are the options you can pass in when you build your object, one by one, no skipping:

  • language β€” specify the language you want highlighted. look in the PLUGINS section for supported languages. (yes, go look, she's not listing them all here.)
  • plugins β€” if you created your own language plugins, you may specify a list of them with this option.
 plugins => [
   ["MyModuleName", "MyLanguageName", "*,ext1;*.ext2", "Section"],
   ....
 ]
  • format_table β€” you must specify this option if you want the highlightText method to do anything useful for you. like, genuinely must. every single key mentioned in the synopsis has to be specified. all of them. the whole roster. don't be shy with it. πŸŽ€
  • substitutions β€” with this option you can specify additional formatting options.

🫢 METHODS 🫢

the full menu of things you can call on her:

  • extensions β€” returns a reference to the extensions hash.
  • language(?$language?) β€” sets and returns the current language that is highlighted. when setting the language a reset is also done. so it's a set-and-return situation, and setting it wipes the slate. two jobs, one method, main character energy.
  • languageAutoSet($filename) β€” suggests language name for the given file $filename.
  • languageList β€” returns a list of languages for which plugins have been defined.
  • languagePlug($language, ?$insensitive?) β€” returns the module name of the plugin for $language.

if $insensitive is set it will also try to match names ignoring case and return the correct module name of the plugin.

e.g. "$highlighter->languagePlug('HtMl', 1);" will return "HTML". lowercase bestie gets recognised, slay. πŸ’…

  • languagePropose($filename) β€” suggests language name for the given file $filename.
  • sections β€” returns a reference to the sections hash.

🌈 ATTRIBUTES 🌈

okay so here's the lore. 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's ok to have definitions for foreground and background colors and so on. however β€” and this is the important part, bestie β€” 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 fulfill 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

and then, quote unquote: "I have modified the XML files so that each highlight mode would get its own attribute. In quite a few cases still not enough attributes were defined. So in some languages different modes have the same attribute."

so yeah. some modes are sharing an attribute because there simply weren't enough to go around. it's a group chat and there aren't enough nicknames. it happens. πŸ“


πŸ’– PLUGINS πŸ’–

ok bestie sit down for this one because it's a whole roster. here's the rundown of every plugin that exists. all of them have been tested in actual use and can be created β€” but the ones with no sample file to their name are marked as such, okay? and the ones marked OK? those highlighted the test file without any apparent mistakes. which is not the same as saying all bugs are shaken out, bestie, do not come for me πŸ™ˆ

the columns are LANGUAGE, MODULE and COMMENT:

  • .desktop β€” Desktop β€” OK ✨
  • 4GL β€” FourGL β€” No sample file
  • 4GL-PER β€” FourGLminusPER β€” No sample file
  • ABC β€” ABC β€” OK
  • AHDL β€” AHDL β€” OK
  • ANSI C89 β€” ANSI_C89 β€” No sample file
  • ASP β€” ASP β€” OK
  • AVR Assembler β€” AVR_Assembler β€” OK
  • AWK β€” AWK β€” OK
  • Ada β€” Ada β€” No sample file
  • Alerts β€” Alerts β€” OK, hidden module πŸ‘€
  • Ansys β€” Ansys β€” No sample file
  • Apache Configuration β€” Apache_Configuration β€” No sample file
  • Asm6502 β€” Asm6502 β€” No sample file
  • Bash β€” Bash β€” OK
  • BibTeX β€” BibTeX β€” OK
  • C β€” C β€” No sample file
  • C# β€” Cdash β€” No sample file
  • C++ β€” Cplusplus β€” OK
  • CGiS β€” CGiS β€” No sample file
  • CMake β€” CMake β€” OK
  • CSS β€” CSS β€” OK
  • CUE Sheet β€” CUE_Sheet β€” No sample file
  • Cg β€” Cg β€” No sample file
  • ChangeLog β€” ChangeLog β€” No sample file
  • Cisco β€” Cisco β€” No sample file
  • Clipper β€” Clipper β€” OK
  • ColdFusion β€” ColdFusion β€” No sample file
  • Common Lisp β€” Common_Lisp β€” OK
  • Component-Pascal β€” ComponentminusPascal β€” No sample file
  • D β€” D β€” No sample file
  • Debian Changelog β€” Debian_Changelog β€” No sample file
  • Debian Control β€” Debian_Control β€” No sample file
  • Diff β€” Diff β€” No sample file
  • Doxygen β€” Doxygen β€” OK
  • E Language β€” E_Language β€” OK
  • Eiffel β€” Eiffel β€” No sample file
  • Email β€” Email β€” OK
  • Euphoria β€” Euphoria β€” OK
  • Fortran β€” Fortran β€” OK
  • FreeBASIC β€” FreeBASIC β€” No sample file
  • GDL β€” GDL β€” No sample file
  • GLSL β€” GLSL β€” OK
  • GNU Assembler β€” GNU_Assembler β€” No sample file
  • GNU Gettext β€” GNU_Gettext β€” No sample file
  • HTML β€” HTML β€” OK
  • Haskell β€” Haskell β€” OK
  • IDL β€” IDL β€” No sample file
  • ILERPG β€” ILERPG β€” No sample file
  • INI Files β€” INI_Files β€” No sample file
  • Inform β€” Inform β€” No sample file
  • Intel x86 (NASM) β€” Intel_X86_NASM β€” seems to have issues 😭
  • JSP β€” JSP β€” OK
  • Java β€” Java β€” OK
  • JavaScript β€” JavaScript β€” OK
  • Javadoc β€” Javadoc β€” No sample file
  • KBasic β€” KBasic β€” No sample file
  • Kate File Template β€” Kate_File_Template β€” No sample file
  • LDIF β€” LDIF β€” No sample file
  • LPC β€” LPC β€” No sample file
  • LaTeX β€” LaTex β€” OK
  • Lex/Flex β€” Lex_Flex β€” OK
  • LilyPond β€” LilyPond β€” OK
  • Literate Haskell β€” Literate_Haskell β€” OK
  • Lua β€” Lua β€” No sample file
  • M3U β€” M3U β€” OK
  • MAB-DB β€” MABminusDB β€” No sample file
  • MIPS Assembler β€” MIPS_Assembler β€” No sample file
  • Makefile β€” Makefile β€” No sample file
  • Mason β€” Mason β€” No sample file
  • Matlab β€” Matlab β€” has issues πŸ’€
  • Modula-2 β€” Modulaminus2 β€” No sample file
  • Music Publisher β€” Music_Publisher β€” No sample file
  • Octave β€” Octave β€” OK
  • PHP (HTML) β€” PHP_HTML β€” OK
  • PHP_PHP β€” PHP_PHP β€” OK, hidden module πŸ‘€
  • POV-Ray β€” POV_Ray β€” OK
  • Pascal β€” Pascal β€” No sample file
  • Perl β€” Perl β€” OK (obviously, it's literally us πŸ’…)
  • PicAsm β€” PicAsm β€” OK
  • Pike β€” Pike β€” OK
  • PostScript β€” PostScript β€” OK
  • Prolog β€” Prolog β€” No sample file
  • PureBasic β€” PureBasic β€” OK
  • Python β€” Python β€” OK
  • Quake Script β€” Quake_Script β€” No sample file
  • R Script β€” R_Script β€” No sample file
  • REXX β€” REXX β€” No sample file
  • RPM Spec β€” RPM_Spec β€” No sample file
  • RSI IDL β€” RSI_IDL β€” No sample file
  • RenderMan RIB β€” RenderMan_RIB β€” OK
  • Ruby β€” Ruby β€” OK
  • SGML β€” SGML β€” No sample file
  • SML β€” SML β€” No sample file
  • SQL β€” SQL β€” No sample file
  • SQL (MySQL) β€” SQL_MySQL β€” No sample file
  • SQL (PostgreSQL) β€” SQL_PostgreSQL β€” No sample file
  • Sather β€” Sather β€” No sample file
  • Scheme β€” Scheme β€” OK
  • Sieve β€” Sieve β€” No sample file
  • Spice β€” Spice β€” OK
  • Stata β€” Stata β€” OK
  • TI Basic β€” TI_Basic β€” No sample file
  • TaskJuggler β€” TaskJuggler β€” No sample file
  • Tcl/Tk β€” TCL_Tk β€” OK
  • UnrealScript β€” UnrealScript β€” OK
  • VHDL β€” VHDL β€” No sample file
  • VRML β€” VRML β€” OK
  • Velocity β€” Velocity β€” No sample file
  • Verilog β€” Verilog β€” No sample file
  • WINE Config β€” WINE_Config β€” No sample file
  • Wikimedia β€” Wikimedia β€” No sample file
  • XML β€” XML β€” OK
  • XML (Debug) β€” XML_Debug β€” No sample file
  • Yacc/Bison β€” Yacc_Bison β€” OK
  • de_DE β€” De_DE β€” No sample file
  • en_EN β€” En_EN β€” No sample file
  • ferite β€” Ferite β€” No sample file
  • nl β€” Nl β€” No sample file
  • progress β€” Progress β€” No sample file
  • scilab β€” Scilab β€” No sample file
  • txt2tags β€” Txt2tags β€” No sample file
  • x.org Configuration β€” X_org_Configuration β€” OK
  • xHarbour β€” XHarbour β€” OK
  • xslt β€” Xslt β€” No sample file
  • yacas β€” Yacas β€” No sample file

andddd one more thing 🫢 β€” the module Syntax::Highlight::Engine::Kate::Convert::ToolKit plus the script hl-kate-convert can be used to convert an existing Kate/KTextEditor Syntax Highlighting file from XML format to Perl. slay.


😭 BUGS 😭

ngl bestie, here's where it gets a lil spicy:

  • Float is detected differently than in the Kate editor. deadass. it just is.
  • the regular expression engine of the Kate editor, qregexp, appears to be more tolerant to mistakes in regular expressions than Perl. which means… error messages. and differences in behaviour. most of the problems were sorted out while developing, because error messages appeared. but as far as differences in behaviour goes? testing is literally 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. so 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. not my problem, that's Kate's problem πŸ’…

✨ TO DO ✨

the vision board, bestie:

  • rebuild the scripts I am using to generate the modules from XML files, so they are more pro-actively tracking flaws in the build of the XML files β€” like missing lists, y'know? also, regular expressions in the XML can be tested better before they are used in plugins.
  • refine the test methods in Syntax::Highlight::Engine::Kate::Template, so that choices for case sensitivity, dynamic behaviour and lookahead can be determined at generate time of the plugin. might increase throughput πŸ‘‘
  • implement code folding.

🫢 ACKNOWLEDGEMENTS 🫢

all the people who wrote Kate and the syntax highlight XML files. every single one. absolute icons, every last one of them 🌸


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. that's the good stuff ✨


🌈 SEE ALSO 🌈


and that's a wrap on the whole page, bestie!! πŸŽ€ this was perl v5.40.1, dated 2026-02-22, and honestly? she ate. go highlight something cute. mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from