All pastes #331969 Raw Edit

Someone

public text v1 · immutable
#331969 ·published 2007-01-29 17:22 UTC
rendered paste body
sub nifty_highlight_code {
	my $self = shift;
	my $html = shift;

	$html =~ s/\[code syntax\=[\'|\"](.*?)[\'|\"]\](.*?)\[\/code\]/$self->process_code($1,$2)/egs;
	return $html;
}


sub process_code {
	my ($self,$lang,$code)=@_;
	
	$lang =~ s/CPP/C/g;
	
    my $hl = new Syntax::Highlight::Engine::Kate(
       language => $lang,
       substitutions => {
          "<" => "&lt;",
          ">" => "&gt;",
          "&" => "&amp;",
          " " => "&nbsp;",
          "\t" => "&nbsp;&nbsp;&nbsp;",
       },
       format_table => {
          Alert => ["<span class='other'>", "</span>"],
          BaseN => ["<span class='other'>", "</span>"],
          BString => ["<span class='other'>", "</span>"],
          Char => ["<span class='other'>", "</span>"],
          Comment => ["<span class='comment'><i>", "</i></span>"],
          DataType => ["<span class='datatype'>", "</span>"],
          DecVal => ["<span class='other'>", "</span>"],
          Error => ["<span class='other'><strong><i>", "</i></strong></span>"],
          Float => ["<span class='other'>", "</span>"],
          Function => ["<span class='key2'>", "</span>"],
          IString => ["<span class='string'>", "</span>"],
          Keyword => ["<strong>", "</strong>"],
          Normal => ["", ""],
          Operator => ["<span class='other'>", "</span>"],
          Others => ["<span class='key1'>", "</span>"],
          RegionMarker => ["<span class='key1'><i>", "</i></span>"],
          Reserved => ["<span class='key1'><strong>", "</strong></span>"],
          String => ["<span class='string'>", "</span>"],
          Variable => ["<span class='key1'><strong>", "</strong></span>"],
          Warning => ["<span class='string'><strong><i>", "</i></strong></span>"],
       },
    );
	
    # my $high = new Text::Highlight(wrapper=>"<div class='code'>%s</div>\n");
    # $code=$high->highlight($lang,$code);
    # $code =~ s/  /&nbsp;&nbsp;/g;
    $code = '<div class="code">' . $hl->highlightText($code) . '</div>';
    return $code;
}