summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/latex.rb
diff options
context:
space:
mode:
authorNathan Youngman <git@nathany.com>2012-10-27 14:22:18 -0600
committerNathan Youngman <git@nathany.com>2012-10-27 14:22:18 -0600
commit3a97b804e0c0df0693e34fb23fd16a65757636ef (patch)
tree25387d06433fd8121666f4f88b937d2c1d0079f7 /lib/coderay/encoders/latex.rb
parent3effca8291ed4941f7b3a1c2088b50274f28aa6f (diff)
downloadcoderay-latex-encoder.tar.gz
Latex encoder from Redminelatex-encoder
Diffstat (limited to 'lib/coderay/encoders/latex.rb')
-rw-r--r--lib/coderay/encoders/latex.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/coderay/encoders/latex.rb b/lib/coderay/encoders/latex.rb
new file mode 100644
index 0000000..5a6e309
--- /dev/null
+++ b/lib/coderay/encoders/latex.rb
@@ -0,0 +1,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