rouge 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,11 +24,14 @@ load load_dir.join('rouge/lexers/shell.rb')
24
24
  load load_dir.join('rouge/lexers/javascript.rb')
25
25
  load load_dir.join('rouge/lexers/css.rb')
26
26
  load load_dir.join('rouge/lexers/html.rb')
27
+ load load_dir.join('rouge/lexers/xml.rb')
27
28
 
28
29
  load load_dir.join('rouge/lexers/tcl.rb')
29
30
  load load_dir.join('rouge/lexers/python.rb')
30
31
 
31
32
  load load_dir.join('rouge/lexers/haskell.rb')
33
+ load load_dir.join('rouge/lexers/scheme.rb')
34
+ load load_dir.join('rouge/lexers/common_lisp.rb')
32
35
 
33
36
  load load_dir.join('rouge/lexers/c.rb')
34
37
  load load_dir.join('rouge/lexers/cpp.rb')
@@ -0,0 +1,349 @@
1
+ module Rouge
2
+ module Lexers
3
+ class CommonLisp < RegexLexer
4
+ tag 'common_lisp'
5
+ aliases 'cl', 'common-lisp'
6
+
7
+ filenames '*.cl', '*.lisp', '*.el' # used for Elisp too
8
+ mimetypes 'text/x-common-lisp'
9
+
10
+ # 638 functions
11
+ BUILTIN_FUNCTIONS = Set.new %w(
12
+ < <= = > >= - / /= * + 1- 1+ abort abs acons acos acosh add-method
13
+ adjoin adjustable-array-p adjust-array allocate-instance
14
+ alpha-char-p alphanumericp append apply apropos apropos-list
15
+ aref arithmetic-error-operands arithmetic-error-operation
16
+ array-dimension array-dimensions array-displacement
17
+ array-element-type array-has-fill-pointer-p array-in-bounds-p
18
+ arrayp array-rank array-row-major-index array-total-size
19
+ ash asin asinh assoc assoc-if assoc-if-not atan atanh atom
20
+ bit bit-and bit-andc1 bit-andc2 bit-eqv bit-ior bit-nand
21
+ bit-nor bit-not bit-orc1 bit-orc2 bit-vector-p bit-xor boole
22
+ both-case-p boundp break broadcast-stream-streams butlast
23
+ byte byte-position byte-size caaaar caaadr caaar caadar
24
+ caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
25
+ cadr call-next-method car cdaaar cdaadr cdaar cdadar cdaddr
26
+ cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr
27
+ ceiling cell-error-name cerror change-class char char< char<=
28
+ char= char> char>= char/= character characterp char-code
29
+ char-downcase char-equal char-greaterp char-int char-lessp
30
+ char-name char-not-equal char-not-greaterp char-not-lessp
31
+ char-upcase cis class-name class-of clear-input clear-output
32
+ close clrhash code-char coerce compile compiled-function-p
33
+ compile-file compile-file-pathname compiler-macro-function
34
+ complement complex complexp compute-applicable-methods
35
+ compute-restarts concatenate concatenated-stream-streams conjugate
36
+ cons consp constantly constantp continue copy-alist copy-list
37
+ copy-pprint-dispatch copy-readtable copy-seq copy-structure
38
+ copy-symbol copy-tree cos cosh count count-if count-if-not
39
+ decode-float decode-universal-time delete delete-duplicates
40
+ delete-file delete-if delete-if-not delete-package denominator
41
+ deposit-field describe describe-object digit-char digit-char-p
42
+ directory directory-namestring disassemble documentation dpb
43
+ dribble echo-stream-input-stream echo-stream-output-stream
44
+ ed eighth elt encode-universal-time endp enough-namestring
45
+ ensure-directories-exist ensure-generic-function eq
46
+ eql equal equalp error eval evenp every exp export expt
47
+ fboundp fceiling fdefinition ffloor fifth file-author
48
+ file-error-pathname file-length file-namestring file-position
49
+ file-string-length file-write-date fill fill-pointer find
50
+ find-all-symbols find-class find-if find-if-not find-method
51
+ find-package find-restart find-symbol finish-output first
52
+ float float-digits floatp float-precision float-radix
53
+ float-sign floor fmakunbound force-output format fourth
54
+ fresh-line fround ftruncate funcall function-keywords
55
+ function-lambda-expression functionp gcd gensym gentemp get
56
+ get-decoded-time get-dispatch-macro-character getf gethash
57
+ get-internal-real-time get-internal-run-time get-macro-character
58
+ get-output-stream-string get-properties get-setf-expansion
59
+ get-universal-time graphic-char-p hash-table-count hash-table-p
60
+ hash-table-rehash-size hash-table-rehash-threshold
61
+ hash-table-size hash-table-test host-namestring identity
62
+ imagpart import initialize-instance input-stream-p inspect
63
+ integer-decode-float integer-length integerp interactive-stream-p
64
+ intern intersection invalid-method-error invoke-debugger
65
+ invoke-restart invoke-restart-interactively isqrt keywordp
66
+ last lcm ldb ldb-test ldiff length lisp-implementation-type
67
+ lisp-implementation-version list list* list-all-packages listen
68
+ list-length listp load load-logical-pathname-translations
69
+ log logand logandc1 logandc2 logbitp logcount logeqv
70
+ logical-pathname logical-pathname-translations logior
71
+ lognand lognor lognot logorc1 logorc2 logtest logxor
72
+ long-site-name lower-case-p machine-instance machine-type
73
+ machine-version macroexpand macroexpand-1 macro-function
74
+ make-array make-broadcast-stream make-concatenated-stream
75
+ make-condition make-dispatch-macro-character make-echo-stream
76
+ make-hash-table make-instance make-instances-obsolete make-list
77
+ make-load-form make-load-form-saving-slots make-package
78
+ make-pathname make-random-state make-sequence make-string
79
+ make-string-input-stream make-string-output-stream make-symbol
80
+ make-synonym-stream make-two-way-stream makunbound map mapc
81
+ mapcan mapcar mapcon maphash map-into mapl maplist mask-field
82
+ max member member-if member-if-not merge merge-pathnames
83
+ method-combination-error method-qualifiers min minusp mismatch mod
84
+ muffle-warning name-char namestring nbutlast nconc next-method-p
85
+ nintersection ninth no-applicable-method no-next-method not notany
86
+ notevery nreconc nreverse nset-difference nset-exclusive-or
87
+ nstring-capitalize nstring-downcase nstring-upcase nsublis
88
+ nsubst nsubst-if nsubst-if-not nsubstitute nsubstitute-if
89
+ nsubstitute-if-not nth nthcdr null numberp numerator nunion
90
+ oddp open open-stream-p output-stream-p package-error-package
91
+ package-name package-nicknames packagep package-shadowing-symbols
92
+ package-used-by-list package-use-list pairlis parse-integer
93
+ parse-namestring pathname pathname-device pathname-directory
94
+ pathname-host pathname-match-p pathname-name pathnamep
95
+ pathname-type pathname-version peek-char phase plusp
96
+ position position-if position-if-not pprint pprint-dispatch
97
+ pprint-fill pprint-indent pprint-linear pprint-newline pprint-tab
98
+ pprint-tabular prin1 prin1-to-string princ princ-to-string print
99
+ print-object probe-file proclaim provide random random-state-p
100
+ rassoc rassoc-if rassoc-if-not rational rationalize rationalp
101
+ read read-byte read-char read-char-no-hang read-delimited-list
102
+ read-from-string read-line read-preserving-whitespace
103
+ read-sequence readtable-case readtablep realp realpart
104
+ reduce reinitialize-instance rem remhash remove
105
+ remove-duplicates remove-if remove-if-not remove-method
106
+ remprop rename-file rename-package replace require rest
107
+ restart-name revappend reverse room round row-major-aref
108
+ rplaca rplacd sbit scale-float schar search second set
109
+ set-difference set-dispatch-macro-character set-exclusive-or
110
+ set-macro-character set-pprint-dispatch set-syntax-from-char
111
+ seventh shadow shadowing-import shared-initialize
112
+ short-site-name signal signum simple-bit-vector-p
113
+ simple-condition-format-arguments simple-condition-format-control
114
+ simple-string-p simple-vector-p sin sinh sixth sleep slot-boundp
115
+ slot-exists-p slot-makunbound slot-missing slot-unbound slot-value
116
+ software-type software-version some sort special-operator-p
117
+ sqrt stable-sort standard-char-p store-value stream-element-type
118
+ stream-error-stream stream-external-format streamp string string<
119
+ string<= string= string> string>= string/= string-capitalize
120
+ string-downcase string-equal string-greaterp string-left-trim
121
+ string-lessp string-not-equal string-not-greaterp string-not-lessp
122
+ stringp string-right-trim string-trim string-upcase sublis subseq
123
+ subsetp subst subst-if subst-if-not substitute substitute-if
124
+ substitute-if-not subtypepsvref sxhash symbol-function
125
+ symbol-name symbolp symbol-package symbol-plist symbol-value
126
+ synonym-stream-symbol syntax: tailp tan tanh tenth terpri third
127
+ translate-logical-pathname translate-pathname tree-equal truename
128
+ truncate two-way-stream-input-stream two-way-stream-output-stream
129
+ type-error-datum type-error-expected-type type-of
130
+ typep unbound-slot-instance unexport unintern union
131
+ unread-char unuse-package update-instance-for-different-class
132
+ update-instance-for-redefined-class upgraded-array-element-type
133
+ upgraded-complex-part-type upper-case-p use-package
134
+ user-homedir-pathname use-value values values-list vector vectorp
135
+ vector-pop vector-push vector-push-extend warn wild-pathname-p
136
+ write write-byte write-char write-line write-sequence write-string
137
+ write-to-string yes-or-no-p y-or-n-p zerop
138
+ ).freeze
139
+
140
+ SPECIAL_FORMS = Set.new %w(
141
+ block catch declare eval-when flet function go if labels lambda
142
+ let let* load-time-value locally macrolet multiple-value-call
143
+ multiple-value-prog1 progn progv quote return-from setq
144
+ symbol-macrolet tagbody the throw unwind-protect
145
+ )
146
+
147
+ MACROS = Set.new %w(
148
+ and assert call-method case ccase check-type cond ctypecase decf
149
+ declaim defclass defconstant defgeneric define-compiler-macro
150
+ define-condition define-method-combination define-modify-macro
151
+ define-setf-expander define-symbol-macro defmacro defmethod
152
+ defpackage defparameter defsetf defstruct deftype defun defvar
153
+ destructuring-bind do do* do-all-symbols do-external-symbols
154
+ dolist do-symbols dotimes ecase etypecase formatter
155
+ handler-bind handler-case ignore-errors incf in-package
156
+ lambda loop loop-finish make-method multiple-value-bind
157
+ multiple-value-list multiple-value-setq nth-value or pop
158
+ pprint-exit-if-list-exhausted pprint-logical-block pprint-pop
159
+ print-unreadable-object prog prog* prog1 prog2 psetf psetq
160
+ push pushnew remf restart-bind restart-case return rotatef
161
+ setf shiftf step time trace typecase unless untrace when
162
+ with-accessors with-compilation-unit with-condition-restarts
163
+ with-hash-table-iterator with-input-from-string with-open-file
164
+ with-open-stream with-output-to-string with-package-iterator
165
+ with-simple-restart with-slots with-standard-io-syntax
166
+ )
167
+
168
+ LAMBDA_LIST_KEYWORDS = Set.new %w(
169
+ &allow-other-keys &aux &body &environment &key &optional &rest
170
+ &whole
171
+ )
172
+
173
+ DECLARATIONS = Set.new %w(
174
+ dynamic-extent ignore optimize ftype inline special ignorable
175
+ notinline type
176
+ )
177
+
178
+ BUILTIN_TYPES = Set.new %w(
179
+ atom boolean base-char base-string bignum bit compiled-function
180
+ extended-char fixnum keyword nil signed-byte short-float
181
+ single-float double-float long-float simple-array
182
+ simple-base-string simple-bit-vector simple-string simple-vector
183
+ standard-char unsigned-byte
184
+
185
+ arithmetic-error cell-error condition control-error
186
+ division-by-zero end-of-file error file-error
187
+ floating-point-inexact floating-point-overflow
188
+ floating-point-underflow floating-point-invalid-operation
189
+ parse-error package-error print-not-readable program-error
190
+ reader-error serious-condition simple-condition simple-error
191
+ simple-type-error simple-warning stream-error storage-condition
192
+ style-warning type-error unbound-variable unbound-slot
193
+ undefined-function warning
194
+ )
195
+
196
+ BUILTIN_CLASSES = Set.new %w(
197
+ array broadcast-stream bit-vector built-in-class character
198
+ class complex concatenated-stream cons echo-stream file-stream
199
+ float function generic-function hash-table integer list
200
+ logical-pathname method-combination method null number package
201
+ pathname ratio rational readtable real random-state restart
202
+ sequence standard-class standard-generic-function standard-method
203
+ standard-object string-stream stream string structure-class
204
+ structure-object symbol synonym-stream t two-way-stream vector
205
+ )
206
+
207
+ def stream_tokens(*a, &b)
208
+ super(*a) do |tok, val|
209
+ case tok
210
+ when Token['Name.Variable']
211
+ if BUILTIN_FUNCTIONS.include? val
212
+ yield Token['Name.Builtin'], val
213
+ elsif SPECIAL_FORMS.include? val
214
+ yield Token['Keyword'], val
215
+ elsif MACROS.include? val
216
+ yield Token['Name.Builtin'], val
217
+ elsif LAMBDA_LIST_KEYWORDS.include? val
218
+ yield Token['Keyword'], val
219
+ elsif DECLARATIONS.include? val
220
+ yield Token['Keyword'], val
221
+ elsif BUILTIN_TYPES.include? val
222
+ yield Token['Keyword.Type'], val
223
+ elsif BUILTIN_CLASSES.include? val
224
+ yield Token['Name.Class'], val
225
+ else
226
+ yield tok, val
227
+ end
228
+ else
229
+ yield tok, val
230
+ end
231
+ end
232
+ end
233
+
234
+ nonmacro = /\\.|[a-zA-Z0-9!$%&*+-\/<=>?@\[\]^_{}~]/
235
+ constituent = /#{nonmacro}|[#.:]/
236
+ terminated = /(?=[ "'()\n,;`])/ # whitespace or terminating macro chars
237
+ symbol = /(\|[^\|]+\||#{nonmacro}#{constituent}*)/
238
+
239
+ state :root do
240
+ rule /\s+/m, 'Text'
241
+ rule /;.*$/, 'Comment.Single'
242
+ rule /#\|/, 'Comment.Multiline', :multiline_comment
243
+
244
+ # encoding comment
245
+ rule /#\d*Y.*$/, 'Comment.Special'
246
+ rule /"(\\.|[^"\\])*"/, 'Literal.String'
247
+
248
+ rule /[:']#{symbol}/, 'Literal.String.Symbol'
249
+ rule /['`]/, 'Operator'
250
+
251
+ # numbers
252
+ rule /[-+]?\d+\.?#{terminated}/, 'Literal.Number.Integer'
253
+ rule %r([-+]?\d+/\d+#{terminated}), 'Literal.Number.Integer'
254
+ rule %r(
255
+ [-+]?
256
+ (\d*\.\d+([defls][-+]?\d+)?
257
+ |\d+(\.\d*)?[defls][-+]?\d+)
258
+ #{terminated}
259
+ )x, 'Literal.Number.Float'
260
+
261
+ # sharpsign strings and characters
262
+ rule /#\\.#{terminated}/, 'Literal.String.Char'
263
+ rule /#\\#{symbol}/, 'Literal.String.Char'
264
+
265
+ rule /#\(/, 'Operator', :root
266
+
267
+ # bitstring
268
+ rule /#\d*\*[01]*/, 'Literal.Other'
269
+
270
+ # uninterned symbol
271
+ rule /#:#{symbol}/, 'Literal.String.Symbol'
272
+
273
+ # read-time and load-time evaluation
274
+ rule /#[.,]/, 'Operator'
275
+
276
+ # function shorthand
277
+ rule /#'/, 'Name.Function'
278
+
279
+ # binary rational
280
+ rule /#b[+-]?[01]+(\/[01]+)?/i, 'Literal.Number'
281
+
282
+ # octal rational
283
+ rule /#o[+-]?[0-7]+(\/[0-7]+)?/i, 'Literal.Number.Oct'
284
+
285
+ # hex rational
286
+ rule /#x[+-]?[0-9a-f]+(\/[0-9a-f]+)?/i, 'Literal.Number'
287
+
288
+ # complex
289
+ rule /(#c)(\()/i do
290
+ group 'Literal.Number'
291
+ group 'Punctuation'
292
+ push :root
293
+ end
294
+
295
+ # arrays and structures
296
+ rule /(#(?:\d+a|s))(\()/i do
297
+ group 'Literal.Other'
298
+ group 'Punctuation'
299
+ push :root
300
+ end
301
+
302
+ # path
303
+ rule /#p?"(\\.|[^"])*"/i
304
+
305
+ # reference
306
+ rule /#\d+[=#]/, 'Operator'
307
+
308
+ # read-time comment
309
+ rule /#+nil#{terminated}\s*\(/, 'Comment.Preproc', :commented_form
310
+
311
+ # read-time conditional
312
+ rule /#[+-]/, 'Operator'
313
+
314
+ # special operators that should have been parsed already
315
+ rule /(,@|,|\.)/, 'Operator'
316
+
317
+ # special constants
318
+ rule /(t|nil)#{terminated}/, 'Name.Constant'
319
+
320
+ # functions and variables
321
+ # note that these get filtered through in stream_tokens
322
+ rule /\*#{symbol}\*/, 'Name.Variable.Global'
323
+ rule symbol, 'Name.Variable'
324
+
325
+ rule /\(/, 'Punctuation', :root
326
+ rule /\)/, 'Punctuation' do
327
+ if stack.empty?
328
+ token 'Error'
329
+ else
330
+ token 'Punctuation'
331
+ pop!
332
+ end
333
+ end
334
+ end
335
+
336
+ state :multiline_comment do
337
+ rule /#\|/, 'Comment.Multiline', :multiline_comment
338
+ rule /\|#/, 'Comment.Multiline', :pop!
339
+ rule /[^\|#]+/, 'Comment.Multiline'
340
+ rule /[\|#]/, 'Comment.Multiline'
341
+ end
342
+
343
+ state :commented_form do
344
+ rule /\(/, 'Comment.Preproc', :commented_form
345
+ rule /\)/, 'Comment.Preproc', :pop!
346
+ end
347
+ end
348
+ end
349
+ end
@@ -0,0 +1,92 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Scheme < RegexLexer
4
+ tag 'scheme'
5
+ filenames '*.scm', '*.ss', '*.rkt'
6
+ mimetypes 'text/x-scheme', 'application/x-scheme'
7
+
8
+ keywords = %w(
9
+ lambda define if else cond and or case let let* letrec begin
10
+ do delay set! => quote quasiquote unquote unquote-splicing
11
+ define-syntax let-syntax letrec-syntax syntax-rules
12
+ )
13
+
14
+ builtins = %w(
15
+ * + - / < <= = > >= abs acos angle append apply asin
16
+ assoc assq assv atan boolean? caaaar caaadr caaar caadar
17
+ caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
18
+ cadr call-with-current-continuation call-with-input-file
19
+ call-with-output-file call-with-values call/cc car cdaaar cdaadr
20
+ cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr
21
+ cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci<=?
22
+ char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase
23
+ char-lower-case? char-numeric? char-ready? char-upcase
24
+ char-upper-case? char-whitespace? char<=? char<? char=? char>=?
25
+ char>? char? close-input-port close-output-port complex? cons
26
+ cos current-input-port current-output-port denominator
27
+ display dynamic-wind eof-object? eq? equal? eqv? eval
28
+ even? exact->inexact exact? exp expt floor for-each force gcd
29
+ imag-part inexact->exact inexact? input-port? integer->char
30
+ integer? interaction-environment lcm length list list->string
31
+ list->vector list-ref list-tail list? load log magnitude
32
+ make-polar make-rectangular make-string make-vector map
33
+ max member memq memv min modulo negative? newline not
34
+ null-environment null? number->string number? numerator odd?
35
+ open-input-file open-output-file output-port? pair? peek-char
36
+ port? positive? procedure? quotient rational? rationalize
37
+ read read-char real-part real? remainder reverse round
38
+ scheme-report-environment set-car! set-cdr! sin sqrt string
39
+ string->list string->number string->symbol string-append
40
+ string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>?
41
+ string-copy string-fill! string-length string-ref
42
+ string-set! string<=? string<? string=? string>=?
43
+ string>? string? substring symbol->string symbol?
44
+ tan transcript-off transcript-on truncate values vector
45
+ vector->list vector-fill! vector-length vector-ref
46
+ vector-set! vector? with-input-from-file with-output-to-file
47
+ write write-char zero?
48
+ )
49
+
50
+ id = /[a-z0-9!$\%&*+,\/:<=>?@^_~|-]+/i
51
+
52
+ escape = Regexp.method(:escape)
53
+
54
+ state :root do
55
+ # comments
56
+ rule /;.*$/, 'Comment.Single'
57
+ rule /\s+/m, 'Text'
58
+ rule /-?\d+\.\d+/, 'Number.Float'
59
+
60
+ # support for uncommon kinds of numbers -
61
+ # have to figure out what the characters mean
62
+ # rule /(#e|#i|#b|#o|#d|#x)[\d.]+/, 'Number'
63
+ rule /"(\\\\|\\"|[^"])*"/, 'Literal.String'
64
+ rule /'#{id}/i, 'Literal.String.Symbol'
65
+ rule /#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
66
+ 'Literal.String.Char'
67
+ rule /#t|#f/, 'Name.Constant'
68
+ rule /(?:'|#|`|,@|,|\.)/, 'Operator'
69
+ rule /(?:#{keywords.map(&escape).join('|')})/,
70
+ 'Keyword'
71
+
72
+ rule /(['#])(\s*)(\()/m do
73
+ group 'Literal.String.Symbol'
74
+ group 'Text'
75
+ group 'Punctuation'
76
+ end
77
+
78
+ rule /\(/, 'Punctuation', :command
79
+ rule /\)/, 'Punctuation'
80
+
81
+ rule id, 'Name.Variable'
82
+ end
83
+
84
+ state :command do
85
+ rule /(?:#{builtins.map(&escape).join('|')})/, 'Name.Builtin', :pop!
86
+ rule id, 'Name.Function', :pop!
87
+ rule(//) { pop! }
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,53 @@
1
+ module Rouge
2
+ module Lexers
3
+ class XML < RegexLexer
4
+ tag 'xml'
5
+ filenames *%w(*.xml *.xsl *.rss *.xslt *.xsd *.wsdl)
6
+ mimetypes *%w(
7
+ text/xml
8
+ application/xml
9
+ image/svg+xml
10
+ application/rss+xml
11
+ application/atom+xml
12
+ )
13
+
14
+ def self.analyze_text(text)
15
+ return 0.5 if text.doctype?
16
+ return 0.5 if text[0..1000] =~ %r(<.+?>.*?</.+?>)m
17
+ return 0.8 if text =~ /\A<\?xml\b/
18
+ end
19
+
20
+ state :root do
21
+ rule /[^<&]+/, 'Text'
22
+ rule /&\S*?;/, 'Name.Entity'
23
+ rule /<!\[CDATA\[.*?\]\]\>/, 'Comment.Preproc'
24
+ rule /<!--/, 'Comment', :comment
25
+ rule /<\?.*?\?>/, 'Comment.Preproc'
26
+ rule /<![^>]*>/, 'Comment.Preproc'
27
+
28
+ # open tags
29
+ rule %r(<\s*[\w:.-]+)m, 'Name.Tag', :tag
30
+
31
+ # self-closing tags
32
+ rule %r(<\s*/\s*[\w:.-]+\s*>)m, 'Name.Tag'
33
+ end
34
+
35
+ state :comment do
36
+ rule /[^-]+/m, 'Comment'
37
+ rule /-->/, 'Comment', :pop!
38
+ rule /-/, 'Comment'
39
+ end
40
+
41
+ state :tag do
42
+ rule /\s+/m, 'Text'
43
+ rule /[\w.:-]+\s*=/m, 'Name.Attribute', :attr
44
+ rule %r(/?\s*>), 'Name.Tag', :pop!
45
+ end
46
+
47
+ state :attr do
48
+ rule /\s+/m, 'Text'
49
+ rule /".*?"|'.*?'|[^\s>]+/, 'Literal.String', :pop!
50
+ end
51
+ end
52
+ end
53
+ end
@@ -5,12 +5,31 @@
5
5
  # this plugin depends on redcarpet
6
6
  require 'redcarpet'
7
7
 
8
+ # stdlib
9
+ require 'cgi'
10
+
8
11
  module Rouge
9
12
  module Plugins
10
13
  module Redcarpet
11
14
  def block_code(code, language)
12
- lexer = Lexer.find(language) || Lexers::Text
13
- formatter = Formatters::HTML.new(:css_class => "highlight #{lexer.tag}")
15
+ name, opts = language.split('?')
16
+
17
+ # parse the options hash from a cgi-style string
18
+ opts = CGI.parse(opts || '').map do |k, vals|
19
+ [ k.to_sym, vals.empty? ? true : vals[0] ]
20
+ end
21
+
22
+ opts = Hash[opts]
23
+
24
+ lexer_class = case name
25
+ when 'guess', nil
26
+ lexer = Lexer.guess(:source => code, :mimetype => opts[:mimetype])
27
+ when String
28
+ Lexer.find(name)
29
+ end || Lexers::Text
30
+
31
+ lexer = lexer_class.new(opts)
32
+ formatter = Formatters::HTML.new(:css_class => "highlight #{lexer_class.tag}")
14
33
 
15
34
  Rouge.highlight(code, lexer, formatter)
16
35
  end
@@ -22,7 +22,7 @@ module Rouge
22
22
  @doctype = $1
23
23
  end
24
24
 
25
- def doctype?(type)
25
+ def doctype?(type=//)
26
26
  type === doctype
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.0.9"
3
+ "0.0.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-08 00:00:00.000000000 Z
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -37,6 +37,9 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - Gemfile
39
39
  - lib/rouge/lexers/python.rb
40
+ - lib/rouge/lexers/common_lisp.rb
41
+ - lib/rouge/lexers/scheme.rb
42
+ - lib/rouge/lexers/xml.rb
40
43
  - lib/rouge/lexers/shell.rb
41
44
  - lib/rouge/lexers/javascript.rb
42
45
  - lib/rouge/lexers/diff.rb