module Haml::Helpers
def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
- Yield: - The block within which to escape newlines
Overloads:
-
find_and_preserve(tags = haml_buffer.options[:preserve]) -
find_and_preserve(input, tags = haml_buffer.options[:preserve])
Parameters:
-
input(String) -- The string within which to escape newlines -
tags(Array) -- Tags that should have newlines escaped
def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block) return find_and_preserve(capture_haml(&block), input || tags) if block re = /<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im input.to_s.gsub(re) do |s| s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible "<#{$1}#{$2}>#{preserve($3)}</#{$1}>" end end