rouge 3.4.1 → 3.5.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 +3 -0
- data/lib/rouge/cli.rb +19 -2
- data/lib/rouge/demos/bpf +7 -0
- data/lib/rouge/demos/brainfuck +5 -0
- data/lib/rouge/demos/magik +6 -0
- data/lib/rouge/formatter.rb +2 -2
- data/lib/rouge/formatters/tex.rb +90 -0
- data/lib/rouge/guessers/glob_mapping.rb +1 -1
- data/lib/rouge/lexer.rb +22 -10
- data/lib/rouge/lexers/abap.rb +11 -11
- data/lib/rouge/lexers/actionscript.rb +34 -34
- data/lib/rouge/lexers/apache.rb +8 -8
- data/lib/rouge/lexers/apple_script.rb +15 -14
- data/lib/rouge/lexers/awk.rb +25 -25
- data/lib/rouge/lexers/biml.rb +4 -4
- data/lib/rouge/lexers/bpf.rb +104 -0
- data/lib/rouge/lexers/brainfuck.rb +53 -0
- data/lib/rouge/lexers/bsl.rb +12 -12
- data/lib/rouge/lexers/c.rb +30 -30
- data/lib/rouge/lexers/ceylon.rb +1 -29
- data/lib/rouge/lexers/cfscript.rb +26 -26
- data/lib/rouge/lexers/clojure.rb +14 -14
- data/lib/rouge/lexers/cmake.rb +14 -14
- data/lib/rouge/lexers/coffeescript.rb +30 -30
- data/lib/rouge/lexers/common_lisp.rb +36 -36
- data/lib/rouge/lexers/conf.rb +6 -6
- data/lib/rouge/lexers/coq.rb +18 -18
- data/lib/rouge/lexers/cpp.rb +8 -8
- data/lib/rouge/lexers/crystal.rb +70 -70
- data/lib/rouge/lexers/csharp.rb +28 -28
- data/lib/rouge/lexers/css.rb +23 -23
- data/lib/rouge/lexers/d.rb +59 -59
- data/lib/rouge/lexers/dart.rb +33 -33
- data/lib/rouge/lexers/digdag.rb +1 -1
- data/lib/rouge/lexers/docker.rb +10 -10
- data/lib/rouge/lexers/dot.rb +16 -16
- data/lib/rouge/lexers/eiffel.rb +20 -20
- data/lib/rouge/lexers/elixir.rb +29 -28
- data/lib/rouge/lexers/elm.rb +29 -29
- data/lib/rouge/lexers/erb.rb +4 -4
- data/lib/rouge/lexers/factor.rb +40 -40
- data/lib/rouge/lexers/fortran.rb +32 -32
- data/lib/rouge/lexers/fsharp.rb +26 -26
- data/lib/rouge/lexers/gherkin.rb +13 -13
- data/lib/rouge/lexers/glsl.rb +0 -4
- data/lib/rouge/lexers/go.rb +1 -1
- data/lib/rouge/lexers/graphql.rb +62 -62
- data/lib/rouge/lexers/groovy.rb +23 -25
- data/lib/rouge/lexers/hack.rb +1 -1
- data/lib/rouge/lexers/haml.rb +25 -29
- data/lib/rouge/lexers/handlebars.rb +18 -18
- data/lib/rouge/lexers/haskell.rb +66 -65
- data/lib/rouge/lexers/hcl.rb +25 -25
- data/lib/rouge/lexers/html.rb +31 -31
- data/lib/rouge/lexers/http.rb +4 -4
- data/lib/rouge/lexers/hylang.rb +14 -14
- data/lib/rouge/lexers/idlang.rb +32 -32
- data/lib/rouge/lexers/igorpro.rb +30 -30
- data/lib/rouge/lexers/ini.rb +12 -12
- data/lib/rouge/lexers/io.rb +7 -7
- data/lib/rouge/lexers/irb.rb +5 -5
- data/lib/rouge/lexers/java.rb +24 -24
- data/lib/rouge/lexers/javascript.rb +51 -51
- data/lib/rouge/lexers/jinja.rb +22 -22
- data/lib/rouge/lexers/json.rb +11 -10
- data/lib/rouge/lexers/json_doc.rb +2 -2
- data/lib/rouge/lexers/jsonnet.rb +18 -18
- data/lib/rouge/lexers/jsp.rb +28 -28
- data/lib/rouge/lexers/jsx.rb +16 -16
- data/lib/rouge/lexers/julia.rb +44 -44
- data/lib/rouge/lexers/kotlin.rb +3 -3
- data/lib/rouge/lexers/lasso.rb +50 -50
- data/lib/rouge/lexers/liquid.rb +53 -53
- data/lib/rouge/lexers/literate_coffeescript.rb +2 -2
- data/lib/rouge/lexers/literate_haskell.rb +5 -5
- data/lib/rouge/lexers/llvm.rb +23 -16
- data/lib/rouge/lexers/lua.rb +3 -3
- data/lib/rouge/lexers/m68k.rb +18 -19
- data/lib/rouge/lexers/magik.rb +126 -0
- data/lib/rouge/lexers/make.rb +22 -28
- data/lib/rouge/lexers/markdown.rb +37 -37
- data/lib/rouge/lexers/mathematica.rb +11 -11
- data/lib/rouge/lexers/matlab.rb +20 -20
- data/lib/rouge/lexers/moonscript.rb +3 -3
- data/lib/rouge/lexers/mosel.rb +17 -17
- data/lib/rouge/lexers/mxml.rb +18 -18
- data/lib/rouge/lexers/nasm.rb +24 -25
- data/lib/rouge/lexers/nginx.rb +14 -14
- data/lib/rouge/lexers/nim.rb +1 -1
- data/lib/rouge/lexers/nix.rb +42 -42
- data/lib/rouge/lexers/objective_c.rb +38 -38
- data/lib/rouge/lexers/ocaml.rb +29 -29
- data/lib/rouge/lexers/pascal.rb +4 -4
- data/lib/rouge/lexers/perl.rb +68 -68
- data/lib/rouge/lexers/php.rb +38 -38
- data/lib/rouge/lexers/plist.rb +14 -14
- data/lib/rouge/lexers/pony.rb +19 -19
- data/lib/rouge/lexers/powershell.rb +25 -25
- data/lib/rouge/lexers/praat.rb +75 -75
- data/lib/rouge/lexers/prolog.rb +26 -20
- data/lib/rouge/lexers/prometheus.rb +30 -30
- data/lib/rouge/lexers/properties.rb +12 -12
- data/lib/rouge/lexers/protobuf.rb +22 -22
- data/lib/rouge/lexers/puppet.rb +31 -31
- data/lib/rouge/lexers/python.rb +52 -52
- data/lib/rouge/lexers/q.rb +12 -12
- data/lib/rouge/lexers/qml.rb +12 -12
- data/lib/rouge/lexers/r.rb +12 -12
- data/lib/rouge/lexers/racket.rb +22 -22
- data/lib/rouge/lexers/ruby.rb +71 -69
- data/lib/rouge/lexers/rust.rb +30 -30
- data/lib/rouge/lexers/sass.rb +8 -8
- data/lib/rouge/lexers/sass/common.rb +40 -40
- data/lib/rouge/lexers/scala.rb +43 -43
- data/lib/rouge/lexers/scheme.rb +18 -18
- data/lib/rouge/lexers/scss.rb +3 -3
- data/lib/rouge/lexers/sed.rb +29 -29
- data/lib/rouge/lexers/shell.rb +61 -52
- data/lib/rouge/lexers/sieve.rb +8 -8
- data/lib/rouge/lexers/slim.rb +24 -24
- data/lib/rouge/lexers/smalltalk.rb +33 -33
- data/lib/rouge/lexers/smarty.rb +12 -12
- data/lib/rouge/lexers/sml.rb +67 -67
- data/lib/rouge/lexers/sqf.rb +1 -1
- data/lib/rouge/lexers/sql.rb +21 -21
- data/lib/rouge/lexers/supercollider.rb +19 -19
- data/lib/rouge/lexers/swift.rb +42 -39
- data/lib/rouge/lexers/tap.rb +20 -20
- data/lib/rouge/lexers/tcl.rb +27 -27
- data/lib/rouge/lexers/terraform.rb +13 -13
- data/lib/rouge/lexers/tex.rb +19 -19
- data/lib/rouge/lexers/toml.rb +18 -18
- data/lib/rouge/lexers/tulip.rb +36 -36
- data/lib/rouge/lexers/turtle.rb +35 -38
- data/lib/rouge/lexers/vala.rb +17 -17
- data/lib/rouge/lexers/vb.rb +27 -27
- data/lib/rouge/lexers/verilog.rb +25 -27
- data/lib/rouge/lexers/vhdl.rb +10 -10
- data/lib/rouge/lexers/viml.rb +14 -14
- data/lib/rouge/lexers/vue.rb +9 -9
- data/lib/rouge/lexers/wollok.rb +25 -25
- data/lib/rouge/lexers/xml.rb +17 -21
- data/lib/rouge/lexers/xojo.rb +15 -15
- data/lib/rouge/lexers/yaml.rb +61 -61
- data/lib/rouge/plugins/redcarpet.rb +1 -1
- data/lib/rouge/tex_theme_renderer.rb +128 -0
- data/lib/rouge/theme.rb +4 -0
- data/lib/rouge/themes/magritte.rb +78 -0
- data/lib/rouge/version.rb +1 -1
- metadata +11 -2
data/lib/rouge/lexers/xml.rb
CHANGED
@@ -7,14 +7,10 @@ module Rouge
|
|
7
7
|
title "XML"
|
8
8
|
desc %q(<desc for="this-lexer">XML</desc>)
|
9
9
|
tag 'xml'
|
10
|
-
filenames
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
image/svg+xml
|
15
|
-
application/rss+xml
|
16
|
-
application/atom+xml
|
17
|
-
)
|
10
|
+
filenames '*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.svg',
|
11
|
+
'*.plist'
|
12
|
+
mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
|
13
|
+
'application/rss+xml', 'application/atom+xml'
|
18
14
|
|
19
15
|
def self.detect?(text)
|
20
16
|
return false if text.doctype?(/html/)
|
@@ -23,12 +19,12 @@ module Rouge
|
|
23
19
|
end
|
24
20
|
|
25
21
|
state :root do
|
26
|
-
rule /[^<&]+/, Text
|
27
|
-
rule /&\S*?;/, Name::Entity
|
28
|
-
rule /<!\[CDATA\[.*?\]\]\>/, Comment::Preproc
|
29
|
-
rule /<!--/, Comment, :comment
|
30
|
-
rule /<\?.*?\?>/, Comment::Preproc
|
31
|
-
rule /<![^>]*>/, Comment::Preproc
|
22
|
+
rule %r/[^<&]+/, Text
|
23
|
+
rule %r/&\S*?;/, Name::Entity
|
24
|
+
rule %r/<!\[CDATA\[.*?\]\]\>/, Comment::Preproc
|
25
|
+
rule %r/<!--/, Comment, :comment
|
26
|
+
rule %r/<\?.*?\?>/, Comment::Preproc
|
27
|
+
rule %r/<![^>]*>/, Comment::Preproc
|
32
28
|
|
33
29
|
# open tags
|
34
30
|
rule %r(<\s*[\w:.-]+)m, Name::Tag, :tag
|
@@ -38,20 +34,20 @@ module Rouge
|
|
38
34
|
end
|
39
35
|
|
40
36
|
state :comment do
|
41
|
-
rule /[^-]+/m, Comment
|
42
|
-
rule /-->/, Comment, :pop!
|
43
|
-
rule /-/, Comment
|
37
|
+
rule %r/[^-]+/m, Comment
|
38
|
+
rule %r/-->/, Comment, :pop!
|
39
|
+
rule %r/-/, Comment
|
44
40
|
end
|
45
41
|
|
46
42
|
state :tag do
|
47
|
-
rule /\s+/m, Text
|
48
|
-
rule /[\w.:-]+\s*=/m, Name::Attribute, :attr
|
43
|
+
rule %r/\s+/m, Text
|
44
|
+
rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr
|
49
45
|
rule %r(/?\s*>), Name::Tag, :pop!
|
50
46
|
end
|
51
47
|
|
52
48
|
state :attr do
|
53
|
-
rule /\s+/m, Text
|
54
|
-
rule /".*?"|'.*?'|[^\s>]+/m, Str, :pop!
|
49
|
+
rule %r/\s+/m, Text
|
50
|
+
rule %r/".*?"|'.*?'|[^\s>]+/m, Str, :pop!
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
data/lib/rouge/lexers/xojo.rb
CHANGED
@@ -34,26 +34,26 @@ module Rouge
|
|
34
34
|
)
|
35
35
|
|
36
36
|
state :root do
|
37
|
-
rule /\s+/, Text::Whitespace
|
37
|
+
rule %r/\s+/, Text::Whitespace
|
38
38
|
|
39
|
-
rule /rem\b.*?$/i, Comment::Single
|
40
|
-
rule
|
41
|
-
rule /\#tag Note.*\#tag EndNote/m, Comment::Preproc
|
42
|
-
rule /\s*[#].*$/x, Comment::Preproc
|
39
|
+
rule %r/rem\b.*?$/i, Comment::Single
|
40
|
+
rule %r(//.*$), Comment::Single
|
41
|
+
rule %r/\#tag Note.*\#tag EndNote/m, Comment::Preproc
|
42
|
+
rule %r/\s*[#].*$/x, Comment::Preproc
|
43
43
|
|
44
|
-
rule /".*?"/, Literal::String::Double
|
45
|
-
rule /[(){}!#,:]/, Punctuation
|
44
|
+
rule %r/".*?"/, Literal::String::Double
|
45
|
+
rule %r/[(){}!#,:]/, Punctuation
|
46
46
|
|
47
|
-
rule /\b(?:#{keywords.join('|')})\b/i, Keyword
|
48
|
-
rule /\b(?:#{keywords_type.join('|')})\b/i, Keyword::Declaration
|
47
|
+
rule %r/\b(?:#{keywords.join('|')})\b/i, Keyword
|
48
|
+
rule %r/\b(?:#{keywords_type.join('|')})\b/i, Keyword::Declaration
|
49
49
|
|
50
|
-
rule /\b(?:#{operator_words.join('|')})\b/i, Operator
|
51
|
-
rule /[+-]?(\d+\.\d*|\d*\.\d+)/i, Literal::Number::Float
|
52
|
-
rule /[+-]?\d+/, Literal::Number::Integer
|
53
|
-
rule /&[CH][0-9a-f]+/i, Literal::Number::Hex
|
54
|
-
rule /&O[0-7]+/i, Literal::Number::Oct
|
50
|
+
rule %r/\b(?:#{operator_words.join('|')})\b/i, Operator
|
51
|
+
rule %r/[+-]?(\d+\.\d*|\d*\.\d+)/i, Literal::Number::Float
|
52
|
+
rule %r/[+-]?\d+/, Literal::Number::Integer
|
53
|
+
rule %r/&[CH][0-9a-f]+/i, Literal::Number::Hex
|
54
|
+
rule %r/&O[0-7]+/i, Literal::Number::Oct
|
55
55
|
|
56
|
-
rule /\b[\w\.]+\b/i, Text
|
56
|
+
rule %r/\b[\w\.]+\b/i, Text
|
57
57
|
rule(%r(<=|>=|<>|[=><\+\-\*\/\\]), Operator)
|
58
58
|
end
|
59
59
|
end
|
data/lib/rouge/lexers/yaml.rb
CHANGED
@@ -78,38 +78,38 @@ module Rouge
|
|
78
78
|
start { reset_indent }
|
79
79
|
|
80
80
|
state :basic do
|
81
|
-
rule /#.*$/, Comment::Single
|
81
|
+
rule %r/#.*$/, Comment::Single
|
82
82
|
end
|
83
83
|
|
84
84
|
state :root do
|
85
85
|
mixin :basic
|
86
86
|
|
87
|
-
rule /\n+/, Text
|
87
|
+
rule %r/\n+/, Text
|
88
88
|
|
89
89
|
# trailing or pre-comment whitespace
|
90
|
-
rule /[ ]+(?=#|$)/, Text
|
90
|
+
rule %r/[ ]+(?=#|$)/, Text
|
91
91
|
|
92
|
-
rule /^%YAML\b/ do
|
92
|
+
rule %r/^%YAML\b/ do
|
93
93
|
token Name::Tag
|
94
94
|
reset_indent
|
95
95
|
push :yaml_directive
|
96
96
|
end
|
97
97
|
|
98
|
-
rule /^%TAG\b/ do
|
98
|
+
rule %r/^%TAG\b/ do
|
99
99
|
token Name::Tag
|
100
100
|
reset_indent
|
101
101
|
push :tag_directive
|
102
102
|
end
|
103
103
|
|
104
104
|
# doc-start and doc-end indicators
|
105
|
-
rule /^(?:---|\.\.\.)(?= |$)/ do
|
105
|
+
rule %r/^(?:---|\.\.\.)(?= |$)/ do
|
106
106
|
token Name::Namespace
|
107
107
|
reset_indent
|
108
108
|
push :block_line
|
109
109
|
end
|
110
110
|
|
111
111
|
# indentation spaces
|
112
|
-
rule /[ ]*(?!\s|$)/ do |m|
|
112
|
+
rule %r/[ ]*(?!\s|$)/ do |m|
|
113
113
|
text, err = save_indent(m[0])
|
114
114
|
token Text, text
|
115
115
|
token Error, err
|
@@ -120,7 +120,7 @@ module Rouge
|
|
120
120
|
state :indentation do
|
121
121
|
rule(/\s*?\n/) { token Text; pop! 2 }
|
122
122
|
# whitespace preceding block collection indicators
|
123
|
-
rule /[ ]+(?=[-:?](?:[ ]|$))/ do |m|
|
123
|
+
rule %r/[ ]+(?=[-:?](?:[ ]|$))/ do |m|
|
124
124
|
token Text
|
125
125
|
continue_indent(m[0])
|
126
126
|
end
|
@@ -138,8 +138,8 @@ module Rouge
|
|
138
138
|
# indented line in the block context
|
139
139
|
state :block_line do
|
140
140
|
# line end
|
141
|
-
rule /[ ]*(?=#|$)/, Text, :pop!
|
142
|
-
rule /[ ]+/, Text
|
141
|
+
rule %r/[ ]*(?=#|$)/, Text, :pop!
|
142
|
+
rule %r/[ ]+/, Text
|
143
143
|
# tags, anchors, and aliases
|
144
144
|
mixin :descriptors
|
145
145
|
# block collections and scalars
|
@@ -148,7 +148,7 @@ module Rouge
|
|
148
148
|
mixin :flow_nodes
|
149
149
|
|
150
150
|
# a plain scalar
|
151
|
-
rule /(?=#{plain_scalar_start}|[?:-][^ \t\n\r\f\v])/ do
|
151
|
+
rule %r/(?=#{plain_scalar_start}|[?:-][^ \t\n\r\f\v])/ do
|
152
152
|
token Name::Variable
|
153
153
|
push :plain_scalar_in_block_context
|
154
154
|
end
|
@@ -156,7 +156,7 @@ module Rouge
|
|
156
156
|
|
157
157
|
state :descriptors do
|
158
158
|
# a full-form tag
|
159
|
-
rule /!<[0-9A-Za-z;\/?:@&=+$,_.!~*'()\[\]%-]+>/, Keyword::Type
|
159
|
+
rule %r/!<[0-9A-Za-z;\/?:@&=+$,_.!~*'()\[\]%-]+>/, Keyword::Type
|
160
160
|
|
161
161
|
# a tag in the form '!', '!suffix' or '!handle!suffix'
|
162
162
|
rule %r(
|
@@ -165,21 +165,21 @@ module Rouge
|
|
165
165
|
)x, Keyword::Type
|
166
166
|
|
167
167
|
# an anchor
|
168
|
-
rule /&[\w-]+/, Name::Label
|
168
|
+
rule %r/&[\w-]+/, Name::Label
|
169
169
|
|
170
170
|
# an alias
|
171
|
-
rule /\*[\w-]+/, Name::Variable
|
171
|
+
rule %r/\*[\w-]+/, Name::Variable
|
172
172
|
end
|
173
173
|
|
174
174
|
state :block_nodes do
|
175
175
|
# implicit key
|
176
|
-
rule /((?:\w[\w -]*)?)(:)(?=\s|$)/ do |m|
|
176
|
+
rule %r/((?:\w[\w -]*)?)(:)(?=\s|$)/ do |m|
|
177
177
|
groups Name::Attribute, Punctuation::Indicator
|
178
178
|
set_indent m[0], :implicit => true
|
179
179
|
end
|
180
180
|
|
181
181
|
# literal and folded scalars
|
182
|
-
rule /[\|>]/ do
|
182
|
+
rule %r/[\|>]/ do
|
183
183
|
token Punctuation::Indicator
|
184
184
|
push :block_scalar_content
|
185
185
|
push :block_scalar_header
|
@@ -187,39 +187,39 @@ module Rouge
|
|
187
187
|
end
|
188
188
|
|
189
189
|
state :flow_nodes do
|
190
|
-
rule /\[/, Punctuation::Indicator, :flow_sequence
|
191
|
-
rule /\{/, Punctuation::Indicator, :flow_mapping
|
192
|
-
rule /'/, Str::Single, :single_quoted_scalar
|
193
|
-
rule /"/, Str::Double, :double_quoted_scalar
|
190
|
+
rule %r/\[/, Punctuation::Indicator, :flow_sequence
|
191
|
+
rule %r/\{/, Punctuation::Indicator, :flow_mapping
|
192
|
+
rule %r/'/, Str::Single, :single_quoted_scalar
|
193
|
+
rule %r/"/, Str::Double, :double_quoted_scalar
|
194
194
|
end
|
195
195
|
|
196
196
|
state :flow_collection do
|
197
|
-
rule /\s+/m, Text
|
197
|
+
rule %r/\s+/m, Text
|
198
198
|
mixin :basic
|
199
|
-
rule /[?:,]/, Punctuation::Indicator
|
199
|
+
rule %r/[?:,]/, Punctuation::Indicator
|
200
200
|
mixin :descriptors
|
201
201
|
mixin :flow_nodes
|
202
202
|
|
203
|
-
rule /(?=#{plain_scalar_start})/ do
|
203
|
+
rule %r/(?=#{plain_scalar_start})/ do
|
204
204
|
push :plain_scalar_in_flow_context
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
208
|
state :flow_sequence do
|
209
|
-
rule /\]/, Punctuation::Indicator, :pop!
|
209
|
+
rule %r/\]/, Punctuation::Indicator, :pop!
|
210
210
|
mixin :flow_collection
|
211
211
|
end
|
212
212
|
|
213
213
|
state :flow_mapping do
|
214
|
-
rule /\}/, Punctuation::Indicator, :pop!
|
214
|
+
rule %r/\}/, Punctuation::Indicator, :pop!
|
215
215
|
mixin :flow_collection
|
216
216
|
end
|
217
217
|
|
218
218
|
state :block_scalar_content do
|
219
|
-
rule /\n+/, Text
|
219
|
+
rule %r/\n+/, Text
|
220
220
|
|
221
221
|
# empty lines never dedent, but they might be part of the scalar.
|
222
|
-
rule /^[ ]+$/ do |m|
|
222
|
+
rule %r/^[ ]+$/ do |m|
|
223
223
|
text = m[0]
|
224
224
|
indent_size = text.size
|
225
225
|
|
@@ -231,7 +231,7 @@ module Rouge
|
|
231
231
|
|
232
232
|
# TODO: ^ doesn't actually seem to affect the match at all.
|
233
233
|
# Find a way to work around this limitation.
|
234
|
-
rule /^[ ]*/ do |m|
|
234
|
+
rule %r/^[ ]*/ do |m|
|
235
235
|
token Text
|
236
236
|
|
237
237
|
indent_size = m[0].size
|
@@ -246,7 +246,7 @@ module Rouge
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
|
-
rule /[^\n\r\f\v]+/, Name::Constant
|
249
|
+
rule %r/[^\n\r\f\v]+/, Name::Constant
|
250
250
|
end
|
251
251
|
|
252
252
|
state :block_scalar_header do
|
@@ -271,46 +271,46 @@ module Rouge
|
|
271
271
|
|
272
272
|
state :ignored_line do
|
273
273
|
mixin :basic
|
274
|
-
rule /[ ]+/, Text
|
275
|
-
rule /\n/, Text, :pop!
|
274
|
+
rule %r/[ ]+/, Text
|
275
|
+
rule %r/\n/, Text, :pop!
|
276
276
|
end
|
277
277
|
|
278
278
|
state :quoted_scalar_whitespaces do
|
279
279
|
# leading and trailing whitespace is ignored
|
280
|
-
rule /^[ ]+/, Text
|
281
|
-
rule /[ ]+$/, Text
|
280
|
+
rule %r/^[ ]+/, Text
|
281
|
+
rule %r/[ ]+$/, Text
|
282
282
|
|
283
|
-
rule /\n+/m, Text
|
283
|
+
rule %r/\n+/m, Text
|
284
284
|
|
285
|
-
rule /[ ]+/, Name::Variable
|
285
|
+
rule %r/[ ]+/, Name::Variable
|
286
286
|
end
|
287
287
|
|
288
288
|
state :single_quoted_scalar do
|
289
289
|
mixin :quoted_scalar_whitespaces
|
290
|
-
rule /\\'/, Str::Escape
|
291
|
-
rule /'/, Str, :pop!
|
292
|
-
rule /[^\s']+/, Str
|
290
|
+
rule %r/\\'/, Str::Escape
|
291
|
+
rule %r/'/, Str, :pop!
|
292
|
+
rule %r/[^\s']+/, Str
|
293
293
|
end
|
294
294
|
|
295
295
|
state :double_quoted_scalar do
|
296
|
-
rule /"/, Str, :pop!
|
296
|
+
rule %r/"/, Str, :pop!
|
297
297
|
mixin :quoted_scalar_whitespaces
|
298
298
|
# escapes
|
299
|
-
rule /\\[0abt\tn\nvfre "\\N_LP]/, Str::Escape
|
300
|
-
rule /\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
299
|
+
rule %r/\\[0abt\tn\nvfre "\\N_LP]/, Str::Escape
|
300
|
+
rule %r/\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
301
301
|
Str::Escape
|
302
|
-
rule /[^ \t\n\r\f\v"\\]+/, Str
|
302
|
+
rule %r/[^ \t\n\r\f\v"\\]+/, Str
|
303
303
|
end
|
304
304
|
|
305
305
|
state :plain_scalar_in_block_context_new_line do
|
306
|
-
rule /^[ ]+\n/, Text
|
307
|
-
rule /\n+/m, Text
|
308
|
-
rule /^(?=---|\.\.\.)/ do
|
306
|
+
rule %r/^[ ]+\n/, Text
|
307
|
+
rule %r/\n+/m, Text
|
308
|
+
rule %r/^(?=---|\.\.\.)/ do
|
309
309
|
pop! 3
|
310
310
|
end
|
311
311
|
|
312
312
|
# dedent detection
|
313
|
-
rule /^[ ]*/ do |m|
|
313
|
+
rule %r/^[ ]*/ do |m|
|
314
314
|
token Text
|
315
315
|
pop!
|
316
316
|
|
@@ -327,34 +327,34 @@ module Rouge
|
|
327
327
|
|
328
328
|
state :plain_scalar_in_block_context do
|
329
329
|
# the : indicator ends a scalar
|
330
|
-
rule /[ ]*(?=:[ \n]|:$)/, Text, :pop!
|
331
|
-
rule /[ ]*:/, Str
|
332
|
-
rule /[ ]+(?=#)/, Text, :pop!
|
333
|
-
rule /[ ]+$/, Text
|
330
|
+
rule %r/[ ]*(?=:[ \n]|:$)/, Text, :pop!
|
331
|
+
rule %r/[ ]*:/, Str
|
332
|
+
rule %r/[ ]+(?=#)/, Text, :pop!
|
333
|
+
rule %r/[ ]+$/, Text
|
334
334
|
# check for new documents or dedents at the new line
|
335
|
-
rule /\n+/ do
|
335
|
+
rule %r/\n+/ do
|
336
336
|
token Text
|
337
337
|
push :plain_scalar_in_block_context_new_line
|
338
338
|
end
|
339
339
|
|
340
|
-
rule /[ ]+/, Str
|
340
|
+
rule %r/[ ]+/, Str
|
341
341
|
rule SPECIAL_VALUES, Name::Constant
|
342
342
|
# regular non-whitespace characters
|
343
|
-
rule /[^\s:]+/, Str
|
343
|
+
rule %r/[^\s:]+/, Str
|
344
344
|
end
|
345
345
|
|
346
346
|
state :plain_scalar_in_flow_context do
|
347
|
-
rule /[ ]*(?=[,:?\[\]{}])/, Text, :pop!
|
348
|
-
rule /[ ]+(?=#)/, Text, :pop!
|
349
|
-
rule /^[ ]+/, Text
|
350
|
-
rule /[ ]+$/, Text
|
351
|
-
rule /\n+/, Text
|
352
|
-
rule /[ ]+/, Name::Variable
|
353
|
-
rule /[^\s,:?\[\]{}]+/, Name::Variable
|
347
|
+
rule %r/[ ]*(?=[,:?\[\]{}])/, Text, :pop!
|
348
|
+
rule %r/[ ]+(?=#)/, Text, :pop!
|
349
|
+
rule %r/^[ ]+/, Text
|
350
|
+
rule %r/[ ]+$/, Text
|
351
|
+
rule %r/\n+/, Text
|
352
|
+
rule %r/[ ]+/, Name::Variable
|
353
|
+
rule %r/[^\s,:?\[\]{}]+/, Name::Variable
|
354
354
|
end
|
355
355
|
|
356
356
|
state :yaml_directive do
|
357
|
-
rule /([ ]+)(\d+\.\d+)/ do
|
357
|
+
rule %r/([ ]+)(\d+\.\d+)/ do
|
358
358
|
groups Text, Num
|
359
359
|
goto :ignored_line
|
360
360
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Rouge
|
2
|
+
class TexThemeRenderer
|
3
|
+
def initialize(theme, opts={})
|
4
|
+
@theme = theme
|
5
|
+
@prefix = opts.fetch(:prefix) { 'RG' }
|
6
|
+
end
|
7
|
+
|
8
|
+
# Our general strategy is this:
|
9
|
+
#
|
10
|
+
# * First, define the \RG{tokname}{content} command, which will
|
11
|
+
# expand into \RG@tok@tokname{content}. We use \csname...\endcsname
|
12
|
+
# to interpolate into a command.
|
13
|
+
#
|
14
|
+
# * Define the default RG* environment, which will enclose the whole
|
15
|
+
# thing. By default this will simply set \ttfamily (select monospace font)
|
16
|
+
# but it can be overridden with \renewcommand by the user to be
|
17
|
+
# any other formatting.
|
18
|
+
#
|
19
|
+
# * Define all the colors using xcolors \definecolor command. First we define
|
20
|
+
# every palette color with a name such as RG@palette@themneame@colorname.
|
21
|
+
# Then we find all foreground and background colors that have literal html
|
22
|
+
# colors embedded in them and define them with names such as
|
23
|
+
# RG@palette@themename@000000. While html allows three-letter colors such
|
24
|
+
# as #FFF, xcolor requires all six characters to be present, so we make sure
|
25
|
+
# to normalize that as well as the case convention in #inline_name.
|
26
|
+
#
|
27
|
+
# * Define the token commands RG@tok@xx. These will take the content as the
|
28
|
+
# argument and format it according to the theme, referring to the color
|
29
|
+
# in the palette.
|
30
|
+
def render(&b)
|
31
|
+
yield <<'END'.gsub('RG', @prefix)
|
32
|
+
\makeatletter
|
33
|
+
\def\RG#1#2{\csname RG@tok@#1\endcsname{#2}}%
|
34
|
+
\newenvironment{RG*}{\ttfamily}{\relax}%
|
35
|
+
END
|
36
|
+
|
37
|
+
base = @theme.class.base_style
|
38
|
+
yield "\\definecolor{#{@prefix}@fgcolor}{HTML}{#{inline_name(base.fg)}}"
|
39
|
+
yield "\\definecolor{#{@prefix}@bgcolor}{HTML}{#{inline_name(base.bg)}}"
|
40
|
+
|
41
|
+
render_palette(@theme.palette, &b)
|
42
|
+
|
43
|
+
@theme.styles.each do |tok, style|
|
44
|
+
render_inline_pallete(style, &b)
|
45
|
+
end
|
46
|
+
|
47
|
+
Token.each_token do |tok|
|
48
|
+
style = @theme.class.get_own_style(tok)
|
49
|
+
style ? render_style(tok, style, &b) : render_blank(tok, &b)
|
50
|
+
end
|
51
|
+
yield '\makeatother'
|
52
|
+
end
|
53
|
+
|
54
|
+
def render_palette(palette, &b)
|
55
|
+
palette.each do |name, color|
|
56
|
+
hex = inline_name(color)
|
57
|
+
|
58
|
+
yield "\\definecolor{#{palette_name(name)}}{HTML}{#{hex}}%"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_inline_pallete(style, &b)
|
63
|
+
gen_inline(style[:fg], &b)
|
64
|
+
gen_inline(style[:bg], &b)
|
65
|
+
end
|
66
|
+
|
67
|
+
def inline_name(color)
|
68
|
+
color =~ /^#(\h+)/ or return nil
|
69
|
+
|
70
|
+
# xcolor does not support 3-character HTML colors,
|
71
|
+
# so we convert them here
|
72
|
+
case $1.size
|
73
|
+
when 6
|
74
|
+
$1
|
75
|
+
when 3
|
76
|
+
# duplicate every character: abc -> aabbcc
|
77
|
+
$1.gsub(/\h/, '\0\0')
|
78
|
+
else
|
79
|
+
raise "invalid HTML color: #{$1}"
|
80
|
+
end.upcase
|
81
|
+
end
|
82
|
+
|
83
|
+
def gen_inline(name, &b)
|
84
|
+
# detect inline colors
|
85
|
+
hex = inline_name(name)
|
86
|
+
return unless hex
|
87
|
+
|
88
|
+
@gen_inline ||= {}
|
89
|
+
@gen_inline[hex] ||= begin
|
90
|
+
yield "\\definecolor{#{palette_name(hex)}}{HTML}{#{hex}}%"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def camelize(name)
|
95
|
+
name.gsub(/_(.)/) { $1.upcase }
|
96
|
+
end
|
97
|
+
|
98
|
+
def palette_name(name)
|
99
|
+
name = inline_name(name) || name.to_s
|
100
|
+
|
101
|
+
"#{@prefix}@palette@#{camelize(@theme.name)}@#{camelize(name.to_s)}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def token_name(tok)
|
105
|
+
"\\csname #@prefix@tok@#{tok.shortname}\\endcsname"
|
106
|
+
end
|
107
|
+
|
108
|
+
def render_blank(tok, &b)
|
109
|
+
out = "\\expandafter\\def#{token_name(tok)}#1{#1}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def render_style(tok, style, &b)
|
113
|
+
out = "\\expandafter\\def#{token_name(tok)}#1{"
|
114
|
+
out << "\\fboxsep=0pt\\colorbox{#{palette_name(style[:bg])}}{" if style[:bg]
|
115
|
+
out << '\\textbf{' if style[:bold]
|
116
|
+
out << '\\textit{' if style[:italic]
|
117
|
+
out << "\\textcolor{#{palette_name(style[:fg])}}{" if style[:fg]
|
118
|
+
out << "#1"
|
119
|
+
# close the right number of curlies
|
120
|
+
out << "}" if style[:bold]
|
121
|
+
out << "}" if style[:italic]
|
122
|
+
out << "}" if style[:fg]
|
123
|
+
out << "}" if style[:bg]
|
124
|
+
out << "}%"
|
125
|
+
yield out
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|