blob: 5a6e3090319a3afc4e93d77eb7462f046a051593 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
module CodeRay
module Encoders
class Latex < Encoder
include Streamable
register_for :latex
FILE_EXTENSION = 'tex'
ALLTT_ESCAPE = { #:nodoc:
'{' => '\lb',
'}' => '\rb',
'\\' => '\bs',
}
HTML_ESCAPE_PATTERN = /[\\{}]/
protected
def text_token text, kind
if text =~ /#{HTML_ESCAPE_PATTERN}/o
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end
k = Tokens::ClassOfKind[kind]
if k == :NO_HIGHLIGHT
text
else
"\\CR#{k}{#{text}}"
end
end
def open_token kind
"\\CR#{Tokens::ClassOfKind[kind]}{"
end
def close_token kind
"}"
end
end
end
end
|