Skip to content

Commit 196b729

Browse files
committed
bring back wrap! method, TODO: benchmark against String#sub
1 parent 74a3c27 commit 196b729

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/coderay/encoders/html/output.rb

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ def self.wrap_string_in string, element, css = nil
1717
end.sub('<%CONTENT%>', string)
1818
end
1919

20+
def self.wrap! str, template, target
21+
target = Regexp.new(Regexp.escape("<%#{target}%>"))
22+
if template =~ target
23+
str[0,0] = $`
24+
str << $'
25+
else
26+
raise "Template target <%%%p%%> not found" % target
27+
end
28+
end
29+
2030
SPAN = '<span class="CodeRay"><%CONTENT%></span>'
2131

2232
DIV = <<-DIV

0 commit comments

Comments
 (0)