rouge 3.19.0 → 3.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rouge.rb +1 -0
- data/lib/rouge/cli.rb +32 -2
- data/lib/rouge/demos/augeas +16 -0
- data/lib/rouge/demos/bibtex +12 -0
- data/lib/rouge/demos/brightscript +6 -0
- data/lib/rouge/demos/email +11 -0
- data/lib/rouge/demos/hlsl +20 -0
- data/lib/rouge/demos/j +12 -0
- data/lib/rouge/demos/janet +3 -0
- data/lib/rouge/demos/livescript +15 -0
- data/lib/rouge/demos/postscript +9 -0
- data/lib/rouge/demos/ssh +4 -0
- data/lib/rouge/demos/systemd +4 -0
- data/lib/rouge/demos/velocity +9 -0
- data/lib/rouge/demos/zig +6 -0
- data/lib/rouge/formatters/html_line_highlighter.rb +26 -0
- data/lib/rouge/lexer.rb +38 -20
- data/lib/rouge/lexers/apex.rb +9 -7
- data/lib/rouge/lexers/augeas.rb +93 -0
- data/lib/rouge/lexers/batchfile.rb +1 -1
- data/lib/rouge/lexers/bibtex.rb +115 -0
- data/lib/rouge/lexers/brightscript.rb +147 -0
- data/lib/rouge/lexers/cpp.rb +11 -4
- data/lib/rouge/lexers/css.rb +3 -1
- data/lib/rouge/lexers/diff.rb +1 -1
- data/lib/rouge/lexers/docker.rb +1 -1
- data/lib/rouge/lexers/elm.rb +5 -5
- data/lib/rouge/lexers/email.rb +39 -0
- data/lib/rouge/lexers/ghc_core.rb +2 -1
- data/lib/rouge/lexers/graphql.rb +1 -1
- data/lib/rouge/lexers/hack.rb +1 -1
- data/lib/rouge/lexers/haskell.rb +27 -19
- data/lib/rouge/lexers/hlsl.rb +166 -0
- data/lib/rouge/lexers/html.rb +7 -7
- data/lib/rouge/lexers/http.rb +8 -2
- data/lib/rouge/lexers/isbl.rb +2 -2
- data/lib/rouge/lexers/j.rb +244 -0
- data/lib/rouge/lexers/janet.rb +218 -0
- data/lib/rouge/lexers/javascript.rb +10 -5
- data/lib/rouge/lexers/jinja.rb +22 -7
- data/lib/rouge/lexers/jsl.rb +1 -1
- data/lib/rouge/lexers/jsonnet.rb +4 -3
- data/lib/rouge/lexers/jsp.rb +2 -3
- data/lib/rouge/lexers/jsx.rb +47 -59
- data/lib/rouge/lexers/julia.rb +4 -2
- data/lib/rouge/lexers/kotlin.rb +7 -3
- data/lib/rouge/lexers/livescript.rb +310 -0
- data/lib/rouge/lexers/opentype_feature_file.rb +26 -42
- data/lib/rouge/lexers/perl.rb +21 -3
- data/lib/rouge/lexers/php.rb +274 -128
- data/lib/rouge/lexers/postscript.rb +93 -0
- data/lib/rouge/lexers/powershell.rb +5 -3
- data/lib/rouge/lexers/q.rb +1 -1
- data/lib/rouge/lexers/rego.rb +27 -12
- data/lib/rouge/lexers/ruby.rb +3 -3
- data/lib/rouge/lexers/rust.rb +3 -1
- data/lib/rouge/lexers/sass/common.rb +1 -0
- data/lib/rouge/lexers/smarty.rb +1 -1
- data/lib/rouge/lexers/ssh.rb +33 -0
- data/lib/rouge/lexers/systemd.rb +34 -0
- data/lib/rouge/lexers/tsx.rb +10 -3
- data/lib/rouge/lexers/twig.rb +4 -4
- data/lib/rouge/lexers/typescript.rb +1 -12
- data/lib/rouge/lexers/typescript/common.rb +18 -4
- data/lib/rouge/lexers/velocity.rb +71 -0
- data/lib/rouge/lexers/wollok.rb +0 -1
- data/lib/rouge/lexers/xml.rb +5 -3
- data/lib/rouge/lexers/yaml.rb +5 -3
- data/lib/rouge/lexers/zig.rb +139 -0
- data/lib/rouge/regex_lexer.rb +56 -1
- data/lib/rouge/version.rb +1 -1
- metadata +29 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5fdf4ccf2083c09f6ce1c899d36f7ef50b2f4bb70e5fa04dc18ce239422f8a
|
4
|
+
data.tar.gz: e40152f9290403580be90d096219bf81a92750e8c02be04f05d6929b1fb186ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9c0bcf9114cb6b260d611777dbeaa7649bc20ad298ddc73fa2b606ca871615051c7f46abfbed3d8121ec08b505e1c3c4c86c2140d5c30a6c6104dae12d15b11
|
7
|
+
data.tar.gz: 061b7d77b9162d45ff5416fefa9a2052199745b31e3897170c79e46311a6b36de959b1f030a903130dda3941c0ca217c13012f27a5c840f0c07b0912b02a93c7
|
data/lib/rouge.rb
CHANGED
@@ -83,6 +83,7 @@ Rouge.load_file 'formatters/html_table'
|
|
83
83
|
Rouge.load_file 'formatters/html_pygments'
|
84
84
|
Rouge.load_file 'formatters/html_legacy'
|
85
85
|
Rouge.load_file 'formatters/html_linewise'
|
86
|
+
Rouge.load_file 'formatters/html_line_highlighter'
|
86
87
|
Rouge.load_file 'formatters/html_line_table'
|
87
88
|
Rouge.load_file 'formatters/html_inline'
|
88
89
|
Rouge.load_file 'formatters/terminal256'
|
data/lib/rouge/cli.rb
CHANGED
@@ -44,6 +44,7 @@ module Rouge
|
|
44
44
|
yield %||
|
45
45
|
yield %|where <command> is one of:|
|
46
46
|
yield %| highlight #{Highlight.desc}|
|
47
|
+
yield %| debug #{Debug.desc}|
|
47
48
|
yield %| help #{Help.desc}|
|
48
49
|
yield %| style #{Style.desc}|
|
49
50
|
yield %| list #{List.desc}|
|
@@ -104,6 +105,8 @@ module Rouge
|
|
104
105
|
Help
|
105
106
|
when 'highlight', 'hi'
|
106
107
|
Highlight
|
108
|
+
when 'debug'
|
109
|
+
Debug
|
107
110
|
when 'style'
|
108
111
|
Style
|
109
112
|
when 'list'
|
@@ -215,7 +218,7 @@ module Rouge
|
|
215
218
|
end
|
216
219
|
end
|
217
220
|
|
218
|
-
def self.
|
221
|
+
def self.parse_opts(argv)
|
219
222
|
opts = {
|
220
223
|
:formatter => supports_truecolor? ? 'terminal-truecolor' : 'terminal256',
|
221
224
|
:theme => 'thankful_eyes',
|
@@ -256,7 +259,11 @@ module Rouge
|
|
256
259
|
end
|
257
260
|
end
|
258
261
|
|
259
|
-
|
262
|
+
opts
|
263
|
+
end
|
264
|
+
|
265
|
+
def self.parse(argv)
|
266
|
+
new(parse_opts(argv))
|
260
267
|
end
|
261
268
|
|
262
269
|
def input_stream
|
@@ -344,6 +351,29 @@ module Rouge
|
|
344
351
|
end
|
345
352
|
end
|
346
353
|
|
354
|
+
class Debug < Highlight
|
355
|
+
def self.desc
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.doc
|
359
|
+
return enum_for(:doc) unless block_given?
|
360
|
+
|
361
|
+
yield %|usage: rougify debug [<options>]|
|
362
|
+
yield %||
|
363
|
+
yield %|Debug a lexer. Similar options to `rougify highlight`, but|
|
364
|
+
yield %|defaults to the `null` formatter, and ensures the `debug`|
|
365
|
+
yield %|option is enabled, to print debugging information to stdout.|
|
366
|
+
end
|
367
|
+
|
368
|
+
def self.parse_opts(argv)
|
369
|
+
out = super(argv)
|
370
|
+
out[:lexer_opts]['debug'] = '1'
|
371
|
+
out[:formatter] = 'null'
|
372
|
+
|
373
|
+
out
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
347
377
|
class Style < CLI
|
348
378
|
def self.desc
|
349
379
|
"print CSS styles"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
(*
|
2
|
+
This is a comment
|
3
|
+
*)
|
4
|
+
module Foo =
|
5
|
+
autoload xfm
|
6
|
+
|
7
|
+
let a = b | c . d
|
8
|
+
|
9
|
+
let lns = a*
|
10
|
+
|
11
|
+
let filter = incl "/path/to/file"
|
12
|
+
. incl "/path/to/other_file"
|
13
|
+
. Util.stdexcl
|
14
|
+
|
15
|
+
(* xmf is the transform *)
|
16
|
+
let xmf = transform lns filter
|
@@ -0,0 +1,12 @@
|
|
1
|
+
@article{Witten:1988hf,
|
2
|
+
author = "Witten, Edward",
|
3
|
+
title = "{Quantum Field Theory and the Jones Polynomial}",
|
4
|
+
journal = "Commun. Math. Phys.",
|
5
|
+
volume = "121",
|
6
|
+
year = "1989",
|
7
|
+
pages = "351-399",
|
8
|
+
doi = "10.1007/BF01217730",
|
9
|
+
note = "[,233(1988)]",
|
10
|
+
reportNumber = "IASSNS-HEP-88-33",
|
11
|
+
SLACcitation = "%%CITATION = CMPHA,121,351;%%"
|
12
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
From: Me <me@example.com>
|
2
|
+
To: You <you@example.com>
|
3
|
+
Date: Tue, 21 Jul 2020 15:14:03 +0000
|
4
|
+
Subject: A very important message
|
5
|
+
|
6
|
+
> Please investigate. Thank you.
|
7
|
+
|
8
|
+
I have investigated.
|
9
|
+
|
10
|
+
--
|
11
|
+
This message is highly confidential and will self-destruct.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
struct PSInput
|
2
|
+
{
|
3
|
+
float4 position : SV_POSITION;
|
4
|
+
float4 color : COLOR;
|
5
|
+
};
|
6
|
+
|
7
|
+
// Vertex shader
|
8
|
+
PSInput VSMain(float4 position : POSITION, float4 color : COLOR)
|
9
|
+
{
|
10
|
+
PSInput result;
|
11
|
+
result.position = position;
|
12
|
+
result.color = color;
|
13
|
+
return result;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Pixel shader
|
17
|
+
float4 PSMain(PSInput input) : SV_TARGET
|
18
|
+
{
|
19
|
+
return input.color;
|
20
|
+
}
|
data/lib/rouge/demos/j
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
NB. Procedural programming
|
2
|
+
fizzbuzz=: monad define
|
3
|
+
for_i. >:i.y do.
|
4
|
+
if. 0 = 15 | i do. echo'FizzBuzz'
|
5
|
+
elseif. 0 = 3 | i do. echo'Fizz'
|
6
|
+
elseif. 0 = 5 | i do. echo'Buzz'
|
7
|
+
else. echo i
|
8
|
+
end.
|
9
|
+
end.
|
10
|
+
)
|
11
|
+
NB. Loopless programming
|
12
|
+
fizzbuzz=: echo@(, ::] ('Fizz' ; 'Buzz') ;@#~ 0 = 3 5&|)@>:@i.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
%!PS
|
2
|
+
/Courier % name the desired font
|
3
|
+
20 selectfont % choose the size in points and establish
|
4
|
+
% the font as the current one
|
5
|
+
72 500 moveto % position the current point at
|
6
|
+
% coordinates 72, 500 (the origin is at the
|
7
|
+
% lower-left corner of the page)
|
8
|
+
(Hello world!) show % stroke the text in parentheses
|
9
|
+
showpage % print all on the page
|
data/lib/rouge/demos/ssh
ADDED
data/lib/rouge/demos/zig
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Formatters
|
6
|
+
class HTMLLineHighlighter < Formatter
|
7
|
+
tag 'html_line_highlighter'
|
8
|
+
|
9
|
+
def initialize(delegate, opts = {})
|
10
|
+
@delegate = delegate
|
11
|
+
@highlight_line_class = opts.fetch(:highlight_line_class, 'hll')
|
12
|
+
@highlight_lines = opts[:highlight_lines] || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def stream(tokens)
|
16
|
+
lineno = 0
|
17
|
+
token_lines(tokens) do |tokens_in_line|
|
18
|
+
lineno += 1
|
19
|
+
line = %(#{@delegate.format(tokens_in_line)}\n)
|
20
|
+
line = %(<span class="#{@highlight_line_class}">#{line}</span>) if @highlight_lines.include? lineno
|
21
|
+
yield line
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rouge/lexer.rb
CHANGED
@@ -38,28 +38,15 @@ module Rouge
|
|
38
38
|
registry[name.to_s]
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# Lexer.find_fancy('erb?parent=tex')
|
46
|
-
#
|
47
|
-
# * You can pass the special name 'guess' so we guess for you,
|
48
|
-
# and you can pass a second argument of the code to guess by
|
49
|
-
#
|
50
|
-
# Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
|
41
|
+
# Same as ::find_fancy, except instead of returning an instantiated
|
42
|
+
# lexer, returns a pair of [lexer_class, options], so that you can
|
43
|
+
# modify or provide additional options to the lexer.
|
51
44
|
#
|
52
|
-
#
|
53
|
-
|
54
|
-
#
|
55
|
-
# This is used in the Redcarpet plugin as well as Rouge's own
|
56
|
-
# markdown lexer for highlighting internal code blocks.
|
57
|
-
#
|
58
|
-
def find_fancy(str, code=nil, additional_options={})
|
59
|
-
|
45
|
+
# Please note: the lexer class might be nil!
|
46
|
+
def lookup_fancy(str, code=nil, default_options={})
|
60
47
|
if str && !str.include?('?') && str != 'guess'
|
61
48
|
lexer_class = find(str)
|
62
|
-
return lexer_class
|
49
|
+
return [lexer_class, default_options]
|
63
50
|
end
|
64
51
|
|
65
52
|
name, opts = str ? str.split('?', 2) : [nil, '']
|
@@ -75,7 +62,7 @@ module Rouge
|
|
75
62
|
[ k.to_s, val ]
|
76
63
|
end
|
77
64
|
|
78
|
-
opts =
|
65
|
+
opts = default_options.merge(Hash[opts])
|
79
66
|
|
80
67
|
lexer_class = case name
|
81
68
|
when 'guess', nil
|
@@ -84,6 +71,29 @@ module Rouge
|
|
84
71
|
self.find(name)
|
85
72
|
end
|
86
73
|
|
74
|
+
[lexer_class, opts]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Find a lexer, with fancy shiny features.
|
78
|
+
#
|
79
|
+
# * The string you pass can include CGI-style options
|
80
|
+
#
|
81
|
+
# Lexer.find_fancy('erb?parent=tex')
|
82
|
+
#
|
83
|
+
# * You can pass the special name 'guess' so we guess for you,
|
84
|
+
# and you can pass a second argument of the code to guess by
|
85
|
+
#
|
86
|
+
# Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
|
87
|
+
#
|
88
|
+
# If the code matches more than one lexer then Guesser::Ambiguous
|
89
|
+
# is raised.
|
90
|
+
#
|
91
|
+
# This is used in the Redcarpet plugin as well as Rouge's own
|
92
|
+
# markdown lexer for highlighting internal code blocks.
|
93
|
+
#
|
94
|
+
def find_fancy(str, code=nil, default_options={})
|
95
|
+
lexer_class, opts = lookup_fancy(str, code, default_options)
|
96
|
+
|
87
97
|
lexer_class && lexer_class.new(opts)
|
88
98
|
end
|
89
99
|
|
@@ -317,6 +327,14 @@ module Rouge
|
|
317
327
|
@debug = Lexer.debug_enabled? && bool_option('debug')
|
318
328
|
end
|
319
329
|
|
330
|
+
# Returns a new lexer with the given options set. Useful for e.g. setting
|
331
|
+
# debug flags post hoc, or providing global overrides for certain options
|
332
|
+
def with(opts={})
|
333
|
+
new_options = @options.dup
|
334
|
+
opts.each { |k, v| new_options[k.to_s] = v }
|
335
|
+
self.class.new(new_options)
|
336
|
+
end
|
337
|
+
|
320
338
|
def as_bool(val)
|
321
339
|
case val
|
322
340
|
when nil, false, 0, '0', 'false', 'off'
|
data/lib/rouge/lexers/apex.rb
CHANGED
@@ -49,7 +49,7 @@ module Rouge
|
|
49
49
|
|
50
50
|
state :root do
|
51
51
|
rule %r/\s+/m, Text
|
52
|
-
|
52
|
+
|
53
53
|
rule %r(//.*?$), Comment::Single
|
54
54
|
rule %r(/\*.*?\*/)m, Comment::Multiline
|
55
55
|
|
@@ -57,17 +57,19 @@ module Rouge
|
|
57
57
|
rule %r/import\b/, Keyword::Namespace, :import
|
58
58
|
|
59
59
|
rule %r/([@$.]?)(#{id})([:(]?)/io do |m|
|
60
|
-
|
60
|
+
lowercased = m[0].downcase
|
61
|
+
uppercased = m[0].upcase
|
62
|
+
if self.class.keywords.include? lowercased
|
61
63
|
token Keyword
|
62
|
-
elsif self.class.soql.include?
|
64
|
+
elsif self.class.soql.include? uppercased
|
63
65
|
token Keyword
|
64
|
-
elsif self.class.declarations.include?
|
66
|
+
elsif self.class.declarations.include? lowercased
|
65
67
|
token Keyword::Declaration
|
66
|
-
elsif self.class.types.include?
|
68
|
+
elsif self.class.types.include? lowercased
|
67
69
|
token Keyword::Type
|
68
|
-
elsif self.class.constants.include?
|
70
|
+
elsif self.class.constants.include? lowercased
|
69
71
|
token Keyword::Constant
|
70
|
-
elsif 'package'
|
72
|
+
elsif lowercased == 'package'
|
71
73
|
token Keyword::Namespace
|
72
74
|
elsif m[1] == "@"
|
73
75
|
token Name::Decorator
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Augeas < RegexLexer
|
7
|
+
title "Augeas"
|
8
|
+
desc "The Augeas programming language (augeas.net)"
|
9
|
+
|
10
|
+
tag 'augeas'
|
11
|
+
aliases 'aug'
|
12
|
+
filenames '*.aug'
|
13
|
+
mimetypes 'text/x-augeas'
|
14
|
+
|
15
|
+
def self.reserved
|
16
|
+
@reserved ||= Set.new %w(
|
17
|
+
_ let del store value counter seq key label autoload incl excl
|
18
|
+
transform test get put in after set clear insa insb print_string
|
19
|
+
print_regexp print_endline print_tree lens_ctype lens_atype
|
20
|
+
lens_ktype lens_vtype lens_format_atype regexp_match
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
state :basic do
|
25
|
+
rule %r/\s+/m, Text
|
26
|
+
rule %r/\(\*/, Comment::Multiline, :comment
|
27
|
+
end
|
28
|
+
|
29
|
+
state :comment do
|
30
|
+
rule %r/\*\)/, Comment::Multiline, :pop!
|
31
|
+
rule %r/\(\*/, Comment::Multiline, :comment
|
32
|
+
rule %r/[^*)]+/, Comment::Multiline
|
33
|
+
rule %r/[*)]/, Comment::Multiline
|
34
|
+
end
|
35
|
+
|
36
|
+
state :root do
|
37
|
+
mixin :basic
|
38
|
+
|
39
|
+
rule %r/(:)(\w\w*)/ do
|
40
|
+
groups Punctuation, Keyword::Type
|
41
|
+
end
|
42
|
+
|
43
|
+
rule %r/\w[\w']*/ do |m|
|
44
|
+
name = m[0]
|
45
|
+
if name == "module"
|
46
|
+
token Keyword::Reserved
|
47
|
+
push :module
|
48
|
+
elsif self.class.reserved.include? name
|
49
|
+
token Keyword::Reserved
|
50
|
+
elsif name =~ /\A[A-Z]/
|
51
|
+
token Keyword::Namespace
|
52
|
+
else
|
53
|
+
token Name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
rule %r/"/, Str, :string
|
58
|
+
rule %r/\//, Str, :regexp
|
59
|
+
|
60
|
+
rule %r([-*+.=?\|]+), Operator
|
61
|
+
rule %r/[\[\](){}:;]/, Punctuation
|
62
|
+
end
|
63
|
+
|
64
|
+
state :module do
|
65
|
+
rule %r/\s+/, Text
|
66
|
+
rule %r/[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
|
67
|
+
end
|
68
|
+
|
69
|
+
state :regexp do
|
70
|
+
rule %r/\//, Str::Regex, :pop!
|
71
|
+
rule %r/[^\\\/]+/, Str::Regex
|
72
|
+
rule %r/\\[\\\/]/, Str::Regex
|
73
|
+
rule %r/\\/, Str::Regex
|
74
|
+
end
|
75
|
+
|
76
|
+
state :string do
|
77
|
+
rule %r/"/, Str, :pop!
|
78
|
+
rule %r/\\/, Str::Escape, :escape
|
79
|
+
rule %r/[^\\"]+/, Str
|
80
|
+
end
|
81
|
+
|
82
|
+
state :escape do
|
83
|
+
rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
|
84
|
+
rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
|
85
|
+
rule %r/o[0-7]+/i, Str::Escape, :pop!
|
86
|
+
rule %r/x[\da-f]+/i, Str::Escape, :pop!
|
87
|
+
rule %r/\d+/, Str::Escape, :pop!
|
88
|
+
rule %r/\s+/, Str::Escape, :pop!
|
89
|
+
rule %r/./, Str, :pop!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|