2
2
use v6 ;
3
3
4
4
# 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.
6
8
#
7
9
# for doc.perl6.org, the build process goes like this:
8
10
# * a cron job on hack.p6c.org as user 'doc.perl6.org' triggers the rebuild.
@@ -129,18 +131,16 @@ sub recursive-dir($dir) {
129
131
# much faster, but with the current state of async/concurrency
130
132
# in Rakudo you risk segfaults, weird errors, etc.
131
133
my $ proc ;
132
- my $ supply ;
133
- my $ supply2 ;
134
- my $ prom ;
134
+ my $ proc-supply ;
135
+ my $ proc-prom ;
135
136
my $ async = True ;
136
137
sub MAIN (
137
138
Bool : $ typegraph = False ,
138
139
Int : $ sparse ,
139
140
Bool : $ disambiguation = True ,
140
141
Bool : $ search-file = True ,
141
142
Bool : $ no-highlight = False ,
142
- Bool : $ no-inline-python = False ,
143
- Bool : $ use-highlights = False ,
143
+ Bool : $ no-proc-async = False ,
144
144
Int : $ parallel = 1 ,
145
145
) {
146
146
@@ -152,12 +152,10 @@ sub MAIN(
152
152
# the installation directory (share/man).
153
153
#
154
154
# Then they can be copied to doc/Programs.
155
- if $ use-highlights and $ async {
155
+ if ! $ no-highlight and ! $ no-proc- async {
156
156
$ 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;
161
159
}
162
160
say ' Creating html/subdirectories ...' ;
163
161
@@ -176,7 +174,7 @@ sub MAIN(
176
174
process-pod-dir ' Language' , : $ sparse , : $ parallel ;
177
175
process-pod-dir ' Type' , : sorted-by{ % h {. key } // -1 }, : $ sparse , : $ parallel ;
178
176
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 ;
180
178
181
179
say ' Composing doc registry ...' ;
182
180
$ * DR . compose;
@@ -959,95 +957,43 @@ sub write-qualified-method-call(:$name!, :$pod!, :$type!) {
959
957
spurt " html/routine/{ escape-filename $ type } .{ escape-filename $ name } .html" , p2h($ p , ' routine' );
960
958
}
961
959
962
- sub highlight-code-blocks (: $ use-inline-python = True , : $ use- highlights = False ) {
960
+ sub highlight-code-blocks (: $ use-highlights = False ) {
963
961
say " highlight-code-blocks has been called" ;
964
- my $ py ;
965
962
if $ use-highlights {
966
963
note " Using highlights" ;
967
964
# return;
968
965
}
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
-
1008
966
% * POD2HTML-CALLBACKS = code => sub (: $ node , : & default ) {
1009
967
for @ ($ node . contents) -> $ c {
1010
968
if $ c ! ~~ Str {
1011
969
# some nested formatting code => we can't highlight this
1012
970
return default ($ node );
1013
971
}
1014
972
}
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;
1017
990
}
1018
991
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} ;
1050
995
}
996
+ $ html ;
1051
997
}
1052
998
}
1053
999
0 commit comments