diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2013-06-17 12:51:49 +0200 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2013-06-17 12:51:49 +0200 |
commit | 196b7296666c12b0c04fa6b8dc42e46ed9331432 (patch) | |
tree | 41413c7dec26fc0d32aacf98a381890b07aec865 /lib/coderay | |
parent | 74a3c27cefca0d24ab66e41fbcfde6d2e4e48cb0 (diff) | |
download | coderay-196b7296666c12b0c04fa6b8dc42e46ed9331432.tar.gz |
bring back wrap! method, TODO: benchmark against String#sub
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/encoders/html/output.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 3841f44..66ff0ba 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -17,6 +17,16 @@ module Encoders end.sub('<%CONTENT%>', string) end + def self.wrap! str, template, target + target = Regexp.new(Regexp.escape("<%#{target}%>")) + if template =~ target + str[0,0] = $` + str << $' + else + raise "Template target <%%%p%%> not found" % target + end + end + SPAN = '<span class="CodeRay"><%CONTENT%></span>' DIV = <<-DIV |