Skip to content

Commit

Permalink
allow adding to the escape hash for custom escaping behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
http://jneen.net/ committed Jun 23, 2019
1 parent 0086498 commit 38de52b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/rouge/formatters/tex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ class Tex < Formatter
"\t" => '{\tab}',
}

ESCAPE_REGEX = /[#{ESCAPE.keys.map(&Regexp.method(:escape)).join}]/om

def initialize(opts={})
@prefix = opts.fetch(:prefix) { 'RG' }
@escapes = opts.fetch(:escapes) { {} }
end

def escape_hash
@escape_hash ||= ESCAPE.merge(@escapes)
end

def escape_regex
@escape_regex ||= /[#{escape_hash.keys.map(&Regexp.method(:escape)).join}]/om
end

def escape_tex(str)
str.gsub(ESCAPE_REGEX, ESCAPE)
str.gsub(escape_regex, escape_hash)
end

def stream(tokens, &b)
Expand Down

0 comments on commit 38de52b

Please sign in to comment.