Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 53 lines (42 sloc) 1.302 kb
9b7c80e @aguids Add syntax highlight support to the manual using the coderay gem
aguids authored
1 # encoding: utf-8
2
3 require "coderay"
4
5 # Registers a to_prawn method on CodeRay. It returns an array of hashes to be
6 # used with formatted_text.
7 #
8 # Usage:
9 #
10 # CodeRay.scan(string, :ruby).to_prawn
11 #
12 class PrawnEncoder < CodeRay::Encoders::Encoder
13 register_for :to_prawn
14
6c21165 @aguids Many tweaks to the manual examples fixing typos, rewording some expla…
aguids authored
15 COLORS = { :default => "FFFFFF",
16
17 :comment => "AEAEAE",
9b7c80e @aguids Add syntax highlight support to the manual using the coderay gem
aguids authored
18 :constant => "88A5D2",
19 :instance_variable => "E8ED97",
20 :integer => "C8FF0E",
21 :float => "C8FF0E",
6c21165 @aguids Many tweaks to the manual examples fixing typos, rewording some expla…
aguids authored
22 :inline_delimiter => "EF804F", # #{} within a string
9b7c80e @aguids Add syntax highlight support to the manual using the coderay gem
aguids authored
23 :keyword => "FEE100",
24
25 # BUG: There appear to be some problem with this token. Method
26 # definitions are considered as ident tokens
27 #
28 :method => "FF5C00",
29 :string => "56D65E",
30 :symbol => "C8FF0E"
31 }
32
33 def setup(options)
34 super
35 @out = []
36 @open = []
37 end
38
39 def text_token(text, kind)
40 color = COLORS[kind] || COLORS[@open.last] || COLORS[:default]
41
42 @out << {:text => text, :color => color}
43 end
44
45 def begin_group(kind)
46 @open << kind
47 end
48
49 def end_group(kind)
50 @open.pop
51 end
52 end
Something went wrong with that request. Please try again.