If there is, I haven’t found it. I have though found a useful Regex
for
doing that. It’s a slightly modified version of the one used in Typo.
[No
source code will go scavenged!] I know I might catch some flack for
doing so
but I choose to add this method to the String class itself, as I use it
a
lot.
class String
def strip_html(leave_whitespace = false)
name = /[\w:_-]+/
value = /([A-Za-z0-9]+|(’[^’]?’|"[^"]?"))/
attr = /(#{name}(\s*=\s*#{value})?)/
rx =
/<[!/?[]?(#{name}|–)(\s+(#{attr}(\s+#{attr})))?\s([!/?]]+|–)?>/
(leave_whitespace) ? self.gsub(rx, “”).strip : self.gsub(rx,
“”).gsub(/\s+/, " ").strip
end
end
Be aware, though, that there is stil a lot of HTML entities left in the
Textilized string. [™, etc.] Depending on your end use, you may
need
to strip those entities as well. Let me know if you do need that because
I’ve written some really handy code for it, completely based on what
transformations RedCloth does. You know, only make the server work as
hard
as it has to.