Skip to content

Commit 3faff50

Browse files
committed
Remove old pygments code. Issue #1070
1 parent 0ffb783 commit 3faff50

File tree

2 files changed

+33
-89
lines changed

2 files changed

+33
-89
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
html: bigpage
44
perl6 htmlify.p6 --parallel=1
55

6-
html-highlights: bigpage
7-
perl6 htmlify.p6 --parallel=1 --use-highlights
8-
6+
html-highlights: html
97

108
init-highlights:
119
ATOMDIR="./highlights/atom-language-perl6"; \

htmlify.p6

Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
use v6;
33

44
# This script isn't in bin/ because it's not meant to be installed.
5-
# For syntax highlighting, needs pygmentize version 2.0 or newer installed
5+
# For syntax highlighting, needs node.js installed.
6+
# Please run make init-highlights to automatically pull in the highlighting
7+
# grammar and build the highlighter.
68
#
79
# for doc.perl6.org, the build process goes like this:
810
# * a cron job on hack.p6c.org as user 'doc.perl6.org' triggers the rebuild.
@@ -129,18 +131,16 @@ sub recursive-dir($dir) {
129131
# much faster, but with the current state of async/concurrency
130132
# in Rakudo you risk segfaults, weird errors, etc.
131133
my $proc;
132-
my $supply;
133-
my $supply2;
134-
my $prom;
134+
my $proc-supply;
135+
my $proc-prom;
135136
my $async = True;
136137
sub MAIN(
137138
Bool :$typegraph = False,
138139
Int :$sparse,
139140
Bool :$disambiguation = True,
140141
Bool :$search-file = True,
141142
Bool :$no-highlight = False,
142-
Bool :$no-inline-python = False,
143-
Bool :$use-highlights = False,
143+
Bool :$no-proc-async = False,
144144
Int :$parallel = 1,
145145
) {
146146

@@ -152,12 +152,10 @@ sub MAIN(
152152
# the installation directory (share/man).
153153
#
154154
# Then they can be copied to doc/Programs.
155-
if $use-highlights and $async {
155+
if !$no-highlight and !$no-proc-async {
156156
$proc = Proc::Async.new('./highlights/node_modules/coffee-script/bin/coffee', './highlights/highlight-filename-from-stdin.coffee', :r, :w);
157-
$supply = $proc.stdout.lines;
158-
$supply2 = $proc.stderr.tap( { .say } );
159-
160-
$prom = $proc.start;
157+
$proc-supply = $proc.stdout.lines;
158+
$proc-prom = $proc.start;
161159
}
162160
say 'Creating html/subdirectories ...';
163161

@@ -176,7 +174,7 @@ sub MAIN(
176174
process-pod-dir 'Language', :$sparse, :$parallel;
177175
process-pod-dir 'Type', :sorted-by{ %h{.key} // -1 }, :$sparse, :$parallel;
178176

179-
highlight-code-blocks(:use-inline-python(!$no-inline-python), :use-highlights($use-highlights)) unless $no-highlight;
177+
highlight-code-blocks(:no-proc-async($no-proc-async)) unless $no-highlight;
180178

181179
say 'Composing doc registry ...';
182180
$*DR.compose;
@@ -959,95 +957,43 @@ sub write-qualified-method-call(:$name!, :$pod!, :$type!) {
959957
spurt "html/routine/{escape-filename $type}.{escape-filename $name}.html", p2h($p, 'routine');
960958
}
961959

962-
sub highlight-code-blocks(:$use-inline-python = True, :$use-highlights = False) {
960+
sub highlight-code-blocks(:$use-highlights = False) {
963961
say "highlight-code-blocks has been called";
964-
my $py;
965962
if $use-highlights {
966963
note "Using highlights";
967964
#return;
968965
}
969-
else {
970-
my $pyg-version = try qx/pygmentize -V/;
971-
if $pyg-version && $pyg-version ~~ /^'Pygments version ' (\d\S+)/ {
972-
if Version.new(~$0) ~~ v2.0+ {
973-
say "pygmentize $0 found; code blocks will be highlighted";
974-
}
975-
else {
976-
say "pygmentize $0 is too old; need at least 2.0";
977-
return;
978-
}
979-
}
980-
else {
981-
say "pygmentize not found; code blocks will not be highlighted";
982-
return;
983-
}
984-
985-
$py = $use-inline-python && try {
986-
require Inline::Python;
987-
my $inline-py = ::('Inline::Python').new();
988-
$inline-py.run(Q:to/END/
989-
import pygments.lexers
990-
import pygments.formatters
991-
p6lexer = pygments.lexers.get_lexer_by_name("perl6")
992-
htmlformatter = pygments.formatters.get_formatter_by_name("html")
993-
994-
def p6format(code):
995-
return pygments.highlight(code, p6lexer, htmlformatter)
996-
END
997-
);
998-
$inline-py;
999-
}
1000-
if $py {
1001-
say "Using syntax highlighting via Inline::Python";
1002-
}
1003-
else {
1004-
say "Error using Inline::Python, falling back to pygmentize: ($!)";
1005-
}
1006-
}
1007-
1008966
%*POD2HTML-CALLBACKS = code => sub (:$node, :&default) {
1009967
for @($node.contents) -> $c {
1010968
if $c !~~ Str {
1011969
# some nested formatting code => we can't highlight this
1012970
return default($node);
1013971
}
1014972
}
1015-
if $py {
1016-
return $py.call('__main__', 'p6format', $node.contents.join);
973+
my $basename = join '-', %*ENV<USER> // 'u', (^100_000).pick, 'pod_to_pyg.pod';
974+
my $tmp_fname = "$*TMPDIR/$basename";
975+
spurt $tmp_fname, $node.contents.join;
976+
LEAVE try unlink $tmp_fname;
977+
my $html;
978+
if $async {
979+
my $promise = Promise.new;
980+
my $tap = $proc-supply.tap( -> $json {
981+
my $parsed-json = from-json($json);
982+
if $parsed-json<file> eq $tmp_fname {
983+
$promise.keep($parsed-json<html>);
984+
$tap.close();
985+
}
986+
} );
987+
$proc.say($tmp_fname);
988+
await $promise;
989+
$html = $promise.result;
1017990
}
1018991
else {
1019-
my $basename = join '-', %*ENV<USER> // 'u', (^100_000).pick, 'pod_to_pyg.pod';
1020-
my $tmp_fname = "$*TMPDIR/$basename";
1021-
spurt $tmp_fname, $node.contents.join;
1022-
LEAVE try unlink $tmp_fname;
1023-
my $command;
1024-
my $thing;
1025-
if $use-highlights {
1026-
if $async {
1027-
my $promise = Promise.new;
1028-
my $tap = $supply.tap( -> $json {
1029-
my $parsed-json = from-json($json);
1030-
if $parsed-json<file> eq $tmp_fname {
1031-
$promise.keep($parsed-json<html>);
1032-
$tap.close();
1033-
}
1034-
} );
1035-
$proc.say($tmp_fname);
1036-
await $promise;
1037-
$thing = $promise.result;
1038-
}
1039-
else {
1040-
$command = ./highlights/node_modules/coffee-script/bin/coffee ./highlights/highlight-file.coffee "$tmp_fname";
1041-
}
1042-
}
1043-
else {
1044-
$command = "pygmentize -l perl6 -f html < $tmp_fname";
1045-
}
1046-
if ! $async or ! $use-highlights {
1047-
$thing = qqx{$command};
1048-
}
1049-
$thing;
992+
my $command = q[./highlights/node_modules/coffee-script/bin/coffee ] ~
993+
q[./highlights/highlight-file.coffee "$tmp_fname"];
994+
$html = qqx{$command};
1050995
}
996+
$html;
1051997
}
1052998
}
1053999

0 commit comments

Comments
 (0)