I want these html tags('<br>', ' ', '>', '<', '<p>', '<font>'
etc...)
to be replaced by the equivalent ruby characters("\n", " ", ">", "<"
etc...).
These html tags can change dynamically according to the inputs.
Is there any way to parse these html tags to equivalent ruby characters?
Thanks Ryan. But I can't guess what are all the tags i will be getting.
Because those are dynamic. Any possible tag can come. So if I have to
use the 'gsub' method, I will have to write for each and every html tag.
Then that will be big.
So I am looking for any other easier way to implement this(something
like html parser kind of).
Sorry. That's my mistake. The final thing i want from the string is a
runnable ruby code. So <p> and <font> tags can be removed from the
string without any replacement.
Now I think, the only way to implement this is to use the 'gsub' method
for each and every possible tag.
Sorry. That's my mistake. The final thing i want from the string is a
runnable ruby code. So <p> and <font> tags can be removed from the
string without any replacement.
Now I think, the only way to implement this is to use the 'gsub'
method
for each and every possible tag.
Well assuming the only tag with special meaning is <br> Then you can
just convert entities to their respective characters (there are tables
of these), <br> to "\n" and then just replace every other tag with ''.
No need for one regexp per tag for that!
But ">" and "<" need to be replaced with ">" and "<"
respectively.
Because I will having some ruby hash code in the string.
I'm not seeing the problem Replace entities and then look for
everything between < and >. Change it to a newline if it's a br, or
just replace it with blank and add it to your list of html tags.
Fred