module CodeRay module Encoders class HTML module Output def self.wrap_string_in string, element, css = nil case element when :span SPAN when :div return string if string[/\A<(?:div|table)\b/] DIV when :page string = wrap_string_in(string, :div) unless string[/\A<(?:div|table)\b/] PAGE.sub('<%CSS%>', css ? css.stylesheet : '') else raise ArgumentError, 'Unknown wrap element: %p' % [element] 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 = '<%CONTENT%>' DIV = <<-DIV
<%CONTENT%>