# X-HTMLifying Code

**URL:** <https://www.ruby-forum.com/t/x-htmlifying-code/57340>\
**Category:** Rails\
**Created:** [April 10, 2006, 4:19am UTC](https://www.ruby-forum.com/t/x-htmlifying-code/57340 "2006-04-10T04:19:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 10, 2006, 4:19am UTC](https://www.ruby-forum.com/t/x-htmlifying-code/57340/1 "2006-04-10T04:19:24Z")

</div>

This falls into the category of “wonder if anyone’s done this”?

The site I’m working on now has affiliate sponsors who provide link  
HTML.  
Almost all of it violates some W3C spec for XHTML, the primary offenders  
being capitalized tag names and unclosed tags like IMG. They also  
include  
ampersands as query-string separators, which also offends the W3C  
Validator.

Has anyone written a snippet to parse links and image tags to make them  
XHTML Transitional safe?

This works in some but not all cases:

@affiliates.each{|a| a.link\_html = a.link\_html.gsub(‘&’, ‘;’).downcase}

# 

not sure about the ; bit

## TIA

View this message in context:  
[http://www.nabble.com/X-HTMLifying-Code-t1422594.html#a3835017](http://www.nabble.com/X-HTMLifying-Code-t1422594.html#a3835017)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 10, 2006, 4:28am UTC](https://www.ruby-forum.com/t/x-htmlifying-code/57340/2 "2006-04-10T04:28:40Z")

</div>

regex is your friend.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 10, 2006, 5:41am UTC](https://www.ruby-forum.com/t/x-htmlifying-code/57340/3 "2006-04-10T05:41:36Z")

</div>

I’m not 100% sure if these are what you’re after, but I think  
they will help.

[http://tinyurl.com/hqs4h](http://tinyurl.com/hqs4h)  
[http://tinyurl.com/hehue](http://tinyurl.com/hehue)

–  
– Tom M.
