@@ -134,6 +134,7 @@ sub MAIN(
134
134
Bool : $ search-file = True ,
135
135
Bool : $ no-highlight = False ,
136
136
Bool : $ no-inline-python = False ,
137
+ Bool : $ use-highlights = False ,
137
138
Int : $ parallel = 1 ,
138
139
) {
139
140
@@ -163,7 +164,7 @@ sub MAIN(
163
164
process-pod-dir ' Language' , : $ sparse , : $ parallel ;
164
165
process-pod-dir ' Type' , : sorted-by{ % h {. key } // -1 }, : $ sparse , : $ parallel ;
165
166
166
- highlight-code-blocks(: use-inline-python(! $ no-inline-python )) unless $ no-highlight ;
167
+ highlight-code-blocks(: use-inline-python(! $ no-inline-python ), : use-highlights( $ use-highlights ) ) unless $ no-highlight ;
167
168
168
169
say ' Composing doc registry ...' ;
169
170
$ * DR . compose;
@@ -946,41 +947,50 @@ sub write-qualified-method-call(:$name!, :$pod!, :$type!) {
946
947
spurt " html/routine/{ escape-filename $ type } .{ escape-filename $ name } .html" , p2h($ p , ' routine' );
947
948
}
948
949
949
- sub highlight-code-blocks (: $ use-inline-python = True ) {
950
- my $ pyg-version = try qx / pygmentize -V/ ;
951
- if $ pyg-version && $ pyg-version ~~ /^ 'Pygments version ' (\d\S + ) / {
952
- if Version . new (~ $0 ) ~~ v2. 0+ {
953
- say " pygmentize $0 found; code blocks will be highlighted" ;
950
+ sub highlight-code-blocks (: $ use-inline-python = True , : $ use-highlights = False ) {
951
+ say " highlight-code-blocks has been called" ;
952
+ my $ py ;
953
+ if $ use-highlights {
954
+ note " Using highlights" ;
955
+ # return;
956
+ }
957
+ else {
958
+ my $ pyg-version = try qx / pygmentize -V/ ;
959
+ if $ pyg-version && $ pyg-version ~~ /^ 'Pygments version ' (\d\S + ) / {
960
+ if Version . new (~ $0 ) ~~ v2. 0+ {
961
+ say " pygmentize $0 found; code blocks will be highlighted" ;
962
+ }
963
+ else {
964
+ say " pygmentize $0 is too old; need at least 2.0" ;
965
+ return ;
966
+ }
954
967
}
955
968
else {
956
- say " pygmentize $0 is too old; need at least 2.0 " ;
969
+ say " pygmentize not found; code blocks will not be highlighted " ;
957
970
return ;
958
971
}
959
- }
960
- else {
961
- say " pygmentize not found; code blocks will not be highlighted" ;
962
- return ;
963
- }
964
-
965
- my $ py = $ use-inline-python && try {
966
- require Inline::Python;
967
- my $ inline-py = ::(' Inline::Python' ). new ();
968
- $ inline-py . run (q {
969
- import pygments.lexers
970
- import pygments.formatters
971
- p6lexer = pygments.lexers.get_lexer_by_name("perl6")
972
- htmlformatter = pygments.formatters.get_formatter_by_name("html")
973
972
974
- def p6format(code):
975
- return pygments.highlight(code, p6lexer, htmlformatter)
976
- } );
977
- $ inline-py ;
978
- }
979
- if $ py {
980
- say " Using syntax highlighting via Inline::Python" ;
981
- }
982
- else {
983
- say " Error using Inline::Python, falling back to pygmentize: ($!)" ;
973
+ $ py = $ use-inline-python && try {
974
+ require Inline::Python;
975
+ my $ inline-py = ::(' Inline::Python' ). new ();
976
+ $ inline-py . run (Q :to /END /
977
+ import pygments.lexers
978
+ import pygments.formatters
979
+ p6lexer = pygments.lexers.get_lexer_by_name("perl6")
980
+ htmlformatter = pygments.formatters.get_formatter_by_name("html")
981
+
982
+ def p6format(code):
983
+ return pygments.highlight(code, p6lexer, htmlformatter)
984
+ END
985
+ );
986
+ $ inline-py ;
987
+ }
988
+ if $ py {
989
+ say " Using syntax highlighting via Inline::Python" ;
990
+ }
991
+ else {
992
+ say " Error using Inline::Python, falling back to pygmentize: ($!)" ;
993
+ }
984
994
}
985
995
986
996
% * POD2HTML-CALLBACKS = code => sub (: $ node , : & default ) {
@@ -998,8 +1008,16 @@ def p6format(code):
998
1008
my $ tmp_fname = " $ * TMPDIR /$ basename" ;
999
1009
spurt $ tmp_fname , $ node . contents. join ;
1000
1010
LEAVE try unlink $ tmp_fname ;
1001
- my $ command = " pygmentize -l perl6 -f html < $ tmp_fname" ;
1002
- qqx { $ command} ;
1011
+ my $ command ;
1012
+ if $ use-highlights {
1013
+ $ command = " ./highlights/node_modules/highlights/bin/highlights -i ./highlights/atom-language-perl6/package.json -s source.perl6fe -f ./highlights/atom-language-perl6/package.json < $ tmp_fname"
1014
+ }
1015
+ else {
1016
+ $ command = " pygmentize -l perl6 -f html < $ tmp_fname" ;
1017
+ }
1018
+ my $ thing = qqx { $ command} ;
1019
+ say " OUTPUT OF HIGHLIGHTS: $ thing" ;
1020
+ $ thing ;
1003
1021
}
1004
1022
}
1005
1023
}
0 commit comments