Created
May 9, 2012 16:45
-
-
Save norman/2646539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
foo | |
</p> | |
<textarea> | |
hello world</textarea> | |
<p> | |
hello world | |
</p> | |
<textarea>hello!</textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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