Skip to content

Instantly share code, notes, and snippets.

@norman
Created May 9, 2012 16:45
Show Gist options
  • Save norman/2646539 to your computer and use it in GitHub Desktop.
Save norman/2646539 to your computer and use it in GitHub Desktop.
<p>
foo
</p>
<textarea>
hello world</textarea>
<p>
hello world
</p>
<textarea>hello!</textarea>
text = File.read("temp.html")
def dumb_gsub(text)
text.gsub(/^(?!\s+$)/m, "..")
end
def textarea_gsub(text)
in_preserve = false
text.split("\n").map do |line|
line.gsub!(/^(?!\s+$)/m, "..") unless in_preserve
in_preserve = true if line =~ /<(textarea|pre)/
in_preserve = false if line =~ /<\/(textarea|pre)/
line
end.join("\n")
end
puts textarea_gsub(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment