This seems like such a common situation that I can’t believe I haven’t
found an easy recipe. What is the best way to close an unclosed tag in
user-submitted input? It doesn’t appear that HPricot has a built-in
method for this, though HPricot looks like the most likely tool to
use. White_list and RedCloth also don’t appear to solve this. What
else should I investigate? TIA!
On Nov 16, 2007 5:19 PM, Stan K. [email protected] wrote:
This seems like such a common situation that I can’t believe I haven’t
found an easy recipe. What is the best way to close an unclosed tag in
user-submitted input? It doesn’t appear that HPricot has a built-in
method for this, though HPricot looks like the most likely tool to
use. White_list and RedCloth also don’t appear to solve this. What
else should I investigate? TIA!
You can run the html through Tidy. Using Mac ports, it’d be port install tidy
.
Tidy also fits nicely into functional tests for your own html. I’ve
used it in continuous builder setups where we needed the whole team,
some of them not very html savvy but still good programmers otherwise,
to contribute valid html.
One problem I encountered however was how to validate partials. To
solve that I would sample the first tag from a partial and then wrap
it with whatever was required to become (minimally) valid HTML. With
a little recursion you can go upward from a partial to a valid?
html document, then run that against tidy.
–
Greg D.
http://destiney.com/
On Nov 16, 3:19 pm, Stan K. [email protected] wrote:
It doesn’t appear that HPricot has a built-in
method for this
I should have looked a bit longer. HPricot makes this trivial:
Hpricot(“A closed tag and an unclosed tag”).to_html
=> “A closed tag and an unclosed tag”