summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-06-17 12:51:49 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-06-17 12:51:49 +0200
commit196b7296666c12b0c04fa6b8dc42e46ed9331432 (patch)
tree41413c7dec26fc0d32aacf98a381890b07aec865 /lib/coderay
parent74a3c27cefca0d24ab66e41fbcfde6d2e4e48cb0 (diff)
downloadcoderay-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.rb10
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