- my $gen = highlightc::CodeGenerator_getInstance($highlightc::XHTML);
- $gen->setFragmentCode(1); # generate html fragment
- $gen->setHTMLEnclosePreTag(1); # include stylish <pre>
- $gen->initLanguage($langfile);
- $gen->initTheme("/dev/null"); # theme is not needed because CSS is not emitted
- $gen->setEncoding("utf-8");
+ eval q{use highlight};
+ if ($@) {
+ print STDERR gettext("warning: highlight perl module not available; falling back to pass through");
+ return $input;
+ }
+
+ my $gen;
+ if (! exists $highlighters{$langfile}) {
+ $gen = highlight::CodeGenerator::getInstance($highlight::XHTML);
+ $gen->setFragmentCode(1); # generate html fragment
+ $gen->setHTMLEnclosePreTag(1); # include stylish <pre>
+ if ($data_dir){
+ # new style, requires a real theme, but has no effect
+ $gen->initTheme($data_dir->getThemePath("seashell.theme"));
+ } else {
+ # old style, anything works.
+ $gen->initTheme("/dev/null");
+ }
+ $gen->loadLanguage($langfile); # must come after initTheme
+ $gen->setEncoding("utf-8");
+ $highlighters{$langfile}=$gen;
+ }
+ else {
+ $gen=$highlighters{$langfile};
+ }