Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'inline-pygments'
  • Loading branch information
moritz committed Feb 20, 2015
2 parents 8255be9 + 63f0b7c commit 471e680
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions htmlify.p6
Expand Up @@ -698,19 +698,44 @@ sub highlight-code-blocks {
say "pygmentize not found; code blocks will not be highlighted";
return;
}

my $py = try {
require Inline::Python;
my $py = ::('Inline::Python').new();
$py.run(q{
import pygments.lexers
import pygments.formatters
p6lexer = pygments.lexers.get_lexer_by_name("perl6")
htmlformatter = pygments.formatters.get_formatter_by_name("html")
def p6format(code):
return pygments.highlight(code, p6lexer, htmlformatter)
});
$py;
}
if defined $py {
say "Using syntax hilight using Inline::Python";
}

%*POD2HTML-CALLBACKS = code => sub (:$node, :&default) {
for @($node.contents) -> $c {
if $c !~~ Str {
# some nested formatting code => we can't hilight this
return default($node);
}
}
my $basename = join '-', %*ENV<USER> // 'u', (^100_000).pick, 'pod_to_pyg.pod';
my $tmp_fname = "$*TMPDIR/$basename";
spurt $tmp_fname, $node.contents.join;
LEAVE try unlink $tmp_fname;
my $command = "pygmentize -l perl6 -f html < $tmp_fname";
return qqx{$command};
if defined $py {
return $py.call('__main__', 'p6format', $node.contents.join);
}
else {
my $basename = join '-', %*ENV<USER> // 'u', (^100_000).pick, 'pod_to_pyg.pod';
my $tmp_fname = "$*TMPDIR/$basename";
spurt $tmp_fname, $node.contents.join;
LEAVE try unlink $tmp_fname;
my $command = "pygmentize -l perl6 -f html < $tmp_fname";
return qqx{$command};

}
}
}

Expand Down

0 comments on commit 471e680

Please sign in to comment.