Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attempt to make Inline::Python optional
... falling back to the old shelling-out code
  • Loading branch information
moritz committed Feb 20, 2015
1 parent b060886 commit 63f0b7c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions htmlify.p6
Expand Up @@ -13,7 +13,6 @@ use Perl6::TypeGraph;
use Perl6::TypeGraph::Viz;
use Perl6::Documentable::Registry;
use Pod::Convenience;
use Inline::Python;

my $*DEBUG = False;

Expand Down Expand Up @@ -710,8 +709,10 @@ sub pygmentize-code-blocks {
return;
}

my $py = Inline::Python.new();
$py.run(q{
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")
Expand All @@ -720,6 +721,11 @@ 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 {
Expand All @@ -728,7 +734,18 @@ def p6format(code):
return default($node);
}
}
return $py.call('__main__', 'p6format', $node.contents.join);
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 63f0b7c

Please sign in to comment.