Syntax Highlighting in Pod::Parser::Groffmom

Ovid on 2009-10-26T23:20:27

I decided that I really needed syntax highlighting in Pod::Parser::Groffman. I have an example at Testing with Test::Class. Note that the Perl examples are now colored. It's not what everyone would like, but it works.

To handle syntax highlighting, you just do this:

 =for highlight Perl
   
  sub add {
      my ( $self, $data ) = @_;
      my $add = $self->in_list_mode ? 'add_to_list' : 'add_to_mom';
      $self->$add($data);
  }

 =end highlight

This turns on syntax highlighting. Allowable highlight types are the types allowed for Syntax::Highlight::Engine::Kate. We default to Perl, so the above can be written as:

 =for highlight 
   
  sub add {
      my ( $self, $data ) = @_;
      my $add = $self->in_list_mode ? 'add_to_list' : 'add_to_mom';
      $self->$add($data);
  }

 =end highlight

Syntax highlighting is experimental and a bit flaky. Some lines after comments are highlighted as comments. Also, POD in verbatim (indented) POD highlights incorrectly. Common_Lisp is allegedly supported by Syntax::Highlight::Engine::Kate, but I was getting weird stack errors when I tried to highlight it.

Also, don't use angle brackets with quote operators like "q" or "qq". The highlighter gets confused. I've not filed any bug reports as I've no idea if the errors are mine or the syntax highlighting module.


Don't use angle brackets?!?

elliot on 2009-10-27T02:13:31

I'm in trouble then. Angle brackets is about all I use nowadays. :]

Re:Don't use angle brackets?!?

Ovid on 2009-10-27T06:58:34

Same here. They broke the highlighting badly, though (worse than just about anything else). I was working fast enough to just get the highlighting in there that I wasn't try to debug the highlighter's issues.

=for ?

Matts on 2009-10-27T15:36:23

Isn't that incorrect usage of =for?

I think it should be =begin.

Re:=for ?

Ovid on 2009-10-28T07:01:14

Er, yup. You're right. Should have caught that sooner. Thanks :)